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

Commita207b85

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 parent5b0b298 commita207b85

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
@@ -45,6 +45,7 @@
4545
#include"replication/logical.h"
4646
#include"replication/logicallauncher.h"
4747
#include"replication/origin.h"
48+
#include"replication/snapbuild.h"
4849
#include"replication/syncrep.h"
4950
#include"replication/walsender.h"
5051
#include"storage/condition_variable.h"
@@ -2651,6 +2652,9 @@ AbortTransaction(void)
26512652
/* Forget about any active REINDEX. */
26522653
ResetReindexState(s->nestingLevel);
26532654

2655+
/* Reset snapshot export state. */
2656+
SnapBuildResetExportedSnapshotState();
2657+
26542658
/* If in parallel mode, clean up workers and exit parallel mode. */
26552659
if (IsInParallelMode())
26562660
{
@@ -4962,6 +4966,11 @@ AbortSubTransaction(void)
49624966
/* Forget about any active REINDEX. */
49634967
ResetReindexState(s->nestingLevel);
49644968

4969+
/*
4970+
* No need for SnapBuildResetExportedSnapshotState() here, snapshot
4971+
* exports are not supported in subtransactions.
4972+
*/
4973+
49654974
/* Exit from parallel mode, if necessary. */
49664975
if (IsInParallelMode())
49674976
{

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,17 +696,33 @@ SnapBuildGetOrBuildSnapshot(SnapBuild *builder, TransactionId xid)
696696
void
697697
SnapBuildClearExportedSnapshot(void)
698698
{
699+
ResourceOwnertmpResOwner;
700+
699701
/* nothing exported, that is the usual case */
700702
if (!ExportInProgress)
701703
return;
702704

703705
if (!IsTransactionState())
704706
elog(ERROR,"clearing exported snapshot in wrong transaction state");
705707

706-
/* make sure nothing could have ever happened */
708+
/*
709+
* AbortCurrentTransaction() takes care of resetting the snapshot state,
710+
* so remember SavedResourceOwnerDuringExport.
711+
*/
712+
tmpResOwner=SavedResourceOwnerDuringExport;
713+
714+
/* make sure nothing could have ever happened */
707715
AbortCurrentTransaction();
708716

709-
CurrentResourceOwner=SavedResourceOwnerDuringExport;
717+
CurrentResourceOwner=tmpResOwner;
718+
}
719+
720+
/*
721+
* Clear snapshot export state during transaction abort.
722+
*/
723+
void
724+
SnapBuildResetExportedSnapshotState(void)
725+
{
710726
SavedResourceOwnerDuringExport=NULL;
711727
ExportInProgress= false;
712728
}

‎src/include/replication/snapbuild.h

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp