| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
| Subject: | Re: Assertion failure in update_local_synced_slot(), slotsync.c:364 |
| Date: | 2026-11-10 09:17:57 |
| Message-ID: | 42acdec3-478b-4b03-a0fa-eedcd987c110@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, Nov10, 2026 at 04:04 AM Masahiko Sawada wrote:
> Hi all,
>
> While reviewing slotsync.c, I hit the assertion failure:
>
> TRAP: failed Assert("MyReplicationSlot->data.persistency ==
> RS_TEMPORARY"), slotsync.c:364
>
> IIUC this is a regression of commit 788ec96d591 (CC'ed Hou and Amit).
> In update_local_synced_slot(), we try to advance the local slot only
> when the remote slot is ahead of it, and if the standby cannot reach a
> consistent snapshot we set the skip reason to
> SS_SKIP_NO_CONSISTENT_SNAPSHOT so that
> update_and_persist_local_synced_slot() doesn't persist the slot.
> However, LogicalSlotAdvanceAndCheckSnapState() has already advanced
> confirmed_flush_lsn to the remote's value in that case (restart_lsn
> and catalog_xmin were already equal to the remote's when the slot was
> created). So in the next cycle the remote slot is no longer ahead, we
> skip the advance entirely, and update_slotsync_skip_stats() overwrites
> the skip reason with SS_SKIP_NONE.
> update_and_persist_local_synced_slot() then persists the slot and
> reports it as sync-ready even though nothing has changed since the
> previous cycle. Once the remote slot advances again and the standby
> still cannot find a consistent snapshot, the assertion above fails.
>
> On non-assert builds, IIUC the problem is worse: the persisted slot
> can be used after promotion, and decoding from it skips the
> transactions between its restart_lsn and the first consistent point,
> causing data loss.
>
> Before that commit, update_and_persist_local_synced_slot() also
> checked found_consistent_snapshot returned by
> update_local_synced_slot() for the current cycle, so a cycle that
> didn't attempt to advance the slot never persisted it.
>
> I've attached a TAP test to reproduce this issue, generated by AI.
Thanks for reporting the issue.
I agree with your analysis, and I think we can fix it by preserving
SS_SKIP_NO_CONSISTENT_SNAPSHOT in update_local_synced_slot() when the
remote slot has not advanced since a previous cycle failed to build a
consistent snapshot.
Attached is a patch for the fix. I also tried to simplify and stabilize
the test and merged it into 040_standby_failover_slots_sync.pl in case
we want to include a test.
--
Best Regards,
Zhijie Hou
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-premature-persistence-of-synced-slots-without.patch | text/plain | 4.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Xuneng Zhou | 2026-11-10 09:25:47 | Re: BGWORKER_INTERRUPTIBLE workers are never restarted after DROP/ALTER/CREATE DATABASE |
| Previous Message | vignesh C | 2026-11-10 09:08:56 | Re: Proposal: Conflict log history table for Logical Replication |