@@ -351,7 +351,6 @@ typedef struct LVRelState
351351 BlockNumber pages_removed ; /* pages remove by truncation */
352352 BlockNumber lpdead_item_pages ; /* # pages with LP_DEAD items */
353353 BlockNumber nonempty_pages ; /* actually, last nonempty page + 1 */
354- bool lock_waiter_detected ;
355354
356355 /* Statistics output by us, for table */
357356 double new_rel_tuples ; /* new estimated total # of tuples */
@@ -439,7 +438,8 @@ static IndexBulkDeleteResult *lazy_cleanup_one_index(Relation indrel,
439438static bool should_attempt_truncation (LVRelState * vacrel ,
440439 VacuumParams * params );
441440static void lazy_truncate_heap (LVRelState * vacrel );
442- static BlockNumber count_nondeletable_pages (LVRelState * vacrel );
441+ static BlockNumber count_nondeletable_pages (LVRelState * vacrel ,
442+ bool * lock_waiter_detected );
443443static long compute_max_dead_tuples (BlockNumber relblocks , bool hasindex );
444444static void lazy_space_alloc (LVRelState * vacrel , int nworkers ,
445445 BlockNumber relblocks );
@@ -929,7 +929,6 @@ lazy_scan_heap(LVRelState *vacrel, VacuumParams *params, bool aggressive)
929929 vacrel -> pages_removed = 0 ;
930930 vacrel -> lpdead_item_pages = 0 ;
931931 vacrel -> nonempty_pages = 0 ;
932- vacrel -> lock_waiter_detected = false;
933932
934933 /* Initialize instrumentation counters */
935934 vacrel -> num_index_scans = 0 ;
@@ -3165,6 +3164,7 @@ lazy_truncate_heap(LVRelState *vacrel)
31653164{
31663165 BlockNumber old_rel_pages = vacrel -> rel_pages ;
31673166 BlockNumber new_rel_pages ;
3167+ bool lock_waiter_detected ;
31683168 int lock_retry ;
31693169
31703170 /* Report that we are now truncating */
@@ -3187,7 +3187,7 @@ lazy_truncate_heap(LVRelState *vacrel)
31873187 * (which is quite possible considering we already hold a lower-grade
31883188 * lock).
31893189 */
3190- vacrel -> lock_waiter_detected = false;
3190+ lock_waiter_detected = false;
31913191 lock_retry = 0 ;
31923192 while (true)
31933193 {
@@ -3207,7 +3207,7 @@ lazy_truncate_heap(LVRelState *vacrel)
32073207 * We failed to establish the lock in the specified number of
32083208 * retries. This means we give up truncating.
32093209 */
3210- vacrel -> lock_waiter_detected = true;
3210+ lock_waiter_detected = true;
32113211 ereport (elevel ,
32123212 (errmsg ("\"%s\": stopping truncate due to conflicting lock request" ,
32133213 vacrel -> relname )));
@@ -3242,7 +3242,7 @@ lazy_truncate_heap(LVRelState *vacrel)
32423242 * other backends could have added tuples to these pages whilst we
32433243 * were vacuuming.
32443244 */
3245- new_rel_pages = count_nondeletable_pages (vacrel );
3245+ new_rel_pages = count_nondeletable_pages (vacrel , & lock_waiter_detected );
32463246 vacrel -> blkno = new_rel_pages ;
32473247
32483248 if (new_rel_pages >= old_rel_pages )
@@ -3281,8 +3281,7 @@ lazy_truncate_heap(LVRelState *vacrel)
32813281 errdetail_internal ("%s" ,
32823282 pg_rusage_show (& ru0 ))));
32833283 old_rel_pages = new_rel_pages ;
3284- } while (new_rel_pages > vacrel -> nonempty_pages &&
3285- vacrel -> lock_waiter_detected );
3284+ } while (new_rel_pages > vacrel -> nonempty_pages && lock_waiter_detected );
32863285}
32873286
32883287/*
@@ -3291,7 +3290,7 @@ lazy_truncate_heap(LVRelState *vacrel)
32913290 * Returns number of nondeletable pages (last nonempty page + 1).
32923291 */
32933292static BlockNumber
3294- count_nondeletable_pages (LVRelState * vacrel )
3293+ count_nondeletable_pages (LVRelState * vacrel , bool * lock_waiter_detected )
32953294{
32963295 BlockNumber blkno ;
32973296 BlockNumber prefetchedUntil ;
@@ -3343,7 +3342,7 @@ count_nondeletable_pages(LVRelState *vacrel)
33433342 (errmsg ("\"%s\": suspending truncate due to conflicting lock request" ,
33443343 vacrel -> relname )));
33453344
3346- vacrel -> lock_waiter_detected = true;
3345+ * lock_waiter_detected = true;
33473346 return blkno ;
33483347 }
33493348 starttime = currenttime ;
0 commit comments