Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MVCC bug with prepared xact with subxacts on standby #8152

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

hlinnaka
Copy link
Contributor

We did not recover the subtransaction IDs of prepared transactions when starting a hot standby from a shutdown checkpoint. As a result, such subtransactions were considered as aborted, rather than in-progress. That would lead to hint bits being set incorrectly, and the subtransactions suddenly becoming visible to old snapshots when the prepared transaction was committed.

To fix, update pg_subtrans with prepared transactions's subxids when starting hot standby from a shutdown checkpoint. The snapshots taken from that state need to be marked as "suboverflowed", so that we also check the pg_subtrans.

Discussion: https://www.postgresql.org/message-id/6b852e98-2d49-4ca1-9e95-db419a2696e0%40iki.fi

NEON: cherry-picked from the upstream thread ahead of time, to unblock #7288. I expect this to be committed to upstream in the next few days, superseding this. NOTE: I did not include the new regression test on v15 and v14 branches, because the test would need some adapting, and we don't run the perl tests on Neon anyway.

@hlinnaka hlinnaka requested a review from a team as a code owner June 25, 2024 10:42
@hlinnaka hlinnaka requested a review from MMeent June 25, 2024 10:42
Copy link

github-actions bot commented Jun 25, 2024

2922 tests run: 2805 passed, 0 failed, 117 skipped (full report)


Code coverage* (full report)

  • functions: 32.5% (6872 of 21133 functions)
  • lines: 50.1% (53636 of 106976 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
1a69cc2 at 2024-06-25T12:08:31.507Z :recycle:

We did not recover the subtransaction IDs of prepared transactions
when starting a hot standby from a shutdown checkpoint. As a result,
such subtransactions were considered as aborted, rather than
in-progress. That would lead to hint bits being set incorrectly, and
the subtransactions suddenly becoming visible to old snapshots when
the prepared transaction was committed.

To fix, update pg_subtrans with prepared transactions's subxids when
starting hot standby from a shutdown checkpoint. The snapshots taken
from that state need to be marked as "suboverflowed", so that we also
check the pg_subtrans.

Discussion: https://www.postgresql.org/message-id/6b852e98-2d49-4ca1-9e95-db419a2696e0%40iki.fi

NEON: cherry-picked from the upstream thread ahead of time, to unblock
#7288. I expect this to be
committed to upstream in the next few days, superseding this. NOTE: I
did not include the new regression test on v15 and v14 branches,
because the test would need some adapting, and we don't run the perl
tests on Neon anyway.
@hlinnaka hlinnaka requested a review from knizhnik June 25, 2024 11:22
@knizhnik
Copy link
Contributor

@hlinnaka hlinnaka merged commit d502313 into main Jun 25, 2024
64 of 65 checks passed
@hlinnaka hlinnaka deleted the cherry-pick-twophase-shutdown-visibility-fix branch June 25, 2024 13:29
@MMeent
Copy link
Contributor

MMeent commented Jun 25, 2024

@hlinnaka
It looks like you forgot to update the subprojects when you merged the Postgres MRs, so now this points to the PR commits, rather than the HEAD of the REF_1X_STABLE_neon branches.

@hlinnaka
Copy link
Contributor Author

@hlinnaka It looks like you forgot to update the subprojects when you merged the Postgres MRs, so now this points to the PR commits, rather than the HEAD of the REF_1X_STABLE_neon branches.

Ah, thanks. I think I used the "Rebase and merge" button on the postgres branches, which changed the commit SHAs.

jcsp pushed a commit that referenced this pull request Jun 25, 2024
We did not recover the subtransaction IDs of prepared transactions when
starting a hot standby from a shutdown checkpoint. As a result, such
subtransactions were considered as aborted, rather than in-progress.
That would lead to hint bits being set incorrectly, and the
subtransactions suddenly becoming visible to old snapshots when the
prepared transaction was committed.

To fix, update pg_subtrans with prepared transactions's subxids when
starting hot standby from a shutdown checkpoint. The snapshots taken
from that state need to be marked as "suboverflowed", so that we also
check the pg_subtrans.

Discussion:
https://www.postgresql.org/message-id/6b852e98-2d49-4ca1-9e95-db419a2696e0%40iki.fi

NEON: cherry-picked from the upstream thread ahead of time, to unblock
#7288. I expect this to be
committed to upstream in the next few days, superseding this. NOTE: I
did not include the new regression test on v15 and v14 branches, because
the test would need some adapting, and we don't run the perl tests on
Neon anyway.
conradludgate pushed a commit that referenced this pull request Jun 27, 2024
We did not recover the subtransaction IDs of prepared transactions when
starting a hot standby from a shutdown checkpoint. As a result, such
subtransactions were considered as aborted, rather than in-progress.
That would lead to hint bits being set incorrectly, and the
subtransactions suddenly becoming visible to old snapshots when the
prepared transaction was committed.

To fix, update pg_subtrans with prepared transactions's subxids when
starting hot standby from a shutdown checkpoint. The snapshots taken
from that state need to be marked as "suboverflowed", so that we also
check the pg_subtrans.

Discussion:
https://www.postgresql.org/message-id/6b852e98-2d49-4ca1-9e95-db419a2696e0%40iki.fi

NEON: cherry-picked from the upstream thread ahead of time, to unblock
#7288. I expect this to be
committed to upstream in the next few days, superseding this. NOTE: I
did not include the new regression test on v15 and v14 branches, because
the test would need some adapting, and we don't run the perl tests on
Neon anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants