| From: | "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com> |
|---|---|
| To: | 'Tristan Su' <sooqing(at)gmail(dot)com> |
| Cc: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | RE: [PATCH] Reuse slot helpers in pg_get_replication_slots and slot copy |
| Date: | 2026-12-02 03:06:52 |
| Message-ID: | OS7PR01MB18317FD13626922F982D286CEF54C2@OS7PR01MB18317.jpnprd01.prod.outlook.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
> copy_replication_slot() scans ReplicationSlotCtl->replication_slots[]
> itself to find the source slot. SearchNamedReplicationSlot() performs
> exactly that lookup, and the caller already holds
> ReplicationSlotControlLock, so it can be called with
> need_lock = false.
This looks a good improvement.
But isn't it better to check whether the slot exists, before acquiring the
spinlock like [1]? This can clarify the normal/abnormal case.
> pg_get_replication_slots() compares slot_contents.data.database with
> InvalidOid three times to distinguish physical from logical slots.
> SlotIsPhysical() expresses the same condition, and the same function
> already uses this macro elsewhere.
One comment:
```
- if (slot_contents.data.database == InvalidOid)
+ if (SlotIsPhysical(&slot_contents))
nulls[i++] = true;
else
values[i++] = NameGetDatum(&slot_contents.data.plugin);
```
Not sure, isn't it clearer to check slot_contents.data.plugin?
[1]:
```
src = SearchNamedReplicationSlot(NameStr(*src_name), false);
if (!src)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("replication slot \"%s\" does not exist", NameStr(*src_name))));
/* Copy the slot contents while holding spinlock */
SpinLockAcquire(&src->mutex);
first_slot_contents = *src;
SpinLockRelease(&src->mutex);
```
Best regards,
Hayato Kuroda
FUJITSU LIMITED
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zhijie Hou | 2026-12-02 03:08:49 | Re: Fix race between copying and dropping a replication slot |
| Previous Message | Henson Choi | 2026-12-02 02:52:59 | Re: Speed up tuplestore_seek() by starting from the nearest known position |