Skip to content

Commit f31cb8a

Browse files
committed
print connectivity matrix only if changed #11
1 parent 1b8929d commit f31cb8a

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

contrib/mmts/multimaster.c

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

233+
static nodemask_t lastKnownMatrix[MAX_NODES];
233234

234235
static void MtmExecutorFinish(QueryDesc *queryDesc);
235236
static void MtmProcessUtility(Node *parsetree, const char *queryString,
@@ -1552,7 +1553,8 @@ static bool
15521553
MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15531554
{
15541555
int i, j, n = Mtm->nAllNodes;
1555-
fprintf(stderr, "Connectivity matrix:\n");
1556+
bool changed = false;
1557+
15561558
for (i = 0; i < n; i++) {
15571559
if (i+1 != MtmNodeId) {
15581560
void* data = RaftableGet(psprintf("node-mask-%d", i+1), NULL, NULL, nowait);
@@ -1563,12 +1565,27 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15631565
} else {
15641566
matrix[i] = Mtm->connectivityMask;
15651567
}
1566-
for (j = 0; j < n; j++) {
1567-
putc(BIT_CHECK(matrix[i], j) ? 'X' : '+', stderr);
1568+
1569+
if (lastKnownMatrix[i] != matrix[i])
1570+
{
1571+
changed = true;
1572+
lastKnownMatrix[i] = matrix[i];
15681573
}
1569-
putc('\n', stderr);
15701574
}
1571-
fputs("-----------------------\n", stderr);
1575+
1576+
/* Print matrix if changed */
1577+
if (changed)
1578+
{
1579+
fprintf(stderr, "Connectivity matrix:\n");
1580+
for (i = 0; i < n; i++)
1581+
{
1582+
for (j = 0; j < n; j++)
1583+
putc(BIT_CHECK(matrix[i], j) ? 'X' : '+', stderr);
1584+
putc('\n', stderr);
1585+
}
1586+
fputs("-----------------------\n", stderr);
1587+
}
1588+
15721589
/* make matrix symetric: required for Bron–Kerbosch algorithm */
15731590
for (i = 0; i < n; i++) {
15741591
for (j = 0; j < i; j++) {
@@ -1577,8 +1594,9 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
15771594
}
15781595
matrix[i] &= ~((nodemask_t)1 << i);
15791596
}
1597+
15801598
return true;
1581-
}
1599+
}
15821600

15831601

15841602
/**
@@ -1599,6 +1617,11 @@ bool MtmRefreshClusterStatus(bool nowait, int testNodeId)
15991617
}
16001618

16011619
clique = MtmFindMaxClique(matrix, Mtm->nAllNodes, &clique_size);
1620+
1621+
if ( clique == (~Mtm->disabledNodeMask & (((nodemask_t)1 << Mtm->nAllNodes)-1)) )
1622+
/* Nothing is changed */
1623+
return false;
1624+
16021625
if (clique_size >= Mtm->nAllNodes/2+1) { /* have quorum */
16031626
fprintf(stderr, "Old mask: ");
16041627
for (i = 0; i < Mtm->nAllNodes; i++) {
@@ -1729,7 +1752,7 @@ void MtmOnNodeDisconnect(int nodeId)
17291752
}
17301753
}
17311754
MtmUnlock();
1732-
} else {
1755+
} else {
17331756
MtmRefreshClusterStatus(false, 0);
17341757
}
17351758
}

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