From 0c1da5a0300f015a7e39f2b40a73fb06c65a78c8 Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Mon, 9 Feb 2015 10:27:14 -0800 Subject: [PATCH] HDFS-7652. Process block reports for erasure coded blocks. Contributed by Zhe Zhang --- .../server/blockmanagement/BlockIdManager.java | 8 ++++++++ .../server/blockmanagement/BlockManager.java | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockIdManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockIdManager.java index a2f8fcc5713..230d9a5d1e9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockIdManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockIdManager.java @@ -212,4 +212,12 @@ public class BlockIdManager { .LAST_RESERVED_BLOCK_ID); generationStampV1Limit = HdfsConstants.GRANDFATHER_GENERATION_STAMP; } + + public static boolean isStripedBlockID(long id) { + return id < 0; + } + + public static long convertToGroupID(long id) { + return id & (~(HdfsConstants.MAX_BLOCKS_IN_GROUP - 1)); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index 54981fb4a68..dda19434b84 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -1943,7 +1943,7 @@ public class BlockManager { break; } - BlockInfoContiguous bi = blocksMap.getStoredBlock(b); + BlockInfoContiguous bi = getStoredBlock(b); if (bi == null) { if (LOG.isDebugEnabled()) { LOG.debug("BLOCK* rescanPostponedMisreplicatedBlocks: " + @@ -2091,7 +2091,7 @@ public class BlockManager { continue; } - BlockInfoContiguous storedBlock = blocksMap.getStoredBlock(iblk); + BlockInfoContiguous storedBlock = getStoredBlock(iblk); // If block does not belong to any file, we are done. if (storedBlock == null) continue; @@ -2231,7 +2231,7 @@ public class BlockManager { } // find block by blockId - BlockInfoContiguous storedBlock = blocksMap.getStoredBlock(block); + BlockInfoContiguous storedBlock = getStoredBlock(block); if(storedBlock == null) { // If blocksMap does not contain reported block id, // the replica should be removed from the data-node. @@ -2529,7 +2529,7 @@ public class BlockManager { DatanodeDescriptor node = storageInfo.getDatanodeDescriptor(); if (block instanceof BlockInfoContiguousUnderConstruction) { //refresh our copy in case the block got completed in another thread - storedBlock = blocksMap.getStoredBlock(block); + storedBlock = getStoredBlock(block); } else { storedBlock = block; } @@ -3410,7 +3410,15 @@ public class BlockManager { } public BlockInfoContiguous getStoredBlock(Block block) { - return blocksMap.getStoredBlock(block); + BlockInfoContiguous info = null; + if (BlockIdManager.isStripedBlockID(block.getBlockId())) { + info = blocksMap.getStoredBlock( + new Block(BlockIdManager.convertToGroupID(block.getBlockId()))); + } + if (info == null) { + info = blocksMap.getStoredBlock(block); + } + return info; } /** updates a block in under replication queue */