| | |
| | | } |
| | | |
| | | // 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 |
| | | } |
| | |
| | | |
| | | var wg sync.WaitGroup |
| | | wg.Add(1) |
| | | go func() { |
| | | ticker := time.NewTicker(300*time.Second) |
| | | go func(tk *time.Ticker) { |
| | | defer tk.Stop() |
| | | defer wg.Done() |
| | | for { |
| | | select { |
| | | case <-tk.C: |
| | | return |
| | | case msg := <- QueryTcpResponseChan: |
| | | logger.Info("Query response's len:", len(msg)) |
| | | err := json.Unmarshal(msg, &dumpSqls) |
| | |
| | | return |
| | | } |
| | | } |
| | | }() |
| | | }(ticker) |
| | | wg.Wait() |
| | | return &dumpSqls,nil |
| | | |
| | |
| | | } |
| | | |
| | | //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 |
| | |
| | | } |
| | | |
| | | //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 |
| | |
| | | } |
| | | 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 |