private DataBlockScanner getNextNamespaceSliceScanner ( int currentNamespaceId ) { Integer nextNsId = null ; while ( ( nextNsId == null ) && datanode . shouldRun && ! blockScannerThread . isInterrupted ( ) ) { waitForOneNameSpaceUp ( ) ; synchronized ( this ) { if ( getNamespaceSetSize ( ) > 0 ) { // Find nextNsId by finding the last modified current log file, if any long lastScanTime = - 1 ; Iterator < Integer > nsidIterator = namespaceScannerMap . keySet ( ) . iterator ( ) ; while ( nsidIterator . hasNext ( ) ) { int nsid = nsidIterator . next ( ) ; for ( FSDataset . FSVolume vol : dataset . volumes . getVolumes ( ) ) { try { File currFile = DataBlockScanner . getCurrentFile ( vol , nsid ) ; if ( currFile . exists ( ) ) { long lastModified = currFile . lastModified ( ) ; if ( lastScanTime < lastModified ) { lastScanTime = lastModified ; nextNsId = nsid ; } } } catch ( IOException e ) { LOG . warn ( "Received exception: " , e ) ; } } } // nextNsId can still be -1 if no current log is found, // find nextNsId sequentially. if ( nextNsId == null ) { try { if ( currentNamespaceId == - 1 ) { nextNsId = namespaceScannerMap . firstKey ( ) ; } else { nextNsId = namespaceScannerMap . higherKey ( currentNamespaceId ) ; if ( nextNsId == null ) { nextNsId = namespaceScannerMap . firstKey ( ) ; } } } catch ( NoSuchElementException e ) { // if firstKey throws an exception continue ; } } if ( nextNsId != null ) { return getNSScanner ( nextNsId ) ; } } } LOG . warn ( "No namespace is up, going to wait" ) ; try { Thread . sleep ( 5000 ) ; } catch ( InterruptedException ex ) { LOG . warn ( "Received exception: " + ex ) ; blockScannerThread . interrupt ( ) ; return null ; } } return null ; }
Find next namespaceId to scan . There should be only one current verification log file . Find which namespace contains the current verification log file and that is used as the starting namespaceId . If no current files are found start with first namespace . However if more than one current files are found the one with latest modification time is used to find the next namespaceId .