Hi Amit and Andres, Here's updated patch On Mon, Aug 9, 2021 at 11:14 AM Ashutosh Bapat < ashutosh.ba...@enterprisedb.com> wrote:
> > > On Sat, Aug 7, 2021 at 11:40 AM Andres Freund <and...@anarazel.de> wrote: > >> Hi, >> >> On 2021-07-12 17:28:15 +0530, Ashutosh Bapat wrote: >> > On Mon, Jul 12, 2021 at 8:39 AM Amit Kapila <amit.kapil...@gmail.com> >> wrote: >> > >> > > On Mon, Jul 5, 2021 at 12:54 PM Masahiko Sawada < >> sawada.m...@gmail.com> >> > > Today, again looking at this patch, I don't think doing elog inside >> > > spinlock is a good idea. We can either release spinlock before it or >> > > use some variable to remember that we need to write such an elog and >> > > do it after releasing the lock. What do you think? >> > >> > >> > The elog will be effective only under DEBUG1, otherwise it will be >> almost a >> > NOOP. I am wondering whether it's worth adding a bool assignment and >> move >> > the elog out only for DEBUG1. Anyway, will defer it to you. >> >> It's *definitely* not ok to do an elog() while holding a spinlock. >> Consider >> what happens if the elog tries to format the message and runs out of >> memory. Or if elog detects the stack depth is too deep. An ERROR would be >> thrown, and we'd loose track of the held spinlock. >> > > Thanks for the clarification. > > Amit, > I will provide the patch changed accordingly. > > -- > Best Wishes, > Ashutosh > -- -- Best Wishes, Ashutosh
From 0a2f2c1f530d72219d9db7bd1ff77c1ae8c4ffe4 Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat <ashutosh.ba...@2ndquadrant.com> Date: Thu, 13 May 2021 13:40:33 +0530 Subject: [PATCH] Report new catalog_xmin candidate in LogicalIncreaseXminForSlot() Similar to LogicalIncreaseRestartDecodingForSlot() add a debug message to LogicalIncreaseXminForSlot() reporting a new catalog_xmin candidate. --- src/backend/replication/logical/logical.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 64b8280c13..6c8c387e73 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -1565,6 +1565,7 @@ LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin) { bool updated_xmin = false; ReplicationSlot *slot; + bool got_new_xmin = false; slot = MyReplicationSlot; @@ -1602,12 +1603,22 @@ LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin) { slot->candidate_catalog_xmin = xmin; slot->candidate_xmin_lsn = current_lsn; + + /* + * Add a line about new xmin in server logs at an appropriate log level + * after releasing the spinlock. + */ + got_new_xmin = true; } SpinLockRelease(&slot->mutex); /* candidate already valid with the current flush position, apply */ if (updated_xmin) LogicalConfirmReceivedLocation(slot->data.confirmed_flush); + + if (got_new_xmin) + elog(DEBUG1, "got new catalog_xmin %u at %X/%X", xmin, + LSN_FORMAT_ARGS(current_lsn)); } /* -- 2.25.1