Re: [HACKERS] Potential hot-standby bug around xacts committed but in xl_running_xacts - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: [HACKERS] Potential hot-standby bug around xacts committed but in xl_running_xacts
Date
Msg-id CANP8+jKGdCTn0JKhNnM42s4DD3qxRxzGwEM0L+BsTjAAAjC=pA@mail.gmail.com
Whole thread Raw
In response to [HACKERS] Re: Potential hot-standby bug around xacts committed but inxl_running_xacts  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On 2 May 2017 at 18:06, Andres Freund <andres@anarazel.de> wrote:

>> What I suggest is that with logical decoding in mind we do this
>> 1. Inject a new record XLOG_SNAPSHOT_START at the start of
>> LogStandbySnapshot(). We start logical decoding from there.
>> 2. Record any transactions that end
>> 3. Now the full XLOG_RUNNING_XACTS record arrives. We apply all xacts
>> that are seen as running, minus any ended between 1 and 3
>
>> This avoids the problems for the race but without holding locks while
>> we log XLOG_RUNNING_XACTS, something that was considered painful for
>> Hot Standby.
>
> I don't think that really solves it, because other transactions could
> just be stuck just after the XLogInsert() forever.  And it'd have the
> issue of having to backpatch a new record.  I'm working on an
> alternative approach, let's hope that that works out.

Backpatchable approach.

1. Record CurrentInsertPosition()
2. LogStandbySnapshot()
3. Insert custom logical wal message containing currentinsertposition
and LSN of (2)

When we decode
1. Read standby snapshot
2. Scan forwards until we see message written by step (3) above, which
is identifiable because it contains LSN of snapshot.
3. Read initial LSN from message then re-scan from LSN until
xl_running_xacts message collecting any commits/aborts and removing
them from snapshot.

No new WAL messages, no locking problem, race condition handled.

-- 
Simon Riggs                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: [HACKERS] CTE inlining
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] logical replication syntax (was DROP SUBSCRIPTION,query cancellations and slot handling)