ChenSammi commented on code in PR #8566: URL: https://github.com/apache/ozone/pull/8566#discussion_r2199429118
########## hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/common/BlockGroup.java: ########## @@ -29,42 +30,67 @@ public final class BlockGroup { private String groupID; - private List<BlockID> blockIDs; + private List<DeletedBlock> deletedBlocks; + private boolean legacyFormat = false; - private BlockGroup(String groupID, List<BlockID> blockIDs) { + private BlockGroup(String groupID, List<DeletedBlock> deletedBlocks, boolean legacyFormat) { this.groupID = groupID; - this.blockIDs = blockIDs; + this.deletedBlocks = deletedBlocks; + this.legacyFormat = legacyFormat; } - public List<BlockID> getBlockIDList() { - return blockIDs; + public List<DeletedBlock> getAllBlocks() { + return deletedBlocks; } public String getGroupID() { return groupID; } + public boolean isLegacyFormat() { + return legacyFormat; + } + public KeyBlocks getProto() { KeyBlocks.Builder kbb = KeyBlocks.newBuilder(); - for (BlockID block : blockIDs) { - kbb.addBlocks(block.getProtobuf()); + for (DeletedBlock block : deletedBlocks) { + if (isLegacyFormat()) { + kbb.addBlocks(block.getProtobuf().getBlockId()); + } else { + kbb.addDeletedBlocks(block.getProtobuf()); + } } return kbb.setKey(groupID).build(); } - /** - * Parses a KeyBlocks proto to a group of blocks. - * @param proto KeyBlocks proto. - * @return a group of blocks. - */ public static BlockGroup getFromProto(KeyBlocks proto) { - List<BlockID> blockIDs = new ArrayList<>(); + return proto.getDeletedBlocksList().isEmpty() ? getFromLegacyProto(proto) : getFromNewProto(proto); + } + + public static BlockGroup getFromNewProto(KeyBlocks proto) { + List<DeletedBlock> blocks = new ArrayList<>(); + for (HddsProtos.DeletedBlock block : proto.getDeletedBlocksList()) { + HddsProtos.ContainerBlockID containerBlockId = block.getBlockId().getContainerBlockID(); + blocks.add(new DeletedBlock(new BlockID(containerBlockId.getContainerID(), + containerBlockId.getLocalID()), + block.getReplicatedSize(), + block.getUnreplicatedSize())); + } + return BlockGroup.newBuilder().setKeyName(proto.getKey()) + .addAllBlocks(blocks).build(); + } + + public static BlockGroup getFromLegacyProto(KeyBlocks proto) { + List<DeletedBlock> blocks = new ArrayList<>(); for (HddsProtos.BlockID block : proto.getBlocksList()) { - blockIDs.add(new BlockID(block.getContainerBlockID().getContainerID(), - block.getContainerBlockID().getLocalID())); + HddsProtos.ContainerBlockID containerBlockId = block.getContainerBlockID(); + blocks.add(new DeletedBlock(new BlockID(containerBlockId.getContainerID(), + containerBlockId.getLocalID()), + -1L, + -1L)); } return BlockGroup.newBuilder().setKeyName(proto.getKey()) - .addAllBlockIDs(blockIDs).build(); + .addAllBlocks(blocks).build(); Review Comment: Can we just use following? It will be more straight forward. ``` // Use blockIDs before DATA_DISTRIBUTION is finalized, and deletedBlocks after DATA_DISTRIBUTION is finalized. @Deprecated private List<BlockID> blockIDs; private List<DeletedBlock> deletedBlocks; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org