private boolean assignInitialVerificationTimes() {
    int numBlocks = 1;
    LogFileHandler log = null;
    synchronized (this) {
      log = verificationLog;
      numBlocks = Math.max(blockMap.size(), 1);
    }

    long now = System.currentTimeMillis();
    LogFileHandler.Reader logReader[] = new LogFileHandler.Reader[2];
    try {
      if (log != null) {
        logReader[0] = log.new Reader(false);
        logReader[1] = log.new Reader(true);
      }
    } catch (IOException e) {
      LOG.warn("Could not read previous verification times : " +
               StringUtils.stringifyException(e));
    }
    
    try {
      for (LogFileHandler.Reader reader : logReader) {
      // update verification times from the verificationLog.
        while (reader != null && reader.hasNext()) {
          if (!datanode.shouldRun
              || datanode.blockScanner.blockScannerThread.isInterrupted()) {
            return false;
          }
          LogEntry entry = LogEntry.parseEntry(reader.next());
          if (entry != null) {
            updateBlockInfo(entry);
            if (now - entry.verificationTime < scanPeriod) {
              BlockScanInfo info = blockMap.get(new Block(entry.blockId, 0,
                  entry.genStamp));
              if (info != null) {
                if (!processedBlocks.contains(entry.blockId)) {
                  bytesLeft-=info.block.getNumBytes();
                  processedBlocks.add(entry.blockId);
                }
                if (reader.file == log.prevFile) {
                  // write the log entry to current file
                  // so that the entry is preserved for later runs.
                  log.appendLine(entry.verificationTime, entry.genStamp,
                      entry.blockId);
                }
              }
            }
          }
        }
      }
    } finally {
      IOUtils.closeStream(logReader[0]);
      IOUtils.closeStream(logReader[1]);
    }
    
    /* Initially spread the block reads over half of 
     * MIN_SCAN_PERIOD so that we don't keep scanning the 
     * blocks too quickly when restarted.
     */
    long verifyInterval = (long) (Math.min( scanPeriod/2.0/numBlocks,
                                            10*60*1000 ));
    long lastScanTime = System.currentTimeMillis() - scanPeriod;
    
    /* Before this loop, entries in blockInfoSet that are not
     * updated above have lastScanTime of <= 0 . Loop until first entry has
     * lastModificationTime > 0.
     */    
    synchronized (this) {
      if (blockInfoSet.size() > 0 ) {
        BlockScanInfo info;
        while ((info =  blockInfoSet.first()).lastScanTime < 0) {
          delBlockInfo(info);        
          info.lastScanTime = lastScanTime;
          lastScanTime += verifyInterval;
          addBlockInfo(info);
        }
      }
    }
    
    return true;
  }
private boolean assignInitialVerificationTimes ( ) { int numBlocks = 1 ; LogFileHandler log = null ; synchronized ( this ) { log = verificationLog ; numBlocks = Math . max ( blockMap . size ( ) , 1 ) ; } long now = System . currentTimeMillis ( ) ; LogFileHandler . Reader logReader [ ] = new LogFileHandler . Reader [ 2 ] ; try { if ( log != null ) { logReader [ 0 ] = log . new Reader ( false ) ; logReader [ 1 ] = log . new Reader ( true ) ; } } catch ( IOException e ) { LOG . warn ( "Could not read previous verification times : " + StringUtils . stringifyException ( e ) ) ; } try { for ( LogFileHandler . Reader reader : logReader ) { while ( reader != null && reader . hasNext ( ) ) { if ( ! datanode . shouldRun || datanode . blockScanner . blockScannerThread . isInterrupted ( ) ) { return false ; } LogEntry entry = LogEntry . parseEntry ( reader . next ( ) ) ; if ( entry != null ) { updateBlockInfo ( entry ) ; if ( now - entry . verificationTime < scanPeriod ) { BlockScanInfo info = blockMap . get ( new Block ( entry . blockId , 0 , entry . genStamp ) ) ; if ( info != null ) { if ( ! processedBlocks . contains ( entry . blockId ) ) { bytesLeft -= info . block . getNumBytes ( ) ; processedBlocks . add ( entry . blockId ) ; } if ( reader . file == log . prevFile ) { log . appendLine ( entry . verificationTime , entry . genStamp , entry . blockId ) ; } } } } } } } finally { IOUtils . closeStream ( logReader [ 0 ] ) ; IOUtils . closeStream ( logReader [ 1 ] ) ; } long verifyInterval = ( long ) ( Math . min ( scanPeriod / 2.0 / numBlocks , 10 * 60 * 1000 ) ) ; long lastScanTime = System . currentTimeMillis ( ) - scanPeriod ; synchronized ( this ) { if ( blockInfoSet . size ( ) > 0 ) { BlockScanInfo info ; while ( ( info = blockInfoSet . first ( ) ) . lastScanTime < 0 ) { delBlockInfo ( info ) ; info . lastScanTime = lastScanTime ; lastScanTime += verifyInterval ; addBlockInfo ( info ) ; } } } return true ; }
Reads the current and previous log files (if any) and marks the blocks
processed if they were processed within last scan period. Copies the log
records of recently scanned blocks from previous to current file.
Returns false if the process was interrupted because the thread is marked
to exit.