| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Tristan Su <sooqing(at)gmail(dot)com> |
| Cc: | 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 02:12:58 |
| Message-ID: | E5C71886-3FEF-409E-8FF0-1D9748310156@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Dec 2, 2026, at 09:55, Tristan Su <sooqing(at)gmail(dot)com> wrote:
>
> Hi all,
>
> I noticed two places in slotfuncs.c that reimplement helpers we already
> have.
>
> 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 change replaces a for loop with SearchNamedReplicationSlot(), I think it’s a nice cleanup.
>
> 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.
```
- if (slot_contents.data.database == InvalidOid)
+ if (SlotIsPhysical(&slot_contents))
values[i++] = CStringGetTextDatum("physical");
else
values[i++] = CStringGetTextDatum("logical");
```
I think this change also improves readability.
>
> No functional change. make check passes, and the patch applies to
> master at cb94cb41. pgindent is clean. No backpatch is intended.
>
> Comments welcome.
>
> Regards,
> Tristan Su
> <0001-Reuse-slot-helpers-in-pg_get_replication_slots-and-s.patch>
A nit comment:
For
```
ReplicationSlot *src = NULL;
```
With the old code, src might not be assigned lately, thus it must be initialized to NULL. But with this change:
```
+ src = SearchNamedReplicationSlot(NameStr(*src_name), false);
```
We no longer need to initialize src.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zhijie Hou | 2026-12-02 02:20:19 | Re: Fix race between copying and dropping a replication slot |
| Previous Message | Chao Li | 2026-12-02 01:57:26 | Re: Restore check_mut_excl_opts, usage in pg_restore and pg_dumpall |