WIP: add recover option

This commit is contained in:
Ingo Oppermann
2023-04-24 10:54:53 +02:00
parent 386bdc0b6e
commit 75c11eb475
3 changed files with 7 additions and 5 deletions

View File

@@ -93,6 +93,7 @@ type ClusterConfig struct {
Name string // Name of the node
Path string // Path where to store all cluster data
Bootstrap bool // Whether to bootstrap a cluster
Recover bool // Whether to recover this node
Address string // Listen address for the raft protocol
JoinAddress string // Address of a member of a cluster to join
@@ -226,7 +227,7 @@ func New(config ClusterConfig) (Cluster, error) {
c.logger.Debug().Log("starting raft")
err = c.startRaft(store, config.Bootstrap, false)
err = c.startRaft(store, config.Bootstrap, config.Recover, false)
if err != nil {
c.shutdownAPI()
return nil, err
@@ -880,7 +881,7 @@ func (c *cluster) GetFile(path string) (io.ReadCloser, error) {
return data, nil
}
func (c *cluster) startRaft(fsm raft.FSM, bootstrap, inmem bool) error {
func (c *cluster) startRaft(fsm raft.FSM, bootstrap, recover, inmem bool) error {
defer func() {
if c.raft == nil && c.raftStore != nil {
c.raftStore.Close()

View File

@@ -105,6 +105,7 @@ func (d *Config) Clone() *Config {
data.Sessions = d.Sessions
data.Service = d.Service
data.Router = d.Router
data.Cluster = d.Cluster
data.Log.Topics = copy.Slice(d.Log.Topics)
@@ -134,8 +135,6 @@ func (d *Config) Clone() *Config {
data.Router.BlockedPrefixes = copy.Slice(d.Router.BlockedPrefixes)
data.Router.Routes = copy.StringMap(d.Router.Routes)
data.Cluster = d.Cluster
data.vars.Transfer(&d.vars)
return data
@@ -277,9 +276,10 @@ func (d *Config) init() {
// Cluster
d.vars.Register(value.NewBool(&d.Cluster.Enable, false), "cluster.enable", "CORE_CLUSTER_ENABLE", nil, "Enable cluster mode", false, false)
d.vars.Register(value.NewBool(&d.Cluster.Bootstrap, false), "cluster.bootstrap", "CORE_CLUSTER_BOOTSTRAP", nil, "Bootstrap a cluster", false, false)
d.vars.Register(value.NewBool(&d.Cluster.Recover, false), "cluster.recover", "CORE_CLUSTER_RECOVER", nil, "Recover a cluster", false, false)
d.vars.Register(value.NewBool(&d.Cluster.Debug, false), "cluster.debug", "CORE_CLUSTER_DEBUG", nil, "Switch to debug mode, not for production", false, false)
d.vars.Register(value.NewAddress(&d.Cluster.Address, ":8000"), "cluster.address", "CORE_CLUSTER_ADDRESS", nil, "Raft listen address", false, true)
d.vars.Register(value.NewString(&d.Cluster.JoinAddress, ""), "cluster.join_address", "CORE_CLUSTER_JOIN_ADDRESS", nil, "Address of a core that is part of the cluster", false, true)
d.vars.Register(value.NewString(&d.Cluster.JoinAddress, ""), "cluster.join_address", "CORE_CLUSTER_JOIN_ADDRESS", nil, "Raft address of a core that is part of the cluster", false, true)
}
// Validate validates the current state of the Config for completeness and sanity. Errors are

View File

@@ -169,6 +169,7 @@ type Data struct {
Cluster struct {
Enable bool `json:"enable"`
Bootstrap bool `json:"bootstrap"`
Recover bool `json:"recover"`
Debug bool `json:"debug"`
Address string `json:"address"`
JoinAddress string `json:"join_address"`