From 3da3a4a979565504ef917b1e94756117ab26d5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=BE=E9=B9=8F?= Date: Mon, 26 Aug 2024 11:43:19 +0800 Subject: [PATCH] Fix the issue of deleting empty directories failing due to cache eviction in CachingInodeStore. --- .../metastore/caching/CachingInodeStore.java | 8 +++++-- ...chingInodeStoreMockedBackingStoreTest.java | 24 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/server/master/src/main/java/alluxio/master/metastore/caching/CachingInodeStore.java b/core/server/master/src/main/java/alluxio/master/metastore/caching/CachingInodeStore.java index 614e5683c34a..b7ed0de3534b 100644 --- a/core/server/master/src/main/java/alluxio/master/metastore/caching/CachingInodeStore.java +++ b/core/server/master/src/main/java/alluxio/master/metastore/caching/CachingInodeStore.java @@ -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 @@ -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); diff --git a/core/server/master/src/test/java/alluxio/master/metastore/caching/CachingInodeStoreMockedBackingStoreTest.java b/core/server/master/src/test/java/alluxio/master/metastore/caching/CachingInodeStoreMockedBackingStoreTest.java index ab85e4fbb807..184405bb5110 100644 --- a/core/server/master/src/test/java/alluxio/master/metastore/caching/CachingInodeStoreMockedBackingStoreTest.java +++ b/core/server/master/src/test/java/alluxio/master/metastore/caching/CachingInodeStoreMockedBackingStoreTest.java @@ -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 @@ -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());