Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ae972c1

Browse files
knizhnikkelvich
authored andcommitted
Fix handling of DDL
1 parent b2f9970 commit ae972c1

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

multimaster.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static void MtmPrepareTransaction(MtmCurrentTrans* x)
489489
MtmLock(LW_EXCLUSIVE);
490490
ts = hash_search(xid2state, &x->xid, HASH_ENTER, NULL);
491491
ts->status = TRANSACTION_STATUS_IN_PROGRESS;
492-
ts->snapshot = x->isReplicated ? INVALID_CSN : x->snapshot;
492+
ts->snapshot = x->isReplicated || !x->containsDML ? INVALID_CSN : x->snapshot;
493493
ts->csn = MtmAssignCSN();
494494
ts->gtid = x->gtid;
495495
ts->cmd = MSG_INVALID;
@@ -868,7 +868,7 @@ mtm_drop_node(PG_FUNCTION_ARGS)
868868
dtm->nNodes -= 1;
869869
if (!IsTransactionBlock())
870870
{
871-
MtmBroadcastUtilityStmt(psprintf("select multimaster.drop_node(%d,%s)", nodeId, dropSlot ? "true" : "false"), true);
871+
MtmBroadcastUtilityStmt(psprintf("select mtm.drop_node(%d,%s)", nodeId, dropSlot ? "true" : "false"), true);
872872
}
873873
if (dropSlot)
874874
{
@@ -989,7 +989,7 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
989989
}
990990
}
991991

992-
static void MtmProcessDDLCommand(char const* queryString)
992+
static bool MtmProcessDDLCommand(char const* queryString)
993993
{
994994
RangeVar *rv;
995995
Relation rel;
@@ -1002,8 +1002,12 @@ static void MtmProcessDDLCommand(char const* queryString)
10021002
rv = makeRangeVar(MULTIMASTER_SCHEMA_NAME, MULTIMASTER_DDL_TABLE, -1);
10031003
rel = heap_openrv_extended(rv, RowExclusiveLock, true);
10041004

1005-
if (rel == NULL) {
1006-
return;
1005+
if (rel == NULL) {
1006+
if (!IsTransactionBlock()) {
1007+
MtmBroadcastUtilityStmt(queryString, false);
1008+
return true;
1009+
}
1010+
return false;
10071011
}
10081012

10091013
tupDesc = RelationGetDescr(rel);
@@ -1026,9 +1030,8 @@ static void MtmProcessDDLCommand(char const* queryString)
10261030
heap_freetuple(tup);
10271031
heap_close(rel, RowExclusiveLock);
10281032

1029-
elog(WARNING, "Replicate command: '%s'", queryString);
1030-
10311033
dtmTx.containsDML = true;
1034+
return false;
10321035
}
10331036

10341037
static void MtmProcessUtility(Node *parsetree, const char *queryString,
@@ -1038,7 +1041,6 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
10381041
bool skipCommand;
10391042
switch (nodeTag(parsetree))
10401043
{
1041-
case T_TransactionStmt:
10421044
case T_PlannedStmt:
10431045
case T_ClosePortalStmt:
10441046
case T_FetchStmt:
@@ -1052,14 +1054,17 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
10521054
case T_LoadStmt:
10531055
case T_VariableSetStmt:
10541056
case T_VariableShowStmt:
1057+
case T_TransactionStmt:
10551058
skipCommand = true;
10561059
break;
10571060
default:
1058-
skipCommand = false;
1061+
skipCommand = false;
10591062
break;
10601063
}
1061-
if (!skipCommand && !dtmTx.isReplicated) {
1062-
MtmProcessDDLCommand(queryString);
1064+
if (!skipCommand && !dtmTx.isReplicated && context == PROCESS_UTILITY_TOPLEVEL) {
1065+
if (MtmProcessDDLCommand(queryString)) {
1066+
return;
1067+
}
10631068
}
10641069
if (PreviousProcessUtilityHook != NULL)
10651070
{

tests/dtmbench.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ void initializeDatabase()
184184
printf("Creating database schema...\n");
185185
{
186186
nontransaction txn(conn);
187+
exec(txn, "drop extension if exists multimsater");
188+
exec(txn, "create extension multimaster");
187189
exec(txn, "drop table if exists t");
188190
exec(txn, "create table t(u int primary key, v int)");
189191
}

tests/reinit-mm.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,5 @@ do
3232
done
3333

3434
sleep 5
35-
echo "Create multimaster extension..."
36-
37-
for ((i=1;i<=n_nodes;i++))
38-
do
39-
port=$((5431+i))
40-
psql postgres -p $port -c "create extension multimaster"
41-
done
42-
4335

4436
echo Done

0 commit comments

Comments
 (0)