Skip to content

Commit 874f125

Browse files
kovdb75Mikhail Rutman
authored andcommitted
[PGPRO-5893] Fixed processing of error for DDL-queries in PgPlSQL block
Tags: atx, multimaster
1 parent baab923 commit 874f125

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/commit.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,39 @@ mtm_commit_cleanup(int status, Datum arg)
135135
/* there was no precommit, we can abort */
136136
PG_TRY();
137137
{
138-
AbortOutOfAnyTransaction();
139-
StartTransactionCommand();
138+
#ifdef PGPRO_EE
139+
int atxLevel = DatumGetInt32(arg);
140+
141+
/*
142+
* If we are inside ATX transaction, we can not call
143+
* AbortOutOfAnyTransaction() because this call will abort
144+
* ALL transactions and we will have problems if the
145+
* calling code is not designed for this case.
146+
*/
147+
if (atxLevel)
148+
{
149+
/* Abort (current ATX transaction only): */
150+
AbortCurrentTransaction();
151+
/* Restart ATX transaction if it was resumed: */
152+
if (atxLevel > getNestLevelATX())
153+
SuspendTransaction();
154+
}
155+
else
156+
#endif
157+
{
158+
AbortOutOfAnyTransaction();
159+
StartTransactionCommand();
160+
}
140161
FinishPreparedTransaction(mtm_commit_state.gid, false, false);
141162
mtm_commit_state.gtx->state.status = GTXAborted;
142163
mtm_log(MtmTxFinish, "%s aborted as own orphaned not precomitted",
143164
mtm_commit_state.gid);
144165
CommitTransactionCommand();
145-
166+
#ifdef PGPRO_EE
167+
/* Restart ATX transaction if it was resumed: */
168+
if (atxLevel > getNestLevelATX())
169+
SuspendTransaction();
170+
#endif
146171
}
147172
/*
148173
* this should be extremely unlikely, but if we fail, don't
@@ -218,7 +243,7 @@ MtmBeginTransaction()
218243
* register gtx hook first (it will be called last)
219244
*/
220245
GlobalTxEnsureBeforeShmemExitHook();
221-
before_shmem_exit(mtm_commit_cleanup, Int32GetDatum(1));
246+
before_shmem_exit(mtm_commit_cleanup, Int32GetDatum(0));
222247
mtm_commit_state.mctx = AllocSetContextCreate(TopMemoryContext,
223248
"MtmCommitContext",
224249
ALLOCSET_DEFAULT_SIZES);
@@ -373,6 +398,9 @@ MtmTwoPhaseCommit(void)
373398
MtmGeneration xact_gen;
374399
char dmq_stream_name[DMQ_STREAM_NAME_MAXLEN];
375400
GTxState gtx_state;
401+
#ifdef PGPRO_EE
402+
int atxLevel = getNestLevelATX();
403+
#endif
376404

377405
if (MtmNo3PC)
378406
{
@@ -714,7 +742,7 @@ MtmTwoPhaseCommit(void)
714742
}
715743
PG_CATCH();
716744
{
717-
mtm_commit_cleanup(0, Int32GetDatum(0));
745+
mtm_commit_cleanup(0, Int32GetDatum(atxLevel));
718746

719747
PG_RE_THROW();
720748
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy