/** * Force the given block in the given file to be marked as complete, * regardless of whether enough replicas are present. This is necessary * when tailing edit logs as a Standby. */ public void forceCompleteBlock(final BlockInfo block) throws IOException { List<ReplicaUnderConstruction> staleReplicas = block.commitBlock(block); removeStaleReplicas(staleReplicas, block); completeBlock(block, null, true); }
/** * Commit a block of a file * * @param block block to be committed * @param commitBlock - contains client reported block length and generation * @return true if the block is changed to committed state. * @throws IOException if the block does not have at least a minimal number * of replicas reported from data-nodes. */ private boolean commitBlock(final BlockInfo block, final Block commitBlock) throws IOException { if (block.getBlockUCState() == BlockUCState.COMMITTED) return false; assert block.getNumBytes() <= commitBlock.getNumBytes() : "commitBlock length is less than the stored one " + commitBlock.getNumBytes() + " vs. " + block.getNumBytes(); if(block.getGenerationStamp() != commitBlock.getGenerationStamp()) { throw new IOException("Commit block with mismatching GS. NN has " + block + ", client submits " + commitBlock); } List<ReplicaUnderConstruction> staleReplicas = block.commitBlock(commitBlock); removeStaleReplicas(staleReplicas, block); return true; }