LocatedBlocksWithMetaInfo updateDatanodeInfo ( LocatedBlocks locatedBlocks ) throws IOException { if ( locatedBlocks . getLocatedBlocks ( ) . size ( ) == 0 ) return new LocatedBlocksWithMetaInfo ( locatedBlocks . getFileLength ( ) , locatedBlocks . getLocatedBlocks ( ) , false , DataTransferProtocol . DATA_TRANSFER_VERSION , getNamespaceId ( ) , this . nameNode . getClientProtocolMethodsFingerprint ( ) ) ; List < LocatedBlock > newBlocks = new ArrayList < LocatedBlock > ( ) ; readLock ( ) ; try { for ( LocatedBlock locBlock : locatedBlocks . getLocatedBlocks ( ) ) { Block block = locBlock . getBlock ( ) ; int numNodes = blocksMap . numNodes ( block ) ; int numCorruptNodes = countNodes ( block ) . corruptReplicas ( ) ; int numCorruptReplicas = corruptReplicas . numCorruptReplicas ( block ) ; if ( numCorruptNodes != numCorruptReplicas ) { LOG . warn ( "Inconsistent number of corrupt replicas for " + block + "blockMap has " + numCorruptNodes + " but corrupt replicas map has " + numCorruptReplicas ) ; } boolean blockCorrupt = numCorruptNodes == numNodes ; int numMachineSet = blockCorrupt ? numNodes : ( numNodes - numCorruptNodes ) ; DatanodeDescriptor [ ] machineSet = new DatanodeDescriptor [ numMachineSet ] ; if ( numMachineSet > 0 ) { numNodes = 0 ; for ( Iterator < DatanodeDescriptor > it = blocksMap . nodeIterator ( block ) ; it . hasNext ( ) ; ) { DatanodeDescriptor dn = it . next ( ) ; boolean replicaCorrupt = corruptReplicas . isReplicaCorrupt ( block , dn ) ; if ( blockCorrupt || ( ! blockCorrupt && ! replicaCorrupt ) ) machineSet [ numNodes ++ ] = dn ; } } // We need to make a copy of the block object before releasing the lock // to prevent the state of block is changed after that and before the // object is serialized to clients, to avoid potential inconsistency. // Further optimization is possible to avoid some object copy. Since it // is so far not a critical path. We leave a safe approach here. // Block blockCopy = null ; if ( block != null ) { blockCopy = new Block ( block ) ; } LocatedBlock newBlock = new LocatedBlock ( blockCopy , machineSet , 0 , blockCorrupt ) ; newBlocks . add ( newBlock ) ; } } finally { readUnlock ( ) ; } return new LocatedBlocksWithMetaInfo ( locatedBlocks . getFileLength ( ) , newBlocks , false , DataTransferProtocol . DATA_TRANSFER_VERSION , getNamespaceId ( ) , this . nameNode . getClientProtocolMethodsFingerprint ( ) ) ; }
Updates DatanodeInfo for each LocatedBlock in locatedBlocks .