Browse Source

HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly (#1334)

HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly
Wang Yuxuan 5 years ago
parent
commit
894e2300d6

+ 2 - 1
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java

@@ -257,10 +257,11 @@ public class MountTableResolver
     Iterator<Entry<String, PathLocation>> it = entries.iterator();
     while (it.hasNext()) {
       Entry<String, PathLocation> entry = it.next();
+      String key = entry.getKey();
       PathLocation loc = entry.getValue();
       String src = loc.getSourcePath();
       if (src != null) {
-        if (isParentEntry(src, path)) {
+        if (isParentEntry(key, path)) {
           LOG.debug("Removing {}", src);
           it.remove();
         }

+ 25 - 0
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java

@@ -704,4 +704,29 @@ public class TestMountTableResolver {
     mountTable.removeEntry("/testlocationcache");
     mountTable.removeEntry("/anothertestlocationcache");
   }
+
+  /**
+   * Test if we add a new entry, the cached locations which are children of it
+   * should be invalidate
+   */
+  @Test
+  public void testInvalidateCache() throws Exception {
+    // Add the entry 1->/ and ensure cache update correctly
+    Map<String, String> map1 = getMountTableEntry("1", "/");
+    MountTable entry1 = MountTable.newInstance("/", map1);
+    mountTable.addEntry(entry1);
+    assertEquals("1->/", mountTable.getDestinationForPath("/").toString());
+    assertEquals("1->/testInvalidateCache/foo", mountTable
+        .getDestinationForPath("/testInvalidateCache/foo").toString());
+
+    // Add the entry 2->/testInvalidateCache and ensure the cached location
+    // under it is invalidated correctly
+    Map<String, String> map2 = getMountTableEntry("2", "/testInvalidateCache");
+    MountTable entry2 = MountTable.newInstance("/testInvalidateCache", map2);
+    mountTable.addEntry(entry2);
+    assertEquals("2->/testInvalidateCache",
+        mountTable.getDestinationForPath("/testInvalidateCache").toString());
+    assertEquals("2->/testInvalidateCache/foo", mountTable
+        .getDestinationForPath("/testInvalidateCache/foo").toString());
+  }
 }