Skip to content

Commit afa7ff6

Browse files
knizhnikkelvich
authored andcommitted
Add mtm.get_last_csn function
1 parent 34d042e commit afa7ff6

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

multimaster--1.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ CREATE FUNCTION mtm.get_csn(tid xid) RETURNS bigint
3131
AS 'MODULE_PATHNAME','mtm_get_csn'
3232
LANGUAGE C;
3333

34+
CREATE FUNCTION mtm.get_last_csn() RETURNS bigint
35+
AS 'MODULE_PATHNAME','mtm_get_last_csn'
36+
LANGUAGE C;
37+
3438

3539
CREATE TYPE mtm.node_state AS ("id" integer, "disabled" bool, "disconnected" bool, "catchUp" bool, "slotLag" bigint, "avgTransDelay" bigint, "lastStatusChange" timestamp, "oldestSnapshot" bigint, "connStr" text);
3640

multimaster.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ PG_FUNCTION_INFO_V1(mtm_poll_node);
107107
PG_FUNCTION_INFO_V1(mtm_recover_node);
108108
PG_FUNCTION_INFO_V1(mtm_get_snapshot);
109109
PG_FUNCTION_INFO_V1(mtm_get_csn);
110+
PG_FUNCTION_INFO_V1(mtm_get_last_csn);
110111
PG_FUNCTION_INFO_V1(mtm_get_nodes_state);
111112
PG_FUNCTION_INFO_V1(mtm_get_cluster_state);
112113
PG_FUNCTION_INFO_V1(mtm_get_cluster_info);
@@ -822,11 +823,11 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
822823
if (ts != NULL) {
823824
if (commit) {
824825
Assert(ts->status == TRANSACTION_STATUS_UNKNOWN);
825-
ts->status = TRANSACTION_STATUS_COMMITTED;
826826
if (x->csn > ts->csn) {
827827
ts->csn = x->csn;
828828
MtmSyncClock(ts->csn);
829829
}
830+
ts->status = TRANSACTION_STATUS_COMMITTED;
830831
} else {
831832
ts->status = TRANSACTION_STATUS_ABORTED;
832833
}
@@ -1461,6 +1462,7 @@ static void MtmInitialize()
14611462
Mtm->recoverySlot = 0;
14621463
Mtm->locks = GetNamedLWLockTranche(MULTIMASTER_NAME);
14631464
Mtm->csn = MtmGetCurrentTime();
1465+
Mtm->lastCsn = INVALID_CSN;
14641466
Mtm->oldestXid = FirstNormalTransactionId;
14651467
Mtm->nLiveNodes = MtmNodes;
14661468
Mtm->nAllNodes = MtmNodes;
@@ -2294,6 +2296,12 @@ mtm_get_snapshot(PG_FUNCTION_ARGS)
22942296
PG_RETURN_INT64(MtmTx.snapshot);
22952297
}
22962298

2299+
Datum
2300+
mtm_get_last_csn(PG_FUNCTION_ARGS)
2301+
{
2302+
PG_RETURN_INT64(Mtm->lastCsn);
2303+
}
2304+
22972305
Datum
22982306
mtm_get_csn(PG_FUNCTION_ARGS)
22992307
{

multimaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ typedef struct
172172
int nActiveTransactions; /* Nunmber of active 2PC transactions */
173173
int nConfigChanges; /* Number of cluster configuration changes */
174174
int64 timeShift; /* Local time correction */
175-
csn_t csn; /* Last obtained CSN: used to provide unique acending CSNs based on system time */
175+
csn_t csn; /* Last obtained timestamp: used to provide unique acending CSNs based on system time */
176+
csn_t lastCsn; /* CSN of last committed transaction */
176177
MtmTransState* votingTransactions; /* L1-list of replicated transactions sendings notifications to coordinator.
177178
This list is used to pass information to mtm-sender BGW */
178179
MtmTransState* transListHead; /* L1 list of all finished transactions present in xid2state hash.

tests/dtmacid.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ void* reader(void* arg)
130130
while ((c2 = random() % conns.size()) == c1);
131131
work txn1(*conns[c1]);
132132
work txn2(*conns[c2]);
133-
result r1 = txn1.exec("select v,xmin,xmax,mtm.get_csn(xmin) from t order by u");
134-
result r2 = txn2.exec("select v,xmin,xmax,mtm.get_csn(xmin) from t order by u");
133+
result r1 = txn1.exec("select v,xmin,xmax,mtm.get_csn(xmin),mtm.get_csn(xmax),mtm.get_snapshot(),mtm.get_last_csn() from t order by u");
134+
result r2 = txn2.exec("select v,xmin,xmax,mtm.get_csn(xmin),mtm.get_csn(xmax),mtm.get_snapshot(),mtm.get_last_csn() from t order by u");
135135
int delta = 0;
136136
for (int i=0; i < cfg.nAccounts; i++) {
137137
int diff = r1[i][0].as(int()) - r2[i][0].as(int());
@@ -140,7 +140,9 @@ void* reader(void* arg)
140140
delta = diff;
141141
if (delta < 0) lt++; else gt++;
142142
} else if (delta != diff) {
143-
printf("Inconsistency found for record %d: [%d,%d]->%ld vs [%d,%d]->%ld\n", i, r1[i][1].as(int()), r1[i][2].as(int()), r1[i][3].as(int64_t()), r2[i][1].as(int()), r2[i][2].as(int()), r2[i][3].as(int64_t()));
143+
printf("Inconsistency found for record %d: [%d,%d]->[%ld,%ld] (snapshot %ld, last CSN %ld) vs. [%d,%d]->[%ld,%ld] (snapshot %ld, last CSN %ld)\n", i,
144+
r1[i][1].as(int()), r1[i][2].as(int()), r1[i][3].as(int64_t()), r1[i][4].as(int64_t()), r1[i][5].as(int64_t()), r1[i][6].as(int64_t()),
145+
r2[i][1].as(int()), r2[i][2].as(int()), r2[i][3].as(int64_t()), r2[i][4].as(int64_t()), r2[i][5].as(int64_t()), r2[i][6].as(int64_t()));
144146
}
145147
}
146148
}

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