From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Review for GetWALAvailability()
Date: Wed, 17 Jun 2020 14:04:37 -0400
Message-ID: <20200617180437.GA1812@alvherre.pgsql> (raw)
In-Reply-To: <f898aa30-053e-3598-f1f1-4b3b431f8f30@oss.nttdata.com>
I think passing the slot name when the slot is also passed is useless
and wasteful; it'd be better to pass NULL for the name and ignore the
strcmp() in that case -- in fact I suggest to forbid passing both name
and slot. (Any failure there would risk raising an error during
checkpoint, which is undesirable.)
So I propose the following tweaks to your patch, and otherwise +1.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:tweak.patch (text/x-diff, 1.7K) downloaddiff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.cindex b94e11a8e7..d99d0e9b42 100644--- a/src/backend/replication/slot.c+++ b/src/backend/replication/slot.c@@ -383,24 +383,25 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
ReplicationSlot *s;
int active_pid;
+ AssertArg((slot == NULL) ^ (name == NULL));+
retry:
Assert(MyReplicationSlot == NULL);
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
/*
- * Search for the slot with the specified name if the slot to- * acquire is not given. If the slot is not found, we either- * return -1 or error out.+ * Search for the slot with the specified name if the slot to acquire is+ * not given. If the slot is not found, we either return -1 or error out.
*/
- s = (slot == NULL) ? SearchNamedReplicationSlot(name) : slot;- if (s == NULL || !s->in_use || strcmp(name, NameStr(s->data.name)) != 0)+ s = slot ? slot : SearchNamedReplicationSlot(name);+ if (s == NULL || !s->in_use ||+ (name && strcmp(name, NameStr(s->data.name)) != 0))
{
+ LWLockRelease(ReplicationSlotControlLock);+
if (behavior == SAB_Inquire)
- {- LWLockRelease(ReplicationSlotControlLock);
return -1;
- }
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("replication slot \"%s\" does not exist", name)));
@@ -1161,8 +1162,7 @@ restart:
* we have to wait on that CV for the process owning
* the slot to be terminated, later.
*/
- wspid = ReplicationSlotAcquireInternal(s, NameStr(slotname),- SAB_Inquire);+ wspid = ReplicationSlotAcquireInternal(s, NULL, SAB_Inquire);
/*
* Exit the loop if we successfully acquired the slot or
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: alvherre@2ndquadrant.com, masao.fujii@oss.nttdata.com, horikyota.ntt@gmail.com
Subject: Re: Review for GetWALAvailability()
In-Reply-To: <20200617180437.GA1812@alvherre.pgsql>
References: <f898aa30-053e-3598-f1f1-4b3b431f8f30@oss.nttdata.com> <20200617180437.GA1812@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox