Skip to content

Commit

Permalink
Fix the issue of deleting empty directories failing due to cache evic…
Browse files Browse the repository at this point in the history
…tion in CachingInodeStore.
  • Loading branch information
顾鹏 authored and gp1314 committed Aug 26, 2024
1 parent 9e373f0 commit 3da3a4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ public boolean hasChildren(InodeDirectoryView inode, ReadOption option) {
if (cached.isPresent()) {
return !cached.get().isEmpty();
}
return !mListingCache.getDataFromBackingStore(inode.getId(), option).isEmpty()
|| mBackingStore.hasChildren(inode);
return !mListingCache.getDataFromBackingStore(inode.getId(), option).isEmpty();
}

@VisibleForTesting
Expand Down Expand Up @@ -854,6 +853,11 @@ private void evict() {
mWeight.get(), System.currentTimeMillis() - startTime);
}

@VisibleForTesting
void evictForTesting() {
evict();
}

private int weight(ListingCacheEntry entry) {
Preconditions.checkNotNull(entry);
Preconditions.checkNotNull(entry.mChildren);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class CachingInodeStoreMockedBackingStoreTest {
ImmutableMap.of(PropertyKey.MASTER_METASTORE_INODE_CACHE_MAX_SIZE, CACHE_SIZE,
PropertyKey.MASTER_METASTORE_INODE_CACHE_EVICT_BATCH_SIZE, 5,
PropertyKey.LEAK_DETECTOR_LEVEL, ResourceLeakDetector.Level.PARANOID,
PropertyKey.LEAK_DETECTOR_EXIT_ON_LEAK, true),
PropertyKey.LEAK_DETECTOR_EXIT_ON_LEAK, true,
PropertyKey.MASTER_METASTORE_INODE_CACHE_LOW_WATER_MARK_RATIO, 0),
Configuration.modifiableGlobal());

@Before
Expand Down Expand Up @@ -335,6 +336,27 @@ public void skipCache() throws Exception {
assertEquals(0, mStore.mInodeCache.getCacheMap().size());
}

@Test
public void evictInodeForTestHasChildren() throws Exception {
MutableInodeDirectory myTestdir =
MutableInodeDirectory.create(500, 0, "guptest", CreateDirectoryContext.defaults());
mStore.writeNewInode(myTestdir);
mStore.mListingCache.evictForTesting();
mStore.mEdgeCache.flush();
mStore.mInodeCache.flush();

long id = 6000;
MutableInodeFile child =
MutableInodeFile.create(id, 500, "child" + id, 0, CreateFileContext.defaults());
mStore.writeNewInode(child);
mStore.addChild(500, child);

mStore.mEdgeCache.flush();

mStore.removeInodeAndParentEdge(child);
assertEquals(false, mStore.hasChildren(myTestdir));
}

private void verifyNoBackingStoreReads() {
verify(mBackingStore, times(0)).getChild(anyLong(), anyString());
verify(mBackingStore, times(0)).getChildId(anyLong(), anyString());
Expand Down

0 comments on commit 3da3a4a

Please sign in to comment.