Parcourir la source

HDFS-14807. SetTimes updates all negative values apart from -1. Contributed by Ayush Saxena.

Ayush Saxena il y a 5 ans
Parent
commit
91b01a1db7

+ 3 - 3
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java

@@ -1145,11 +1145,11 @@ public interface ClientProtocol {
    * Sets the modification and access time of the file to the specified time.
    * @param src The string representation of the path
    * @param mtime The number of milliseconds since Jan 1, 1970.
-   *              Setting mtime to -1 means that modification time should not
+   *              Setting negative mtime means that modification time should not
    *              be set by this call.
    * @param atime The number of milliseconds since Jan 1, 1970.
-   *              Setting atime to -1 means that access time should not be set
-   *              by this call.
+   *              Setting negative atime means that access time should not be
+   *              set by this call.
    *
    * @throws org.apache.hadoop.security.AccessControlException permission denied
    * @throws java.io.FileNotFoundException file <code>src</code> is not found

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java

@@ -475,14 +475,14 @@ public class FSDirAttrOp {
     boolean status = false;
     INode inode = iip.getLastINode();
     int latest = iip.getLatestSnapshotId();
-    if (mtime != -1) {
+    if (mtime >= 0) {
       inode = inode.setModificationTime(mtime, 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
+    if (atime >= 0 && (status || force
         || atime > inode.getAccessTime() + fsd.getAccessTimePrecision())) {
       inode.setAccessTime(atime, latest,
           fsd.getFSNamesystem().getSnapshotManager().

+ 7 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetTimes.java

@@ -139,6 +139,13 @@ public class TestSetTimes {
                          " (" + mtime1 + ")");
       assertTrue(atime1 != 0);
 
+      // check setting negative value for atime and mtime.
+      fileSys.setTimes(file1, -2, -2);
+      // The values shouldn't change.
+      stat = fileSys.getFileStatus(file1);
+      assertEquals(mtime1, stat.getModificationTime());
+      assertEquals(atime1, stat.getAccessTime());
+
       //
       // record dir times
       //