Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b20bea

Browse files
knizhnikkelvich
authored andcommitted
Add mtm.inject_2pc_error function
1 parentbe81ae1 commit5b20bea

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

‎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+
CREATEFUNCTIONmtm.inject_2pc_error(stageinteger) RETURNS void
69+
AS'MODULE_PATHNAME','mtm_inject_2pc_error'
70+
LANGUAGE C;
71+
6872
CREATETABLEIF NOT EXISTSmtm.ddl_log (issuedtimestamp with time zonenot null, querytext);
6973

7074
CREATETABLEIF NOT EXISTSmtm.local_tables(rel_schematext, rel_nametext,primary key(rel_schema, rel_name));

‎multimaster.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ PG_FUNCTION_INFO_V1(mtm_get_cluster_state);
113113
PG_FUNCTION_INFO_V1(mtm_get_cluster_info);
114114
PG_FUNCTION_INFO_V1(mtm_make_table_local);
115115
PG_FUNCTION_INFO_V1(mtm_dump_lock_graph);
116+
PG_FUNCTION_INFO_V1(mtm_inject_2pc_error);
116117

117118
staticSnapshotMtmGetSnapshot(Snapshotsnapshot);
118119
staticvoidMtmInitialize(void);
@@ -687,6 +688,10 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
687688
return;
688689
}
689690

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

@@ -741,6 +746,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
741746
{
742747
MtmTransState*ts;
743748

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

787800

@@ -1483,6 +1496,7 @@ static void MtmInitialize()
14831496
Mtm->gcCount=0;
14841497
Mtm->nConfigChanges=0;
14851498
Mtm->localTablesHashLoaded= false;
1499+
Mtm->inject2PCError=0;
14861500
for (i=0;i<MtmNodes;i++) {
14871501
Mtm->nodes[i].oldestSnapshot=0;
14881502
Mtm->nodes[i].transDelay=0;
@@ -2426,12 +2440,13 @@ mtm_get_cluster_info(PG_FUNCTION_ARGS)
24262440
usrfctx= (MtmGetClusterInfoCtx*)palloc(sizeof(MtmGetNodeStateCtx));
24272441
get_call_result_type(fcinfo,NULL,&desc);
24282442
funcctx->attinmeta=TupleDescGetAttInMetadata(desc);
2429-
usrfctx->nodeId=1;
2443+
usrfctx->nodeId=0;
24302444
funcctx->user_fctx=usrfctx;
24312445
MemoryContextSwitchTo(oldcontext);
24322446
}
24332447
funcctx=SRF_PERCALL_SETUP();
24342448
usrfctx= (MtmGetClusterInfoCtx*)funcctx->user_fctx;
2449+
while (++usrfctx->nodeId <=Mtm->nAllNodes&&BIT_CHECK(Mtm->disabledNodeMask,usrfctx->nodeId-1));
24352450
if (usrfctx->nodeId>Mtm->nAllNodes) {
24362451
SRF_RETURN_DONE(funcctx);
24372452
}
@@ -2527,6 +2542,12 @@ Datum mtm_dump_lock_graph(PG_FUNCTION_ARGS)
25272542
returnCStringGetTextDatum(s->data);
25282543
}
25292544

2545+
Datummtm_inject_2pc_error(PG_FUNCTION_ARGS)
2546+
{
2547+
Mtm->inject2PCError=PG_GETARG_INT32(0);
2548+
PG_RETURN_VOID();
2549+
}
2550+
25302551
/*
25312552
* -------------------------------------------
25322553
* Broadcast utulity statements
@@ -2794,9 +2815,12 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
27942815
}
27952816
break;
27962817
caseTRANS_STMT_PREPARE:
2818+
elog(ERROR,"Two phase commit is not supported by multimaster");
2819+
break;
27972820
caseTRANS_STMT_COMMIT_PREPARED:
27982821
caseTRANS_STMT_ROLLBACK_PREPARED:
2799-
elog(ERROR,"Two phase commit is not supported by multimaster");
2822+
skipCommand= true;
2823+
break;
28002824
default:
28012825
break;
28022826
}

‎multimaster.h

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

167167
boollocalTablesHashLoaded;/* Whether data from local_tables table is loaded in shared memory hash table */
168+
intinject2PCError;/* Simulate error during 2PC commit at this node */
168169
intnLiveNodes;/* Number of active nodes */
169170
intnAllNodes;/* Total numbber of nodes */
170171
intnReceivers;/* Number of initialized logical receivers (used to determine moment when Mtm intialization is completed */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp