Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failed to delete an empty directory due to cache evict #18675

Open
wants to merge 2 commits into
base: master-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding this test case! My understanding is, once your code is merged, this test case is no longer needed right? In other words, if your code is merged, assertEquals(false, mStore.hasChildren(myTestdir)); will return false.

MutableInodeDirectory myTestdir =
MutableInodeDirectory.create(500, 0, "evicttest", 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
Loading