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

Commit 34d042e

Browse files
knizhnikkelvich
authored andcommitted
Add mtm.get_csn function
1 parent 8e9e4fd commit 34d042e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

multimaster--1.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ CREATE FUNCTION mtm.get_snapshot() RETURNS bigint
2727
AS 'MODULE_PATHNAME','mtm_get_snapshot'
2828
LANGUAGE C;
2929

30+
CREATE FUNCTION mtm.get_csn(tid xid) RETURNS bigint
31+
AS 'MODULE_PATHNAME','mtm_get_csn'
32+
LANGUAGE C;
33+
3034

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

multimaster.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ PG_FUNCTION_INFO_V1(mtm_add_node);
106106
PG_FUNCTION_INFO_V1(mtm_poll_node);
107107
PG_FUNCTION_INFO_V1(mtm_recover_node);
108108
PG_FUNCTION_INFO_V1(mtm_get_snapshot);
109+
PG_FUNCTION_INFO_V1(mtm_get_csn);
109110
PG_FUNCTION_INFO_V1(mtm_get_nodes_state);
110111
PG_FUNCTION_INFO_V1(mtm_get_cluster_state);
111112
PG_FUNCTION_INFO_V1(mtm_get_cluster_info);
@@ -451,12 +452,13 @@ static TransactionId
451452
MtmAdjustOldestXid(TransactionId xid)
452453
{
453454
int i;
455+
csn_t oldestSnapshot = INVALID_CSN;
454456
MtmTransState *prev = NULL;
455457
MtmTransState *ts = (MtmTransState*)hash_search(MtmXid2State, &xid, HASH_FIND, NULL);
456458
MTM_LOG1("%d: MtmAdjustOldestXid(%d): snapshot=%ld, csn=%ld, status=%d", MyProcPid, xid, ts != NULL ? ts->snapshot : 0, ts != NULL ? ts->csn : 0, ts != NULL ? ts->status : -1);
457459
Mtm->gcCount = 0;
458460
if (ts != NULL) {
459-
csn_t oldestSnapshot = ts->snapshot;
461+
oldestSnapshot = ts->snapshot;
460462
Mtm->nodes[MtmNodeId-1].oldestSnapshot = oldestSnapshot;
461463
for (i = 0; i < Mtm->nAllNodes; i++) {
462464
if (!BIT_CHECK(Mtm->disabledNodeMask, i)
@@ -486,6 +488,7 @@ MtmAdjustOldestXid(TransactionId xid)
486488
if (prev != NULL) {
487489
Mtm->transListHead = prev;
488490
Mtm->oldestXid = xid = prev->xid;
491+
MTM_LOG1("%d: MtmAdjustOldestXid: oldestXid=%d, olderstSnapshot=%ld", MyProcPid, xid, oldestSnapshot);
489492
} else if (TransactionIdPrecedes(Mtm->oldestXid, xid)) {
490493
xid = Mtm->oldestXid;
491494
}
@@ -2291,6 +2294,23 @@ mtm_get_snapshot(PG_FUNCTION_ARGS)
22912294
PG_RETURN_INT64(MtmTx.snapshot);
22922295
}
22932296

2297+
Datum
2298+
mtm_get_csn(PG_FUNCTION_ARGS)
2299+
{
2300+
TransactionId xid = PG_GETARG_INT32(0);
2301+
MtmTransState* ts;
2302+
csn_t csn = INVALID_CSN;
2303+
2304+
MtmLock(LW_SHARED);
2305+
ts = hash_search(MtmXid2State, &xid, HASH_FIND, NULL);
2306+
if (ts != NULL) {
2307+
csn = ts->csn;
2308+
}
2309+
MtmUnlock();
2310+
2311+
return csn;
2312+
}
2313+
22942314
typedef struct
22952315
{
22962316
int nodeId;

tests/dtmacid.cpp

Lines changed: 3 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 from t order by u");
134-
result r2 = txn2.exec("select v from t order by u");
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");
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,7 @@ 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\n", i);
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()));
144144
}
145145
}
146146
}

0 commit comments

Comments
 (0)