@@ -351,7 +351,6 @@ typedef struct LVRelState
351
351
BlockNumber pages_removed ; /* pages remove by truncation */
352
352
BlockNumber lpdead_item_pages ; /* # pages with LP_DEAD items */
353
353
BlockNumber nonempty_pages ; /* actually, last nonempty page + 1 */
354
- bool lock_waiter_detected ;
355
354
356
355
/* Statistics output by us, for table */
357
356
double new_rel_tuples ; /* new estimated total # of tuples */
@@ -439,7 +438,8 @@ static IndexBulkDeleteResult *lazy_cleanup_one_index(Relation indrel,
439
438
static bool should_attempt_truncation (LVRelState * vacrel ,
440
439
VacuumParams * params );
441
440
static 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 );
443
443
static long compute_max_dead_tuples (BlockNumber relblocks , bool hasindex );
444
444
static void lazy_space_alloc (LVRelState * vacrel , int nworkers ,
445
445
BlockNumber relblocks );
@@ -929,7 +929,6 @@ lazy_scan_heap(LVRelState *vacrel, VacuumParams *params, bool aggressive)
929
929
vacrel -> pages_removed = 0 ;
930
930
vacrel -> lpdead_item_pages = 0 ;
931
931
vacrel -> nonempty_pages = 0 ;
932
- vacrel -> lock_waiter_detected = false;
933
932
934
933
/* Initialize instrumentation counters */
935
934
vacrel -> num_index_scans = 0 ;
@@ -3165,6 +3164,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3165
3164
{
3166
3165
BlockNumber old_rel_pages = vacrel -> rel_pages ;
3167
3166
BlockNumber new_rel_pages ;
3167
+ bool lock_waiter_detected ;
3168
3168
int lock_retry ;
3169
3169
3170
3170
/* Report that we are now truncating */
@@ -3187,7 +3187,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3187
3187
* (which is quite possible considering we already hold a lower-grade
3188
3188
* lock).
3189
3189
*/
3190
- vacrel -> lock_waiter_detected = false;
3190
+ lock_waiter_detected = false;
3191
3191
lock_retry = 0 ;
3192
3192
while (true)
3193
3193
{
@@ -3207,7 +3207,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3207
3207
* We failed to establish the lock in the specified number of
3208
3208
* retries. This means we give up truncating.
3209
3209
*/
3210
- vacrel -> lock_waiter_detected = true;
3210
+ lock_waiter_detected = true;
3211
3211
ereport (elevel ,
3212
3212
(errmsg ("\"%s\": stopping truncate due to conflicting lock request" ,
3213
3213
vacrel -> relname )));
@@ -3242,7 +3242,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3242
3242
* other backends could have added tuples to these pages whilst we
3243
3243
* were vacuuming.
3244
3244
*/
3245
- new_rel_pages = count_nondeletable_pages (vacrel );
3245
+ new_rel_pages = count_nondeletable_pages (vacrel , & lock_waiter_detected );
3246
3246
vacrel -> blkno = new_rel_pages ;
3247
3247
3248
3248
if (new_rel_pages >= old_rel_pages )
@@ -3281,8 +3281,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3281
3281
errdetail_internal ("%s" ,
3282
3282
pg_rusage_show (& ru0 ))));
3283
3283
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 );
3286
3285
}
3287
3286
3288
3287
/*
@@ -3291,7 +3290,7 @@ lazy_truncate_heap(LVRelState *vacrel)
3291
3290
* Returns number of nondeletable pages (last nonempty page + 1).
3292
3291
*/
3293
3292
static BlockNumber
3294
- count_nondeletable_pages (LVRelState * vacrel )
3293
+ count_nondeletable_pages (LVRelState * vacrel , bool * lock_waiter_detected )
3295
3294
{
3296
3295
BlockNumber blkno ;
3297
3296
BlockNumber prefetchedUntil ;
@@ -3343,7 +3342,7 @@ count_nondeletable_pages(LVRelState *vacrel)
3343
3342
(errmsg ("\"%s\": suspending truncate due to conflicting lock request" ,
3344
3343
vacrel -> relname )));
3345
3344
3346
- vacrel -> lock_waiter_detected = true;
3345
+ * lock_waiter_detected = true;
3347
3346
return blkno ;
3348
3347
}
3349
3348
starttime = currenttime ;
0 commit comments