Repository navigation
Execute the invalidations of a transaction wherever it ends - #2409
Open
my-ship-it wants to merge 1 commit into
Open
my-ship-it wants to merge 1 commit into
my-ship-it wants to merge 1 commit into
Conversation
A transaction we do not decode may still have changed the catalog, and its invalidation messages have to be executed anyway or this backend keeps cache entries it has no business keeping. Four places end such a transaction -- ReorderBufferForget, ReorderBufferInvalidate, ReorderBufferReplay and ReorderBufferStreamTXN -- and all four declined to do it unless the transaction had a base snapshot: the first two by testing for one, the other two by asserting that a transaction with nothing decoded has no messages either. The snapshot was once required. In the original implementation the messages were executed under the transaction's own historic snapshot -- SetupHistoricSnapshot(txn->base_snapshot, txn->tuplecid_hash) -- because executing one could read the catalog, and a transaction without a snapshot had none to offer. The assertions beside it said that this was not supposed to happen. c6ff84b took the requirement away. Invalidations are executed outside a valid transaction now, which is the whole point of doing it that way: entries are marked invalid without the catalog being read, so no snapshot has to be set up. The conditions and the assertions stayed behind, and a271a1b carried them into ReorderBufferInvalidate when prepare-time decoding arrived. On the commit path they still hold, because SnapBuildCommitTxn hands a catalog-modifying transaction a base snapshot for this exact purpose -- "we might need to execute invalidations, add snapshot" -- and DecodeCommit calls it before deciding to skip. A prepare is not a commit and nothing calls it there, so a prepared transaction we are not decoding arrives with invalidations and no snapshot, and the assertion that was meant to be unreachable fires. On a Cloudberry segment that is an ordinary DDL in another database, which is to say constantly. ReorderBufferReplay is the worse of the two assertions: a transaction with nothing decoded is not a transaction with nothing to do, and the branch goes on to free it, so the messages are not merely skipped but lost. The streaming one only returns, leaving them to be executed at commit. So all four execute them whenever there are any, and the conditions that no longer decide anything go. That leaves one rule rather than four sites agreeing by coincidence: invalidation messages are executed wherever a transaction ends, whether or not anything of it was decoded.
Contributor
|
Sooo, since when we are supporting logical decoding? Is there some project ongoing? |
Contributor
Author
Thanks for your interest. I have implemented table subscription and logical decoding on MPP using an extension and will share it later. Some small kernel adjustments are required to support the extension, allowing third-party extensions to capture distributed transaction boundaries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Executes a transaction's invalidation messages wherever the transaction ends,
instead of only when it happens to have a base snapshot.
Four places end a transaction whose contents were not decoded —
ReorderBufferForget,ReorderBufferInvalidate,ReorderBufferReplayandReorderBufferStreamTXN— and all four declined to execute its invalidationmessages: the first two by testing
txn->base_snapshot != NULL, the other twoby asserting that a transaction with nothing decoded has no messages either.
The snapshot requirement has not existed since 2016. Invalidations used to
be executed under the transaction's own historic snapshot, so there had to be
one. Upstream
c6ff84b06a6changed them to be executed outside a validtransaction — entries are marked invalid without the catalog being read, so no
snapshot is needed. The conditions and the assertions stayed behind, and
a271a1b50e9carried them intoReorderBufferInvalidatewhen prepare-timedecoding arrived in PG14.
Why it bites here
On the commit path the old condition still happens to hold, because
SnapBuildCommitTxn()hands a catalog-modifying transaction a base snapshotfor exactly this purpose (
snapbuild.c: "we might need to executeinvalidations, add snapshot"), and
DecodeCommitcalls it before deciding toskip.
DecodePreparecalls no such thing. A prepare is not a commit, so aprepared transaction we are not decoding arrives with invalidations and no
snapshot — and on a Cloudberry segment that is an ordinary DDL in another
database, which is to say constantly, because ordinary DDL here is two-phase.
Measured on a 3-segment cluster with a logical slot open: 313 core files in
three minutes, all from
Assert(txn->ninvalidations == 0).ReorderBufferReplayis the worse of the two assertions: a transaction withnothing decoded is not a transaction with nothing to do, and the branch goes on
to free it, so the messages are not merely skipped but lost. The streaming one
only returns, leaving them for commit.
This is upstream code, and the hole is upstream's too
Nothing in these four sites is Cloudberry's. Upstream reaches the same place
through
DecodePrepare→ReorderBufferInvalidate, where the stale conditionis an
ifrather than anAssert— so upstream does not crash, it silentlydrops the invalidations and leaves the backend holding catalog cache entries
it should have dropped. Same defect, different symptom; two-phase decoding is
rare upstream and constant here.
I intend to propose the same change to
pgsql-hackers, argued from the droppedinvalidations rather than from our assertion. If reviewers would rather wait and
take it through the next merge instead of carrying it here, say so — I would
rather land it here first, because on this side it is a crash and not a
latent one.
Type of Change
Test Plan
No new test: the fix removes conditions, and the case that reaches them needs a
two-phase logical slot plus concurrent DDL in another database — reproducible,
but not as a regression test without a lot of scaffolding. What was done:
main(reorderbuffer.o, no warnings)wal_level = logicaland atwo-phase slot, DDL running in another database. Before: assertion
failures at the rate given above. After: none, over a multi-hour run.
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance: none. The removed test was a branch on a pointer; executing
invalidation messages is what this path was always supposed to do.
User-facing changes: a logical decoding session no longer asserts on a
prepared transaction it is not decoding, and no longer leaves stale catalog
cache entries behind on the paths where it previously skipped the messages.
Dependencies: none.
Checklist