private void sendIncrementalBlockReport ( long startTime ) throws Exception { // check if there are newly received blocks Block [ ] receivedAndDeletedBlockArray = null ; int numBlocksReceivedAndDeleted = 0 ; int currentPendingRequests = 0 ; synchronized ( receivedAndDeletedBlockList ) { // construct the ACKs array lastDeletedReport = startTime ; numBlocksReceivedAndDeleted = receivedAndDeletedBlockList . size ( ) ; if ( numBlocksReceivedAndDeleted > 0 ) { receivedAndDeletedBlockArray = receivedAndDeletedBlockList . toArray ( new Block [ numBlocksReceivedAndDeleted ] ) ; receivedAndDeletedBlockList . clear ( ) ; currentPendingRequests = pendingReceivedRequests ; pendingReceivedRequests = 0 ; } } // process received + deleted // if exception is thrown, add all blocks to the retry list if ( receivedAndDeletedBlockArray != null ) { long [ ] failed = null ; try { IncrementalBlockReport ibr = new IncrementalBlockReport ( receivedAndDeletedBlockArray ) ; long rpcStartTime = 0 ; if ( LOG . isDebugEnabled ( ) ) { rpcStartTime = System . nanoTime ( ) ; LOG . debug ( "sending blockReceivedAndDeletedNew " + receivedAndDeletedBlockArray . length + " blocks to " + namenodeAddress ) ; } failed = avatarnode . blockReceivedAndDeletedNew ( nsRegistration , ibr ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "finished blockReceivedAndDeletedNew " + "to " + namenodeAddress + " time: " + ( System . nanoTime ( ) - rpcStartTime ) + " ns" ) ; } boolean isPrimaryCached = isPrimaryServiceCached ( ) ; // if we talk to primary failed must be null // if we talk to standby failed shouldn't be null if ( isPrimaryCached && failed != null ) { //this should never happen //the primary can't switch to standby throw new IOException ( "Primary started acting as standby" ) ; } else if ( ! isPrimaryCached && failed == null ) { String msg = "Received null response from standby for incremental" + " block report. " ; if ( clearPrimaryCommandProcessed ) { LOG . info ( msg + "Failover is in progress" + " - will not clear primary again" ) ; } else { LOG . info ( msg + "Standby is acting as primary. Clearing primary" ) ; // failover - we need to refresh our knowledge this . clearPrimary ( ) ; } } } catch ( Exception e ) { processFailedBlocks ( receivedAndDeletedBlockArray , currentPendingRequests ) ; throw e ; } if ( failed != null && failed . length != 0 ) { processFailedReceivedDeleted ( failed , receivedAndDeletedBlockArray ) ; } } }
Sends an incremental block report to the Namenode .