Re: [HACKERS] logical decoding of two-phase transactions - Mailing list pgsql-hackers
From | Petr Jelinek |
---|---|
Subject | Re: [HACKERS] logical decoding of two-phase transactions |
Date | |
Msg-id | abf61103-fff7-c7c3-481f-e2729db0e069@2ndquadrant.com Whole thread Raw |
In response to | Re: [HACKERS] logical decoding of two-phase transactions (Craig Ringer <craig@2ndquadrant.com>) |
Responses |
Re: [HACKERS] logical decoding of two-phase transactions
Re: [HACKERS] logical decoding of two-phase transactions |
List | pgsql-hackers |
On 02/03/17 13:23, Craig Ringer wrote: > On 2 March 2017 at 16:20, Stas Kelvich <s.kelvich@postgrespro.ru> wrote: >> >>> On 2 Mar 2017, at 11:00, Craig Ringer <craig@2ndquadrant.com> wrote: >>> >>> We already have it, because we just decoded the PREPARE TRANSACTION. >>> I'm preparing a patch revision to demonstrate this. >> >> Yes, we already have it, but if server reboots between commit prepared (all >> prepared state is gone) and decoding of this commit prepared then we loose >> that mapping, isn’t it? > > I was about to explain how restart_lsn works again, and how that would > mean we'd always re-decode the PREPARE TRANSACTION before any COMMIT > PREPARED or ROLLBACK PREPARED on crash. But... > > Actually, the way you've implemented it, that won't be the case. You > treat PREPARE TRANSACTION as a special-case of COMMIT, and the client > will presumably send replay confirmation after it has applied the > PREPARE TRANSACTION. In fact, it has to if we want 2PC to work with > synchronous replication. This will allow restart_lsn to advance to > after the PREPARE TRANSACTION record if there's no other older xact > and we see a suitable xl_running_xacts record. So we wouldn't decode > the PREPARE TRANSACTION again after restart. > Unless we just don't let restart_lsn to go forward if there is 2pc that wasn't decoded yet (twopcs store the prepare lsn) but that's probably too much of a kludge. > > It's also worth noting that with your current approach, 2PC xacts will > produce two calls to the output plugin's commit() callback, once for > the PREPARE TRANSACTION and another for the COMMIT PREPARED or > ROLLBACK PREPARED, the latter two with a faked-up state. I'm not a > huge fan of that. It's not entirely backward compatible since it > violates the previously safe assumption that there's a 1:1 > relationship between begin and commit callbacks with no interleaving, > for one thing, and I think it's also a bit misleading to send a > PREPARE TRANSACTION to a callback that could previously only receive a > true commit. > > I particularly dislike calling a commit callback for an abort. So I'd > like to look further into the interface side of things. I'm inclined > to suggest adding new callbacks for 2pc prepare, commit and rollback, > and if the output plugin doesn't set them fall back to the existing > behaviour. Plugins that aren't interested in 2PC (think ETL) should > probably not have to deal with it, we might as well just send them > only the actually committed xacts, when they commit. > I think this is a good approach to handle it. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
pgsql-hackers by date: