From 164c94a4d82ccad8277b1c2dcb32943102d846aa Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期六, 12 十月 2019 10:15:27 +0800
Subject: [PATCH] 修改SnapshotPath为配置文件可配
---
agent.go | 12 ++++++------
config.go | 10 +++++++---
agent_test.go | 2 +-
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/agent.go b/agent.go
index 0e36706..ceb7479 100644
--- a/agent.go
+++ b/agent.go
@@ -61,9 +61,9 @@
}
// Create create serf agent with config
-func Create(conf *Config) (*Agent, error) {
+func Create(conf *Config, snapshotPath string) (*Agent, error) {
// config cover to serf config
- serfConf, err := conf.convertToSerf()
+ serfConf, err := conf.convertToSerf(snapshotPath)
if err != nil {
return nil, err
}
@@ -586,8 +586,8 @@
}
//Init serf Init
-func Init(clusterID string, password string, nodeID string, addrs []string) (*Agent, error) {
- agent, err := InitNode(clusterID, password, nodeID)
+func Init(clusterID string, password string, nodeID string, addrs []string, snapshotPath string) (*Agent, error) {
+ agent, err := InitNode(clusterID, password, nodeID, snapshotPath)
if err != nil {
logger.Error("InitNode failed, error: %s", err)
return agent, err
@@ -603,7 +603,7 @@
}
//InitNode web鍚庡彴鏀跺埌鍒涘缓闆嗙兢鐨勮姹傦紝
-func InitNode(clusterID string, password string, nodeID string) (*Agent, error) {
+func InitNode(clusterID string, password string, nodeID string, snapshotPath string) (*Agent, error) {
conf := DefaultConfig()
logger.Info("clusterID:", clusterID, "password:", password, "nodeID:", nodeID)
conf.ClusterID = clusterID
@@ -619,7 +619,7 @@
}
conf.EncryptKey = password
}
- agent, err := Create(conf)
+ agent, err := Create(conf, snapshotPath)
if err != nil {
logger.Error("create agent failed, error: %s", err)
return agent, err
diff --git a/agent_test.go b/agent_test.go
index fbabde6..da7e004 100644
--- a/agent_test.go
+++ b/agent_test.go
@@ -28,7 +28,7 @@
conf := DefaultConfig()
conf.ClusterID = "testCluster"
conf.NodeName = "testnode"
- agent, err := Create(conf)
+ agent, err := Create(conf, "./snapshotfile")
if err != nil {
t.Errorf("create agent failed, error: %s", err)
}
diff --git a/config.go b/config.go
index 14f4453..68a158b 100644
--- a/config.go
+++ b/config.go
@@ -20,7 +20,6 @@
"fmt"
"net"
"strconv"
-
//"github.com/apache/servicecomb-service-center/syncer/pkg/utils"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/serf/cmd/serf/command/agent"
@@ -46,7 +45,7 @@
MaxQuerySize = 50 * 1024 * 1024
MaxUserEventSize = 5 * 1024
ReplayOnJoinDefault = false
- SnapshotPathDefault = "/opt/vasystem/serfSnapShot"
+ SnapshotPathDefault = "./serfSnapShot"
MaxEventBufferCount = 2048
TcpTransportPort = 30194 //tcp浼犺緭澶ф暟鎹噺鎺ュ彛
@@ -90,7 +89,7 @@
}
// convertToSerf convert Config to serf.Config
-func (c *Config) convertToSerf() (*serf.Config, error) {
+func (c *Config) convertToSerf(snapshotPath string) (*serf.Config, error) {
serfConf := serf.DefaultConfig()
bindIP, bindPort, err := SplitHostPort(c.BindAddr, DefaultBindPort)
@@ -123,7 +122,12 @@
if c.Mode == ModeCluster && c.RetryMaxAttempts <= 0 {
c.RetryMaxAttempts = retryMaxAttempts
}
+
c.SnapshotPath = SnapshotPathDefault
+ if snapshotPath != "" {
+ c.SnapshotPath = snapshotPath
+ }
+
c.ReplayOnJoin = ReplayOnJoinDefault
serfConf.QueryResponseSizeLimit = c.QueryResponseSizeLimit
--
Gitblit v1.8.0