Skip to content

Commit 75c6ced

Browse files
committed
Fix memory context usage for concurrent DDL statements
1 parent 3f4a139 commit 75c6ced

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

contrib/mmts/multimaster.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,18 +3942,18 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
39423942
break;
39433943

39443944
case T_VacuumStmt:
3945-
if (context == PROCESS_UTILITY_TOPLEVEL) {
3945+
skipCommand = true;
3946+
if (context == PROCESS_UTILITY_TOPLEVEL) {
39463947
MtmProcessDDLCommand(queryString, false, true);
39473948
MtmTx.isDistributed = false;
3948-
skipCommand = true;
3949-
break;
3950-
} else {
3949+
} else if (MtmApplyContext != NULL) {
39513950
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
39523951
Assert(oldContext != MtmApplyContext);
39533952
MtmVacuumStmt = (VacuumStmt*)copyObject(parsetree);
39543953
MemoryContextSwitchTo(oldContext);
39553954
return;
39563955
}
3956+
break;
39573957

39583958
case T_CreateDomainStmt:
39593959
/* Detect temp tables access */
@@ -4050,10 +4050,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
40504050
MtmProcessDDLCommand(queryString, false, true);
40514051
MtmTx.isDistributed = false;
40524052
skipCommand = true;
4053-
} else {
4053+
} else if (MtmApplyContext != NULL) {
40544054
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
40554055
Assert(oldContext != MtmApplyContext);
4056-
MtmIndexStmt = indexStmt;
4056+
MtmIndexStmt = (IndexStmt*)copyObject(indexStmt);
40574057
MemoryContextSwitchTo(oldContext);
40584058
return;
40594059
}
@@ -4070,10 +4070,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
40704070
MtmProcessDDLCommand(queryString, false, true);
40714071
MtmTx.isDistributed = false;
40724072
skipCommand = true;
4073-
} else {
4073+
} else if (MtmApplyContext != NULL) {
40744074
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
40754075
Assert(oldContext != MtmApplyContext);
4076-
MtmDropStmt = stmt;
4076+
MtmDropStmt = (DropStmt*)copyObject(stmt);
40774077
MemoryContextSwitchTo(oldContext);
40784078
return;
40794079
}

contrib/mmts/pglogical_apply.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,21 @@ process_remote_message(StringInfo s)
390390
if (rc < 0) {
391391
elog(ERROR, "Failed to execute utility statement %s", messageBody);
392392
} else {
393+
PushActiveSnapshot(GetTransactionSnapshot());
394+
393395
if (MtmVacuumStmt != NULL) {
394396
ExecVacuum(MtmVacuumStmt, 1);
395397
} else if (MtmIndexStmt != NULL) {
398+
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
396399
Oid relid = RangeVarGetRelidExtended(MtmIndexStmt->relation, ShareUpdateExclusiveLock,
397400
false, false,
398401
NULL,
399402
NULL);
400403

401404
/* Run parse analysis ... */
402-
//MtmIndexStmt = transformIndexStmt(relid, MtmIndexStmt, messageBody);
403-
404-
PushActiveSnapshot(GetTransactionSnapshot());
405+
MtmIndexStmt = transformIndexStmt(relid, MtmIndexStmt, messageBody);
405406

407+
MemoryContextSwitchTo(oldContext);
406408

407409
DefineIndex(relid, /* OID of heap relation */
408410
MtmIndexStmt,
@@ -412,12 +414,11 @@ process_remote_message(StringInfo s)
412414
false, /* skip_build */
413415
false); /* quiet */
414416

415-
if (ActiveSnapshotSet())
416-
PopActiveSnapshot();
417-
418417
} else if (MtmDropStmt != NULL) {
419418
RemoveObjects(MtmDropStmt);
420419
}
420+
if (ActiveSnapshotSet())
421+
PopActiveSnapshot();
421422
}
422423
if (standalone) {
423424
CommitTransactionCommand();

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