Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j18kD-0008WK-L3 for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Feb 2020 13:04:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j18kB-0002OC-Ux for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Feb 2020 13:04:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j18kB-0002O5-IN for pgsql-bugs@lists.postgresql.org; Mon, 10 Feb 2020 13:04:55 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1j18k8-0002hH-Tv for pgsql-bugs@lists.postgresql.org; Mon, 10 Feb 2020 13:04:55 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 23BA821C4C3F; Mon, 10 Feb 2020 16:04:51 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from ars-thinkpad (nat03-43-2.netorn.net [188.35.130.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 8EE7A21C4A92; Mon, 10 Feb 2020 16:04:50 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1581339890; bh=LfduhdpXovYDS1bsBalK4c7o3sh1wKMk0xv3idcp7k4=; h=References:From:To:Cc:Subject:In-reply-to:Date; b=eFNCGHgNXVI20UxCH2FhVANGHAJ4591K2bfvyPQQaITCusIajqmM6wLEv2SwbCSt+ GySX/IZqHRBAjvqFGfXb72d2B3R7OhNN7QD+VeGW73pC8FBJTxkrp81gHssqnoHquo CZ4WcTvXZKSUzSTjJxsyABC2OJpI+xf9St4npRSo= References: <87ftjifoql.fsf@ars-thinkpad> <20191024213157.7pm6niybfxgpvmgg@alap3.anarazel.de> <87eez1fh48.fsf@ars-thinkpad> <8736bs81sx.fsf@ars-thinkpad> <871rrb942q.fsf@ars-thinkpad> <87zhdx76d5.fsf@ars-thinkpad> <8736bjoiax.fsf@ars-thinkpad> User-agent: mu4e 1.1.0; emacs 26.0.50 From: Arseny Sher To: Amit Kapila Cc: Andres Freund , "Hsu\, John" , "pgsql-bugs\@lists.postgresql.org" Subject: Re: ERROR: subtransaction logged without previous top-level txn record In-reply-to: Date: Mon, 10 Feb 2020 16:04:46 +0300 Message-ID: <87wo8ulhjl.fsf@ars-thinkpad> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain Amit Kapila writes: >> I don't believe you can that without persisting additional >> data. Basically, what we need is list of transactions who are running at >> the point of snapshot serialization *and* already wrote something before >> it -- those we hadn't seen in full and can't decode. We have no such >> data currently. The closest thing we have is xl_running_xacts->nextXid, >> but >> >> 1) issued xid doesn't necessarily means xact actually wrote something, >> so we can't just skip xl_xact_assignment for xid < nextXid, it might >> still be decoded >> 2) snapshot might be serialized not at xl_running_xacts anyway >> >> Surely this thing doesn't deserve changing persisted data format. >> > > I agree that it won't be a good idea to change the persisted data > format, especially in back-branches. I don't see any fix which can > avoid this without doing major changes in the code. Apart from this, > we have to come up with a solution for point (3) discussed in the > above email [1] which again could be change in design. I think we can > first try to proceed with the patch > 0002-Stop-demanding-that-top-xact-must-be-seen-before--v2 and then we > can discuss the other patch. I can't see a way to write a test case > for this, can you think of any way? Yeah, let's finally get it. Attached is raw version of isolation test triggering false 'subtransaction logged without...' (case (1)). However, frankly I don't see much value in it, so I'm dubious whether it should be included in the patch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=subxact_logged_without_top_test.patch diff --git a/contrib/test_decoding/specs/subxact_logged_without_top.spec b/contrib/test_decoding/specs/subxact_logged_without_top.spec new file mode 100644 index 0000000000..55b51357a9 --- /dev/null +++ b/contrib/test_decoding/specs/subxact_logged_without_top.spec @@ -0,0 +1,51 @@ + +setup +{ + SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding'); -- must be first write in xact + CREATE TABLE harvest(apples integer); + CREATE OR REPLACE FUNCTION subxacts() returns void as $$ + BEGIN + FOR i in 1 .. 65 LOOP + BEGIN + INSERT INTO harvest VALUES (42); + EXCEPTION + WHEN OTHERS THEN + RAISE; + END; + END LOOP; + END; $$LANGUAGE 'plpgsql'; +} + +teardown +{ + DROP TABLE IF EXISTS harvest; + SELECT 'stop' FROM pg_drop_replication_slot('isolation_slot'); +} + +session "s0" +setup { SET synchronous_commit=on; } +step "s0_begin" { BEGIN; } +step "s0_first_subxact" { + DO LANGUAGE plpgsql $$ + BEGIN + BEGIN + INSERT INTO harvest VALUES (41); + EXCEPTION WHEN OTHERS THEN RAISE; + END; + END $$; +} +step "s0_many_subxacts" { select subxacts(); } +step "s0_commit" { COMMIT; } + +session "s1" +setup { SET synchronous_commit=on; } +step "s1_begin" { BEGIN; } +step "s1_dml" { INSERT INTO harvest VALUES (43); } +step "s1_commit" { COMMIT; } + +session "s2" +setup { SET synchronous_commit=on; } +step "s2_checkpoint" { CHECKPOINT; } +step "s2_get_changes" { SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); } + +permutation "s0_begin" "s0_first_subxact" "s2_checkpoint" "s1_begin" "s1_dml" "s0_many_subxacts" "s0_commit" "s2_checkpoint" "s2_get_changes" "s1_commit" "s2_get_changes" --=-=-= Content-Type: text/plain -- cheers, Arseny --=-=-=--