Re: logical decoding and replication of sequences, take 2
Tomas Vondra <tomas.vondra@enterprisedb.com>
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Amit Kapila <amit.kapila16@gmail.com>,
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Masahiko Sawada <sawada.mshk@gmail.com>,
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2023-07-12T19:05:15Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Migrate logical slots to the new node during an upgrade.
- 29d0a77fa660 17.0 cited
-
Make test_decoding ddl.out shorter
- d6677b93c79b 17.0 landed
- c5c5832600e9 14.9 landed
- b1dc946eee3d 16.0 landed
- 3bb8b9342f8a 15.4 landed
-
Fix snapshot handling in logicalmsg_decode
- 949ac32e1267 15.3 landed
- 8b9cbd42b61f 14.8 landed
- 4df581fa0f4b 13.11 landed
- 497f863f0598 12.15 landed
- 8de91ebf2ac1 11.20 landed
- 7fe1aa991b62 16.0 landed
-
doc: Adjust a few more references to "postmaster"
- 17e72ec45d31 16.0 cited
-
Revert "Logical decoding of sequences"
- 2c7ea57e56ca 15.0 cited
Attachments
- 0001-Make-test_decoding-ddl.out-shorter-20230712.patch (text/x-patch) patch 0001
- 0002-Logical-decoding-of-sequences-20230712.patch (text/x-patch) patch 0002
- 0003-Add-decoding-of-sequences-to-test_decoding-20230712.patch (text/x-patch) patch 0003
- 0004-Add-decoding-of-sequences-to-built-in-repli-20230712.patch (text/x-patch) patch 0004
- 0005-Simplify-protocol-versioning-20230712.patch (text/x-patch) patch 0005
Hi, here's a rebased and significantly reworked version of this patch series, based on the recent reviews and discussion. Let me go through the main differences: 1) reorder the patches to have the "shortening" of test output first 2) merge the various "fix" patches in to the three main patches 0002 - introduce sequence decoding infrastructure 0003 - add sequences to test_decoding 0004 - add sequences to built-in replication I've kept those patches separate to make the evolution easier to follow and discuss, but it was necessary to cleanup the patch series and make it clearer what the current state is. 3) simplify the replicated state As suggested by Ashutosh, it may not be a good idea to replicate the (last_value, log_cnt, is_called) tuple, as that's pretty tightly tied to our internal implementation. Which may not be the right thing for other plugins. So this new patch replicates just "value" which is pretty much (last_value + log_cnt), representing the next value that should be safe to generate on the subscriber (in case of a failover). 4) simplify test_decoding code & tests I realized I can ditch some of the test_decoding changes, because at some point we chose to only include sequences in test_decoding when explicitly requested. So the tests don't need to disable that, it's the other way - one test needs to enable it. This now also prints the single value, instead of the three values. 5) minor tweaks in the built-in replication This adopts the relaxed LOCK code to allow locking sequences during the initial sync, and also adopts the replication of a single value (this affects the "apply" side of that change too). 6) simplified protocol versioning The main open question I had was what to do about protocol versioning for the built-in replication - how to decide whether the subscriber can apply sequences, and what should happen if we decode sequence but the subscriber does not support that. I was not entirely sure we want to handle this by a simple version check, because that maps capabilities to a linear scale, which seems pretty limiting. That is, each protocol version just grows, and new version number means support of a new capability - like replication of two-phase commits, or sequences. Which is nice, but it does not allow supporting just the later feature, for example - you can't skip one. Which is why 2PC decoding has both a version and a subscription flag, which allows exactly that ... When discussing this off-list with Peter Eisentraut, he reminded me of his old message in the thread: https://www.postgresql.org/message-id/8046273f-ea88-5c97-5540-0ccd5d244fd4@enterprisedb.com where he advocates for exactly this simplified behavior. So I took a stab at it and 0005 should be doing that. I keep it as a separate patch for now, to make the changes clearer, but ultimately it should be merged into 0003 and 0004 parts. It's not particularly complex change, it mostly ditches the subscription option (which also means columns in the pg_subscription catalog), and a flag in the decoding context. But the main change is in pgoutput_sequence(), where we protocol_version and error-out if it's not the right version (instead of just ignoring the sequence). AFAICS this behaves as expected - with PG15 subscriber, I get an ERROR on the publisher side from the sequence callback. But it no occurred to me we could do the same thing with the original approach - allow the per-subscription "sequences" flag, but error out when the subscriber did not enable that capability ... Hopefully, I haven't forgotten to address any important point from the reviews ... The one thing I'm not really sure about is how it interferes with the replication of DDL. But in principle, if it decodes DDL for ALTER SEQUENCE, I don't see why it would be a problem that we then decode and replicate the WAL for the sequence state. But if it is a problem, we should be able to skip this WAL record with the initial sequence state (which I think should be possible thanks to the "created" flag this patch adds to the WAL record). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company