From 6b08d7de5f1aa6ee5347903fa7457ef243c1b7cf Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Fri, 30 Nov 2012 02:51:25 +0000 Subject: [PATCH] HDFS-4242. Map.Entry is incorrectly used in LeaseManager since the behavior of it is undefined after the iteration or modifications of the map. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1415480 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 4 ++++ .../hdfs/server/namenode/LeaseManager.java | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index daf86cdaf7..6303154c2c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -639,6 +639,10 @@ Release 2.0.3-alpha - Unreleased HDFS-4216. Do not ignore QuotaExceededException when adding symlinks. (szetszwo) + HDFS-4242. Map.Entry is incorrectly used in LeaseManager since the behavior + of it is undefined after the iteration or modifications of the map. + (szetszwo) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES 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 fd1cbfcc57..b1764b7d3c 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 @@ -17,9 +17,12 @@ */ package org.apache.hadoop.hdfs.server.namenode; +import static org.apache.hadoop.util.Time.now; + import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -39,8 +42,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import static org.apache.hadoop.util.Time.now; - /** * LeaseManager does the lease housekeeping for writing on files. * This class also provides useful static methods for lease recovery. @@ -340,7 +341,8 @@ synchronized void changeLease(String src, String dst, } final int len = overwrite.length(); - for(Map.Entry entry : findLeaseWithPrefixPath(src, sortedLeasesByPath)) { + for(Map.Entry entry + : findLeaseWithPrefixPath(src, sortedLeasesByPath).entrySet()) { final String oldpath = entry.getKey(); final Lease lease = entry.getValue(); //overwrite must be a prefix of oldpath @@ -355,7 +357,8 @@ synchronized void changeLease(String src, String dst, } synchronized void removeLeaseWithPrefixPath(String prefix) { - for(Map.Entry entry : findLeaseWithPrefixPath(prefix, sortedLeasesByPath)) { + for(Map.Entry entry + : findLeaseWithPrefixPath(prefix, sortedLeasesByPath).entrySet()) { if (LOG.isDebugEnabled()) { LOG.debug(LeaseManager.class.getSimpleName() + ".removeLeaseWithPrefixPath: entry=" + entry); @@ -364,13 +367,13 @@ synchronized void removeLeaseWithPrefixPath(String prefix) { } } - static private List> findLeaseWithPrefixPath( + static private Map findLeaseWithPrefixPath( String prefix, SortedMap path2lease) { if (LOG.isDebugEnabled()) { LOG.debug(LeaseManager.class.getSimpleName() + ".findLease: prefix=" + prefix); } - List> entries = new ArrayList>(); + final Map entries = new HashMap(); final int srclen = prefix.length(); for(Map.Entry entry : path2lease.tailMap(prefix).entrySet()) { @@ -379,7 +382,7 @@ static private List> findLeaseWithPrefixPath( return entries; } if (p.length() == srclen || p.charAt(srclen) == Path.SEPARATOR_CHAR) { - entries.add(entry); + entries.put(entry.getKey(), entry.getValue()); } } return entries;