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

Commit 02f431a

Browse files
committed
add traces
1 parent f5b6d8a commit 02f431a

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

contrib/mmts/arbiter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ static void MtmTransReceiver(Datum arg)
853853
if (MtmIsCoordinator(ts)) {
854854
switch (msg->code) {
855855
case MSG_READY:
856+
MTM_TXTRACE(ts, "MtmTransReceiver got MSG_READY");
856857
if (ts->nVotes >= Mtm->nLiveNodes) {
857858
MtmAbortTransaction(ts);
858859
MtmWakeUpBackend(ts);
@@ -875,6 +876,7 @@ static void MtmTransReceiver(Datum arg)
875876
} else if (MtmUseDtm) {
876877
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
877878
ts->nVotes = 1; /* I voted myself */
879+
MTM_TXTRACE(ts, "MtmTransReceiver send MSG_PREPARE");
878880
MtmSendNotificationMessage(ts, MSG_PREPARE);
879881
} else {
880882
Assert(ts->status == TRANSACTION_STATUS_IN_PROGRESS);
@@ -894,6 +896,7 @@ static void MtmTransReceiver(Datum arg)
894896
}
895897
break;
896898
case MSG_PREPARED:
899+
MTM_TXTRACE(ts, "MtmTransReceiver got MSG_PREPARED");
897900
if (ts->nVotes >= Mtm->nLiveNodes) {
898901
MtmAbortTransaction(ts);
899902
MtmWakeUpBackend(ts);

contrib/mmts/multimaster.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ MtmCreateTransState(MtmCurrentTrans* x)
708708
/* I am coordinator of transaction */
709709
ts->gtid.xid = x->xid;
710710
ts->gtid.node = MtmNodeId;
711-
ts->gid[0] = '\0';
711+
//ts->gid[0] = '\0';
712+
strcpy(ts->gid, x->gid);
712713
}
713714
return ts;
714715
}
@@ -724,6 +725,7 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
724725
{
725726
MtmTransState* ts;
726727
TransactionId* subxids;
728+
MTM_TXTRACE(x, "PrePrepareTransaction Start");
727729

728730
if (!x->isDistributed) {
729731
return;
@@ -782,7 +784,8 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
782784
MtmAddSubtransactions(ts, subxids, ts->nSubxids);
783785
MTM_LOG3("%d: MtmPrePrepareTransaction prepare commit of %d (gtid.xid=%d, gtid.node=%d, CSN=%ld)",
784786
MyProcPid, x->xid, ts->gtid.xid, ts->gtid.node, ts->csn);
785-
MtmUnlock();
787+
MtmUnlock();
788+
MTM_TXTRACE(x, "PrePrepareTransaction Finish");
786789
}
787790

788791
/*
@@ -810,6 +813,7 @@ static void
810813
MtmPostPrepareTransaction(MtmCurrentTrans* x)
811814
{
812815
MtmTransState* ts;
816+
MTM_TXTRACE(x, "PostPrepareTransaction Start");
813817

814818
if (Mtm->inject2PCError == 2) {
815819
Mtm->inject2PCError = 0;
@@ -845,7 +849,9 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
845849
while (!ts->votingCompleted && Mtm->status == MTM_ONLINE && ts->status != TRANSACTION_STATUS_ABORTED && start + transTimeout >= MtmGetSystemTime())
846850
{
847851
MtmUnlock();
852+
MTM_TXTRACE(x, "PostPrepareTransaction WaitLatch Start");
848853
result = WaitLatch(&MyProc->procLatch, WL_LATCH_SET|WL_TIMEOUT, MtmHeartbeatRecvTimeout);
854+
MTM_TXTRACE(x, "PostPrepareTransaction WaitLatch Finish");
849855
if (result & WL_LATCH_SET) {
850856
ResetLatch(&MyProc->procLatch);
851857
}
@@ -868,6 +874,8 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
868874
Mtm->inject2PCError = 0;
869875
elog(ERROR, "ERROR INJECTION for transaction %d (%s)", x->xid, x->gid);
870876
}
877+
878+
MTM_TXTRACE(x, "PostPrepareTransaction Finish");
871879
}
872880

873881

@@ -1064,8 +1072,9 @@ csn_t MtmGetTransactionCSN(TransactionId xid)
10641072
}
10651073

10661074
void MtmWakeUpBackend(MtmTransState* ts)
1067-
{
1068-
if (!ts->votingCompleted) {
1075+
{
1076+
if (!ts->votingCompleted) {
1077+
MTM_TXTRACE(ts, "MtmWakeUpBackend");
10691078
MTM_LOG3("Wakeup backed procno=%d, pid=%d", ts->procno, ProcGlobal->allProcs[ts->procno].pid);
10701079
ts->votingCompleted = true;
10711080
SetLatch(&ProcGlobal->allProcs[ts->procno].procLatch);

contrib/mmts/multimaster.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define MTM_LOG4(fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
3333
#endif
3434

35+
#define MTM_TXTRACE(tx, event) \
36+
fprintf(stderr, "[MTM_TXTRACE] [%s] [%lld] %s\n", tx->gid, (long long)MtmGetSystemTime(), event)
3537
#define MULTIMASTER_NAME "multimaster"
3638
#define MULTIMASTER_SCHEMA_NAME "mtm"
3739
#define MULTIMASTER_DDL_TABLE "ddl_log"

contrib/mmts/pglogical_proto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ pglogical_write_commit(StringInfo out, PGLogicalOutputData *data,
178178
if (txn->xact_action != XLOG_XACT_COMMIT) {
179179
pq_sendstring(out, txn->gid);
180180
}
181+
182+
MTM_TXTRACE(txn, "pglogical_write_commit Finish");
181183
}
182184

183185
/*

contrib/mmts/tests2/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ if [ "$1" = 'postgres' ]; then
8888
multimaster.conn_strings = '$CONNSTRS'
8989
multimaster.heartbeat_recv_timeout = 1000
9090
multimaster.heartbeat_send_timeout = 250
91+
multimaster.twopc_min_timeout = 40000
9192
EOF
9293

9394
tail -n 20 $PGDATA/postgresql.conf

src/backend/replication/logical/decode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*
2525
* -------------------------------------------------------------------------
2626
*/
27+
#include <sys/time.h>
28+
#include <time.h>
29+
2730
#include "postgres.h"
2831

2932
#include "access/heapam.h"
@@ -643,6 +646,15 @@ DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
643646
int i;
644647
TransactionId xid = parsed->twophase_xid;
645648

649+
struct timeval tv;
650+
int64 ts;
651+
652+
gettimeofday(&tv, NULL);
653+
ts = (int64)tv.tv_sec*USECS_PER_SEC + tv.tv_usec;
654+
655+
fprintf(stderr, "[MTM_TXTRACE] [%s] [%lld] DecodePrepare Started\n",
656+
parsed->twophase_gid, (long long) ts);
657+
646658
if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
647659
{
648660
origin_lsn = parsed->origin_lsn;

0 commit comments

Comments
 (0)