From 894e2300d60f6222b80ed5afca22e4e17551cf6a Mon Sep 17 00:00:00 2001 From: Wang Yuxuan <601377065@qq.com> Date: Sat, 24 Aug 2019 01:46:39 +0800 Subject: [PATCH] HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly (#1334) HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly --- .../resolver/MountTableResolver.java | 3 ++- .../resolver/TestMountTableResolver.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java index 8baa5e22a1..c72afc57da 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java @@ -257,10 +257,11 @@ private void invalidateLocationCache(final String path) { Iterator> it = entries.iterator(); while (it.hasNext()) { Entry 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(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java index ada2815872..32c54d9cb7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java @@ -704,4 +704,29 @@ public void testLocationCache() throws Exception { 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 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 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()); + } } \ No newline at end of file