From c79e7f7d997596e0c38ae4cddff2bd0910581c16 Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Tue, 28 Apr 2015 18:05:46 -0700 Subject: [PATCH] HDFS-8273. FSNamesystem#Delete() should not call logSync() when holding the lock. Contributed by Haohui Mai. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/FSDirDeleteOp.java | 1 - .../hdfs/server/namenode/FSNamesystem.java | 22 +++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 5d9e983ca4..1c4cfb459c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -627,6 +627,9 @@ Release 2.7.1 - UNRELEASED HDFS-8070. Pre-HDFS-7915 DFSClient cannot use short circuit on post-HDFS-7915 DataNode (cmccabe) + HDFS-8273. FSNamesystem#Delete() should not call logSync() when holding the + lock. (wheat9) + Release 2.7.0 - 2015-04-20 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java index 02eb1de9ae..2192c240ed 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java @@ -175,7 +175,6 @@ static BlocksMapUpdateInfo deleteInternal( incrDeletedFileCount(filesRemoved); fsn.removeLeasesAndINodes(src, removedINodes, true); - fsd.getEditLog().logSync(); if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* Namesystem.delete: " 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 229c4d1350..0ec81d8874 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 @@ -3690,6 +3690,7 @@ boolean delete(String src, boolean recursive, boolean logRetryCache) } finally { writeUnlock(); } + getEditLog().logSync(); if (toRemovedBlocks != null) { removeBlocks(toRemovedBlocks); // Incremental deletion of blocks } @@ -4695,22 +4696,21 @@ public LazyPersistFileScrubber(final int scrubIntervalSec) { * blocks and unlink them from the namespace. */ private void clearCorruptLazyPersistFiles() - throws SafeModeException, AccessControlException, - UnresolvedLinkException, IOException { + throws IOException { BlockStoragePolicy lpPolicy = blockManager.getStoragePolicy("LAZY_PERSIST"); - List filesToDelete = new ArrayList(); - + List filesToDelete = new ArrayList<>(); + boolean changed = false; writeLock(); - try { final Iterator it = blockManager.getCorruptReplicaBlockIterator(); while (it.hasNext()) { Block b = it.next(); BlockInfoContiguous blockInfo = blockManager.getStoredBlock(b); - if (blockInfo.getBlockCollection().getStoragePolicyID() == lpPolicy.getId()) { + if (blockInfo.getBlockCollection().getStoragePolicyID() + == lpPolicy.getId()) { filesToDelete.add(blockInfo.getBlockCollection()); } } @@ -4718,9 +4718,10 @@ private void clearCorruptLazyPersistFiles() for (BlockCollection bc : filesToDelete) { LOG.warn("Removing lazyPersist file " + bc.getName() + " with no replicas."); BlocksMapUpdateInfo toRemoveBlocks = - FSDirDeleteOp.deleteInternal( - FSNamesystem.this, bc.getName(), - INodesInPath.fromINode((INodeFile) bc), false); + FSDirDeleteOp.deleteInternal( + FSNamesystem.this, bc.getName(), + INodesInPath.fromINode((INodeFile) bc), false); + changed |= toRemoveBlocks != null; if (toRemoveBlocks != null) { removeBlocks(toRemoveBlocks); // Incremental deletion of blocks } @@ -4728,6 +4729,9 @@ private void clearCorruptLazyPersistFiles() } finally { writeUnlock(); } + if (changed) { + getEditLog().logSync(); + } } @Override