agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Justin Pryzby <[email protected]>
Subject: [PATCH v19 2/2] add callback for truncation
Date: Sun, 16 Feb 2020 20:25:13 -0600
---
src/backend/access/heap/vacuumlazy.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 5e734ee..de3b92f 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -2503,9 +2503,15 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
BlockNumber new_rel_pages;
PGRUsage ru0;
int lock_retry;
+ ErrorContextCallback errcallback;
+ vacuum_error_callback_arg errcbarg;
pg_rusage_init(&ru0);
+ /* Setup error traceback support for ereport() */
+ init_vacuum_error_callback(&errcallback, &errcbarg, onerel,
+ PROGRESS_VACUUM_PHASE_TRUNCATE);
+
/* Report that we are now truncating */
pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
PROGRESS_VACUUM_PHASE_TRUNCATE);
@@ -2586,11 +2592,18 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
return;
}
+ /* Setup error traceback support for ereport() */
+ errcbarg.blkno = new_rel_pages;
+ error_context_stack = &errcallback;
+
/*
* Okay to truncate.
*/
RelationTruncate(onerel, new_rel_pages);
+ /* Pop the error context stack */
+ error_context_stack = errcallback.previous;
+
/*
* We can release the exclusive lock as soon as we have truncated.
* Other backends can't safely access the relation until they have
@@ -2630,6 +2643,12 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
BlockNumber blkno;
BlockNumber prefetchedUntil;
instr_time starttime;
+ ErrorContextCallback errcallback;
+ vacuum_error_callback_arg errcbarg;
+
+ /* Setup error traceback support for ereport() */
+ init_vacuum_error_callback(&errcallback, &errcbarg, onerel,
+ PROGRESS_VACUUM_PHASE_TRUNCATE);
/* Initialize the starttime if we check for conflicting lock requests */
INSTR_TIME_SET_CURRENT(starttime);
@@ -2693,6 +2712,10 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
blkno--;
+ /* Setup error traceback support for ereport() */
+ errcbarg.blkno = blkno;
+ error_context_stack = &errcallback;
+
/* If we haven't prefetched this lot yet, do so now. */
if (prefetchedUntil > blkno)
{
@@ -2711,6 +2734,9 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
buf = ReadBufferExtended(onerel, MAIN_FORKNUM, blkno,
RBM_NORMAL, vac_strategy);
+ /* Pop the error context stack */
+ error_context_stack = errcallback.previous;
+
/* In this phase we only need shared access to the buffer */
LockBuffer(buf, BUFFER_LOCK_SHARE);
@@ -3470,6 +3496,10 @@ vacuum_error_callback(void *arg)
break;
case PROGRESS_VACUUM_PHASE_TRUNCATE:
+ errcontext(_("while truncating relation \"%s.%s\" to %u blocks"),
+ cbarg->relnamespace, cbarg->relname, cbarg->blkno);
+ break;
+
case PROGRESS_VACUUM_PHASE_FINAL_CLEANUP:
default:
return; /* Shouldn't happen: do nothing */
@@ -3485,6 +3515,7 @@ init_vacuum_error_callback(ErrorContextCallback *errcallback,
{
case PROGRESS_VACUUM_PHASE_SCAN_HEAP:
case PROGRESS_VACUUM_PHASE_VACUUM_HEAP:
+ case PROGRESS_VACUUM_PHASE_TRUNCATE:
errcbarg->relname = RelationGetRelationName(rel);
errcbarg->indname = NULL; /* Not used for heap */
break;
--
2.7.4
--2FkSFaIQeDFoAt0B--
view thread (10+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v19 2/2] add callback for truncation
In-Reply-To: <no-message-id-188578@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox