|
@@ -699,7 +699,7 @@ public class BlockManager implements BlockStatsMXBean {
|
|
|
* @throws IOException if the block does not have at least a minimal number
|
|
|
* of replicas reported from data-nodes.
|
|
|
*/
|
|
|
- private static boolean commitBlock(final BlockInfo block,
|
|
|
+ private boolean commitBlock(final BlockInfo block,
|
|
|
final Block commitBlock) throws IOException {
|
|
|
if (block.getBlockUCState() == BlockUCState.COMMITTED)
|
|
|
return false;
|
|
@@ -710,7 +710,9 @@ public class BlockManager implements BlockStatsMXBean {
|
|
|
throw new IOException("Commit block with mismatching GS. NN has " +
|
|
|
block + ", client submits " + commitBlock);
|
|
|
}
|
|
|
- block.commitBlock(commitBlock);
|
|
|
+ List<ReplicaUnderConstruction> staleReplicas =
|
|
|
+ block.commitBlock(commitBlock);
|
|
|
+ removeStaleReplicas(staleReplicas, block);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -836,7 +838,8 @@ public class BlockManager implements BlockStatsMXBean {
|
|
|
* when tailing edit logs as a Standby.
|
|
|
*/
|
|
|
public void forceCompleteBlock(final BlockInfo block) throws IOException {
|
|
|
- block.commitBlock(block);
|
|
|
+ List<ReplicaUnderConstruction> staleReplicas = block.commitBlock(block);
|
|
|
+ removeStaleReplicas(staleReplicas, block);
|
|
|
completeBlock(block, null, true);
|
|
|
}
|
|
|
|
|
@@ -3173,6 +3176,17 @@ public class BlockManager implements BlockStatsMXBean {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void removeStaleReplicas(List<ReplicaUnderConstruction> staleReplicas,
|
|
|
+ BlockInfo block) {
|
|
|
+ for (ReplicaUnderConstruction r : staleReplicas) {
|
|
|
+ removeStoredBlock(block,
|
|
|
+ r.getExpectedStorageLocation().getDatanodeDescriptor());
|
|
|
+ NameNode.blockStateChangeLog
|
|
|
+ .debug("BLOCK* Removing stale replica {}" + " of {}", r,
|
|
|
+ Block.toString(r));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get all valid locations of the block & add the block to results
|
|
|
* return the length of the added block; 0 if the block is not added
|
|
@@ -3509,6 +3523,13 @@ public class BlockManager implements BlockStatsMXBean {
|
|
|
return blocksMap.getStoredBlock(block);
|
|
|
}
|
|
|
|
|
|
+ public void updateLastBlock(BlockInfo lastBlock, ExtendedBlock newBlock) {
|
|
|
+ lastBlock.setNumBytes(newBlock.getNumBytes());
|
|
|
+ List<ReplicaUnderConstruction> staleReplicas = lastBlock
|
|
|
+ .setGenerationStampAndVerifyReplicas(newBlock.getGenerationStamp());
|
|
|
+ removeStaleReplicas(staleReplicas, lastBlock);
|
|
|
+ }
|
|
|
+
|
|
|
/** updates a block in under replication queue */
|
|
|
private void updateNeededReplications(final BlockInfo block,
|
|
|
final int curReplicasDelta, int expectedReplicasDelta) {
|