HDFS-10342. BlockManager#createLocatedBlocks should not check corrupt replicas if none are corrupt. Contributed by Kuhu Shukla.
(cherry picked from commit b10c936020
)
Conflicts:
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
This commit is contained in:
parent
da70d6f25d
commit
65a41696b2
|
@ -963,12 +963,18 @@ public class BlockManager implements BlockStatsMXBean {
|
||||||
DatanodeStorageInfo[] machines = new DatanodeStorageInfo[numMachines];
|
DatanodeStorageInfo[] machines = new DatanodeStorageInfo[numMachines];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
if (numMachines > 0) {
|
if (numMachines > 0) {
|
||||||
|
final boolean noCorrupt = (numCorruptReplicas == 0);
|
||||||
for(DatanodeStorageInfo storage : blocksMap.getStorages(blk)) {
|
for(DatanodeStorageInfo storage : blocksMap.getStorages(blk)) {
|
||||||
final DatanodeDescriptor d = storage.getDatanodeDescriptor();
|
if (storage.getState() != State.FAILED) {
|
||||||
final boolean replicaCorrupt = corruptReplicas.isReplicaCorrupt(blk, d);
|
if (noCorrupt) {
|
||||||
if ((isCorrupt || (!replicaCorrupt)) &&
|
|
||||||
storage.getState() != State.FAILED) {
|
|
||||||
machines[j++] = storage;
|
machines[j++] = storage;
|
||||||
|
} else {
|
||||||
|
final DatanodeDescriptor d = storage.getDatanodeDescriptor();
|
||||||
|
final boolean replicaCorrupt = isReplicaCorrupt(blk, d);
|
||||||
|
if (isCorrupt || !replicaCorrupt) {
|
||||||
|
machines[j++] = storage;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4062,4 +4068,8 @@ public class BlockManager implements BlockStatsMXBean {
|
||||||
boolean isGenStampInFuture(Block block) {
|
boolean isGenStampInFuture(Block block) {
|
||||||
return blockIdManager.isGenStampInFuture(block);
|
return blockIdManager.isGenStampInFuture(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isReplicaCorrupt(BlockInfo blk, DatanodeDescriptor d) {
|
||||||
|
return corruptReplicas.isReplicaCorrupt(blk, d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1201,4 +1201,23 @@ public class TestBlockManager {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsReplicaCorruptCall() throws Exception {
|
||||||
|
BlockManager spyBM = spy(bm);
|
||||||
|
List<DatanodeStorageInfo> origStorages = getStorages(0, 1, 3);
|
||||||
|
List<DatanodeDescriptor> origNodes = getNodes(origStorages);
|
||||||
|
BlockInfo blockInfo = addBlockOnNodes(0, origNodes);
|
||||||
|
spyBM.createLocatedBlocks(new BlockInfo[]{blockInfo}, 3L, false, 0L, 3L,
|
||||||
|
false, false, null);
|
||||||
|
verify(spyBM, Mockito.atLeast(0)).
|
||||||
|
isReplicaCorrupt(Mockito.any(BlockInfo.class),
|
||||||
|
Mockito.any(DatanodeDescriptor.class));
|
||||||
|
addCorruptBlockOnNodes(0, origNodes);
|
||||||
|
spyBM.createLocatedBlocks(new BlockInfo[]{blockInfo}, 3L, false, 0L, 3L,
|
||||||
|
false, false, null);
|
||||||
|
verify(spyBM, Mockito.atLeast(1)).
|
||||||
|
isReplicaCorrupt(Mockito.any(BlockInfo.class),
|
||||||
|
Mockito.any(DatanodeDescriptor.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue