This is an automated email from the ASF dual-hosted git repository.
msingh pushed a commit to branch HDDS-4454
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/HDDS-4454 by this push:
new 67c3771 HDDS-5483. Validate block file length during put block (#2463)
67c3771 is described below
commit 67c377129d67dd163d0bbd497788bebde032173f
Author: Sadanand Shenoy <[email protected]>
AuthorDate: Mon Aug 2 21:35:11 2021 +0530
HDDS-5483. Validate block file length during put block (#2463)
---
.../ozone/container/keyvalue/KeyValueHandler.java | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
index 44a7352..bf16aae 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.container.keyvalue;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -69,6 +70,7 @@ import
org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingP
import org.apache.hadoop.ozone.container.common.volume.VolumeSet;
import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils;
import org.apache.hadoop.ozone.container.keyvalue.impl.BlockManagerImpl;
+import org.apache.hadoop.ozone.container.keyvalue.impl.ChunkManagerDummyImpl;
import org.apache.hadoop.ozone.container.keyvalue.impl.ChunkManagerFactory;
import org.apache.hadoop.ozone.container.keyvalue.interfaces.BlockManager;
import org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager;
@@ -98,6 +100,7 @@ import static
org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuil
import static
org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuilders.putBlockResponseSuccess;
import static
org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuilders.unsupportedRequest;
import static
org.apache.hadoop.hdds.scm.utils.ClientCommandsUtils.getReadChunkVersion;
+import static
org.apache.hadoop.ozone.container.common.impl.ChunkLayOutVersion.FILE_PER_BLOCK;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.slf4j.Logger;
@@ -460,6 +463,20 @@ public class KeyValueHandler extends Handler {
ContainerProtos.BlockData data = request.getPutBlock().getBlockData();
BlockData blockData = BlockData.getFromProtoBuf(data);
Preconditions.checkNotNull(blockData);
+ ChunkLayOutVersion layoutVersion =
+ ChunkLayOutVersion.getConfiguredVersion(conf);
+ if (layoutVersion == FILE_PER_BLOCK &&
+ // ChunkManagerDummyImpl doesn't persist to disk, don't check here
+ !chunkManager.getClass()
+ .isAssignableFrom(ChunkManagerDummyImpl.class)) {
+ File blockFile = layoutVersion
+ .getChunkFile(kvContainer.getContainerData(),
+ blockData.getBlockID(), null);
+ // ensure that the putBlock length <= blockFile length
+ Preconditions.checkArgument(blockFile.length() >= blockData.getSize(),
+ "BlockData in putBlock() has more length "
+ + "than the actual data written into the disk");
+ }
boolean incrKeyCount = false;
if (!request.getPutBlock().hasEof() || request.getPutBlock().getEof()) {
@@ -478,7 +495,7 @@ public class KeyValueHandler extends Handler {
metrics.incContainerBytesStats(Type.PutBlock, numBytes);
} catch (StorageContainerException ex) {
return ContainerUtils.logAndReturnError(LOG, ex, request);
- } catch (IOException ex) {
+ } catch (IOException | IllegalArgumentException ex) {
return ContainerUtils.logAndReturnError(LOG,
new StorageContainerException("Put Key failed", ex, IO_EXCEPTION),
request);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]