Skip to content

Commit 9972466

Browse files
committed
Debug 2PC
1 parent a6f1b55 commit 9972466

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

contrib/mmts/multimaster.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ MtmBeginTransaction(MtmCurrentTrans* x)
538538
x->gtid.xid = InvalidTransactionId;
539539
MtmUnlock();
540540

541-
MTM_TRACE("MtmLocalTransaction: %s transaction %u uses local snapshot %lu\n", x->isDistributed ? "distributed" : "local", x->xid, x->snapshot);
541+
MTM_TRACE("%d: MtmLocalTransaction: %s transaction %u uses local snapshot %lu\n",
542+
MyProcPid, x->isDistributed ? "distributed" : "local", x->xid, x->snapshot);
542543
}
543544
}
544545

@@ -583,7 +584,7 @@ MtmCheckClusterLock()
583584
} else {
584585
/* All lockers are synchronized their logs */
585586
/* Remove lock and mark them as receovered */
586-
elog(WARNING, "Complete recovery of %d nodes (node mask %llx)", dtm->nLockers, dtm->nodeLockerMask);
587+
elog(WARNING, "Complete recovery of %d nodes (node mask %lx)", dtm->nLockers, dtm->nodeLockerMask);
587588
Assert(dtm->walSenderLockerMask == 0);
588589
Assert((dtm->nodeLockerMask & dtm->disabledNodeMask) == dtm->nodeLockerMask);
589590
dtm->disabledNodeMask &= ~dtm->nodeLockerMask;
@@ -606,7 +607,7 @@ static void MtmPrecommitTransaction(MtmCurrentTrans* x)
606607
MtmTransState* ts;
607608
int i;
608609

609-
if (!x->isDistributed) {
610+
if (!x->isDistributed || x->isPrepared) {
610611
return;
611612
}
612613

@@ -657,6 +658,7 @@ static void
657658
MtmPrepareTransaction(MtmCurrentTrans* x)
658659
{
659660
MtmPrecommitTransaction(x);
661+
MTM_TRACE("Prepare transaction %d", x->xid);
660662
x->isPrepared = true;
661663
}
662664

@@ -666,6 +668,7 @@ MtmCommitPreparedTransaction(MtmCurrentTrans* x)
666668
TransactionId *subxids;
667669
int nSubxids;
668670
nSubxids = xactGetCommittedChildren(&subxids);
671+
MTM_TRACE("%d: Commit prepared transaction %d\n", MyProcPid, x->xid);
669672
if (!MtmCommitTransaction(x->xid, nSubxids, subxids))
670673
{
671674
elog(ERROR, "Commit of transaction %d is rejected by DTM", x->xid);
@@ -718,8 +721,12 @@ static int64 MtmGetSlotLag(int nodeId)
718721
static void
719722
MtmEndTransaction(MtmCurrentTrans* x, bool commit)
720723
{
721-
if (x->isDistributed && commit) {
724+
MTM_TRACE("%d: End transaction %d, prepared=%d, distributed=%d -> %s\n", MyProcPid, x->xid, x->isPrepared, x->isDistributed, commit ? "commit" : "abort");
725+
if (x->isDistributed && commit) {
722726
MtmTransState* ts;
727+
if (x->isPrepared) {
728+
return;
729+
}
723730
MtmLock(LW_EXCLUSIVE);
724731
ts = hash_search(xid2state, &x->xid, HASH_FIND, NULL);
725732
Assert(ts != NULL);
@@ -1541,8 +1548,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
15411548
switch (stmt->kind)
15421549
{
15431550
case TRANS_STMT_COMMIT:
1544-
if (MtmUse2PC) {
1551+
if (MtmUse2PC && dtmTx.isDistributed && dtmTx.containsDML) {
15451552
char* gid = MtmGenerateGid();
1553+
if (!IsTransactionBlock()) {
1554+
elog(WARNING, "Start transaction block for %d", dtmTx.xid);
1555+
CommitTransactionCommand();
1556+
StartTransactionCommand();
1557+
}
15461558
if (!PrepareTransactionBlock(gid))
15471559
{
15481560
elog(WARNING, "Failed to prepare transaction %s", gid);
@@ -1826,7 +1838,7 @@ void MtmRefreshClusterStatus(bool nowait)
18261838

18271839
clique = MtmFindMaxClique(matrix, MtmNodes, &clique_size);
18281840
if (clique_size >= MtmNodes/2+1) { /* have quorum */
1829-
elog(WARNING, "Find clique %llx, disabledNodeMask %llx", clique, dtm->disabledNodeMask);
1841+
elog(WARNING, "Find clique %lx, disabledNodeMask %lx", clique, dtm->disabledNodeMask);
18301842
MtmLock(LW_EXCLUSIVE);
18311843
mask = ~clique & (((nodemask_t)1 << MtmNodes)-1) & ~dtm->disabledNodeMask; /* new disabled nodes mask */
18321844
for (i = 0; mask != 0; i++, mask >>= 1) {
@@ -1853,7 +1865,7 @@ void MtmRefreshClusterStatus(bool nowait)
18531865
MtmSwitchClusterMode(MTM_RECOVERY);
18541866
}
18551867
} else {
1856-
elog(WARNING, "Clique %llx has no quorum", clique);
1868+
elog(WARNING, "Clique %lx has no quorum", clique);
18571869
}
18581870
}
18591871

contrib/mmts/pglogical_apply.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ void MtmExecutor(int id, void* work, size_t size)
880880
}
881881
PG_CATCH();
882882
{
883+
MTM_TRACE("%d: REMOTE abort transaction %d\n", MyProcPid, GetCurrentTransactionId());
884+
PG_RE_THROW();
883885
FlushErrorState();
884886
MTM_TRACE("%d: REMOTE abort transaction %d\n", MyProcPid, GetCurrentTransactionId());
885887
AbortCurrentTransaction();

contrib/postgres_fdw/tests/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
CXX=g++
2-
CXXFLAGS=-g -Wall -O2 -pthread
2+
CXXFLAGS=-g -Wall -O0 -pthread
33

44
all: dtmbench
55

66
dtmbench: dtmbench.cpp
77
$(CXX) $(CXXFLAGS) -o dtmbench dtmbench.cpp -lpqxx
88

99
clean:
10-
rm -f dtmbench
10+
rm -f dtmbench

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