diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 58bc3df..39a0fdb 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -319,6 +319,13 @@ typedef struct LVRelStats VacErrPhase phase; } LVRelStats; +/* Struct for saving and restoring vacuum error information. */ +typedef struct LVSavedErrInfo +{ + BlockNumber blkno; + VacErrPhase phase; +} LVSavedErrInfo; + /* A few variables that don't seem worth passing around as parameters */ static int elevel = -1; @@ -388,8 +395,9 @@ static void end_parallel_vacuum(Relation *Irel, IndexBulkDeleteResult **stats, static LVSharedIndStats *get_indstats(LVShared *lvshared, int n); static bool skip_parallel_vacuum_index(Relation indrel, LVShared *lvshared); static void vacuum_error_callback(void *arg); -static void update_vacuum_error_info(LVRelStats *errinfo, int phase, - BlockNumber blkno); +static void update_vacuum_error_info(LVRelStats *errinfo, LVSavedErrInfo *oldpos, + int phase, BlockNumber blkno); +static void restore_vacuum_error_info(LVRelStats *errinfo, const LVSavedErrInfo *oldpos); /* @@ -538,7 +546,7 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, * which we add context information to errors, so we don't need to * revert to the previous phase. */ - update_vacuum_error_info(vacrelstats, VACUUM_ERRCB_PHASE_TRUNCATE, + update_vacuum_error_info(vacrelstats, NULL, VACUUM_ERRCB_PHASE_TRUNCATE, vacrelstats->nonempty_pages); lazy_truncate_heap(onerel, vacrelstats); } @@ -948,7 +956,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED, blkno); - update_vacuum_error_info(vacrelstats, VACUUM_ERRCB_PHASE_SCAN_HEAP, + update_vacuum_error_info(vacrelstats, NULL, VACUUM_ERRCB_PHASE_SCAN_HEAP, blkno); if (blkno == next_unskippable_block) @@ -1820,15 +1828,14 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats) int npages; PGRUsage ru0; Buffer vmbuffer = InvalidBuffer; - LVRelStats olderrinfo; + LVSavedErrInfo oldpos; /* Report that we are now vacuuming the heap */ pgstat_progress_update_param(PROGRESS_VACUUM_PHASE, PROGRESS_VACUUM_PHASE_VACUUM_HEAP); /* Update error traceback information */ - olderrinfo = *vacrelstats; - update_vacuum_error_info(vacrelstats, VACUUM_ERRCB_PHASE_VACUUM_HEAP, + update_vacuum_error_info(vacrelstats, &oldpos, VACUUM_ERRCB_PHASE_VACUUM_HEAP, InvalidBlockNumber); pg_rusage_init(&ru0); @@ -1879,9 +1886,7 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats) errdetail_internal("%s", pg_rusage_show(&ru0)))); /* Revert to the previous phase information for error traceback */ - update_vacuum_error_info(vacrelstats, - olderrinfo.phase, - olderrinfo.blkno); + restore_vacuum_error_info(vacrelstats, &oldpos); } /* @@ -1904,13 +1909,12 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, int uncnt = 0; TransactionId visibility_cutoff_xid; bool all_frozen; - LVRelStats olderrinfo; + LVSavedErrInfo oldpos; pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, blkno); /* Update error traceback information */ - olderrinfo = *vacrelstats; - update_vacuum_error_info(vacrelstats, VACUUM_ERRCB_PHASE_VACUUM_HEAP, + update_vacuum_error_info(vacrelstats, &oldpos, VACUUM_ERRCB_PHASE_VACUUM_HEAP, blkno); START_CRIT_SECTION(); @@ -1990,9 +1994,7 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, } /* Revert to the previous phase information for error traceback */ - update_vacuum_error_info(vacrelstats, - olderrinfo.phase, - olderrinfo.blkno); + restore_vacuum_error_info(vacrelstats, &oldpos); return tupindex; } @@ -2402,7 +2404,7 @@ lazy_vacuum_index(Relation indrel, IndexBulkDeleteResult **stats, IndexVacuumInfo ivinfo; const char *msg; PGRUsage ru0; - LVRelStats olderrinfo; + LVSavedErrInfo oldpos; pg_rusage_init(&ru0); @@ -2414,16 +2416,15 @@ lazy_vacuum_index(Relation indrel, IndexBulkDeleteResult **stats, ivinfo.num_heap_tuples = reltuples; ivinfo.strategy = vac_strategy; - /* Update error traceback information */ - olderrinfo = *vacrelstats; - /* + * Update error traceback information. + * * The index name is saved only during this phase and restored immediately * after this phase. See vacuum_error_callback. */ Assert(vacrelstats->indname == NULL); vacrelstats->indname = pstrdup(RelationGetRelationName(indrel)); - update_vacuum_error_info(vacrelstats, + update_vacuum_error_info(vacrelstats, &oldpos, VACUUM_ERRCB_PHASE_VACUUM_INDEX, InvalidBlockNumber); @@ -2443,9 +2444,7 @@ lazy_vacuum_index(Relation indrel, IndexBulkDeleteResult **stats, errdetail_internal("%s", pg_rusage_show(&ru0)))); /* Revert to the previous phase information for error traceback */ - update_vacuum_error_info(vacrelstats, - olderrinfo.phase, - olderrinfo.blkno); + restore_vacuum_error_info(vacrelstats, &oldpos); pfree(vacrelstats->indname); vacrelstats->indname = NULL; } @@ -2464,7 +2463,7 @@ lazy_cleanup_index(Relation indrel, IndexVacuumInfo ivinfo; const char *msg; PGRUsage ru0; - LVRelStats olderrcbarg; + LVSavedErrInfo oldpos; pg_rusage_init(&ru0); @@ -2477,25 +2476,22 @@ lazy_cleanup_index(Relation indrel, ivinfo.num_heap_tuples = reltuples; ivinfo.strategy = vac_strategy; - /* Update error traceback information */ - olderrcbarg = *vacrelstats; - /* + * Update error traceback information. + * * The index name is saved only during this phase and restored immediately * after this phase. See vacuum_error_callback. */ Assert(vacrelstats->indname == NULL); vacrelstats->indname = pstrdup(RelationGetRelationName(indrel)); - update_vacuum_error_info(vacrelstats, + update_vacuum_error_info(vacrelstats, &oldpos, VACUUM_ERRCB_PHASE_INDEX_CLEANUP, InvalidBlockNumber); *stats = index_vacuum_cleanup(&ivinfo, *stats); /* Revert back to the old phase information for error traceback */ - update_vacuum_error_info(vacrelstats, - olderrcbarg.phase, - olderrcbarg.blkno); + restore_vacuum_error_info(vacrelstats, &oldpos); pfree(vacrelstats->indname); vacrelstats->indname = NULL; @@ -3611,10 +3607,30 @@ vacuum_error_callback(void *arg) } } -/* Update vacuum error callback for the current phase and block. */ +/* + * Updates the information required for vacuum error callback. This also saves + * the current information which can be later restored via restore_vacuum_error_info. + */ static void -update_vacuum_error_info(LVRelStats *errinfo, int phase, BlockNumber blkno) +update_vacuum_error_info(LVRelStats *errinfo, LVSavedErrInfo *oldpos, int phase, + BlockNumber blkno) { + if (oldpos) + { + oldpos->blkno = errinfo->blkno; + oldpos->phase = errinfo->phase; + } + errinfo->blkno = blkno; errinfo->phase = phase; } + +/* + * Restores the vacuum information saved via a prior call to update_vacuum_error_info. + */ +static void +restore_vacuum_error_info(LVRelStats *errinfo, const LVSavedErrInfo *oldpos) +{ + errinfo->blkno = oldpos->blkno; + errinfo->phase = oldpos->phase; +} diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index c65a552..7eaaad1 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -1250,6 +1250,7 @@ LUID LVDeadTuples LVParallelState LVRelStats +LVSavedErrInfo LVShared LVSharedIndStats LWLock