@Test public void testInvalidatePrefix() throws Exception { metadataCache = new MetadataCache(1024, 3600); Stat.Builder a, b, c, d; a = getIntializedStatBuilder(); b = getIntializedStatBuilder(); c = getIntializedStatBuilder(); d = getIntializedStatBuilder(); a.setIno(0); b.setIno(1); c.setIno(2); d.setIno(3); String dir = "/dir"; metadataCache.updateStat(dir, a.build()); metadataCache.updateStat(dir + "/file1", b.build()); metadataCache.updateStat(dir + ".file1", c.build()); metadataCache.updateStat(dir + "Zfile1", d.build()); metadataCache.invalidatePrefix(dir); assertNull(metadataCache.getStat(dir)); assertNull(metadataCache.getStat(dir + "/file1")); Stat statC = metadataCache.getStat(dir + ".file1"); assertNotNull(statC); assertEquals(2, statC.getIno()); Stat statD = metadataCache.getStat(dir + "Zfile1"); assertNotNull(statD); assertEquals(3, statD.getIno()); }
protected void invalidatePrefix(String path) { if (path.isEmpty() || !enabled) { return; } List<String> indicesToRemove = new ArrayList<String>(); writeLock.lock(); try { cache.remove(path); pathIndex.remove(path); if (!path.endsWith("/")) { path = path + "/"; } for (String deletePath : pathIndex.tailSet(path)) { if (!deletePath.startsWith(path)) { break; } cache.remove(deletePath); indicesToRemove.add(deletePath); } pathIndex.removeAll(indicesToRemove); } finally { writeLock.unlock(); } }
MetadataCache { protected void invalidatePrefix(String path) { if (path.isEmpty() || !enabled) { return; } List<String> indicesToRemove = new ArrayList<String>(); writeLock.lock(); try { cache.remove(path); pathIndex.remove(path); if (!path.endsWith("/")) { path = path + "/"; } for (String deletePath : pathIndex.tailSet(path)) { if (!deletePath.startsWith(path)) { break; } cache.remove(deletePath); indicesToRemove.add(deletePath); } pathIndex.removeAll(indicesToRemove); } finally { writeLock.unlock(); } } }
MetadataCache { protected void invalidatePrefix(String path) { if (path.isEmpty() || !enabled) { return; } List<String> indicesToRemove = new ArrayList<String>(); writeLock.lock(); try { cache.remove(path); pathIndex.remove(path); if (!path.endsWith("/")) { path = path + "/"; } for (String deletePath : pathIndex.tailSet(path)) { if (!deletePath.startsWith(path)) { break; } cache.remove(deletePath); indicesToRemove.add(deletePath); } pathIndex.removeAll(indicesToRemove); } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS); }
MetadataCache { protected void invalidatePrefix(String path) { if (path.isEmpty() || !enabled) { return; } List<String> indicesToRemove = new ArrayList<String>(); writeLock.lock(); try { cache.remove(path); pathIndex.remove(path); if (!path.endsWith("/")) { path = path + "/"; } for (String deletePath : pathIndex.tailSet(path)) { if (!deletePath.startsWith(path)) { break; } cache.remove(deletePath); indicesToRemove.add(deletePath); } pathIndex.removeAll(indicesToRemove); } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS);  }
MetadataCache { protected void invalidatePrefix(String path) { if (path.isEmpty() || !enabled) { return; } List<String> indicesToRemove = new ArrayList<String>(); writeLock.lock(); try { cache.remove(path); pathIndex.remove(path); if (!path.endsWith("/")) { path = path + "/"; } for (String deletePath : pathIndex.tailSet(path)) { if (!deletePath.startsWith(path)) { break; } cache.remove(deletePath); indicesToRemove.add(deletePath); } pathIndex.removeAll(indicesToRemove); } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS);   }