Skip to content

Commit

Permalink
Add nodes-file-dir configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ohkinozomu committed Aug 3, 2024
1 parent 633231b commit 6f5701e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cluster/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (a *Agent) Start() (err error) {
OnJoinLog(a.Config.NodeName, raftAddr, "setup raft", nil)

// create and join cluster
if utils.PathExists(a.getNodesFile()) {
ms := discovery.GenMemberAddrs(discovery.ReadMembers(a.getNodesFile()))
if utils.PathExists(a.getNodesFile(a.Config.NodesFileDir)) {
ms := discovery.GenMemberAddrs(discovery.ReadMembers(a.getNodesFile(a.Config.NodesFileDir)))
if ms != nil {
a.Config.Members = ms
}
Expand Down Expand Up @@ -271,7 +271,10 @@ func (a *Agent) raftPropose(msg *message.Message) {
}
}

func (a *Agent) getNodesFile() string {
func (a *Agent) getNodesFile(nodesFileDir string) string {
if nodesFileDir != "" {
return filepath.Join(nodesFileDir, a.Config.NodeName+"-"+NodesFile)
}
return a.Config.NodeName + "-" + NodesFile
}

Expand All @@ -280,7 +283,7 @@ func (a *Agent) getPeersFile() string {
}

func (a *Agent) genNodesFile() {
if err := discovery.GenNodesFile(a.getNodesFile(), a.membership.Members()); err != nil {
if err := discovery.GenNodesFile(a.getNodesFile(a.Config.NodesFileDir), a.membership.Members()); err != nil {
log.Error("gen nodes file", "error", err)
}
if err := a.raftPeer.GenPeersFile(a.getPeersFile()); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func realMain(ctx context.Context) error {
flag.IntVar(&cfg.Redis.Options.DB, "redis-db", 0, "redis db for cluster mode")
flag.BoolVar(&cfg.Log.Enable, "log-enable", true, "log enabled or not")
flag.StringVar(&cfg.Log.Filename, "log-file", "./logs/comqtt.log", "log filename")
flag.StringVar(&cfg.Cluster.NodesFileDir, "nodes-file-dir", "", "directory holds nodes.json assisting node discovery for cluster")
//parse arguments
flag.Parse()
//load config file
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type Cluster struct {
InboundPoolSize int `yaml:"inbound-pool-size" json:"inbound-pool-size"`
OutboundPoolSize int `yaml:"outbound-pool-size" json:"outbound-pool-size"`
InoutPoolNonblocking bool `yaml:"inout-pool-nonblocking" json:"inout-pool-nonblocking"`
NodesFileDir string `yaml:"nodes-file-dir" json:"nodes-file-dir"`
}

func GenTlsConfig(conf *Config) (*tls2.Config, error) {
Expand Down

0 comments on commit 6f5701e

Please sign in to comment.