BUG #14279: Logical decoding misses a transaction completely

Started by Marko Tiikkajaover 9 years ago7 messagesbugs
Jump to latest
#1Marko Tiikkaja
marko@joh.to

The following bug has been logged on the website:

Bug reference: 14279
Logged by: Marko Tiikkaja
Email address: marko@joh.to
PostgreSQL version: 9.5.3
Operating system: Linux
Description:

Hi,

The following transaction does not get decoded at all in logical decoding:

BEGIN;
INSERT INTO foo VALUES ('bar');
SAVEPOINT s;
SELECT 1 FROM foo FOR UPDATE;
RELEASE SAVEPOINT s;
COMMIT;

The problem seems to be that ReorderBufferCommitChild() overwrites the main
transaction's base_snapshot with a NULL because it thinks the
subtransaction's base_snapshot_lsn=0 is older than the main transaction's
actual snapshot, which in ReorderBufferCommit:

/*
* If this transaction didn't have any real changes in our database,
it's
* OK not to have a snapshot. Note that ReorderBufferCommitChild will
have
* transferred its snapshot to this transaction if it had one and the
* toplevel tx didn't.
*/
if (txn->base_snapshot == NULL)
{
Assert(txn->ninvalidations == 0);
ReorderBufferCleanupTXN(rb, txn);
return;
}

causes the entire transaction to be skipped. I didn't debug further.

(Thanks to Andres Freund and Andrew Gierth for helping me track this problem
down!)

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Andrew Gierth
andrew@tao11.riddles.org.uk
In reply to: Marko Tiikkaja (#1)
Re: BUG #14279: Logical decoding misses a transaction completely

"marko" == marko <marko@joh.to> writes:

marko> The problem seems to be that ReorderBufferCommitChild()
marko> overwrites the main transaction's base_snapshot with a NULL
marko> because it thinks the subtransaction's base_snapshot_lsn=0 is
marko> older than the main transaction's actual snapshot

i.e. here in ReorderBufferCommitChild:

/*
* Pass the our base snapshot to the parent transaction if it doesn't have
* one, or ours is older. That can happen if there are no changes in the
* toplevel transaction but in one of the child transactions. This allows
* the parent to simply use it's base snapshot initially.
*/
if (txn->base_snapshot == NULL ||
txn->base_snapshot_lsn > subtxn->base_snapshot_lsn)
{

it's possible for subtxn to exist, but for subtxn->base_snapshot to be
NULL and base_snapshot_lsn to be 0, and obviously propagating this to
txn is wrong.

--
Andrew (irc:RhodiumToad)

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Marko Tiikkaja
marko@joh.to
In reply to: Andrew Gierth (#2)
Re: BUG #14279: Logical decoding misses a transaction completely

Ping. This is a very serious issue and it would be really good to
include it in the minor releases. I've attached a patch for 9.5 with a
test case and verified that it fixes the problem with our application.

.m

Attachments:

bug_14279.patchtext/x-patch; name=bug_14279.patchDownload+46-13
#4Michael Paquier
michael@paquier.xyz
In reply to: Marko Tiikkaja (#3)
Re: BUG #14279: Logical decoding misses a transaction completely

On Sun, Aug 7, 2016 at 7:49 PM, Marko Tiikkaja <marko@joh.to> wrote:

Ping. This is a very serious issue and it would be really good to include
it in the minor releases. I've attached a patch for 9.5 with a test case
and verified that it fixes the problem with our application.

Right. That's up to Robert or Andres to pick up that at this point. I
just added them in CC for awareness.
--
Michael

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#4)
Re: BUG #14279: Logical decoding misses a transaction completely

Michael Paquier <michael.paquier@gmail.com> writes:

On Sun, Aug 7, 2016 at 7:49 PM, Marko Tiikkaja <marko@joh.to> wrote:

Ping. This is a very serious issue and it would be really good to include
it in the minor releases. I've attached a patch for 9.5 with a test case
and verified that it fixes the problem with our application.

Right. That's up to Robert or Andres to pick up that at this point. I
just added them in CC for awareness.

Andres is on vacation, and if Robert is around it'd be better for him to
be looking at the toast snapshot problem. I can pick this up, probably.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#6Michael Paquier
michael@paquier.xyz
In reply to: Tom Lane (#5)
Re: BUG #14279: Logical decoding misses a transaction completely

On Mon, Aug 8, 2016 at 1:14 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Michael Paquier <michael.paquier@gmail.com> writes:

On Sun, Aug 7, 2016 at 7:49 PM, Marko Tiikkaja <marko@joh.to> wrote:

Ping. This is a very serious issue and it would be really good to include
it in the minor releases. I've attached a patch for 9.5 with a test case
and verified that it fixes the problem with our application.

Right. That's up to Robert or Andres to pick up that at this point. I
just added them in CC for awareness.

Andres is on vacation, and if Robert is around it'd be better for him to
be looking at the toast snapshot problem. I can pick this up, probably.

I was going to review that, until I noticed that it has already been
addressed by bcbecbc. Thanks!
--
Michael

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#7Andres Freund
andres@anarazel.de
In reply to: Tom Lane (#5)
Re: BUG #14279: Logical decoding misses a transaction completely

On 2016-08-07 12:14:02 -0400, Tom Lane wrote:

Michael Paquier <michael.paquier@gmail.com> writes:

On Sun, Aug 7, 2016 at 7:49 PM, Marko Tiikkaja <marko@joh.to> wrote:

Ping. This is a very serious issue and it would be really good to include
it in the minor releases. I've attached a patch for 9.5 with a test case
and verified that it fixes the problem with our application.

Right. That's up to Robert or Andres to pick up that at this point. I
just added them in CC for awareness.

Andres is on vacation, and if Robert is around it'd be better for him to
be looking at the toast snapshot problem. I can pick this up, probably.

Thanks for that. I was too tired to address this before the vacation,
sorry for that.

Andres

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs