void assignPrimaryDatanode() {
    //assign the first alive datanode as the primary datanode

    if (targets.length == 0) {
      NameNode.stateChangeLog.warn("BLOCK*"
        + " INodeFileUnderConstruction.initLeaseRecovery:"
        + " No blocks found, lease removed.");
    }

    int previous = primaryNodeIndex;
    Block lastBlock = this.getLastBlock();
    // find an alive datanode beginning from previous.
    // This causes us to cycle through the targets on successive retries.
    for(int i = 1; i <= targets.length; i++) {
      int j = (previous + i)%targets.length;
      if (targets[j].isAlive) {
        DatanodeDescriptor primary = targets[primaryNodeIndex = j]; 
        primary.addBlockToBeRecovered(lastBlock, targets);
        NameNode.stateChangeLog.info("BLOCK* " + lastBlock
          + " recovery started, primary=" + primary);
        return;
      }
    }
  }
void assignPrimaryDatanode ( ) { if ( targets . length == 0 ) { NameNode . stateChangeLog . warn ( "BLOCK*" + " INodeFileUnderConstruction.initLeaseRecovery:" + " No blocks found, lease removed." ) ; } int previous = primaryNodeIndex ; Block lastBlock = this . getLastBlock ( ) ; for ( int i = 1 ; i <= targets . length ; i ++ ) { int j = ( previous + i ) % targets . length ; if ( targets [ j ] . isAlive ) { DatanodeDescriptor primary = targets [ primaryNodeIndex = j ] ; primary . addBlockToBeRecovered ( lastBlock , targets ) ; NameNode . stateChangeLog . info ( "BLOCK* " + lastBlock + " recovery started, primary=" + primary ) ; return ; } } }
Initialize lease recovery for this object