Quellcode durchsuchen

HADOOP-14499. Findbugs warning in LocalMetadataStore.
Contributed by Sean Mackrory.

Steve Loughran vor 8 Jahren
Ursprung
Commit
309b8c0f83

+ 7 - 5
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/LocalMetadataStore.java

@@ -297,7 +297,6 @@ public class LocalMetadataStore implements MetadataStore {
     }
     Iterator<Map.Entry<Path, DirListingMetadata>> dirs =
         dirHash.entrySet().iterator();
-    Collection<Path> ancestors = new LinkedList<>();
     while (dirs.hasNext()) {
       Map.Entry<Path, DirListingMetadata> entry = dirs.next();
       Path path = entry.getKey();
@@ -311,11 +310,14 @@ public class LocalMetadataStore implements MetadataStore {
           newChildren.add(child);
         }
       }
-      if (newChildren.size() == 0) {
-        dirs.remove();
-        ancestors.add(entry.getKey());
-      } else {
+      if (newChildren.size() != oldChildren.size()) {
         dirHash.put(path, new DirListingMetadata(path, newChildren, false));
+        if (!path.isRoot()) {
+          DirListingMetadata parent = dirHash.get(path.getParent());
+          if (parent != null) {
+            parent.setAuthoritative(false);
+          }
+        }
       }
     }
   }

+ 29 - 0
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/MetadataStoreTestBase.java

@@ -688,6 +688,35 @@ public abstract class MetadataStoreTestBase extends Assert {
     assertDeleted("/pruneDirs/dir/file");
   }
 
+  @Test
+  public void testPruneUnsetsAuthoritative() throws Exception {
+    String rootDir = "/unpruned-root-dir";
+    String grandparentDir = rootDir + "/pruned-grandparent-dir";
+    String parentDir = grandparentDir + "/pruned-parent-dir";
+    String staleFile = parentDir + "/stale-file";
+    String freshFile = rootDir + "/fresh-file";
+    String[] directories = {rootDir, grandparentDir, parentDir};
+
+    createNewDirs(rootDir, grandparentDir, parentDir);
+    long time = System.currentTimeMillis();
+    ms.put(new PathMetadata(
+        new FileStatus(0, false, 0, 0, time - 1, strToPath(staleFile)),
+        Tristate.FALSE, false));
+    ms.put(new PathMetadata(
+        new FileStatus(0, false, 0, 0, time + 1, strToPath(freshFile)),
+        Tristate.FALSE, false));
+
+    ms.prune(time);
+    DirListingMetadata listing;
+    for (String directory : directories) {
+      Path path = strToPath(directory);
+      if (ms.get(path) != null) {
+        listing = ms.listChildren(path);
+        assertFalse(listing.isAuthoritative());
+      }
+    }
+  }
+
   /*
    * Helper functions.
    */