diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index a59fb4da2a3..f32e0cad656 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -147,6 +147,9 @@ Trunk (Unreleased) Block Pool Used, Block Pool Used(%) and Failed Volumes. (Brahma Reddy Battula via suresh) + HDFS-4052. BlockManager#invalidateWork should print log outside the lock. + (Jing Zhao via suresh) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index 9af8eb4cbef..822aeff65c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -2856,6 +2856,9 @@ assert storedBlock.findDatanode(dn) < 0 : "Block " + block * @return number of blocks scheduled for removal during this iteration. */ private int invalidateWorkForOneNode(String nodeId) { + final List toInvalidate; + final DatanodeDescriptor dn; + namesystem.writeLock(); try { // blocks should not be replicated or removed if safe mode is on @@ -2865,10 +2868,23 @@ assert storedBlock.findDatanode(dn) < 0 : "Block " + block } // get blocks to invalidate for the nodeId assert nodeId != null; - return invalidateBlocks.invalidateWork(nodeId); + dn = datanodeManager.getDatanode(nodeId); + if (dn == null) { + invalidateBlocks.remove(nodeId); + return 0; + } + toInvalidate = invalidateBlocks.invalidateWork(nodeId, dn); + if (toInvalidate == null) { + return 0; + } } finally { namesystem.writeUnlock(); } + if (NameNode.stateChangeLog.isInfoEnabled()) { + NameNode.stateChangeLog.info("BLOCK* " + getClass().getSimpleName() + + ": ask " + dn + " to delete " + toInvalidate); + } + return toInvalidate.size(); } boolean blockHasEnoughRacks(Block b) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java index 588d8df444d..2a10ee2253c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java @@ -134,26 +134,7 @@ class InvalidateBlocks { return new ArrayList(node2blocks.keySet()); } - /** Invalidate work for the storage. */ - int invalidateWork(final String storageId) { - final DatanodeDescriptor dn = datanodeManager.getDatanode(storageId); - if (dn == null) { - remove(storageId); - return 0; - } - final List toInvalidate = invalidateWork(storageId, dn); - if (toInvalidate == null) { - return 0; - } - - if (NameNode.stateChangeLog.isInfoEnabled()) { - NameNode.stateChangeLog.info("BLOCK* " + getClass().getSimpleName() - + ": ask " + dn + " to delete " + toInvalidate); - } - return toInvalidate.size(); - } - - private synchronized List invalidateWork( + synchronized List invalidateWork( final String storageId, final DatanodeDescriptor dn) { final LightWeightHashSet set = node2blocks.get(storageId); if (set == null) {