From ff91453227488902d8c730d69c90fb1a97b35d75 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Wed, 15 Feb 2012 22:00:08 +0000 Subject: [PATCH] HDFS-2938. Recursive delete of a large directory make namenode unresponsive. Contributed by Hari Mankude. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1244752 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/FSNamesystem.java | 27 ++++++++++--------- .../namenode/TestLargeDirectoryDelete.java | 5 +++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 0ab243cc285..6ce1558d04e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -251,6 +251,9 @@ Release 0.23.2 - UNRELEASED HDFS-2950. Secondary NN HTTPS address should be listed as a NAMESERVICE_SPECIFIC_KEY. (todd) + HDFS-2938. Recursive delete of a large directory make namenode + unresponsive. (Hari Mankude via suresh) + Release 0.23.1 - 2012-02-08 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index e70ed27c2fe..f846295f0e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -1980,15 +1980,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats, } finally { writeUnlock(); } - - getEditLog().logSync(); - - writeLock(); - try { - removeBlocks(collectedBlocks); // Incremental deletion of blocks - } finally { - writeUnlock(); - } + getEditLog().logSync(); + removeBlocks(collectedBlocks); // Incremental deletion of blocks collectedBlocks.clear(); if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* Namesystem.delete: " @@ -1997,16 +1990,24 @@ public class FSNamesystem implements Namesystem, FSClusterStats, return true; } - /** From the given list, incrementally remove the blocks from blockManager */ + /** + * From the given list, incrementally remove the blocks from blockManager + * Writelock is dropped and reacquired every BLOCK_DELETION_INCREMENT to + * ensure that other waiters on the lock can get in. See HDFS-2938 + */ private void removeBlocks(List blocks) { - assert hasWriteLock(); int start = 0; int end = 0; while (start < blocks.size()) { end = BLOCK_DELETION_INCREMENT + start; end = end > blocks.size() ? blocks.size() : end; - for (int i=start; i 0) { - synchronized(mc.getNamesystem()) { + mc.getNamesystem().writeLock(); + try { lockOps++; + } finally { + mc.getNamesystem().writeUnlock(); } Thread.sleep(1); }