Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b353aa

Browse files
committed
Reset properly snapshot export state during transaction abort
During a replication slot creation, an ERROR generated in the sametransaction as the one creating a to-be-exported snapshot would haveleft the backend in an inconsistent state, as the associated staticexport snapshot state was not being reset on transaction abort, but onlyon the follow-up command received by the WAL sender that created thissnapshot on replication slot creation. This would trigger inconsistencyfailures if this session tried to export again a snapshot, like duringthe creation of a replication slot.Note that a snapshot export cannot happen in a transaction block, sothere is no need to worry resetting this state for subtransactionaborts. Also, this inconsistent state would very unlikely show up tousers. For example, one case where this could happen is anout-of-memory error when building the initial snapshot to-be-exported.Dilip found this problem while poking at a different patch, that causedan error in this code path for reasons unrelated to HEAD.Author: Dilip KumarReviewed-by: Michael Paquier, Zhihong YuDiscussion:https://postgr.es/m/CAFiTN-s0zA1Kj0ozGHwkYkHwa5U0zUE94RSc_g81WrpcETB5=w@mail.gmail.comBackpatch-through: 9.6
1 parent3e4c8db commit5b353aa

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include"replication/logical.h"
4747
#include"replication/logicallauncher.h"
4848
#include"replication/origin.h"
49+
#include"replication/snapbuild.h"
4950
#include"replication/syncrep.h"
5051
#include"replication/walsender.h"
5152
#include"storage/condition_variable.h"
@@ -2698,6 +2699,9 @@ AbortTransaction(void)
26982699
/* Reset logical streaming state. */
26992700
ResetLogicalStreamingState();
27002701

2702+
/* Reset snapshot export state. */
2703+
SnapBuildResetExportedSnapshotState();
2704+
27012705
/* If in parallel mode, clean up workers and exit parallel mode. */
27022706
if (IsInParallelMode())
27032707
{
@@ -5010,6 +5014,11 @@ AbortSubTransaction(void)
50105014
/* Reset logical streaming state. */
50115015
ResetLogicalStreamingState();
50125016

5017+
/*
5018+
* No need for SnapBuildResetExportedSnapshotState() here, snapshot
5019+
* exports are not supported in subtransactions.
5020+
*/
5021+
50135022
/* Exit from parallel mode, if necessary. */
50145023
if (IsInParallelMode())
50155024
{

‎src/backend/replication/logical/snapbuild.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,17 +673,33 @@ SnapBuildGetOrBuildSnapshot(SnapBuild *builder, TransactionId xid)
673673
void
674674
SnapBuildClearExportedSnapshot(void)
675675
{
676+
ResourceOwnertmpResOwner;
677+
676678
/* nothing exported, that is the usual case */
677679
if (!ExportInProgress)
678680
return;
679681

680682
if (!IsTransactionState())
681683
elog(ERROR,"clearing exported snapshot in wrong transaction state");
682684

683-
/* make sure nothing could have ever happened */
685+
/*
686+
* AbortCurrentTransaction() takes care of resetting the snapshot state,
687+
* so remember SavedResourceOwnerDuringExport.
688+
*/
689+
tmpResOwner=SavedResourceOwnerDuringExport;
690+
691+
/* make sure nothing could have ever happened */
684692
AbortCurrentTransaction();
685693

686-
CurrentResourceOwner=SavedResourceOwnerDuringExport;
694+
CurrentResourceOwner=tmpResOwner;
695+
}
696+
697+
/*
698+
* Clear snapshot export state during transaction abort.
699+
*/
700+
void
701+
SnapBuildResetExportedSnapshotState(void)
702+
{
687703
SavedResourceOwnerDuringExport=NULL;
688704
ExportInProgress= false;
689705
}

‎src/include/replication/snapbuild.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern void SnapBuildSnapDecRefcount(Snapshot snap);
7070
externSnapshotSnapBuildInitialSnapshot(SnapBuild*builder);
7171
externconstchar*SnapBuildExportSnapshot(SnapBuild*snapstate);
7272
externvoidSnapBuildClearExportedSnapshot(void);
73+
externvoidSnapBuildResetExportedSnapshotState(void);
7374

7475
externSnapBuildStateSnapBuildCurrentState(SnapBuild*snapstate);
7576
externSnapshotSnapBuildGetOrBuildSnapshot(SnapBuild*builder,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp