-
Notifications
You must be signed in to change notification settings - Fork 599
HDDS-5483. Validate block file length during put block #2463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.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.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 @@ ContainerCommandResponseProto handlePutBlock( | |
| 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 @@ ContainerCommandResponseProto handlePutBlock( | |
| 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); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think layout-specific code would be better added to each
ChunkManagerimplementation instead of such==andisAssignableFromchecks. Take a look atfinishWriteChunks()andshutdown().