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

Commit ad75913

Browse files
committed
Add mtm.inject_2pc_error function
1 parent 6154c13 commit ad75913

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

contrib/mmts/multimaster--1.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ CREATE FUNCTION mtm.poll_node(nodeId integer, noWait boolean default FALSE) RETU
6565
AS 'MODULE_PATHNAME','mtm_poll_node'
6666
LANGUAGE C;
6767

68+
CREATE FUNCTION mtm.inject_2pc_error(stage integer) RETURNS void
69+
AS 'MODULE_PATHNAME','mtm_inject_2pc_error'
70+
LANGUAGE C;
71+
6872
CREATE TABLE IF NOT EXISTS mtm.ddl_log (issued timestamp with time zone not null, query text);
6973

7074
CREATE TABLE IF NOT EXISTS mtm.local_tables(rel_schema text, rel_name text, primary key(rel_schema, rel_name));

contrib/mmts/multimaster.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ PG_FUNCTION_INFO_V1(mtm_get_cluster_state);
114114
PG_FUNCTION_INFO_V1(mtm_get_cluster_info);
115115
PG_FUNCTION_INFO_V1(mtm_make_table_local);
116116
PG_FUNCTION_INFO_V1(mtm_dump_lock_graph);
117+
PG_FUNCTION_INFO_V1(mtm_inject_2pc_error);
117118

118119
static Snapshot MtmGetSnapshot(Snapshot snapshot);
119120
static void MtmInitialize(void);
@@ -688,6 +689,10 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
688689
return;
689690
}
690691

692+
if (Mtm->inject2PCError == 1) {
693+
Mtm->inject2PCError = 0;
694+
elog(ERROR, "ERROR INJECTION for transaction %d (%s)", x->xid, x->gid);
695+
}
691696
x->xid = GetCurrentTransactionId();
692697
Assert(TransactionIdIsValid(x->xid));
693698

@@ -742,6 +747,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
742747
{
743748
MtmTransState* ts;
744749

750+
if (Mtm->inject2PCError == 2) {
751+
Mtm->inject2PCError = 0;
752+
elog(ERROR, "ERROR INJECTION for transaction %d (%s)", x->xid, x->gid);
753+
}
745754
MtmLock(LW_EXCLUSIVE);
746755
ts = hash_search(MtmXid2State, &x->xid, HASH_FIND, NULL);
747756
Assert(ts != NULL);
@@ -783,6 +792,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
783792
MTM_LOG3("%d: Result of vote: %d", MyProcPid, ts->status);
784793
MtmUnlock();
785794
}
795+
if (Mtm->inject2PCError == 3) {
796+
Mtm->inject2PCError = 0;
797+
elog(ERROR, "ERROR INJECTION for transaction %d (%s)", x->xid, x->gid);
798+
}
786799
}
787800

788801

@@ -1484,6 +1497,7 @@ static void MtmInitialize()
14841497
Mtm->gcCount = 0;
14851498
Mtm->nConfigChanges = 0;
14861499
Mtm->localTablesHashLoaded = false;
1500+
Mtm->inject2PCError = 0;
14871501
for (i = 0; i < MtmNodes; i++) {
14881502
Mtm->nodes[i].oldestSnapshot = 0;
14891503
Mtm->nodes[i].transDelay = 0;
@@ -2427,12 +2441,13 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
24272441
usrfctx = (MtmGetClusterInfoCtx*)palloc(sizeof(MtmGetNodeStateCtx));
24282442
get_call_result_type(fcinfo, NULL, &desc);
24292443
funcctx->attinmeta = TupleDescGetAttInMetadata(desc);
2430-
usrfctx->nodeId = 1;
2444+
usrfctx->nodeId = 0;
24312445
funcctx->user_fctx = usrfctx;
24322446
MemoryContextSwitchTo(oldcontext);
24332447
}
24342448
funcctx = SRF_PERCALL_SETUP();
24352449
usrfctx = (MtmGetClusterInfoCtx*)funcctx->user_fctx;
2450+
while (++usrfctx->nodeId <= Mtm->nAllNodes && BIT_CHECK(Mtm->disabledNodeMask, usrfctx->nodeId-1));
24362451
if (usrfctx->nodeId > Mtm->nAllNodes) {
24372452
SRF_RETURN_DONE(funcctx);
24382453
}
@@ -2528,6 +2543,12 @@ Datum mtm_dump_lock_graph(PG_FUNCTION_ARGS)
25282543
return CStringGetTextDatum(s->data);
25292544
}
25302545

2546+
Datum mtm_inject_2pc_error(PG_FUNCTION_ARGS)
2547+
{
2548+
Mtm->inject2PCError = PG_GETARG_INT32(0);
2549+
PG_RETURN_VOID();
2550+
}
2551+
25312552
/*
25322553
* -------------------------------------------
25332554
* Broadcast utulity statements
@@ -2800,9 +2821,12 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
28002821
}
28012822
break;
28022823
case TRANS_STMT_PREPARE:
2824+
elog(ERROR, "Two phase commit is not supported by multimaster");
2825+
break;
28032826
case TRANS_STMT_COMMIT_PREPARED:
28042827
case TRANS_STMT_ROLLBACK_PREPARED:
2805-
elog(ERROR, "Two phase commit is not supported by multimaster");
2828+
skipCommand = true;
2829+
break;
28062830
default:
28072831
break;
28082832
}

contrib/mmts/multimaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ typedef struct
165165
nodemask_t reconnectMask; /* Mask of nodes connection to which has to be reestablished by sender */
166166

167167
bool localTablesHashLoaded; /* Whether data from local_tables table is loaded in shared memory hash table */
168+
int inject2PCError; /* Simulate error during 2PC commit at this node */
168169
int nLiveNodes; /* Number of active nodes */
169170
int nAllNodes; /* Total numbber of nodes */
170171
int nReceivers; /* Number of initialized logical receivers (used to determine moment when Mtm intialization is completed */

0 commit comments

Comments
 (0)