Skip to content

Commit 10b1d73

Browse files
authored
HDFS-17154. EC: Fix bug in updateBlockForPipeline after failover. (#5941). Contributed by Shuyan Zhang.
Reviewed-by: Haiyang Hu <haiyang.hu@shopee.com> Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
1 parent ea87aa2 commit 10b1d73

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/LocatedStripedBlock.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class LocatedStripedBlock extends LocatedBlock {
3636
private static final byte[] EMPTY_INDICES = {};
3737
private static final Token<BlockTokenIdentifier> EMPTY_TOKEN = new Token<>();
3838

39-
private final byte[] blockIndices;
39+
private byte[] blockIndices;
4040
private Token<BlockTokenIdentifier>[] blockTokens;
4141

4242
@SuppressWarnings({"unchecked"})
@@ -72,6 +72,10 @@ public byte[] getBlockIndices() {
7272
return this.blockIndices;
7373
}
7474

75+
public void setBlockIndices(byte[] blockIndices) {
76+
this.blockIndices = blockIndices;
77+
}
78+
7579
@Override
7680
public boolean isStriped() {
7781
return true;

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import org.apache.hadoop.hdfs.protocol.ECTopologyVerifierResult;
103103
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
104104
import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
105+
import org.apache.hadoop.hdfs.protocol.LocatedStripedBlock;
105106
import org.apache.hadoop.hdfs.protocol.SnapshotStatus;
106107
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
107108
import static org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.*;
@@ -5966,8 +5967,26 @@ LocatedBlock bumpBlockGenerationStamp(ExtendedBlock block,
59665967
block.setGenerationStamp(nextGenerationStamp(
59675968
blockManager.isLegacyBlock(block.getLocalBlock())));
59685969

5969-
locatedBlock = BlockManager.newLocatedBlock(
5970-
block, file.getLastBlock(), null, -1);
5970+
BlockInfo lastBlockInfo = file.getLastBlock();
5971+
locatedBlock = BlockManager.newLocatedBlock(block, lastBlockInfo,
5972+
null, -1);
5973+
if (lastBlockInfo.isStriped() &&
5974+
((BlockInfoStriped) lastBlockInfo).getTotalBlockNum() >
5975+
((LocatedStripedBlock) locatedBlock).getBlockIndices().length) {
5976+
// The location info in BlockUnderConstructionFeature may not be
5977+
// complete after a failover, so we just return all block tokens for a
5978+
// striped block. This will disrupt the correspondence between
5979+
// LocatedStripedBlock.blockIndices and LocatedStripedBlock.locs,
5980+
// which is not used in client side. The correspondence between
5981+
// LocatedStripedBlock.blockIndices and LocatedBlock.blockToken is
5982+
// ensured.
5983+
byte[] indices =
5984+
new byte[((BlockInfoStriped) lastBlockInfo).getTotalBlockNum()];
5985+
for (int i = 0; i < indices.length; ++i) {
5986+
indices[i] = (byte) i;
5987+
}
5988+
((LocatedStripedBlock) locatedBlock).setBlockIndices(indices);
5989+
}
59715990
blockManager.setBlockToken(locatedBlock,
59725991
BlockTokenIdentifier.AccessMode.WRITE);
59735992
} finally {

0 commit comments

Comments
 (0)