Use the StatePath to config when loading the state
This commit is contained in:
@ -23,16 +23,17 @@ type Cluster struct {
|
||||
mlConfig *memberlist.Config
|
||||
localNode *common.Node
|
||||
LocalName string
|
||||
statePath string
|
||||
state *state
|
||||
events chan memberlist.NodeEvent
|
||||
}
|
||||
|
||||
// New is used to create a new Cluster instance
|
||||
// The returned instance is ready to be updated with the local node settings then joined
|
||||
func New(init bool, clusterKey []byte, bindAddr string, bindPort int, useIPAsName bool) (*Cluster, error) {
|
||||
func New(init bool, clusterKey []byte, bindAddr string, bindPort int, statePath string, useIPAsName bool) (*Cluster, error) {
|
||||
state := &state{}
|
||||
if !init {
|
||||
loadState(state)
|
||||
loadState(state, statePath)
|
||||
}
|
||||
|
||||
clusterKey, err := computeClusterKey(state, clusterKey)
|
||||
@ -61,8 +62,9 @@ func New(init bool, clusterKey []byte, bindAddr string, bindPort int, useIPAsNam
|
||||
LocalName: ml.LocalNode().Name,
|
||||
// The big channel buffer is a work-around for https://github.com/hashicorp/memberlist/issues/23
|
||||
// More than this many simultaneous events will deadlock cluster.members()
|
||||
events: make(chan memberlist.NodeEvent, 100),
|
||||
state: state,
|
||||
events: make(chan memberlist.NodeEvent, 100),
|
||||
state: state,
|
||||
statePath: statePath,
|
||||
}
|
||||
return &cluster, nil
|
||||
}
|
||||
@ -94,7 +96,7 @@ func (c *Cluster) Join(addrs []string) error {
|
||||
|
||||
// Leave saves the current state before leaving, then leaves the cluster
|
||||
func (c *Cluster) Leave() {
|
||||
c.state.save()
|
||||
c.state.save(c.statePath)
|
||||
c.ml.Leave(10 * time.Second)
|
||||
c.ml.Shutdown() //nolint: errcheck
|
||||
}
|
||||
@ -144,7 +146,7 @@ func (c *Cluster) Members() <-chan []common.Node {
|
||||
}
|
||||
c.state.Nodes = nodes
|
||||
changes <- nodes
|
||||
c.state.save()
|
||||
c.state.save(c.statePath)
|
||||
}
|
||||
}()
|
||||
return changes
|
||||
|
Reference in New Issue
Block a user