Skip to content

Commit 252dd43

Browse files
knizhnikkelvich
authored andcommitted
Fix memory context usage for concurrent DDL statements
1 parent ed18103 commit 252dd43

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

multimaster.c

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

39433943
case T_VacuumStmt:
3944-
if (context == PROCESS_UTILITY_TOPLEVEL) {
3944+
skipCommand = true;
3945+
if (context == PROCESS_UTILITY_TOPLEVEL) {
39453946
MtmProcessDDLCommand(queryString, false, true);
39463947
MtmTx.isDistributed = false;
3947-
skipCommand = true;
3948-
break;
3949-
} else {
3948+
} else if (MtmApplyContext != NULL) {
39503949
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
39513950
Assert(oldContext != MtmApplyContext);
39523951
MtmVacuumStmt = (VacuumStmt*)copyObject(parsetree);
39533952
MemoryContextSwitchTo(oldContext);
39543953
return;
39553954
}
3955+
break;
39563956

39573957
case T_CreateDomainStmt:
39583958
/* Detect temp tables access */
@@ -4049,10 +4049,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
40494049
MtmProcessDDLCommand(queryString, false, true);
40504050
MtmTx.isDistributed = false;
40514051
skipCommand = true;
4052-
} else {
4052+
} else if (MtmApplyContext != NULL) {
40534053
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
40544054
Assert(oldContext != MtmApplyContext);
4055-
MtmIndexStmt = indexStmt;
4055+
MtmIndexStmt = (IndexStmt*)copyObject(indexStmt);
40564056
MemoryContextSwitchTo(oldContext);
40574057
return;
40584058
}
@@ -4069,10 +4069,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
40694069
MtmProcessDDLCommand(queryString, false, true);
40704070
MtmTx.isDistributed = false;
40714071
skipCommand = true;
4072-
} else {
4072+
} else if (MtmApplyContext != NULL) {
40734073
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
40744074
Assert(oldContext != MtmApplyContext);
4075-
MtmDropStmt = stmt;
4075+
MtmDropStmt = (DropStmt*)copyObject(stmt);
40764076
MemoryContextSwitchTo(oldContext);
40774077
return;
40784078
}

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