LiuGuH opened a new pull request, #9004: URL: https://github.com/apache/hadoop/pull/9004
JIRA: [HDFS-17732](https://github.com/apache/hadoop/pull/7414) ### Description of PR When a block is committed, `BlockManager.addExpectedReplicasToPending` should add the block's expected storage locations into `PendingReconstructionBlocks` if the datanode IBR from those locations has not arrived yet. For an EC block group, however, the current code only does this when `blkStriped.getRealTotalBlockNum() == expectedStorages.length`. That guard is wrong for small striped files: whenever the EC file size is `<= ecPolicy.getCellSize() * (ecPolicy.getNumDataUnits() - 1)`, `getRealTotalBlockNum()` is always smaller than `expectedStorages.length`. As a result the expected locations are never added to pendingReconstruction, and the NameNode schedules a reconstruction task before the remaining IBRs arrive. For example, with XOR-2-1-1024k and a file <= 1024k, the single block group has three internal blocks (blk0, blk1, blk2) but only blk0 and blk2 carry data. After the NameNode receives IBR0 and the client closes the file, the block commits with `getRealTotalBlockNum() == 1` while `expectedStorages.length == 3`, so blk1 and blk2 are not added to PendingReconstructionBlocks. The block then completes but is still missing an internal block, so it is added to neededReconstruction and an EC reconstruction task is delivered to DN2. When DN2 later reports blk2 and the reconstructed blk2', DN2 ends up holding two internal blocks of the same group (blk2 and blk2'), increasing the risk of data loss; for other policies, the NameNode may record only the later replica. The correct behavior is: - `addExpectedReplicasToPending` should add an EC block's expected storage locations into `PendingReconstructionBlocks`, just like it does for replicated blocks. - To avoid waiting for `PendingReconstructionBlocks` timeout, remove a block from `PendingReconstructionBlocks` when a file is closed or an IBR arrives and the block already has enough replicas. This patch: - Simplifies `BlockManager.addExpectedReplicasToPending` so striped blocks are handled like replicated blocks: every expected storage location that has not reported yet is added to pendingReconstruction. - Removes stale pending entries once a striped block is complete and has enough effective replicas, in both `BlockManager.addStoredBlock` and `BlockManager.checkRedundancy`. - Adds `BlockManagerTestUtil.getNumReplicasInPendingReconstruction` and the regression test `testECAddExpectedReplicasToPending`. ### How was this patch tested? - Added `TestDistributedFileSystem#testECAddExpectedReplicasToPending`: uses a 3-datanode MiniDFSCluster with XOR-2-1-1024k, pauses IBR on two datanodes while writing a 1 MiB striped file, and asserts: - the reported internal blocks count is 1 and two expected locations are pending, - after resuming IBR the pending count drops to 0, the block reports 2 internal blocks, and the block is COMPLETE. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
