diff --git a/dora/core/client/fs/src/main/java/alluxio/client/file/cache/LocalCacheManager.java b/dora/core/client/fs/src/main/java/alluxio/client/file/cache/LocalCacheManager.java index 4874820581cc..35ce12dda13c 100644 --- a/dora/core/client/fs/src/main/java/alluxio/client/file/cache/LocalCacheManager.java +++ b/dora/core/client/fs/src/main/java/alluxio/client/file/cache/LocalCacheManager.java @@ -751,6 +751,50 @@ public boolean append(PageId pageId, int appendAt, byte[] page, CacheContext cac return put(pageId, page, cacheContext); } + /** + * delete the specified page. Be cautious that this method will return true if the page + * does not exist since the page already gone. + * + * @param pageId page identifier + * @param isTemporary whether is it temporary or not + * @return whether the page is deleted successfully or not + */ + public boolean deletePageIfExists(PageInfo info, boolean isTemporary) { + if (mState.get() != READ_WRITE) { + Metrics.DELETE_NOT_READY_ERRORS.inc(); + Metrics.DELETE_ERRORS.inc(); + return false; + } + boolean ok = true; + ReadWriteLock pageLock = getPageLock(info.getPageId()); + try (LockResource r = new LockResource(pageLock.writeLock())) { + try (LockResource r1 = new LockResource(mPageMetaStore.getLock().writeLock())) { + try { + mPageMetaStore.removePage(info.getPageId(), isTemporary); + } catch (PageNotFoundException e) { + Metrics.DELETE_NON_EXISTING_PAGE_ERRORS.inc(); + Metrics.DELETE_ERRORS.inc(); + // pass through to delete the page from page store + } + } + try { + info.getLocalCacheDir().getPageStore().delete(info.getPageId(), isTemporary); + } catch (IOException e) { + LOG.error("Failed to delete page {} (isTemporary: {}) from pageStore.", + info.getPageId(), isTemporary, e); + ok = false; + Metrics.DELETE_STORE_DELETE_ERRORS.inc(); + Metrics.DELETE_ERRORS.inc(); + } catch (PageNotFoundException e) { + Metrics.DELETE_NON_EXISTING_PAGE_ERRORS.inc(); + Metrics.DELETE_ERRORS.inc(); + ok = true; + } + LOG.debug("delete({}) exits, success: {}", info.getPageId(), ok); + return ok; + } + } + /** * Restores a page store at the configured location, updating meta store accordingly. * If restore process fails, cleanup the location and create a new page store. @@ -921,7 +965,7 @@ public void invalidate(Predicate predicate) { PageInfo pageInfo = pageInfoOpt.get(); boolean isPageDeleted = false; if (predicate.test(pageInfo)) { - isPageDeleted = delete(pageInfo.getPageId()); + isPageDeleted = deletePageIfExists(pageInfo, false); } if (isPageDeleted) { MetricsSystem.meter(MetricKey.CLIENT_CACHE_PAGES_INVALIDATED.getName()).mark();