From fe74fac2766d2b1bba7511028a157fdea775a1c3 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Tue, 10 Oct 2023 07:43:37 +0300 Subject: [PATCH] Fix handling flush error in prefetch (#5473) ## Problem See https://neondb.slack.com/archives/C05U648A9NJ In case of failure of flush in prefetch, prefetch state is reseted. We need to retry register buffer attempt, otherwise we will get assertion failure. ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist --------- Co-authored-by: Konstantin Knizhnik --- pgxn/neon/pagestore_smgr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pgxn/neon/pagestore_smgr.c b/pgxn/neon/pagestore_smgr.c index 2e4364cbfa..5e172a0be4 100644 --- a/pgxn/neon/pagestore_smgr.c +++ b/pgxn/neon/pagestore_smgr.c @@ -721,7 +721,7 @@ prefetch_register_buffer(BufferTag tag, bool *force_latest, XLogRecPtr *force_ls /* use an intermediate PrefetchRequest struct to ensure correct alignment */ req.buftag = tag; - + Retry: entry = prfh_lookup(MyPState->prf_hash, (PrefetchRequest *) &req); if (entry != NULL) @@ -858,7 +858,11 @@ prefetch_register_buffer(BufferTag tag, bool *force_latest, XLogRecPtr *force_ls if (flush_every_n_requests > 0 && MyPState->ring_unused - MyPState->ring_flush >= flush_every_n_requests) { - page_server->flush(); + if (!page_server->flush()) + { + /* Prefetch set is reset in case of error, so we should try to register our request once again */ + goto Retry; + } MyPState->ring_flush = MyPState->ring_unused; }