From: | Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> |
Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Subject: | Re: logical decoding and replication of sequences, take 2 |
Date: | 2023-07-29 13:03:31 |
Message-ID: | f83e610c-8efd-0c40-585a-2b25fc1b2dcf@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 7/28/23 14:35, Ashutosh Bapat wrote:
>
> ...
>
> We hold a strong lock on sequence when changing its relfilenode. The
> sequence whose relfilenode is being changed can not be accessed by any
> concurrent transaction. So I am not able to understand what you are
> trying to say.
>
> I think per (top level) transaction hash table is cleaner design. It
> puts the hash table where it should be. But if that makes code
> difficult, current design works too.
>
I was thinking about switching to the per-txn hash, so here's a patch
adopting that approach (in part 0006). I can't say it's much simpler,
but maybe it can be simplified a bit. Most of the complexity comes from
assignments maybe happening with a delay, so it's hard to say what's a
top-level xact.
The patch essentially does this:
1) the HTAB is moved to ReorderBufferTXN
2) after decoding SGMR_CREATE, we add an entry to the current TXN and
(for subtransactions) to the parent TXN (even the copy references the
subxact)
3) when processing an assignment, we copy the HTAB entries from the
subxact to the parent
4) after a subxact abort, we remove the HTAB entries from the parent
5) while searching for the relfilenode, we only scan the HTAB in the
top-level xacts (this is possible due to the copying)
This could work without the copy in parent HTAB, but then we'd have to
scan all the transactions for every increment. And there may be many
lookups and many (sub)transactions, but only a small number of new
relfilenodes. So it seems like a good tradeoff.
If we could convince ourselves the subxact has to be already assigned
while decoding the sequence change, then we could simply search only the
current transaction (and the parent). But I've been unable to convince
myself that's guaranteed.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachment | Content-Type | Size |
---|---|---|
0001-Logical-decoding-of-sequences-20230729.patch | text/x-patch | 54.3 KB |
0002-Add-decoding-of-sequences-to-test_decoding-20230729.patch | text/x-patch | 20.6 KB |
0003-Add-decoding-of-sequences-to-built-in-repli-20230729.patch | text/x-patch | 256.8 KB |
0004-Catchup-up-to-a-LSN-after-copy-of-the-seque-20230729.patch | text/x-patch | 3.1 KB |
0005-use-page-LSN-for-sequences-20230729.patch | text/x-patch | 12.4 KB |
0006-per-transaction-hash-of-sequences-20230729.patch | text/x-patch | 17.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Rui Zhao | 2023-07-29 15:10:22 | pg_upgrade fails with in-place tablespace |
Previous Message | Tomas Vondra | 2023-07-29 12:38:07 | Re: logical decoding and replication of sequences, take 2 |