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 br...@apache.org on 2017/05/10 05:40:16 UTC

hadoop git commit: HDFS-11373. Backport HDFS-11258 and HDFS-11272(File mtime change could not save to editlog). (Contributed by Jimmy Xiang, backported by Akira Ajisaka)

Repository: hadoop
Updated Branches:
  refs/heads/branch-2.7 2875462c2 -> 48c5e37ab


HDFS-11373. Backport HDFS-11258 and HDFS-11272(File mtime change could not save to editlog). (Contributed by Jimmy Xiang, backported by Akira Ajisaka)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/48c5e37a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/48c5e37a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/48c5e37a

Branch: refs/heads/branch-2.7
Commit: 48c5e37abfb1874e0b36b075543abe1a1c841cc1
Parents: 2875462
Author: Brahma Reddy Battula <br...@apache.org>
Authored: Wed May 10 11:06:57 2017 +0530
Committer: Brahma Reddy Battula <br...@apache.org>
Committed: Wed May 10 11:06:57 2017 +0530

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  4 +
 .../hdfs/server/namenode/FSDirAttrOp.java       | 18 ++---
 .../hdfs/server/namenode/TestFSDirAttrOp.java   | 81 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/48c5e37a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 0df8482..ce225d9 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -265,6 +265,10 @@ Release 2.7.4 - UNRELEASED
 
     HDFS-11766. Fix findbugs warning in branch-2.7. (Chen Liang via aajisaka)
 
+	HDFS-11373. Backport HDFS-11258 and HDFS-11272
+	(File mtime change could not save to editlog).
+	(Contributed by Jimmy Xiang, backported by Akira Ajisaka)
+
 Release 2.7.3 - 2016-08-25
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48c5e37a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java
index 8b4793c..1aef7dc 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java
@@ -464,18 +464,12 @@ public class FSDirAttrOp {
       inode = inode.setModificationTime(mtime, latest);
       status = true;
     }
-    if (atime != -1) {
-      long inodeTime = inode.getAccessTime();
-
-      // if the last access time update was within the last precision interval, then
-      // no need to store access time
-      if (atime <= inodeTime + fsd.getFSNamesystem().getAccessTimePrecision()
-          && !force) {
-        status =  false;
-      } else {
-        inode.setAccessTime(atime, latest);
-        status = true;
-      }
+    // if the last access time update was within the last precision interval,
+    // then no need to store access time
+    if (atime != -1 && (status || force || atime > inode.getAccessTime() +
+        fsd.getFSNamesystem().getAccessTimePrecision())) {
+      inode.setAccessTime(atime, latest);
+      status = true;
     }
     return status;
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48c5e37a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirAttrOp.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirAttrOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirAttrOp.java
new file mode 100644
index 0000000..ec90fbc
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSDirAttrOp.java
@@ -0,0 +1,81 @@
+/**
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.UnresolvedLinkException;
+import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test {@link FSDirAttrOp}.
+ */
+public class TestFSDirAttrOp {
+  public static final Log LOG = LogFactory.getLog(TestFSDirAttrOp.class);
+
+  private boolean unprotectedSetTimes(long atime, long atime0, long precision,
+      long mtime, boolean force) throws QuotaExceededException,
+      UnresolvedLinkException {
+    FSDirectory fsd = Mockito.mock(FSDirectory.class);
+    FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
+    INodesInPath iip = Mockito.mock(INodesInPath.class);
+    INode inode = Mockito.mock(INode.class);
+
+    when(fsd.getFSNamesystem()).thenReturn(fsn);
+    when(fsn.getAccessTimePrecision()).thenReturn(precision);
+    when(fsd.getINodesInPath("", true)).thenReturn(iip);
+    when(fsd.hasWriteLock()).thenReturn(Boolean.TRUE);
+    when(iip.getLastINode()).thenReturn(inode);
+    when(iip.getLatestSnapshotId()).thenReturn(Mockito.anyInt());
+    when(inode.getAccessTime()).thenReturn(atime0);
+
+    return FSDirAttrOp.unprotectedSetTimes(fsd, "", mtime, atime, force);
+  }
+
+  @Test
+  public void testUnprotectedSetTimes() throws Exception {
+    // atime < access time + precision
+    assertFalse("SetTimes should not update access time "
+          + "because it's within the last precision interval",
+        unprotectedSetTimes(100, 0, 1000, -1, false));
+
+    // atime = access time + precision
+    assertFalse("SetTimes should not update access time "
+          + "because it's within the last precision interval",
+        unprotectedSetTimes(1000, 0, 1000, -1, false));
+
+    // atime > access time + precision
+    assertTrue("SetTimes should update access time",
+        unprotectedSetTimes(1011, 10, 1000, -1, false));
+
+    // atime < access time + precision, but force is set
+    assertTrue("SetTimes should update access time",
+        unprotectedSetTimes(100, 0, 1000, -1, true));
+
+    // atime < access time + precision, but mtime is set
+    assertTrue("SetTimes should update access time",
+        unprotectedSetTimes(100, 0, 1000, 1, false));
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org