Skip to content

Commit 4c08ecd

Browse files
Fix assertion when decrementing eager scanning success and failure counters.
Previously, we asserted that the eager scan's success and failure counters were positive before decrementing them. However, this assumption was incorrect, as it's possible that some blocks have already been eagerly scanned by the time eager scanning is disabled. This commit replaces the assertions with guards to handle this scenario gracefully. With this change, we continue to allow read-ahead operations by the read stream that exceed the success and failure caps. While there is a possibility that overruns will trigger eager scans of additional pages, this does not pose a practical concern as the overruns will not be substantial and remain within an acceptable range. Reviewed-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://postgr.es/m/CAD21AoConf6tkVCv-=JhQJj56kYsDwo4jG5+WqgT+ukSkYomSQ@mail.gmail.com
1 parent c53f3b9 commit 4c08ecd

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,25 @@ lazy_scan_heap(LVRelState *vacrel)
14131413

14141414
if (vm_page_frozen)
14151415
{
1416-
Assert(vacrel->eager_scan_remaining_successes > 0);
1417-
vacrel->eager_scan_remaining_successes--;
1416+
if (vacrel->eager_scan_remaining_successes > 0)
1417+
vacrel->eager_scan_remaining_successes--;
14181418

14191419
if (vacrel->eager_scan_remaining_successes == 0)
14201420
{
1421+
/*
1422+
* Report only once that we disabled eager scanning. We
1423+
* may eagerly read ahead blocks in excess of the success
1424+
* or failure caps before attempting to freeze them, so we
1425+
* could reach here even after disabling additional eager
1426+
* scanning.
1427+
*/
1428+
if (vacrel->eager_scan_max_fails_per_region > 0)
1429+
ereport(vacrel->verbose ? INFO : DEBUG2,
1430+
(errmsg("disabling eager scanning after freezing %u eagerly scanned blocks of \"%s.%s.%s\"",
1431+
orig_eager_scan_success_limit,
1432+
vacrel->dbname, vacrel->relnamespace,
1433+
vacrel->relname)));
1434+
14211435
/*
14221436
* If we hit our success cap, permanently disable eager
14231437
* scanning by setting the other eager scan management
@@ -1426,19 +1440,10 @@ lazy_scan_heap(LVRelState *vacrel)
14261440
vacrel->eager_scan_remaining_fails = 0;
14271441
vacrel->next_eager_scan_region_start = InvalidBlockNumber;
14281442
vacrel->eager_scan_max_fails_per_region = 0;
1429-
1430-
ereport(vacrel->verbose ? INFO : DEBUG2,
1431-
(errmsg("disabling eager scanning after freezing %u eagerly scanned blocks of \"%s.%s.%s\"",
1432-
orig_eager_scan_success_limit,
1433-
vacrel->dbname, vacrel->relnamespace,
1434-
vacrel->relname)));
14351443
}
14361444
}
1437-
else
1438-
{
1439-
Assert(vacrel->eager_scan_remaining_fails > 0);
1445+
else if (vacrel->eager_scan_remaining_fails > 0)
14401446
vacrel->eager_scan_remaining_fails--;
1441-
}
14421447
}
14431448

14441449
/*

0 commit comments

Comments
 (0)