Skip to content

Commit e91a49a

Browse files
committed
print connectivity matrix only if changed #11
1 parent 83ea67b commit e91a49a

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

multimaster.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static ExecutorFinish_hook_type PreviousExecutorFinishHook;
229229
static ProcessUtility_hook_type PreviousProcessUtilityHook;
230230
static shmem_startup_hook_type PreviousShmemStartupHook;
231231

232+
static nodemask_t lastKnownMatrix[MAX_NODES];
232233

233234
static void MtmExecutorFinish(QueryDesc *queryDesc);
234235
static void MtmProcessUtility(Node *parsetree, const char *queryString,
@@ -1551,7 +1552,8 @@ static bool
15511552
MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15521553
{
15531554
int i, j, n = Mtm->nAllNodes;
1554-
fprintf(stderr, "Connectivity matrix:\n");
1555+
bool changed = false;
1556+
15551557
for (i = 0; i < n; i++) {
15561558
if (i+1 != MtmNodeId) {
15571559
void* data = RaftableGet(psprintf("node-mask-%d", i+1), NULL, NULL, nowait);
@@ -1562,12 +1564,27 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15621564
} else {
15631565
matrix[i] = Mtm->connectivityMask;
15641566
}
1565-
for (j = 0; j < n; j++) {
1566-
putc(BIT_CHECK(matrix[i], j) ? 'X' : '+', stderr);
1567+
1568+
if (lastKnownMatrix[i] != matrix[i])
1569+
{
1570+
changed = true;
1571+
lastKnownMatrix[i] = matrix[i];
15671572
}
1568-
putc('\n', stderr);
15691573
}
1570-
fputs("-----------------------\n", stderr);
1574+
1575+
/* Print matrix if changed */
1576+
if (changed)
1577+
{
1578+
fprintf(stderr, "Connectivity matrix:\n");
1579+
for (i = 0; i < n; i++)
1580+
{
1581+
for (j = 0; j < n; j++)
1582+
putc(BIT_CHECK(matrix[i], j) ? 'X' : '+', stderr);
1583+
putc('\n', stderr);
1584+
}
1585+
fputs("-----------------------\n", stderr);
1586+
}
1587+
15711588
/* make matrix symetric: required for Bron–Kerbosch algorithm */
15721589
for (i = 0; i < n; i++) {
15731590
for (j = 0; j < i; j++) {
@@ -1576,8 +1593,9 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15761593
}
15771594
matrix[i] &= ~((nodemask_t)1 << i);
15781595
}
1596+
15791597
return true;
1580-
}
1598+
}
15811599

15821600

15831601
/**
@@ -1598,6 +1616,11 @@ bool MtmRefreshClusterStatus(bool nowait, int testNodeId)
15981616
}
15991617

16001618
clique = MtmFindMaxClique(matrix, Mtm->nAllNodes, &clique_size);
1619+
1620+
if ( clique == (~Mtm->disabledNodeMask & (((nodemask_t)1 << Mtm->nAllNodes)-1)) )
1621+
/* Nothing is changed */
1622+
return false;
1623+
16011624
if (clique_size >= Mtm->nAllNodes/2+1) { /* have quorum */
16021625
fprintf(stderr, "Old mask: ");
16031626
for (i = 0; i < Mtm->nAllNodes; i++) {
@@ -1728,7 +1751,7 @@ void MtmOnNodeDisconnect(int nodeId)
17281751
}
17291752
}
17301753
MtmUnlock();
1731-
} else {
1754+
} else {
17321755
MtmRefreshClusterStatus(false, 0);
17331756
}
17341757
}

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