HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly (#1334)
HDFS-14761. RBF: MountTableResolver cannot invalidate cache correctly
This commit is contained in:
parent
20064b69a8
commit
894e2300d6
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue