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 bug in prefetch cleanup #7277

Merged
merged 3 commits into from
Apr 4, 2024
Merged

Fix bug in prefetch cleanup #7277

merged 3 commits into from
Apr 4, 2024

Conversation

knizhnik
Copy link
Contributor

Problem

Running test_pageserver_restarts_under_workload in POR #7275 I get the following assertion failure in prefetch:

#5  0x00005587220d4bf0 in ExceptionalCondition (
    conditionName=0x7fbf24d003c8 "(ring_index) < MyPState->ring_unused && (ring_index) >= MyPState->ring_last", 
    fileName=0x7fbf24d00240 "/home/knizhnik/neon.main//pgxn/neon/pagestore_smgr.c", lineNumber=644)
    at /home/knizhnik/neon.main//vendor/postgres-v16/src/backend/utils/error/assert.c:66
#6  0x00007fbf24cebc9b in prefetch_set_unused (ring_index=1509) at /home/knizhnik/neon.main//pgxn/neon/pagestore_smgr.c:644
#7  0x00007fbf24cec613 in prefetch_register_buffer (tag=..., force_latest=0x0, force_lsn=0x0)
    at /home/knizhnik/neon.main//pgxn/neon/pagestore_smgr.c:891
#8  0x00007fbf24cef21e in neon_prefetch (reln=0x5587233b7388, forknum=MAIN_FORKNUM, blocknum=14110)
    at /home/knizhnik/neon.main//pgxn/neon/pagestore_smgr.c:2055

(gdb) p ring_index
$1 = 1509
(gdb) p MyPState->ring_unused
$2 = 1636
(gdb) p MyPState->ring_last
$3 = 1636

Summary of changes

Check status of prefetch_wait_for

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

@knizhnik
Copy link
Contributor Author

@MMeent please look at prefetch_set_unused code:

prefetch_set_unused(uint64 ring_index)
{
	PrefetchRequest *slot = GetPrfSlot(ring_index);

	if (ring_index < MyPState->ring_last)
		return;					/* Should already be unused */

	Assert(MyPState->ring_unused > ring_index);

GetPrfSlot contains assertion check:

#define GetPrfSlot(ring_index) ( \
	( \
		AssertMacro((ring_index) < MyPState->ring_unused && \
					(ring_index) >= MyPState->ring_last), \
		&MyPState->prf_buffer[((ring_index) % readahead_buffer_size)] \
	) \
)

which makes this checks contradictory or redundant.
If we really assume that prefetch_set_unused can be called for already unused slot, then we should move this check before
GetPrfSlot:

prefetch_set_unused(uint64 ring_index)
{
	PrefetchRequest *slot;

	if (ring_index < MyPState->ring_last)
		return;					/* Should already be unused */

	slot = GetPrfSlot(ring_index);
	if (slot->status == PRFS_UNUSED)
		return;

Copy link

github-actions bot commented Mar 29, 2024

2748 tests run: 2608 passed, 0 failed, 140 skipped (full report)


Code coverage* (full report)

  • functions: 28.1% (6385 of 22723 functions)
  • lines: 47.0% (44996 of 95824 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
c902a19 at 2024-04-03T15:36:26.997Z :recycle:

Reset prefetch queue even if connection is not yet established
@knizhnik knizhnik merged commit ae15acd into main Apr 4, 2024
53 checks passed
@knizhnik knizhnik deleted the prefetch_cleanup_fix branch April 4, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants