You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by dh...@apache.org on 2010/06/17 03:44:32 UTC
svn commit: r955445 - in /hadoop/common/branches/branch-0.20-append:
CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
Author: dhruba
Date: Thu Jun 17 01:44:32 2010
New Revision: 955445
URL: http://svn.apache.org/viewvc?rev=955445&view=rev
Log:
HDFS-1204. Lease expiration should recover single files,
not entire lease holder (Sam Rash via dhruba)
Added:
hadoop/common/branches/branch-0.20-append/src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
Modified:
hadoop/common/branches/branch-0.20-append/CHANGES.txt
hadoop/common/branches/branch-0.20-append/src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
Modified: hadoop/common/branches/branch-0.20-append/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-append/CHANGES.txt?rev=955445&r1=955444&r2=955445&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-append/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-append/CHANGES.txt Thu Jun 17 01:44:32 2010
@@ -56,6 +56,9 @@ Release 0.20-append - Unreleased
HDFS-1141. completeFile does not check lease ownership.
(Todd Lipcon via dhruba)
+ HDFS-1204. Lease expiration should recover single files,
+ not entire lease holder (Sam Rash via dhruba)
+
Release 0.20.3 - Unreleased
NEW FEATURES
Modified: hadoop/common/branches/branch-0.20-append/src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-append/src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java?rev=955445&r1=955444&r2=955445&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-append/src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java (original)
+++ hadoop/common/branches/branch-0.20-append/src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java Thu Jun 17 01:44:32 2010
@@ -370,7 +370,7 @@ public class LeaseManager {
}
/** Check the leases beginning from the oldest. */
- private synchronized void checkLeases() {
+ synchronized void checkLeases() {
for(; sortedLeases.size() > 0; ) {
final Lease oldest = sortedLeases.first();
if (!oldest.expiredHardLimit()) {
@@ -388,7 +388,7 @@ public class LeaseManager {
oldest.getPaths().toArray(leasePaths);
for(String p : leasePaths) {
try {
- fsnamesystem.internalReleaseLease(oldest, p);
+ fsnamesystem.internalReleaseLeaseOne(oldest, p);
} catch (IOException e) {
LOG.error("Cannot release the path "+p+" in the lease "+oldest, e);
removing.add(p);
Added: hadoop/common/branches/branch-0.20-append/src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-append/src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java?rev=955445&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.20-append/src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java (added)
+++ hadoop/common/branches/branch-0.20-append/src/test/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java Thu Jun 17 01:44:32 2010
@@ -0,0 +1,96 @@
+/**
+ * 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 junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.util.Daemon;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.IOException;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.spy;
+
+public class TestLeaseManager extends TestCase {
+ public static final Log LOG = LogFactory.getLog(TestLeaseManager.class);
+
+ /*
+ * test case: two leases are added for a singler holder, should use
+ * the internalReleaseOne method
+ */
+ public void testMultiPathLeaseRecovery()
+ throws IOException, InterruptedException {
+ Configuration conf = new Configuration();
+ MiniDFSCluster cluster = new MiniDFSCluster(conf, 3, true, null);
+ NameNode namenode = cluster.getNameNode();
+ FSNamesystem spyNamesystem = spy(namenode.getNamesystem());
+ LeaseManager leaseManager = new LeaseManager(spyNamesystem);
+
+ spyNamesystem.leaseManager = leaseManager;
+ spyNamesystem.lmthread.interrupt();
+
+ String holder = "client-1";
+ String path1 = "/file-1";
+ String path2 = "/file-2";
+
+ CalledAnswer internalReleaseCalled = new CalledAnswer();
+ CalledAnswer internalReleaseOneCalled = new CalledAnswer();
+ doAnswer(internalReleaseCalled)
+ .when(spyNamesystem)
+ .internalReleaseLease((LeaseManager.Lease) anyObject(), anyString());
+ doAnswer(internalReleaseOneCalled)
+ .when(spyNamesystem)
+ .internalReleaseLeaseOne((LeaseManager.Lease) anyObject(), anyString());
+
+ leaseManager.setLeasePeriod(1, 2);
+ leaseManager.addLease(holder, path1);
+ leaseManager.addLease(holder, path2);
+ Thread.sleep(1000);
+
+ synchronized (spyNamesystem) { // checkLeases is always called with FSN lock
+ leaseManager.checkLeases();
+ }
+
+ assertTrue("internalReleaseOne not called", internalReleaseOneCalled.isCalled());
+ assertFalse("internalRelease called", internalReleaseCalled.isCalled());
+ }
+
+ private static class CalledAnswer<T> implements Answer<T>{
+ private volatile boolean called = false;
+
+ @Override
+ public T answer(InvocationOnMock invocationOnMock) throws Throwable {
+ called = true;
+
+ return (T)invocationOnMock.callRealMethod();
+ }
+
+ public boolean isCalled() {
+ return called;
+ }
+ }
+}
\ No newline at end of file