synchronized void openInfo ( ) throws IOException { if ( src == null && blocks == null ) { throw new IOException ( "No file provided to open" ) ; } LocatedBlocks newInfo = src != null ? getLocatedBlocks ( src , 0 , prefetchSize ) : blocks ; if ( newInfo == null ) { throw new FileNotFoundException ( "Cannot open filename " + src ) ; } // I think this check is not correct. A file could have been appended to // between two calls to openInfo(). if ( locatedBlocks != null && ! locatedBlocks . isUnderConstruction ( ) && ! newInfo . isUnderConstruction ( ) ) { Iterator < LocatedBlock > oldIter = locatedBlocks . getLocatedBlocksCopy ( ) . iterator ( ) ; Iterator < LocatedBlock > newIter = newInfo . getLocatedBlocks ( ) . iterator ( ) ; while ( oldIter . hasNext ( ) && newIter . hasNext ( ) ) { if ( ! oldIter . next ( ) . getBlock ( ) . equals ( newIter . next ( ) . getBlock ( ) ) ) { throw new IOException ( "Blocklist for " + src + " has changed!" ) ; } } } // if the file is under construction, then fetch size of last block // from datanode. if ( newInfo . isUnderConstruction ( ) && newInfo . locatedBlockCount ( ) > 0 ) { LocatedBlock last = newInfo . get ( newInfo . locatedBlockCount ( ) - 1 ) ; if ( last . getLocations ( ) . length > 0 ) { try { Block newBlock = getBlockInfo ( last ) ; // only if the block has data (not null) if ( newBlock != null ) { long newBlockSize = newBlock . getNumBytes ( ) ; newInfo . setLastBlockSize ( newBlock . getBlockId ( ) , newBlockSize ) ; } } catch ( IOException e ) { DFSClient . LOG . debug ( "DFSClient file " + src + " is being concurrently append to" + " but datanodes probably does not have block " + last . getBlock ( ) , e ) ; } } } this . locatedBlocks = new DFSLocatedBlocks ( newInfo , locatedBlockExpireTimeout ) ; this . currentNode = null ; if ( ! newInfo . isUnderConstruction ( ) ) { // No block should be under construction if the file is finalized. isCurrentBlockUnderConstruction = false ; } }
Grab the open - file info from namenode