Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,16 @@ ContainerCommandResponseProto> executePutBlock(boolean close,
}

if (checksumBlockData != null) {
List<ChunkInfo> currentChunks = getContainerBlockData().getChunksList();

// We need to determine the size of the chunklist
// for verification based on the size of the blockgrouplength.
int chunkSize = calcEffectiveChunkSize(blockData, totalNodes, blockGroupLength);
List<ChunkInfo> checksumBlockDataChunks = checksumBlockData.getChunks();
if (chunkSize > 0) {
checksumBlockDataChunks = checksumBlockData.getChunks().subList(0, chunkSize);
}

List<ChunkInfo> currentChunks = getContainerBlockData().getChunksList();

Preconditions.checkArgument(
currentChunks.size() == checksumBlockDataChunks.size(),
Expand Down Expand Up @@ -177,6 +185,24 @@ ContainerCommandResponseProto> executePutBlock(boolean close,
return executePutBlock(close, force, blockGroupLength);
}

private int calcEffectiveChunkSize(BlockData[] blockGroup,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this calculation really needed? We know the block size we are recovering (blockGroupLength) which is earlier calculated as the min(put_block_size) across the stripe.

Can we then simply divide blockGroupLength / chunkSize and round up to give the number of chunks, and from there know the number of checksum chunks we need to recover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing the code! The calculation method you suggested is feasible, and the code will become more concise. I will try to make the modifications.

int replicaCount, long blockGroupLength) {
Preconditions.checkState(blockGroup.length == replicaCount);
int effectiveChunkSize = 0;
for (int i = 0; i < replicaCount; i++) {
if (blockGroup[i] == null) {
continue;
}
String lenStr = blockGroup[i].getMetadata().
get(OzoneConsts.BLOCK_GROUP_LEN_KEY_IN_PUT_BLOCK);
long calcBlockGroupLength = Long.parseLong(lenStr);
if (blockGroupLength == calcBlockGroupLength) {
effectiveChunkSize = Math.max(effectiveChunkSize, blockGroup[i].getChunks().size());
}
}
return effectiveChunkSize;
}

public CompletableFuture<ContainerProtos.
ContainerCommandResponseProto> executePutBlock(boolean close,
boolean force, long blockGroupLength, ByteString checksum)
Expand Down