@@ -61,15 +61,16 @@ countZeroBits(nodemask_t mask, int nNodes)
61
61
}
62
62
63
63
static void
64
- MtmSetClusterStatus (MtmNodeStatus status )
64
+ MtmSetClusterStatus (MtmNodeStatus status , char * statusReason )
65
65
{
66
66
if (Mtm -> status == status )
67
67
return ;
68
68
69
69
Mtm -> nConfigChanges += 1 ; /* this will restart backends */
70
70
71
- MTM_LOG1 ("[STATE] Switching status from %s to %s status" ,
72
- MtmNodeStatusMnem [Mtm -> status ], MtmNodeStatusMnem [status ]);
71
+ MTM_LOG1 ("[STATE] Switching status from %s to %s status: %s" ,
72
+ MtmNodeStatusMnem [Mtm -> status ], MtmNodeStatusMnem [status ],
73
+ statusReason );
73
74
74
75
/*
75
76
* Do some actions on specific status transitions.
@@ -101,13 +102,15 @@ MtmSetClusterStatus(MtmNodeStatus status)
101
102
}
102
103
103
104
Mtm -> status = status ;
105
+ Mtm -> statusReason = statusReason ;
104
106
}
105
107
106
108
static void
107
109
MtmCheckState (void )
108
110
{
109
111
// int nVotingNodes = MtmGetNumberOfVotingNodes();
110
112
bool isEnabledState ;
113
+ char * statusReason = "node is disabled by default" ;
111
114
MtmNodeStatus old_status ;
112
115
int nEnabled = countZeroBits (Mtm -> disabledNodeMask , Mtm -> nAllNodes );
113
116
int nConnected = countZeroBits (SELF_CONNECTIVITY_MASK , Mtm -> nAllNodes );
@@ -126,42 +129,50 @@ MtmCheckState(void)
126
129
(MtmMajorNode || Mtm -> refereeGrant ),
127
130
maskToString (Mtm -> stoppedNodeMask , Mtm -> nAllNodes ));
128
131
129
- isEnabledState =
130
- ( (nConnected >= Mtm -> nAllNodes /2 + 1 ) /* majority */
131
- // XXXX: should we restrict major with two nodes setup?
132
- || (nConnected == Mtm -> nAllNodes /2 && MtmMajorNode ) /* or half + major node */
133
- || (nConnected == Mtm -> nAllNodes /2 && Mtm -> refereeGrant ) ) /* or half + referee */
134
- && (BIT_CHECK (Mtm -> clique , MtmNodeId - 1 ) || Mtm -> refereeGrant ) /* in clique when non-major */
135
- && !BIT_CHECK (Mtm -> stoppedNodeMask , MtmNodeId - 1 ); /* is not stopped */
132
+ #define ENABLE_IF (cond , reason ) if (!(condition) && !isEnabledState) { \
133
+ isEnabledState = true; statusReason = reason; }
134
+ #define DISABLE_IF (cond , reason ) if ((condition) && isEnabledState) { \
135
+ isEnabledState = false; statusReason = reason; }
136
+
137
+ isEnabledState = false;
138
+ ENABLE_IF (nConnected >= Mtm -> nAllNodes /2 + 1 ,
139
+ "node belongs to the majority group" );
140
+ ENABLE_IF (nConnected == Mtm -> nAllNodes /2 && MtmMajorNode ,
141
+ "node is a major node" );
142
+ ENABLE_IF (nConnected == Mtm -> nAllNodes /2 && Mtm -> refereeGrant ,
143
+ "node has a referee grant" );
144
+ DISABLE_IF (!BIT_CHECK (Mtm -> clique , MtmNodeId - 1 ) && !Mtm -> refereeGrant ,
145
+ "node is not in clique and has no referree grant" );
146
+ DISABLE_IF (BIT_CHECK (Mtm -> stoppedNodeMask , MtmNodeId - 1 ),
147
+ "node is stopped manually" );
148
+
149
+ #undef ENABLE_IF
150
+ #undef DISABLE_IF
136
151
137
152
/* ANY -> MTM_DISABLED */
138
153
if (!isEnabledState )
139
154
{
140
155
// BIT_SET(Mtm->disabledNodeMask, MtmNodeId-1);
141
- MtmSetClusterStatus (MTM_DISABLED );
156
+ MtmSetClusterStatus (MTM_DISABLED , statusReason );
142
157
MtmDisableNode (MtmNodeId );
143
158
return ;
144
159
}
145
160
146
161
switch (Mtm -> status )
147
162
{
148
163
case MTM_DISABLED :
149
- if (isEnabledState )
150
- {
151
- MtmSetClusterStatus (MTM_RECOVERY );
164
+ MtmSetClusterStatus (MTM_RECOVERY , statusReason );
152
165
153
- if (old_status != Mtm -> status )
154
- MtmCheckState ();
155
- return ;
156
- }
157
- break ;
166
+ if (old_status != Mtm -> status )
167
+ MtmCheckState ();
168
+ return ;
158
169
159
170
case MTM_RECOVERY :
160
171
if (!BIT_CHECK (Mtm -> disabledNodeMask , MtmNodeId - 1 ))
161
172
{
162
173
MTM_LOG1 ("[LOCK] set lock on MTM_RECOVERY switch" );
163
174
BIT_SET (Mtm -> originLockNodeMask , MtmNodeId - 1 ); // kk trick, XXXX: log that
164
- MtmSetClusterStatus (MTM_RECOVERED );
175
+ MtmSetClusterStatus (MTM_RECOVERED , statusReason );
165
176
166
177
if (old_status != Mtm -> status )
167
178
MtmCheckState ();
@@ -186,7 +197,7 @@ MtmCheckState(void)
186
197
*/
187
198
MTM_LOG1 ("[LOCK] release lock on MTM_RECOVERED switch" );
188
199
BIT_CLEAR (Mtm -> originLockNodeMask , MtmNodeId - 1 );
189
- MtmSetClusterStatus (MTM_ONLINE );
200
+ MtmSetClusterStatus (MTM_ONLINE , statusReason );
190
201
191
202
if (old_status != Mtm -> status )
192
203
MtmCheckState ();
0 commit comments