Skip to content

Commit

Permalink
fix delete non existing page
Browse files Browse the repository at this point in the history
  • Loading branch information
jja725 committed Jun 5, 2024
1 parent 36b0b16 commit 49c8137
Showing 1 changed file with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,51 @@ 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(PageId pageId, boolean isTemporary) {
if (mState.get() != READ_WRITE) {
Metrics.DELETE_NOT_READY_ERRORS.inc();
Metrics.DELETE_ERRORS.inc();
return false;
}
ReadWriteLock pageLock = getPageLock(pageId);
try (LockResource r = new LockResource(pageLock.writeLock())) {
PageInfo pageInfo;
try (LockResource r1 = new LockResource(mPageMetaStore.getLock().writeLock())) {
try {
pageInfo = mPageMetaStore.removePage(pageId, isTemporary);
} catch (PageNotFoundException e) {
Metrics.DELETE_NON_EXISTING_PAGE_ERRORS.inc();
Metrics.DELETE_ERRORS.inc();
return true;
}
}
boolean ok = true;
try {
pageInfo.getLocalCacheDir().getPageStore().delete(pageInfo.getPageId(), isTemporary);
} catch (IOException e) {
LOG.error("Failed to delete page {} (isTemporary: {}) from pageStore.",
pageInfo.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: {}", pageId, 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.
Expand Down Expand Up @@ -921,7 +966,7 @@ public void invalidate(Predicate<PageInfo> predicate) {
PageInfo pageInfo = pageInfoOpt.get();
boolean isPageDeleted = false;
if (predicate.test(pageInfo)) {
isPageDeleted = delete(pageInfo.getPageId());
isPageDeleted = deletePageIfExists(pageInfo.getPageId(), false);
}
if (isPageDeleted) {
MetricsSystem.meter(MetricKey.CLIENT_CACHE_PAGES_INVALIDATED.getName()).mark();
Expand Down

0 comments on commit 49c8137

Please sign in to comment.