Skip to content

Commit fcd6771

Browse files
knizhnikkelvich
authored andcommitted
Handle distributed readonly transactions committed without setting status in CLOG
1 parent cdead0f commit fcd6771

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

contrib/multimaster/multimaster.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static int MMWorkers;
141141
static char* DtmHost;
142142
static int DtmPort;
143143
static int DtmBufferSize;
144+
static bool DtmVoted;
144145

145146
static ExecutorFinish_hook_type PreviousExecutorFinishHook = NULL;
146147
static void MMExecutorFinish(QueryDesc *queryDesc);
@@ -645,6 +646,7 @@ static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, Transaction
645646
{
646647
if (TransactionIdIsValid(DtmNextXid))
647648
{
649+
DtmVoted = true;
648650
if (status == TRANSACTION_STATUS_ABORTED || !MMIsDistributedTrans)
649651
{
650652
PgTransactionIdSetTreeStatus(xid, nsubxids, subxids, status, lsn);
@@ -774,6 +776,9 @@ DtmXactCallback(XactEvent event, void *arg)
774776
case XACT_EVENT_ABORT:
775777
if (TransactionIdIsValid(DtmNextXid))
776778
{
779+
if (!DtmVoted) {
780+
DtmGlobalSetTransStatus(DtmNextXid, TRANSACTION_STATUS_ABORTED, false);
781+
}
777782
if (event == XACT_EVENT_COMMIT)
778783
{
779784
/*
@@ -784,6 +789,7 @@ DtmXactCallback(XactEvent event, void *arg)
784789
hash_search(xid_in_doubt, &DtmNextXid, HASH_REMOVE, NULL);
785790
LWLockRelease(dtm->hashLock);
786791
}
792+
#if 0 /* should be handled now using DtmVoted flag */
787793
else
788794
{
789795
/*
@@ -796,6 +802,7 @@ DtmXactCallback(XactEvent event, void *arg)
796802
DtmGlobalSetTransStatus(DtmNextXid, TRANSACTION_STATUS_ABORTED, false);
797803
}
798804
}
805+
#endif
799806
DtmNextXid = InvalidTransactionId;
800807
DtmLastSnapshot = NULL;
801808
}
@@ -1008,6 +1015,7 @@ void MMBeginTransaction(void)
10081015
elog(ERROR, "Arbiter was not able to assign XID");
10091016
XTM_INFO("%d: Start global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);
10101017

1018+
DtmVoted = false;
10111019
DtmHasGlobalSnapshot = true;
10121020
DtmLastSnapshot = NULL;
10131021
MMIsDistributedTrans = false;
@@ -1020,6 +1028,7 @@ void MMJoinTransaction(TransactionId xid)
10201028
DtmNextXid = xid;
10211029
if (!TransactionIdIsValid(DtmNextXid))
10221030
elog(ERROR, "Arbiter was not able to assign XID");
1031+
DtmVoted = false;
10231032

10241033
DtmGlobalGetSnapshot(DtmNextXid, &DtmSnapshot, &dtm->minXid);
10251034
XTM_INFO("%d: Join global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);

contrib/multimaster/tests/mm.pgb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
\setrandom id1 1 100000
2+
\setrandom id2 1 100000
3+
begin;
4+
--select v from t where u=:id;
5+
update t set v = v - 1 where u=:id1;
6+
update t set v = v + 1 where u=:id2;
7+
commit;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pgbench -M prepared -f mm.pgb -T 15 -P 1 -c 50 -j 16 -r postgres

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