void saveFilesUnderConstruction ( SaveNamespaceContext ctx , DataOutputStream out ) throws IOException { synchronized ( leaseManager ) { int pathsToSave = 0 ; Iterator < Lease > itrl = leaseManager . getSortedLeases ( ) . iterator ( ) ; while ( itrl . hasNext ( ) ) { Lease lease = itrl . next ( ) ; for ( String path : lease . getPaths ( ) ) { // verify that path exists in namespace INode node = dir . getFileINode ( path ) ; if ( node != null && node . isUnderConstruction ( ) ) { pathsToSave ++ ; } else if ( node == null ) { // ignore the path and continue. String msg = "saveLeases - counting - found path " + path + " but no matching entry in namespace." ; LOG . warn ( msg ) ; continue ; } else { throw new IOException ( "saveLeases found path " + path + " but is not under construction." ) ; } } } if ( pathsToSave != leaseManager . countPath ( ) ) { LOG . warn ( "Number of leases mismatch: " + pathsToSave + " are valid, lease manager indicated: " + leaseManager . countPath ( ) ) ; } out . writeInt ( pathsToSave ) ; // write the size int pathsSaved = 0 ; LightWeightLinkedSet < Lease > sortedLeases = leaseManager . getSortedLeases ( ) ; Iterator < Lease > itr = sortedLeases . iterator ( ) ; while ( itr . hasNext ( ) ) { ctx . checkCancelled ( ) ; Lease lease = itr . next ( ) ; for ( String path : lease . getPaths ( ) ) { // verify that path exists in namespace INode node = dir . getFileINode ( path ) ; if ( node == null ) { // ignore the path and continue. String msg = "saveLeases found path " + path + " but no matching entry in namespace." ; LOG . warn ( msg ) ; continue ; } if ( ! node . isUnderConstruction ( ) ) { throw new IOException ( "saveLeases found path " + path + " but is not under construction." ) ; } INodeFileUnderConstruction cons = ( INodeFileUnderConstruction ) node ; FSImageSerialization . writeINodeUnderConstruction ( out , cons , path ) ; pathsSaved ++ ; } } if ( pathsSaved != pathsToSave ) { String msg = "Saved paths: " + pathsSaved + " is not equal to what we thought we would save: " + pathsToSave ; LOG . error ( msg ) ; throw new IOException ( msg ) ; } } }
Serializes leases .