From: | Peter Smith <smithpb2250(at)gmail(dot)com> |
---|---|
To: | Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com> |
Subject: | Re: Avoid updating inactive_since for invalid replication slots |
Date: | 2025-02-04 03:06:32 |
Message-ID: | CAHut+PuBg3SPGAUDmgSBag+w2XxUC0NH8TVv5NAZE4FGhvLbeQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Nisha.
Some review comments for patch v1-0001
======
GENERAL - Missing Test case?
1.
Should there be some before/after test case for 'active_since' value
with invalid slots to verify that the patch is doing what it says?
======
src/backend/replication/slot.c
ReplicationSlotAcquire:
2.
I saw some other code in ReplicationSlotAcquire doing:
/*
* Reset the time since the slot has become inactive as the slot is active
* now.
*/
SpinLockAcquire(&s->mutex);
s->inactive_since = 0;
SpinLockRelease(&s->mutex);
~
Should that be changed to use the new function like:
ReplicationSlotSetInactiveSince(s, 0, true);
Or (if not) then it probably needs a comment to say why not.
~~~
RestoreSlotFromDisk:
3.
+ if (now == 0)
+ now = GetCurrentTimestamp();
+
+ ReplicationSlotSetInactiveSince(slot, now, false);
3a.
The code from v65-0001 in the other thread [1] (where the bulk of this
v1 patch came from) used to have a RestoreSlotFromDisk function
comment saying "Avoid calling ReplicationSlotSetInactiveSince() here,
as it will not set the time for invalid slots."
In other words, yesterday we were deliberately NOT calling function
ReplicationSlotSetInactiveSince, but today we deliberately ARE calling
it (???).
Why has it changed?
~~~
3b.
The other code that is similar to this deferred assignment of 'now'
(see function update_synced_slots_inactive_since) includes a comment
/* Use the same inactive_since time for all the slots. */.
Should this code do the same?
~
======
src/include/replication/slot.h
4.
+static inline void
+ReplicationSlotSetInactiveSince(ReplicationSlot *s, TimestampTz now,
+ bool acquire_lock)
+{
+ if (s->data.invalidated != RS_INVAL_NONE)
+ return;
+
+ if (acquire_lock)
+ SpinLockAcquire(&s->mutex);
+
+ s->inactive_since = now;
+
+ if (acquire_lock)
+ SpinLockRelease(&s->mutex);
+}
+
4a.
I think it might not be a good idea to call the parameter 'now',
because that might not always be the meaning -- e.g. In another
comment I suggested passing a value 0.
A more generic TimestampTz name like 'ts' might be better here; just
the caller argument can be called 'now' when appropriate.
~
4b.
Since this is a static inline function I assume performance is
important (e.g. sometimes it is called within a spinlock). If that is
the case, then maybe writing this logic with fewer conditions would be
better.
SUGGESTION
if (s->data.invalidated == RS_INVAL_NONE)
{
if (acquire_lock)
{
SpinLockAcquire(&s->mutex);
s->inactive_since = ts;
SpinLockRelease(&s->mutex);
}
else
s->inactive_since = now;
}
Kind Regards,
Peter Smith.
Fujitsu Australia
From | Date | Subject | |
---|---|---|---|
Next Message | vignesh C | 2025-02-04 03:19:17 | Re: Proposal: Filter irrelevant change before reassemble transactions during logical decoding |
Previous Message | Amit Langote | 2025-02-04 03:05:07 | Re: SQL/JSON json_table plan clause |