From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Implement streaming mode in ReorderBuffer.
Date: Sat, 08 Aug 2020 02:29:17 +0000
Message-ID: <E1k4Ebl-0006ps-1P@gemulon.postgresql.org> (raw)
Implement streaming mode in ReorderBuffer.
Instead of serializing the transaction to disk after reaching the
logical_decoding_work_mem limit in memory, we consume the changes we have
in memory and invoke stream API methods added by commit 45fdc9738b.
However, sometimes if we have incomplete toast or speculative insert we
spill to the disk because we can't generate the complete tuple and stream.
And, as soon as we get the complete tuple we stream the transaction
including the serialized changes.
We can do this incremental processing thanks to having assignments
(associating subxact with toplevel xacts) in WAL right away, and
thanks to logging the invalidation messages at each command end. These
features are added by commits 0bead9af48 and c55040ccd0 respectively.
Now that we can stream in-progress transactions, the concurrent aborts
may cause failures when the output plugin consults catalogs (both system
and user-defined).
We handle such failures by returning ERRCODE_TRANSACTION_ROLLBACK
sqlerrcode from system table scan APIs to the backend or WALSender
decoding a specific uncommitted transaction. The decoding logic on the
receipt of such a sqlerrcode aborts the decoding of the current
transaction and continue with the decoding of other transactions.
We have ReorderBufferTXN pointer in each ReorderBufferChange by which we
know which xact it belongs to. The output plugin can use this to decide
which changes to discard in case of stream_abort_cb (e.g. when a subxact
gets discarded).
We also provide a new option via SQL APIs to fetch the changes being
streamed.
Author: Dilip Kumar, Tomas Vondra, Amit Kapila, Nikhil Sontakke
Reviewed-by: Amit Kapila, Kuntal Ghosh, Ajin Cherian
Tested-by: Neha Sharma, Mahendra Singh Thalor and Ajin Cherian
Discussion: https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7259736a6e5b7c7588fff9578370736a6648acbb
Modified Files
--------------
contrib/test_decoding/Makefile | 2 +-
contrib/test_decoding/expected/stream.out | 94 +++
contrib/test_decoding/expected/truncate.out | 6 +
contrib/test_decoding/sql/stream.sql | 30 +
contrib/test_decoding/sql/truncate.sql | 1 +
contrib/test_decoding/test_decoding.c | 13 +
doc/src/sgml/logicaldecoding.sgml | 9 +-
doc/src/sgml/test-decoding.sgml | 22 +
src/backend/access/heap/heapam.c | 13 +
src/backend/access/heap/heapam_visibility.c | 42 +-
src/backend/access/index/genam.c | 53 ++
src/backend/access/table/tableam.c | 8 +
src/backend/access/transam/xact.c | 19 +
src/backend/replication/logical/decode.c | 17 +-
src/backend/replication/logical/logical.c | 10 +
src/backend/replication/logical/reorderbuffer.c | 981 +++++++++++++++++++++---
src/include/access/heapam_xlog.h | 1 +
src/include/access/tableam.h | 55 ++
src/include/access/xact.h | 4 +
src/include/replication/logical.h | 1 +
src/include/replication/reorderbuffer.h | 56 +-
21 files changed, 1331 insertions(+), 106 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: akapila@postgresql.org
Subject: Re: pgsql: Implement streaming mode in ReorderBuffer.
In-Reply-To: <E1k4Ebl-0006ps-1P@gemulon.postgresql.org>
References: <E1k4Ebl-0006ps-1P@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox