Skip to content

Commit

Permalink
Rename Expect to BootstrapExpect. Fixes #223.
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Jun 20, 2014
1 parent 26a9edf commit 924e4bc
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 44 deletions.
4 changes: 2 additions & 2 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func (a *Agent) consulConfig() *consul.Config {
if a.config.RejoinAfterLeave {
base.RejoinAfterLeave = true
}
if a.config.Expect != 0 {
base.Expect = a.config.Expect
if a.config.BootstrapExpect != 0 {
base.BootstrapExpect = a.config.BootstrapExpect
}
if a.config.Protocol > 0 {
base.ProtocolVersion = uint8(a.config.Protocol)
Expand Down
21 changes: 9 additions & 12 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *Command) readConfig() *Config {

cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server")
cmdFlags.BoolVar(&cmdConfig.Bootstrap, "bootstrap", false, "enable server bootstrap mode")
cmdFlags.IntVar(&cmdConfig.Expect, "expect", 0, "enable automatic bootstrap via expect mode")
cmdFlags.IntVar(&cmdConfig.BootstrapExpect, "bootstrap-expect", 0, "enable automatic bootstrap via expect mode")

cmdFlags.StringVar(&cmdConfig.ClientAddr, "client", "", "address to bind client listeners to (DNS, HTTP, RPC)")
cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to")
Expand Down Expand Up @@ -130,27 +130,24 @@ func (c *Command) readConfig() *Config {
}

// Expect can only work when acting as a server
if config.Expect != 0 && !config.Server {
if config.BootstrapExpect != 0 && !config.Server {
c.Ui.Error("Expect mode cannot be enabled when server mode is not enabled")
return nil
}

// Expect & Bootstrap are mutually exclusive
if config.Expect != 0 && config.Bootstrap {
if config.BootstrapExpect != 0 && config.Bootstrap {
c.Ui.Error("Bootstrap cannot be provided with an expected server count")
return nil
}

// Warn if we are in expect mode
if config.Expect != 0 {
if config.Expect == 1 {
// just use bootstrap mode
c.Ui.Error("WARNING: Expect Mode is specified as 1; this is the same as Bootstrap mode.")
config.Expect = 0
config.Bootstrap = true
} else {
c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, looking for %v servers!", config.Expect))
}
if config.BootstrapExpect == 1 {
c.Ui.Error("WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.")
config.BootstrapExpect = 0
config.Bootstrap = true
} else if config.BootstrapExpect > 0 {
c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, expecting %d servers", config.BootstrapExpect))
}

// Warn if we are in bootstrap mode
Expand Down
24 changes: 12 additions & 12 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ type Config struct {
// permits that node to elect itself leader
Bootstrap bool `mapstructure:"bootstrap"`

// Expect tries to automatically bootstrap the Consul cluster,
// BootstrapExpect tries to automatically bootstrap the Consul cluster,
// by witholding peers until enough servers join.
Expect int `mapstructure:"expect"`
BootstrapExpect int `mapstructure:"bootstrap_expect"`

// Server controls if this agent acts like a Consul server,
// or merely as a client. Servers have more state, take part
Expand Down Expand Up @@ -223,14 +223,14 @@ type dirEnts []os.FileInfo
// DefaultConfig is used to return a sane default configuration
func DefaultConfig() *Config {
return &Config{
Bootstrap: false,
Expect: 0,
Server: false,
Datacenter: consul.DefaultDC,
Domain: "consul.",
LogLevel: "INFO",
ClientAddr: "127.0.0.1",
BindAddr: "0.0.0.0",
Bootstrap: false,
BootstrapExpect: 0,
Server: false,
Datacenter: consul.DefaultDC,
Domain: "consul.",
LogLevel: "INFO",
ClientAddr: "127.0.0.1",
BindAddr: "0.0.0.0",
Ports: PortConfig{
DNS: 8600,
HTTP: 8500,
Expand Down Expand Up @@ -455,8 +455,8 @@ func MergeConfig(a, b *Config) *Config {
if b.Bootstrap {
result.Bootstrap = true
}
if b.Expect != 0 {
result.Expect = b.Expect
if b.BootstrapExpect != 0 {
result.BootstrapExpect = b.BootstrapExpect
}
if b.Datacenter != "" {
result.Datacenter = b.Datacenter
Expand Down
16 changes: 8 additions & 8 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestDecodeConfig(t *testing.T) {
}

// Expect bootstrap
input = `{"server": true, "expect": 3}`
input = `{"server": true, "bootstrap_expect": 3}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
Expand All @@ -104,7 +104,7 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: %#v", config)
}

if config.Expect != 3 {
if config.BootstrapExpect != 3 {
t.Fatalf("bad: %#v", config)
}

Expand Down Expand Up @@ -441,7 +441,7 @@ func TestDecodeConfig_Check(t *testing.T) {
func TestMergeConfig(t *testing.T) {
a := &Config{
Bootstrap: false,
Expect: 0,
BootstrapExpect: 0,
Datacenter: "dc1",
DataDir: "/tmp/foo",
DNSRecursor: "127.0.0.1:1001",
Expand All @@ -459,11 +459,11 @@ func TestMergeConfig(t *testing.T) {
}

b := &Config{
Bootstrap: true,
Expect: 3,
Datacenter: "dc2",
DataDir: "/tmp/bar",
DNSRecursor: "127.0.0.2:1001",
Bootstrap: true,
BootstrapExpect: 3,
Datacenter: "dc2",
DataDir: "/tmp/bar",
DNSRecursor: "127.0.0.2:1001",
DNSConfig: DNSConfig{
NodeTTL: 10 * time.Second,
ServiceTTL: map[string]time.Duration{
Expand Down
4 changes: 2 additions & 2 deletions consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type Config struct {
// other nodes being present
Bootstrap bool

// Expect mode is used to automatically bring up a collection of
// BootstrapExpect mode is used to automatically bring up a collection of
// Consul servers. This can be used to automatically bring up a collection
// of nodes.
Expect int
BootstrapExpect int

// Datacenter is the datacenter this Consul server represents
Datacenter string
Expand Down
10 changes: 5 additions & 5 deletions consul/serf.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *Server) nodeJoin(me serf.MemberEvent, wan bool) {
}

// If we still expecting to bootstrap, may need to handle this
if s.config.Expect != 0 {
if s.config.BootstrapExpect != 0 {
s.maybeBootstrap()
}
}
Expand All @@ -170,7 +170,7 @@ func (s *Server) maybeBootstrap() {
// Bootstrap can only be done if there are no committed logs,
// remove our expectations of bootstrapping
if index != 0 {
s.config.Expect = 0
s.config.BootstrapExpect = 0
return
}

Expand All @@ -186,7 +186,7 @@ func (s *Server) maybeBootstrap() {
s.logger.Printf("[ERR] consul: Member %v has a conflicting datacenter, ignoring", member)
continue
}
if p.Expect != 0 && p.Expect != s.config.Expect {
if p.Expect != 0 && p.Expect != s.config.BootstrapExpect {
s.logger.Printf("[ERR] consul: Member %v has a conflicting expect value. All nodes should expect the same number.", member)
return
}
Expand All @@ -198,7 +198,7 @@ func (s *Server) maybeBootstrap() {
}

// Skip if we haven't met the minimum expect count
if len(addrs) < s.config.Expect {
if len(addrs) < s.config.BootstrapExpect {
return
}

Expand All @@ -209,7 +209,7 @@ func (s *Server) maybeBootstrap() {
}

// Bootstrapping comlete, don't enter this again
s.config.Expect = 0
s.config.BootstrapExpect = 0
}

// nodeFailed is used to handle fail events on both the serf clustes
Expand Down
4 changes: 2 additions & 2 deletions consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, w
if s.config.Bootstrap {
conf.Tags["bootstrap"] = "1"
}
if s.config.Expect != 0 {
conf.Tags["expect"] = fmt.Sprintf("%d", s.config.Expect)
if s.config.BootstrapExpect != 0 {
conf.Tags["expect"] = fmt.Sprintf("%d", s.config.BootstrapExpect)
}
conf.MemberlistConfig.LogOutput = s.config.LogOutput
conf.LogOutput = s.config.LogOutput
Expand Down
2 changes: 1 addition & 1 deletion consul/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) {
dir, config := testServerConfig(t, name)
config.Datacenter = dc
config.Bootstrap = false
config.Expect = expect
config.BootstrapExpect = expect
server, err := NewServer(config)
if err != nil {
t.Fatalf("err: %v", err)
Expand Down

0 comments on commit 924e4bc

Please sign in to comment.