@@ -13,27 +13,28 @@ import (
13
13
metrics "github.com/armon/go-metrics"
14
14
)
15
15
16
- type nodeStateType int
16
+ type NodeStateType int
17
17
18
18
const (
19
- stateAlive nodeStateType = iota
20
- stateSuspect
21
- stateDead
22
- stateLeft
19
+ StateAlive NodeStateType = iota
20
+ StateSuspect
21
+ StateDead
22
+ StateLeft
23
23
)
24
24
25
25
// Node represents a node in the cluster.
26
26
type Node struct {
27
- Name string
28
- Addr net.IP
29
- Port uint16
30
- Meta []byte // Metadata from the delegate for this node.
31
- PMin uint8 // Minimum protocol version this understands
32
- PMax uint8 // Maximum protocol version this understands
33
- PCur uint8 // Current version node is speaking
34
- DMin uint8 // Min protocol version for the delegate to understand
35
- DMax uint8 // Max protocol version for the delegate to understand
36
- DCur uint8 // Current version delegate is speaking
27
+ Name string
28
+ Addr net.IP
29
+ Port uint16
30
+ Meta []byte // Metadata from the delegate for this node.
31
+ State NodeStateType // State of the node.
32
+ PMin uint8 // Minimum protocol version this understands
33
+ PMax uint8 // Maximum protocol version this understands
34
+ PCur uint8 // Current version node is speaking
35
+ DMin uint8 // Min protocol version for the delegate to understand
36
+ DMax uint8 // Max protocol version for the delegate to understand
37
+ DCur uint8 // Current version delegate is speaking
37
38
}
38
39
39
40
// Address returns the host:port form of a node's address, suitable for use
@@ -60,7 +61,7 @@ func (n *Node) String() string {
60
61
type nodeState struct {
61
62
Node
62
63
Incarnation uint32 // Last known incarnation number
63
- State nodeStateType // Current state
64
+ State NodeStateType // Current state
64
65
StateChange time.Time // Time last state change happened
65
66
}
66
67
@@ -77,7 +78,7 @@ func (n *nodeState) FullAddress() Address {
77
78
}
78
79
79
80
func (n * nodeState ) DeadOrLeft () bool {
80
- return n .State == stateDead || n .State == stateLeft
81
+ return n .State == StateDead || n .State == StateLeft
81
82
}
82
83
83
84
// ackHandler is used to register handlers for incoming acks and nacks.
@@ -321,7 +322,7 @@ func (m *Memberlist) probeNode(node *nodeState) {
321
322
defer func () {
322
323
m .awareness .ApplyDelta (awarenessDelta )
323
324
}()
324
- if node .State == stateAlive {
325
+ if node .State == StateAlive {
325
326
if err := m .encodeAndSendMsg (node .FullAddress (), pingMsg , & ping ); err != nil {
326
327
m .logger .Printf ("[ERR] memberlist: Failed to send ping: %s" , err )
327
328
if failedRemote (err ) {
@@ -396,7 +397,7 @@ HANDLE_REMOTE_FAILURE:
396
397
kNodes := kRandomNodes (m .config .IndirectChecks , m .nodes , func (n * nodeState ) bool {
397
398
return n .Name == m .config .Name ||
398
399
n .Name == node .Name ||
399
- n .State != stateAlive
400
+ n .State != StateAlive
400
401
})
401
402
m .nodeLock .RUnlock ()
402
403
@@ -573,10 +574,10 @@ func (m *Memberlist) gossip() {
573
574
}
574
575
575
576
switch n .State {
576
- case stateAlive , stateSuspect :
577
+ case StateAlive , StateSuspect :
577
578
return false
578
579
579
- case stateDead :
580
+ case StateDead :
580
581
return time .Since (n .StateChange ) > m .config .GossipToTheDeadTime
581
582
582
583
default :
@@ -623,7 +624,7 @@ func (m *Memberlist) pushPull() {
623
624
m .nodeLock .RLock ()
624
625
nodes := kRandomNodes (1 , m .nodes , func (n * nodeState ) bool {
625
626
return n .Name == m .config .Name ||
626
- n .State != stateAlive
627
+ n .State != StateAlive
627
628
})
628
629
m .nodeLock .RUnlock ()
629
630
@@ -681,7 +682,7 @@ func (m *Memberlist) verifyProtocol(remote []pushNodeState) error {
681
682
682
683
for _ , rn := range remote {
683
684
// If the node isn't alive, then skip it
684
- if rn .State != stateAlive {
685
+ if rn .State != StateAlive {
685
686
continue
686
687
}
687
688
@@ -710,7 +711,7 @@ func (m *Memberlist) verifyProtocol(remote []pushNodeState) error {
710
711
711
712
for _ , n := range m .nodes {
712
713
// Ignore non-alive nodes
713
- if n .State != stateAlive {
714
+ if n .State != StateAlive {
714
715
continue
715
716
}
716
717
@@ -981,7 +982,7 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
981
982
Port : a .Port ,
982
983
Meta : a .Meta ,
983
984
},
984
- State : stateDead ,
985
+ State : StateDead ,
985
986
}
986
987
if len (a .Vsn ) > 5 {
987
988
state .PMin = a .Vsn [0 ]
@@ -1021,7 +1022,7 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
1021
1022
time .Since (state .StateChange ) > m .config .DeadNodeReclaimTime )
1022
1023
1023
1024
// Allow the address to be updated if a dead node is being replaced.
1024
- if state .State == stateLeft || (state .State == stateDead && canReclaim ) {
1025
+ if state .State == StateLeft || (state .State == StateDead && canReclaim ) {
1025
1026
m .logger .Printf ("[INFO] memberlist: Updating address for left or failed node %s from %v:%d to %v:%d" ,
1026
1027
state .Name , state .Addr , state .Port , net .IP (a .Addr ), a .Port )
1027
1028
updatesNode = true
@@ -1106,8 +1107,8 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
1106
1107
state .Meta = a .Meta
1107
1108
state .Addr = a .Addr
1108
1109
state .Port = a .Port
1109
- if state .State != stateAlive {
1110
- state .State = stateAlive
1110
+ if state .State != StateAlive {
1111
+ state .State = StateAlive
1111
1112
state .StateChange = time .Now ()
1112
1113
}
1113
1114
}
@@ -1117,7 +1118,7 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
1117
1118
1118
1119
// Notify the delegate of any relevant updates
1119
1120
if m .config .Events != nil {
1120
- if oldState == stateDead || oldState == stateLeft {
1121
+ if oldState == StateDead || oldState == StateLeft {
1121
1122
// if Dead/Left -> Alive, notify of join
1122
1123
m .config .Events .NotifyJoin (& state .Node )
1123
1124
@@ -1157,7 +1158,7 @@ func (m *Memberlist) suspectNode(s *suspect) {
1157
1158
}
1158
1159
1159
1160
// Ignore non-alive nodes
1160
- if state .State != stateAlive {
1161
+ if state .State != StateAlive {
1161
1162
return
1162
1163
}
1163
1164
@@ -1175,7 +1176,7 @@ func (m *Memberlist) suspectNode(s *suspect) {
1175
1176
1176
1177
// Update the state
1177
1178
state .Incarnation = s .Incarnation
1178
- state .State = stateSuspect
1179
+ state .State = StateSuspect
1179
1180
changeTime := time .Now ()
1180
1181
state .StateChange = changeTime
1181
1182
@@ -1199,7 +1200,7 @@ func (m *Memberlist) suspectNode(s *suspect) {
1199
1200
fn := func (numConfirmations int ) {
1200
1201
m .nodeLock .Lock ()
1201
1202
state , ok := m .nodeMap [s .Node ]
1202
- timeout := ok && state .State == stateSuspect && state .StateChange == changeTime
1203
+ timeout := ok && state .State == StateSuspect && state .StateChange == changeTime
1203
1204
m .nodeLock .Unlock ()
1204
1205
1205
1206
if timeout {
@@ -1265,9 +1266,9 @@ func (m *Memberlist) deadNode(d *dead) {
1265
1266
// If the dead message was send by the node itself, mark it is left
1266
1267
// instead of dead.
1267
1268
if d .Node == d .From {
1268
- state .State = stateLeft
1269
+ state .State = StateLeft
1269
1270
} else {
1270
- state .State = stateDead
1271
+ state .State = StateDead
1271
1272
}
1272
1273
state .StateChange = time .Now ()
1273
1274
@@ -1282,7 +1283,7 @@ func (m *Memberlist) deadNode(d *dead) {
1282
1283
func (m * Memberlist ) mergeState (remote []pushNodeState ) {
1283
1284
for _ , r := range remote {
1284
1285
switch r .State {
1285
- case stateAlive :
1286
+ case StateAlive :
1286
1287
a := alive {
1287
1288
Incarnation : r .Incarnation ,
1288
1289
Node : r .Name ,
@@ -1293,14 +1294,14 @@ func (m *Memberlist) mergeState(remote []pushNodeState) {
1293
1294
}
1294
1295
m .aliveNode (& a , nil , false )
1295
1296
1296
- case stateLeft :
1297
+ case StateLeft :
1297
1298
d := dead {Incarnation : r .Incarnation , Node : r .Name , From : r .Name }
1298
1299
m .deadNode (& d )
1299
- case stateDead :
1300
+ case StateDead :
1300
1301
// If the remote node believes a node is dead, we prefer to
1301
1302
// suspect that node instead of declaring it dead instantly
1302
1303
fallthrough
1303
- case stateSuspect :
1304
+ case StateSuspect :
1304
1305
s := suspect {Incarnation : r .Incarnation , Node : r .Name , From : m .config .Name }
1305
1306
m .suspectNode (& s )
1306
1307
}
0 commit comments