Update memberlist for the node renaming change

This commit is contained in:
Kyle Havlovitz 2019-03-13 15:55:54 -07:00
parent df4ec913f0
commit 106fde20b3
3 changed files with 31 additions and 21 deletions

View File

@ -7,8 +7,8 @@ package memberlist
// a node out and prevent it from being considered a peer // a node out and prevent it from being considered a peer
// using application specific logic. // using application specific logic.
type AliveDelegate interface { type AliveDelegate interface {
// NotifyMerge is invoked when a merge could take place. // NotifyAlive is invoked when a message about a live
// Provides a list of the nodes known by the peer. If // node is received from the network. Returning a non-nil
// the return value is non-nil, the merge is canceled. // error prevents the node from being considered a peer.
NotifyAlive(peer *Node) error NotifyAlive(peer *Node) error
} }

View File

@ -9,7 +9,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/armon/go-metrics" metrics "github.com/armon/go-metrics"
) )
type nodeStateType int type nodeStateType int
@ -891,6 +891,7 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
// Check if we've never seen this node before, and if not, then // Check if we've never seen this node before, and if not, then
// store this node in our node map. // store this node in our node map.
var updatesNode bool
if !ok { if !ok {
state = &nodeState{ state = &nodeState{
Node: Node{ Node: Node{
@ -926,29 +927,36 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
// Update numNodes after we've added a new node // Update numNodes after we've added a new node
atomic.AddUint32(&m.numNodes, 1) atomic.AddUint32(&m.numNodes, 1)
} } else {
// Check if this address is different than the existing node unless the old node is dead.
if !bytes.Equal([]byte(state.Addr), a.Addr) || state.Port != a.Port {
// Allow the address to be updated if a dead node is being replaced.
if state.State == stateDead {
m.logger.Printf("[INFO] memberlist: Updating address for failed node %s from %v:%d to %v:%d",
state.Name, state.Addr, state.Port, net.IP(a.Addr), a.Port)
updatesNode = true
} else {
m.logger.Printf("[ERR] memberlist: Conflicting address for %s. Mine: %v:%d Theirs: %v:%d Old state: %v",
state.Name, state.Addr, state.Port, net.IP(a.Addr), a.Port, state.State)
// Check if this address is different than the existing node // Inform the conflict delegate if provided
if !bytes.Equal([]byte(state.Addr), a.Addr) || state.Port != a.Port { if m.config.Conflict != nil {
m.logger.Printf("[ERR] memberlist: Conflicting address for %s. Mine: %v:%d Theirs: %v:%d", other := Node{
state.Name, state.Addr, state.Port, net.IP(a.Addr), a.Port) Name: a.Node,
Addr: a.Addr,
// Inform the conflict delegate if provided Port: a.Port,
if m.config.Conflict != nil { Meta: a.Meta,
other := Node{ }
Name: a.Node, m.config.Conflict.NotifyConflict(&state.Node, &other)
Addr: a.Addr, }
Port: a.Port, return
Meta: a.Meta,
} }
m.config.Conflict.NotifyConflict(&state.Node, &other)
} }
return
} }
// Bail if the incarnation number is older, and this is not about us // Bail if the incarnation number is older, and this is not about us
isLocalNode := state.Name == m.config.Name isLocalNode := state.Name == m.config.Name
if a.Incarnation <= state.Incarnation && !isLocalNode { if a.Incarnation <= state.Incarnation && !isLocalNode && !updatesNode {
return return
} }
@ -1006,6 +1014,8 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
// Update the state and incarnation number // Update the state and incarnation number
state.Incarnation = a.Incarnation state.Incarnation = a.Incarnation
state.Meta = a.Meta state.Meta = a.Meta
state.Addr = a.Addr
state.Port = a.Port
if state.State != stateAlive { if state.State != stateAlive {
state.State = stateAlive state.State = stateAlive
state.StateChange = time.Now() state.StateChange = time.Now()

2
vendor/vendor.json vendored
View File

@ -146,7 +146,7 @@
{"path":"github.com/hashicorp/hil","checksumSHA1":"kqCMCHy2b+RBMKC+ER+OPqp8C3E=","revision":"1e86c6b523c55d1fa6c6e930ce80b548664c95c2","revisionTime":"2016-07-11T23:18:37Z"}, {"path":"github.com/hashicorp/hil","checksumSHA1":"kqCMCHy2b+RBMKC+ER+OPqp8C3E=","revision":"1e86c6b523c55d1fa6c6e930ce80b548664c95c2","revisionTime":"2016-07-11T23:18:37Z"},
{"path":"github.com/hashicorp/hil/ast","checksumSHA1":"UICubs001+Q4MsUf9zl2vcMzWQQ=","revision":"1e86c6b523c55d1fa6c6e930ce80b548664c95c2","revisionTime":"2016-07-11T23:18:37Z"}, {"path":"github.com/hashicorp/hil/ast","checksumSHA1":"UICubs001+Q4MsUf9zl2vcMzWQQ=","revision":"1e86c6b523c55d1fa6c6e930ce80b548664c95c2","revisionTime":"2016-07-11T23:18:37Z"},
{"path":"github.com/hashicorp/logutils","checksumSHA1":"vt+P9D2yWDO3gdvdgCzwqunlhxU=","revision":"0dc08b1671f34c4250ce212759ebd880f743d883","revisionTime":"2015-06-09T07:04:31Z"}, {"path":"github.com/hashicorp/logutils","checksumSHA1":"vt+P9D2yWDO3gdvdgCzwqunlhxU=","revision":"0dc08b1671f34c4250ce212759ebd880f743d883","revisionTime":"2015-06-09T07:04:31Z"},
{"path":"github.com/hashicorp/memberlist","checksumSHA1":"j4pWTjW3SFOPVwWBEZPuNHETnLE=","revision":"b38abf62d7f3ce5225722cd62a90cfb098e02519","revisionTime":"2019-02-04T18:04:39Z"}, {"path":"github.com/hashicorp/memberlist","checksumSHA1":"8aXKnwU1vIeum/LaFtp2O6H0/+Y=","revision":"11f323a32dc835ba6ce39cde2b04919a6bfd32ec","revisionTime":"2019-03-13T22:54:10Z"},
{"path":"github.com/hashicorp/net-rpc-msgpackrpc","checksumSHA1":"qnlqWJYV81ENr61SZk9c65R1mDo=","revision":"a14192a58a694c123d8fe5481d4a4727d6ae82f3","revisionTime":"2015-11-16T02:03:38Z"}, {"path":"github.com/hashicorp/net-rpc-msgpackrpc","checksumSHA1":"qnlqWJYV81ENr61SZk9c65R1mDo=","revision":"a14192a58a694c123d8fe5481d4a4727d6ae82f3","revisionTime":"2015-11-16T02:03:38Z"},
{"path":"github.com/hashicorp/raft","checksumSHA1":"3U9bQLEMikE47n4TZP6uOdgXIyQ=","revision":"da92cfe76e0c1c9b94bbc9d884ec4b2b3b90b699","revisionTime":"2018-08-17T18:12:11Z","version":"master","versionExact":"master"}, {"path":"github.com/hashicorp/raft","checksumSHA1":"3U9bQLEMikE47n4TZP6uOdgXIyQ=","revision":"da92cfe76e0c1c9b94bbc9d884ec4b2b3b90b699","revisionTime":"2018-08-17T18:12:11Z","version":"master","versionExact":"master"},
{"path":"github.com/hashicorp/raft-boltdb","checksumSHA1":"QAxukkv54/iIvLfsUP6IK4R0m/A=","revision":"d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee","revisionTime":"2015-02-01T20:08:39Z"}, {"path":"github.com/hashicorp/raft-boltdb","checksumSHA1":"QAxukkv54/iIvLfsUP6IK4R0m/A=","revision":"d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee","revisionTime":"2015-02-01T20:08:39Z"},