Author: brandonli Date: Thu Feb 20 22:27:13 2014 New Revision: 1570366 URL: http://svn.apache.org/r1570366 Log: HDFS-5944. LeaseManager:findLeaseWithPrefixPath can't handle path like /a/b/ and cause SecondaryNameNode failed do checkpoint. Contributed by Yunjiong Zhao
Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1570366&r1=1570365&r2=1570366&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Thu Feb 20 22:27:13 2014 @@ -540,6 +540,9 @@ Release 2.4.0 - UNRELEASED HDFS-5962. Mtime and atime are not persisted for symbolic links. (Akira Ajisaka via kihwal) + HDFS-5944. LeaseManager:findLeaseWithPrefixPath can't handle path like /a/b/ + and cause SecondaryNameNode failed do checkpoint (Yunjiong Zhao via brandonli) + BREAKDOWN OF HDFS-5698 SUBTASKS AND RELATED JIRAS HDFS-5717. Save FSImage header in protobuf. (Haohui Mai via jing9) Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java?rev=1570366&r1=1570365&r2=1570366&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java Thu Feb 20 22:27:13 2014 @@ -339,7 +339,12 @@ public class LeaseManager { } final Map<String, Lease> entries = new HashMap<String, Lease>(); - final int srclen = prefix.length(); + int srclen = prefix.length(); + + // prefix may ended with '/' + if (prefix.charAt(srclen - 1) == Path.SEPARATOR_CHAR) { + srclen -= 1; + } for(Map.Entry<String, Lease> entry : path2lease.tailMap(prefix).entrySet()) { final String p = entry.getKey(); Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java?rev=1570366&view=auto ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java (added) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java Thu Feb 20 22:27:13 2014 @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.namenode; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hdfs.HdfsConfiguration; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.junit.Test; +import org.mockito.Mockito; + + +public class TestLeaseManager { + Configuration conf = new HdfsConfiguration(); + + @Test + public void testRemoveLeaseWithPrefixPath() throws Exception { + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); + cluster.waitActive(); + + LeaseManager lm = NameNodeAdapter.getLeaseManager(cluster.getNamesystem()); + lm.addLease("holder1", "/a/b"); + lm.addLease("holder2", "/a/c"); + assertNotNull(lm.getLeaseByPath("/a/b")); + assertNotNull(lm.getLeaseByPath("/a/c")); + + lm.removeLeaseWithPrefixPath("/a"); + + assertNull(lm.getLeaseByPath("/a/b")); + assertNull(lm.getLeaseByPath("/a/c")); + + lm.addLease("holder1", "/a/b"); + lm.addLease("holder2", "/a/c"); + + lm.removeLeaseWithPrefixPath("/a/"); + + assertNull(lm.getLeaseByPath("/a/b")); + assertNull(lm.getLeaseByPath("/a/c")); + } +}