Use config.Peers when passing -join flag
Removes the two separate variables in the meta.Config. -join will now override the Peers var.pull/3478/head
parent
2938601e9e
commit
06d8ff7c13
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
@ -83,7 +84,7 @@ func (cmd *Command) Run(args ...string) error {
|
|||
}
|
||||
|
||||
if options.Join != "" {
|
||||
config.Meta.Join = options.Join
|
||||
config.Meta.Peers = strings.Split(options.Join, ",")
|
||||
}
|
||||
|
||||
// Validate the configuration.
|
||||
|
|
|
@ -38,9 +38,6 @@ type Config struct {
|
|||
LeaderLeaseTimeout toml.Duration `toml:"leader-lease-timeout"`
|
||||
CommitTimeout toml.Duration `toml:"commit-timeout"`
|
||||
ClusterTracing bool `toml:"cluster-tracing"`
|
||||
|
||||
// The join command-line argument
|
||||
Join string `toml:"-"`
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
|
|
|
@ -395,11 +395,13 @@ func (r *rpc) call(dest string, req proto.Message) (proto.Message, error) {
|
|||
|
||||
// Should always have a size and type
|
||||
if exp := 16; len(data) < exp {
|
||||
r.traceCluster("recv: %v", string(data))
|
||||
return nil, fmt.Errorf("rpc %v failed: short read: got %v, exp %v", rpcType, len(data), exp)
|
||||
}
|
||||
|
||||
sz := btou64(data[0:8])
|
||||
if len(data[8:]) != int(sz) {
|
||||
r.traceCluster("recv: %v", string(data))
|
||||
return nil, fmt.Errorf("rpc %v failed: short read: got %v, exp %v", rpcType, len(data[8:]), sz)
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ type Store struct {
|
|||
|
||||
// All peers in cluster. Used during bootstrapping.
|
||||
peers []string
|
||||
join string
|
||||
|
||||
data *Data
|
||||
|
||||
|
@ -131,7 +130,6 @@ func NewStore(c *Config) *Store {
|
|||
s := &Store{
|
||||
path: c.Dir,
|
||||
peers: c.Peers,
|
||||
join: c.Join,
|
||||
data: &Data{},
|
||||
|
||||
ready: make(chan struct{}),
|
||||
|
@ -277,8 +275,9 @@ func (s *Store) loadState() error {
|
|||
}
|
||||
|
||||
func (s *Store) joinCluster() error {
|
||||
|
||||
// No join options, so nothing to do
|
||||
if s.join == "" {
|
||||
if len(s.peers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -290,9 +289,9 @@ func (s *Store) joinCluster() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
s.Logger.Printf("joining cluster at: %v", s.join)
|
||||
s.Logger.Printf("joining cluster at: %v", s.peers)
|
||||
for {
|
||||
for _, join := range strings.Split(s.join, ",") {
|
||||
for _, join := range s.peers {
|
||||
res, err := s.rpc.join(s.Addr.String(), join)
|
||||
if err != nil {
|
||||
s.Logger.Printf("join failed: %v", err)
|
||||
|
@ -663,7 +662,6 @@ func (s *Store) handleExecConn(conn net.Conn) {
|
|||
// This function runs in a separate goroutine.
|
||||
func (s *Store) serveRPCListener() {
|
||||
defer s.wg.Done()
|
||||
<-s.ready
|
||||
|
||||
for {
|
||||
// Accept next TCP connection.
|
||||
|
|
|
@ -1025,7 +1025,7 @@ func MustOpenCluster(n int) *Cluster {
|
|||
|
||||
func (c *Cluster) Join() error {
|
||||
config := NewConfig(filepath.Join(c.path, strconv.Itoa(len(c.Stores))))
|
||||
config.Join = c.Stores[0].Addr.String()
|
||||
config.Peers = []string{c.Stores[0].Addr.String()}
|
||||
s := NewStore(config)
|
||||
if err := s.Open(); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue