Author: cutting Date: Tue Dec 12 13:13:46 2006 New Revision: 486312 URL: http://svn.apache.org/viewvc?view=rev&rev=486312 Log: HADOOP-764. Reduce memory allocations in namenode some. Contributed by Dhruba.
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=486312&r1=486311&r2=486312 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Tue Dec 12 13:13:46 2006 @@ -54,6 +54,9 @@ 15. HADOOP-796. Provide more convenient access to failed task information in the web interface. (Sanjay Dahiya via cutting) +16. HADOOP-764. Reduce memory allocations in namenode some. + (Dhruba Borthakur via cutting) + Release 0.9.1 - 2006-12-06 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?view=diff&rev=486312&r1=486311&r2=486312 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Tue Dec 12 13:13:46 2006 @@ -1378,10 +1378,9 @@ nodeInfo.isAlive = false; } - Block deadblocks[] = nodeInfo.getBlocks(); - if( deadblocks != null ) - for( int i = 0; i < deadblocks.length; i++ ) - removeStoredBlock(deadblocks[i], nodeInfo); + for (Iterator<Block> it = nodeInfo.getBlockIterator(); it.hasNext(); ) { + removeStoredBlock(it.next(), nodeInfo); + } unprotectedRemoveDatanode(nodeInfo); } @@ -1464,40 +1463,44 @@ // Modify the (block-->datanode) map, according to the difference // between the old and new block report. // - int oldPos = 0, newPos = 0; - Block oldReport[] = node.getBlocks(); - while (oldReport != null && newReport != null && oldPos < oldReport.length && newPos < newReport.length) { - int cmp = oldReport[oldPos].compareTo(newReport[newPos]); - + int newPos = 0; + boolean modified = false; + Iterator<Block> iter = node.getBlockIterator(); + Block oldblk = iter.hasNext() ? iter.next() : null; + Block newblk = (newReport != null && newReport.length > 0) ? + newReport[0] : null; + + while (oldblk != null || newblk != null) { + + int cmp = (oldblk == null) ? 1 : + ((newblk == null) ? -1 : oldblk.compareTo(newblk)); + if (cmp == 0) { // Do nothing, blocks are the same - oldPos++; newPos++; + oldblk = iter.hasNext() ? iter.next() : null; + newblk = (newPos < newReport.length) + ? newReport[newPos] : null; } else if (cmp < 0) { // The old report has a block the new one does not - removeStoredBlock(oldReport[oldPos], node); - oldPos++; + removeStoredBlock(oldblk, node); + modified = true; + oldblk = iter.hasNext() ? iter.next() : null; } else { // The new report has a block the old one does not - addStoredBlock(newReport[newPos], node); + addStoredBlock(newblk, node); + modified = true; newPos++; + newblk = (newPos < newReport.length) + ? newReport[newPos] : null; } } - while (oldReport != null && oldPos < oldReport.length) { - // The old report has a block the new one does not - removeStoredBlock(oldReport[oldPos], node); - oldPos++; - } - while (newReport != null && newPos < newReport.length) { - // The new report has a block the old one does not - addStoredBlock(newReport[newPos], node); - newPos++; - } - // // Modify node so it has the new blockreport // - node.updateBlocks(newReport); + if (modified) { + node.updateBlocks(newReport); + } // // We've now completely updated the node's block report profile.