| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Scott Ray <scott(at)scottray(dot)io> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, Kuroda, Hayato/黒田 隼人 <kuroda(dot)hayato(at)fujitsu(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
| Subject: | Re: Recovery conflict resolution misses backends that import snapshots |
| Date: | 2026-07-26 23:49:33 |
| Message-ID: | amadDbubjWo_Jag1@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, Jul 25, 2026 at 11:03:52PM +0000, Scott Ray wrote:
> There is a silent bug in standby conflict resolution that can cause
> incorrect results. In ResolveRecoveryConflictWithSnapshot, the standby
> calls GetConflictingVirtualXIDs once, then waits for each returned VXID
> to disappear. However, after GetConflictingVirtualXIDs releases the
> ProcArrayLock, a backend may import a conflicting snapshot from one of
> the backends GetConflictingVirtualXIDs identified as conflicting. The
> resulting VXID conflicts with recovery, but
> ResolveRecoveryConflictWithSnapshot doesn't know it has to wait for the
> new VXID to disappear before proceeding, so the standby removes tuple
> versions or index entries that the importing backend needs.
Hmm. It looks like you are right here. I am not the most fluent here
with this area of the code, so adding in CC a couple of folks who
could perhaps comment, being usually interested on these matters.
> The first attached patch adds a TAP test that fails deterministically
> on unpatched master. The second makes
> ResolveRecoveryConflictWithSnapshot call GetConflictingVirtualXIDs
> until the result is empty, at which point importing a conflicting
> snapshot is impossible: acquiring a conflicting xmin requires a live,
> conflicting VXID as a source.
+ /*
+ * Scan until no conflicting VXID remains.
[...]
+ for (;;)
+ {
Adding a code pattern that could potentially cause this code path to
loop infinitely is not what I would call a principled approach, I
would call it a risky one.
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nico Williams | 2026-07-26 23:53:20 | Re: document the dangers of granting TRIGGER or REFERENCES |
| Previous Message | Michael Paquier | 2026-07-26 23:36:09 | Re: pg_rewind does not rewind diverging timelines |