From: lxiaogang5 <lxiaogang5@gmail.com>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: There is a defect in the ReplicationSlotCreate() function whereit iterates throughReplicationSlotCtl->replication_slots[max_replication_slots] to find a slotbut does not break out of the loop when a slot is found.
Date: Wed, 15 Jan 2025 10:03:28 +0800
Message-ID: <tencent_C9916D9ADB19FCA6B55DAC0C@qq.com> (raw)
References: <tencent_4F926019B88B74E2E7F51E57@qq.com>
<D57D44E8-C6FE-41FD-9D43-105BB9B73366@yesql.se>
<div style="min-height:22px;margin-bottom:8px;"><br></div><div style="min-height:22px;margin-bottom:8px;">Yes, it's this piece of code. Thank you for your patient explanation. What you said makes a lot of sense. Even after obtaining the available slots, we still need to traverse and check if there are any duplicate slots.</div><div id="QQMailSignature" class="mail-footer" aria-hidden="true"><hr style="margin: 0 0 10px 0;border: 0;border-bottom:1px solid #E6E8EB;height:0;line-height:0;font-size:0;padding: 20px 0 0 0;width: 50px;">发自我的iPhone</div><div id="original-content"><br><br><div class="xm_mail_oringinal_describe"><div style="font-size:70%;padding:2px 0;">------------------ Original ------------------</div><div style="font-size:70%;background:#f0f0f0;color:#212121;padding:8px;border-radius:4px"><div><b>From:</b> Daniel Gustafsson <daniel@yesql.se></div><div><b>Date:</b> Tue,Jan 14,2025 6:57 PM</div><div><b>To:</b> lxiaogang5 <lxiaogang5@gmail.com></div><div><b>Cc:</b> pgsql-bugs <pgsql-bugs@postgresql.org></div><div><b>Subject:</b> Re: There is a defect in the ReplicationSlotCreate() function whereit iterates throughReplicationSlotCtl->replication_slots[max_replication_slots] to find a slotbut does not break out of the loop when a slot is found.</div></div></div><br><pre style="white-space:pre-wrap;">> On 14 Jan 2025, at 05:24, lxiaogang5 <lxiaogang5@gmail.com> wrote:
> There is a logical defect in the function ReplicationSlotCreate (creating a new slot) when it internally traverses the ReplicationSlotCtl->replication_slots[max_replication_slots] array. When an available slot is found (slot = s), it should break the current for loop. This issue still exists in the latest code, resulting in wasted CPU resources.
We could exit early, but any system which max_replication_slots set high enough
that the savings are measurable in a non-hot codepath is likely having other
performance problems as well (max_replication_slots is by default 10).
If you feel strongly about I suggest creating a patch and submitting. Also,
please don't send 6Mb images of text when simply copy/paste of the text would
have worked even better.
--
Daniel Gustafsson
</pre></div>
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: lxiaogang5@gmail.com, daniel@yesql.se
Subject: Re: There is a defect in the ReplicationSlotCreate() function whereit iterates throughReplicationSlotCtl->replication_slots[max_replication_slots] to find a slotbut does not break out of the loop when a slot is found.
In-Reply-To: <tencent_C9916D9ADB19FCA6B55DAC0C@qq.com>
* 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