@Test public void testInvalidateDirEntry() throws Exception { metadataCache.invalidateDirEntry("not exists", "no name"); metadataCache.updateStat("foobar", getIntializedStatBuilder().build()); metadataCache.invalidateDirEntry("foobar", "no name"); DirectoryEntries entries = getDummyDirEntries(); DirectoryEntry entry = DirectoryEntry.newBuilder().setName("dir1") .setStbuf(getIntializedStatBuilder()).build(); DirectoryEntry entry2 = DirectoryEntry.newBuilder().setName("dir2") .setStbuf(getIntializedStatBuilder()).build(); entries = entries.toBuilder().addEntries(entry).addEntries(entry2).build(); metadataCache.updateDirEntries("foobar", entries); DirectoryEntries getEntries = metadataCache.getDirEntries("foobar", 0, 10); assertEquals(entries, getEntries); metadataCache.invalidateDirEntry("foobar", "dir2"); getEntries = metadataCache.getDirEntries("foobar", 0, 10); assertEquals(2, getEntries.getEntriesCount()); for (DirectoryEntry dirEntry : getEntries.getEntriesList()) { assertNotSame("dir2", dirEntry.getName()); } }
protected void invalidateDirEntry(String pathToDirectory, String entryName) { if (pathToDirectory.isEmpty() || entryName.isEmpty() || !enabled) { return; } writeLock.lock(); try { MetadataCacheEntry entry = cache.get(pathToDirectory); if (entry != null) { if (entry.getDirectoryEntries() == null) { return; } DirectoryEntries.Builder dirEntriesBuilder = DirectoryEntries.newBuilder(); for (int i = 0; i < entry.getDirectoryEntries().getEntriesCount(); i++) { if (!entry.getDirectoryEntries().getEntries(i).getName().equals(entryName)) { dirEntriesBuilder.addEntries(entry.getDirectoryEntries().getEntries(i)); } } entry.setDirectoryEntries(dirEntriesBuilder.build()); } } finally { writeLock.unlock(); } }
MetadataCache { protected void invalidateDirEntry(String pathToDirectory, String entryName) { if (pathToDirectory.isEmpty() || entryName.isEmpty() || !enabled) { return; } writeLock.lock(); try { MetadataCacheEntry entry = cache.get(pathToDirectory); if (entry != null) { if (entry.getDirectoryEntries() == null) { return; } DirectoryEntries.Builder dirEntriesBuilder = DirectoryEntries.newBuilder(); for (int i = 0; i < entry.getDirectoryEntries().getEntriesCount(); i++) { if (!entry.getDirectoryEntries().getEntries(i).getName().equals(entryName)) { dirEntriesBuilder.addEntries(entry.getDirectoryEntries().getEntries(i)); } } entry.setDirectoryEntries(dirEntriesBuilder.build()); } } finally { writeLock.unlock(); } } }
MetadataCache { protected void invalidateDirEntry(String pathToDirectory, String entryName) { if (pathToDirectory.isEmpty() || entryName.isEmpty() || !enabled) { return; } writeLock.lock(); try { MetadataCacheEntry entry = cache.get(pathToDirectory); if (entry != null) { if (entry.getDirectoryEntries() == null) { return; } DirectoryEntries.Builder dirEntriesBuilder = DirectoryEntries.newBuilder(); for (int i = 0; i < entry.getDirectoryEntries().getEntriesCount(); i++) { if (!entry.getDirectoryEntries().getEntries(i).getName().equals(entryName)) { dirEntriesBuilder.addEntries(entry.getDirectoryEntries().getEntries(i)); } } entry.setDirectoryEntries(dirEntriesBuilder.build()); } } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS); }
MetadataCache { protected void invalidateDirEntry(String pathToDirectory, String entryName) { if (pathToDirectory.isEmpty() || entryName.isEmpty() || !enabled) { return; } writeLock.lock(); try { MetadataCacheEntry entry = cache.get(pathToDirectory); if (entry != null) { if (entry.getDirectoryEntries() == null) { return; } DirectoryEntries.Builder dirEntriesBuilder = DirectoryEntries.newBuilder(); for (int i = 0; i < entry.getDirectoryEntries().getEntriesCount(); i++) { if (!entry.getDirectoryEntries().getEntries(i).getName().equals(entryName)) { dirEntriesBuilder.addEntries(entry.getDirectoryEntries().getEntries(i)); } } entry.setDirectoryEntries(dirEntriesBuilder.build()); } } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS);  }
MetadataCache { protected void invalidateDirEntry(String pathToDirectory, String entryName) { if (pathToDirectory.isEmpty() || entryName.isEmpty() || !enabled) { return; } writeLock.lock(); try { MetadataCacheEntry entry = cache.get(pathToDirectory); if (entry != null) { if (entry.getDirectoryEntries() == null) { return; } DirectoryEntries.Builder dirEntriesBuilder = DirectoryEntries.newBuilder(); for (int i = 0; i < entry.getDirectoryEntries().getEntriesCount(); i++) { if (!entry.getDirectoryEntries().getEntries(i).getName().equals(entryName)) { dirEntriesBuilder.addEntries(entry.getDirectoryEntries().getEntries(i)); } } entry.setDirectoryEntries(dirEntriesBuilder.build()); } } finally { writeLock.unlock(); } } protected  MetadataCache(long maxNumberOfEntries, long ttlS);   }