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

Commit a8f07d2

Browse files
knizhnikkelvich
authored andcommitted
Add more columns to node/cluster state function
1 parent ad9bb1b commit a8f07d2

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

arbiter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ static void MtmTransReceiver(Datum arg)
641641
switch (msg->code) {
642642
case MSG_READY:
643643
Assert(ts->status == TRANSACTION_STATUS_ABORTED || ts->status == TRANSACTION_STATUS_IN_PROGRESS);
644-
Assert(ts->nVotes < ds->nNodes);
644+
Assert(ts->nVotes < ds->nNodes);
645+
ds->nodeTransDelay[msg->node-1] += MtmGetCurrentTime() - ts->csn;
645646
if (++ts->nVotes == ds->nNodes) {
646647
/* All nodes are finished their transactions */
647648
if (ts->status == TRANSACTION_STATUS_IN_PROGRESS) {

multimaster--1.0.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ AS 'MODULE_PATHNAME','mtm_get_snapshot'
2424
LANGUAGE C;
2525

2626

27-
CREATE TYPE mtm.node_state AS (id integer, disabled bool, disconnected bool, catchUp bool, slotLag bigint, connStr text);
27+
CREATE TYPE mtm.node_state AS (id integer, disabled bool, disconnected bool, catchUp bool, slotLag bigint, avgTransDelay bigint, connStr text);
2828

2929
CREATE FUNCTION mtm.get_nodes_state() RETURNS SETOF mtm.node_state
3030
AS 'MODULE_PATHNAME','mtm_get_nodes_state'
3131
LANGUAGE C;
3232

33-
CREATE TYPE mtm.cluster_state AS (status text, disabledNodeMask bigint, disconnectedNodeMask bigint, catchUpNodeMask bigint, nNodes integer, nActiveQueries integer, queueSize bigint);
33+
CREATE TYPE mtm.cluster_state AS (status text, disabledNodeMask bigint, disconnectedNodeMask bigint, catchUpNodeMask bigint, nNodes integer, nActiveQueries integer, queueSize bigint, transCount bigint, timeShift bigint, recoverySlot integer);
3434

3535
CREATE FUNCTION mtm.get_cluster_state() RETURNS mtm.cluster_state
3636
AS 'MODULE_PATHNAME','mtm_get_cluster_state'

multimaster.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,15 @@ static void MtmInitialize()
464464
dtm->transListTail = &dtm->transListHead;
465465
dtm->nReceivers = 0;
466466
dtm->timeShift = 0;
467+
dtm->transCount = 0;
468+
memset(dtm->nodeTransDelay, 0, sizeof(dtm->nodeTransDelay));
467469
PGSemaphoreCreate(&dtm->votingSemaphore);
468470
PGSemaphoreReset(&dtm->votingSemaphore);
469471
SpinLockInit(&dtm->spinlock);
470472
BgwPoolInit(&dtm->pool, MtmExecutor, MtmDatabaseName, MtmQueueSize);
471473
RegisterXactCallback(MtmXactCallback, NULL);
472474
dtmTx.snapshot = INVALID_CSN;
473-
dtmTx.xid = InvalidTransactionId;
475+
dtmTx.xid = InvalidTransactionId;
474476
}
475477
xid2state = MtmCreateHash();
476478
MtmDoReplication = true;
@@ -628,7 +630,8 @@ static void MtmPrecommitTransaction(MtmCurrentTrans* x)
628630
ts->procno = MyProc->pgprocno;
629631
ts->nVotes = 0;
630632
ts->done = false;
631-
633+
dtm->transCount += 1;
634+
632635
if (TransactionIdIsValid(x->gtid.xid)) {
633636
ts->gtid = x->gtid;
634637
} else {
@@ -1282,8 +1285,8 @@ typedef struct
12821285
int nodeId;
12831286
char* connStrPtr;
12841287
TupleDesc desc;
1285-
Datum values[6];
1286-
bool nulls[6];
1288+
Datum values[7];
1289+
bool nulls[7];
12871290
} MtmGetNodeStateCtx;
12881291

12891292
Datum
@@ -1319,11 +1322,12 @@ mtm_get_nodes_state(PG_FUNCTION_ARGS)
13191322
lag = MtmGetSlotLag(usrfctx->nodeId);
13201323
usrfctx->values[4] = Int64GetDatum(lag);
13211324
usrfctx->nulls[4] = lag < 0;
1325+
usrfctx->values[5] = Int64GetDatum(dtm->transCount ? dtm->nodeTransDelay[usrfctx->nodeId-1]/dtm->transCount : 0);
13221326
p = strchr(usrfctx->connStrPtr, ',');
13231327
if (p != NULL) {
13241328
*p++ = '\0';
13251329
}
1326-
usrfctx->values[5] = CStringGetTextDatum(usrfctx->connStrPtr);
1330+
usrfctx->values[6] = CStringGetTextDatum(usrfctx->connStrPtr);
13271331
usrfctx->connStrPtr = p;
13281332
usrfctx->nodeId += 1;
13291333

@@ -1334,8 +1338,8 @@ Datum
13341338
mtm_get_cluster_state(PG_FUNCTION_ARGS)
13351339
{
13361340
TupleDesc desc;
1337-
Datum values[7];
1338-
bool nulls[7] = {false};
1341+
Datum values[10];
1342+
bool nulls[10] = {false};
13391343
get_call_result_type(fcinfo, NULL, &desc);
13401344

13411345
values[0] = CStringGetTextDatum(MtmNodeStatusMnem[dtm->status]);
@@ -1345,6 +1349,10 @@ mtm_get_cluster_state(PG_FUNCTION_ARGS)
13451349
values[4] = Int32GetDatum(dtm->nNodes);
13461350
values[5] = Int32GetDatum((int)dtm->pool.active);
13471351
values[6] = Int64GetDatum(BgwPoolGetQueueSize(&dtm->pool));
1352+
values[7] = Int64GetDatum(dtm->transCount);
1353+
values[8] = Int64GetDatum(dtm->timeShift);
1354+
values[9] = Int32GetDatum(dtm->recoverySlot);
1355+
nulls[9] = dtm->recoverySlot == 0;
13481356

13491357
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(desc, values, nulls)));
13501358
}

multimaster.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ typedef struct
113113
It is cleanup by MtmGetOldestXmin */
114114
MtmTransState** transListTail; /* Tail of L1 list of all finished transactionds, used to append new elements.
115115
This list is expected to be in CSN ascending order, by strict order may be violated */
116+
uint64 transCount; /* Counter of transactions perfromed by this node */
117+
time_t nodeTransDelay[MAX_NODES]; /* Time of waiting transaction acknowledgment from node */
116118
BgwPool pool; /* Pool of background workers for applying logical replication patches */
117119
} MtmState;
118120

0 commit comments

Comments
 (0)