Re: [HACKERS] Issues with logical replication - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] Issues with logical replication
Date
Msg-id CA+TgmoanD-sMvKCBi_8tqptfUnLn-4O61XQredLwFRCWGZCadg@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] Issues with logical replication  (Stas Kelvich <s.kelvich@postgrespro.ru>)
Responses Re: [HACKERS] Issues with logical replication  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Wed, Nov 15, 2017 at 8:20 PM, Stas Kelvich <s.kelvich@postgrespro.ru> wrote:
> I did a sketch of first approach just to confirm that it solves the problem.
> But there I hold ProcArrayLock during update of flag. Since only reader is
> GetRunningTransactionData it possible to have a custom lock there. In
> this case GetRunningTransactionData will hold three locks simultaneously,
> since it already holds ProcArrayLock and XidGenLock =)

To me, it seems like SnapBuildWaitSnapshot() is fundamentally
misdesigned, and ideally Petr (who wrote the patch) or Andres (who
committed it) ought to get involved here and help fix this problem.
My own first inclination would be to rewrite this as a loop: if the
transaction ID precedes the oldest running XID, then continue; else if
TransactionIdDidCommit() || TransactionIdDidAbort() then conclude that
we don't need to wait; else XactLockTableWait() then loop.  That way,
if you hit the race condition, you'll just busy-wait instead of doing
the wrong thing.  Maybe insert a sleep(1) if we retry more than once.
That sucks, of course, but it seems like a better idea than trying to
redesign XactLockTableWait() or the procarray, which could affect an
awful lot of other things.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Schedule for migration to pglister
Next
From: Tom Lane
Date:
Subject: Re: Further simplification of c.h's #include section