diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-10-18 11:55:42 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-10-18 11:55:42 +0900 |
commit | 409f9ca4471331be0f77b665ff3a1836a41de5b3 (patch) | |
tree | c27ce0d8603a0e9e8a08ab61c1ceca8dd1c00737 /src/backend/access/transam/xact.c | |
parent | 384f1abdb9b0f669279fcd57ba2173eb31724740 (diff) | |
download | postgresql-409f9ca4471331be0f77b665ff3a1836a41de5b3.tar.gz postgresql-409f9ca4471331be0f77b665ff3a1836a41de5b3.zip |
Reset properly snapshot export state during transaction abort
During a replication slot creation, an ERROR generated in the same
transaction as the one creating a to-be-exported snapshot would have
left the backend in an inconsistent state, as the associated static
export snapshot state was not being reset on transaction abort, but only
on the follow-up command received by the WAL sender that created this
snapshot on replication slot creation. This would trigger inconsistency
failures if this session tried to export again a snapshot, like during
the creation of a replication slot.
Note that a snapshot export cannot happen in a transaction block, so
there is no need to worry resetting this state for subtransaction
aborts. Also, this inconsistent state would very unlikely show up to
users. For example, one case where this could happen is an
out-of-memory error when building the initial snapshot to-be-exported.
Dilip found this problem while poking at a different patch, that caused
an error in this code path for reasons unrelated to HEAD.
Author: Dilip Kumar
Reviewed-by: Michael Paquier, Zhihong Yu
Discussion: https://postgr.es/m/CAFiTN-s0zA1Kj0ozGHwkYkHwa5U0zUE94RSc_g81WrpcETB5=w@mail.gmail.com
Backpatch-through: 9.6
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r-- | src/backend/access/transam/xact.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 4cc38f0d85e..d96881c0de5 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -46,6 +46,7 @@ #include "replication/logical.h" #include "replication/logicallauncher.h" #include "replication/origin.h" +#include "replication/snapbuild.h" #include "replication/syncrep.h" #include "replication/walsender.h" #include "storage/condition_variable.h" @@ -2698,6 +2699,9 @@ AbortTransaction(void) /* Reset logical streaming state. */ ResetLogicalStreamingState(); + /* Reset snapshot export state. */ + SnapBuildResetExportedSnapshotState(); + /* If in parallel mode, clean up workers and exit parallel mode. */ if (IsInParallelMode()) { @@ -5010,6 +5014,11 @@ AbortSubTransaction(void) /* Reset logical streaming state. */ ResetLogicalStreamingState(); + /* + * No need for SnapBuildResetExportedSnapshotState() here, snapshot + * exports are not supported in subtransactions. + */ + /* Exit from parallel mode, if necessary. */ if (IsInParallelMode()) { |