void replaceNode(String path, INode[] inodes, INodeFile oldnode, INodeFile newnode,
                           boolean updateDiskspace) throws IOException {
    writeLock();
    try {
      long dsOld = oldnode.diskspaceConsumed();

      //
      // Remove the node from the namespace
      //
      if (!oldnode.removeNode()) {
        NameNode.stateChangeLog.warn("DIR* FSDirectory.replaceNode: " +
                                     "failed to remove " + path);
        throw new IOException("FSDirectory.replaceNode: " +
                              "failed to remove " + path);
      }
      
      /* Currently oldnode and newnode are assumed to contain the same
       * blocks. Otherwise, blocks need to be removed from the blocksMap.
       */
      if (inodes == null) {
        inodes = rootDir.getExistingPathINodes(path);
      }
      INodeDirectory parent = (INodeDirectory)inodes[inodes.length-2];
      newnode.setLocalName(oldnode.getLocalNameBytes());
      parent.addChild(newnode, false);
      inodes[inodes.length-1] = newnode;

      //check if disk space needs to be updated.
      long dsNew = 0;
      if (updateDiskspace && (dsNew = newnode.diskspaceConsumed()) != dsOld) {
        try {
          updateSpaceConsumed(path, null, 0, dsNew-dsOld);
        } catch (QuotaExceededException e) {
          // undo
          replaceNode(path, inodes, newnode, oldnode, false);
          throw e;
        }
      }

      int index = 0;
      for (Block b : newnode.getBlocks()) {
        BlockInfo info = 
            getFSNamesystem().blocksMap.addINode(b, newnode, 
                newnode.getReplication());
        newnode.setBlock(index, info); // inode refers to the block in BlocksMap
        index++;
      }
      
      inodeMap.remove(oldnode);
      inodeMap.put(newnode);
    } finally {
      writeUnlock();
    }
  }
void replaceNode ( String path , INode [ ] inodes , INodeFile oldnode , INodeFile newnode , boolean updateDiskspace ) throws IOException { writeLock ( ) ; try { long dsOld = oldnode . diskspaceConsumed ( ) ; if ( ! oldnode . removeNode ( ) ) { NameNode . stateChangeLog . warn ( "DIR* FSDirectory.replaceNode: " + "failed to remove " + path ) ; throw new IOException ( "FSDirectory.replaceNode: " + "failed to remove " + path ) ; } if ( inodes == null ) { inodes = rootDir . getExistingPathINodes ( path ) ; } INodeDirectory parent = ( INodeDirectory ) inodes [ inodes . length - 2 ] ; newnode . setLocalName ( oldnode . getLocalNameBytes ( ) ) ; parent . addChild ( newnode , false ) ; inodes [ inodes . length - 1 ] = newnode ; long dsNew = 0 ; if ( updateDiskspace && ( dsNew = newnode . diskspaceConsumed ( ) ) != dsOld ) { try { updateSpaceConsumed ( path , null , 0 , dsNew - dsOld ) ; } catch ( QuotaExceededException e ) { replaceNode ( path , inodes , newnode , oldnode , false ) ; throw e ; } } int index = 0 ; for ( Block b : newnode . getBlocks ( ) ) { BlockInfo info = getFSNamesystem ( ) . blocksMap . addINode ( b , newnode , newnode . getReplication ( ) ) ; newnode . setBlock ( index , info ) ; index ++ ; } inodeMap . remove ( oldnode ) ; inodeMap . put ( newnode ) ; } finally { writeUnlock ( ) ; } }
@see #replaceNode(String, INodeFile, INodeFile)