From fd2ba4911bec60386a106c85aedd5cc99cd8cab3 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Thu, 30 Jan 2014 21:21:15 +0000 Subject: [PATCH] HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery. Contributed by Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1562970 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hdfs/server/namenode/FSNamesystem.java | 8 ++--- .../hdfs/server/namenode/LeaseManager.java | 36 ------------------- 3 files changed, 7 insertions(+), 40 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 0f0054fde97..4c6cf2e3634 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -299,6 +299,9 @@ Release 2.4.0 - UNRELEASED OPTIMIZATIONS + HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery + (todd) + BUG FIXES HDFS-5492. Port HDFS-2069 (Incorrect default trash interval in the 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 cd7bcf43769..ef2c28622f9 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 @@ -3800,7 +3800,7 @@ private void commitOrCompleteLastBlock(final INodeFile fileINode, final long diff = fileINode.getPreferredBlockSize() - commitBlock.getNumBytes(); if (diff > 0) { try { - String path = leaseManager.findPath(fileINode); + String path = fileINode.getFullPathName(); dir.updateSpaceConsumed(path, 0, -diff*fileINode.getFileReplication()); } catch (IOException e) { LOG.warn("Unexpected exception while updating disk space.", e); @@ -4002,7 +4002,7 @@ void commitBlockSynchronization(ExtendedBlock lastblock, @VisibleForTesting String closeFileCommitBlocks(INodeFile pendingFile, BlockInfo storedBlock) throws IOException { - String src = leaseManager.findPath(pendingFile); + String src = pendingFile.getFullPathName(); // commit the last block and complete it if it has minimum replicas commitOrCompleteLastBlock(pendingFile, storedBlock); @@ -4024,7 +4024,7 @@ String closeFileCommitBlocks(INodeFile pendingFile, BlockInfo storedBlock) @VisibleForTesting String persistBlocks(INodeFile pendingFile, boolean logRetryCache) throws IOException { - String src = leaseManager.findPath(pendingFile); + String src = pendingFile.getFullPathName(); dir.persistBlocks(src, pendingFile, logRetryCache); return src; } @@ -5952,7 +5952,7 @@ private void updatePipelineInternal(String clientName, ExtendedBlock oldBlock, .getDatanodeStorageInfos(newNodes, newStorageIDs); blockinfo.setExpectedLocations(storages); - String src = leaseManager.findPath(pendingFile); + String src = pendingFile.getFullPathName(); dir.persistBlocks(src, pendingFile, logRetryCache); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java index 8b5fb81815f..b9f9d10396e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java @@ -179,24 +179,6 @@ synchronized Lease reassignLease(Lease lease, String src, String newHolder) { return addLease(newHolder, src); } - /** - * Finds the pathname for the specified pendingFile - */ - public synchronized String findPath(INodeFile pendingFile) - throws IOException { - FileUnderConstructionFeature uc = pendingFile.getFileUnderConstructionFeature(); - Preconditions.checkArgument(uc != null); - Lease lease = getLease(uc.getClientName()); - if (lease != null) { - String src = lease.findPath(pendingFile); - if (src != null) { - return src; - } - } - throw new IOException("pendingFile (=" + pendingFile + ") not found." - + "(lease=" + lease + ")"); - } - /** * Renew the lease(s) held by the given client */ @@ -252,24 +234,6 @@ public boolean expiredSoftLimit() { return now() - lastUpdate > softLimit; } - /** - * @return the path associated with the pendingFile and null if not found. - */ - private String findPath(INodeFile pendingFile) { - try { - for (String src : paths) { - INode node = fsnamesystem.dir.getINode(src); - if (node == pendingFile - || (node.isFile() && node.asFile() == pendingFile)) { - return src; - } - } - } catch (UnresolvedLinkException e) { - throw new AssertionError("Lease files should reside on this FS"); - } - return null; - } - /** Does this lease contain any path? */ boolean hasPath() {return !paths.isEmpty();}