Re: Logical decoding restart problems

From: Stas Kelvich <s(dot)kelvich(at)postgrespro(dot)ru>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: konstantin knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Petr Jelinek <petr(at)2ndquadrant(dot)com>
Subject: Re: Logical decoding restart problems
Date: 2016-08-25 12:03:23
Message-ID: 45164FA8-9F79-4101-87F4-A65AACDB03E4@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 20 Aug 2016, at 15:59, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
>
> I'll wait for a test case or some more detail.

Thanks for clarification about how restart_lsn is working.

Digging slightly deeper into this topic revealed that problem was in two phase decoding, not it logical decoding itself.
While I was writing DecodePrepare() I've and copied call to SnapBuildCommitTxn() function from DecodeCommit()
which was removing current transaction from running list and that’s obviously wrong thing to do for a prepared tx.

So I end up with following workaround:

--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -950,7 +950,7 @@ SnapBuildAbortTxn(SnapBuild *builder, XLogRecPtr lsn,
*/
void
SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
- int nsubxacts, TransactionId *subxacts)
+ int nsubxacts, TransactionId *subxacts, bool isCommit)
{
int nxact;

@@ -1026,7 +1026,8 @@ SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
* Make sure toplevel txn is not tracked in running txn's anymore, switch
* state to consistent if possible.
*/
- SnapBuildEndTxn(builder, lsn, xid);
+ if (isCommit)
+ SnapBuildEndTxn(builder, lsn, xid);

Calling SnapBuildCommitTxn with isCommit=true from commit and false from Prepare. However while I’m not
observing partially decoded transactions anymore, I’m not sure that this is right way to build proper snapshot and
something else isn’t broken.

Also while I was playing psycopg2 logical decoding client I do see empty transaction containing only
BEGIN/COMMIT (with test_decoding output plugin, and current postgres master).

--
Stas Kelvich
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2016-08-25 12:59:48 Re: patch proposal
Previous Message Gerdan Santos 2016-08-25 11:39:32 Re: \timing interval