Rename Expect to BootstrapExpect. Fixes #223.

pull/235/head
Armon Dadgar 2014-06-19 17:08:48 -07:00
parent 26a9edff4c
commit 924e4bc7f1
8 changed files with 41 additions and 44 deletions

View File

@ -175,8 +175,8 @@ func (a *Agent) consulConfig() *consul.Config {
if a.config.RejoinAfterLeave { if a.config.RejoinAfterLeave {
base.RejoinAfterLeave = true base.RejoinAfterLeave = true
} }
if a.config.Expect != 0 { if a.config.BootstrapExpect != 0 {
base.Expect = a.config.Expect base.BootstrapExpect = a.config.BootstrapExpect
} }
if a.config.Protocol > 0 { if a.config.Protocol > 0 {
base.ProtocolVersion = uint8(a.config.Protocol) base.ProtocolVersion = uint8(a.config.Protocol)

View File

@ -63,7 +63,7 @@ func (c *Command) readConfig() *Config {
cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server") cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server")
cmdFlags.BoolVar(&cmdConfig.Bootstrap, "bootstrap", false, "enable server bootstrap mode") 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.ClientAddr, "client", "", "address to bind client listeners to (DNS, HTTP, RPC)")
cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to") cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to")
@ -130,27 +130,24 @@ func (c *Command) readConfig() *Config {
} }
// Expect can only work when acting as a server // 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") c.Ui.Error("Expect mode cannot be enabled when server mode is not enabled")
return nil return nil
} }
// Expect & Bootstrap are mutually exclusive // 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") c.Ui.Error("Bootstrap cannot be provided with an expected server count")
return nil return nil
} }
// Warn if we are in expect mode // Warn if we are in expect mode
if config.Expect != 0 { if config.BootstrapExpect == 1 {
if config.Expect == 1 { c.Ui.Error("WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.")
// just use bootstrap mode config.BootstrapExpect = 0
c.Ui.Error("WARNING: Expect Mode is specified as 1; this is the same as Bootstrap mode.") config.Bootstrap = true
config.Expect = 0 } else if config.BootstrapExpect > 0 {
config.Bootstrap = true c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, expecting %d servers", config.BootstrapExpect))
} else {
c.Ui.Error(fmt.Sprintf("WARNING: Expect Mode enabled, looking for %v servers!", config.Expect))
}
} }
// Warn if we are in bootstrap mode // Warn if we are in bootstrap mode

View File

@ -65,9 +65,9 @@ type Config struct {
// permits that node to elect itself leader // permits that node to elect itself leader
Bootstrap bool `mapstructure:"bootstrap"` 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. // 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, // Server controls if this agent acts like a Consul server,
// or merely as a client. Servers have more state, take part // or merely as a client. Servers have more state, take part
@ -223,14 +223,14 @@ type dirEnts []os.FileInfo
// DefaultConfig is used to return a sane default configuration // DefaultConfig is used to return a sane default configuration
func DefaultConfig() *Config { func DefaultConfig() *Config {
return &Config{ return &Config{
Bootstrap: false, Bootstrap: false,
Expect: 0, BootstrapExpect: 0,
Server: false, Server: false,
Datacenter: consul.DefaultDC, Datacenter: consul.DefaultDC,
Domain: "consul.", Domain: "consul.",
LogLevel: "INFO", LogLevel: "INFO",
ClientAddr: "127.0.0.1", ClientAddr: "127.0.0.1",
BindAddr: "0.0.0.0", BindAddr: "0.0.0.0",
Ports: PortConfig{ Ports: PortConfig{
DNS: 8600, DNS: 8600,
HTTP: 8500, HTTP: 8500,
@ -455,8 +455,8 @@ func MergeConfig(a, b *Config) *Config {
if b.Bootstrap { if b.Bootstrap {
result.Bootstrap = true result.Bootstrap = true
} }
if b.Expect != 0 { if b.BootstrapExpect != 0 {
result.Expect = b.Expect result.BootstrapExpect = b.BootstrapExpect
} }
if b.Datacenter != "" { if b.Datacenter != "" {
result.Datacenter = b.Datacenter result.Datacenter = b.Datacenter

View File

@ -94,7 +94,7 @@ func TestDecodeConfig(t *testing.T) {
} }
// Expect bootstrap // Expect bootstrap
input = `{"server": true, "expect": 3}` input = `{"server": true, "bootstrap_expect": 3}`
config, err = DecodeConfig(bytes.NewReader([]byte(input))) config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
@ -104,7 +104,7 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: %#v", config) t.Fatalf("bad: %#v", config)
} }
if config.Expect != 3 { if config.BootstrapExpect != 3 {
t.Fatalf("bad: %#v", config) t.Fatalf("bad: %#v", config)
} }
@ -441,7 +441,7 @@ func TestDecodeConfig_Check(t *testing.T) {
func TestMergeConfig(t *testing.T) { func TestMergeConfig(t *testing.T) {
a := &Config{ a := &Config{
Bootstrap: false, Bootstrap: false,
Expect: 0, BootstrapExpect: 0,
Datacenter: "dc1", Datacenter: "dc1",
DataDir: "/tmp/foo", DataDir: "/tmp/foo",
DNSRecursor: "127.0.0.1:1001", DNSRecursor: "127.0.0.1:1001",
@ -459,11 +459,11 @@ func TestMergeConfig(t *testing.T) {
} }
b := &Config{ b := &Config{
Bootstrap: true, Bootstrap: true,
Expect: 3, BootstrapExpect: 3,
Datacenter: "dc2", Datacenter: "dc2",
DataDir: "/tmp/bar", DataDir: "/tmp/bar",
DNSRecursor: "127.0.0.2:1001", DNSRecursor: "127.0.0.2:1001",
DNSConfig: DNSConfig{ DNSConfig: DNSConfig{
NodeTTL: 10 * time.Second, NodeTTL: 10 * time.Second,
ServiceTTL: map[string]time.Duration{ ServiceTTL: map[string]time.Duration{

View File

@ -44,10 +44,10 @@ type Config struct {
// other nodes being present // other nodes being present
Bootstrap bool 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 // Consul servers. This can be used to automatically bring up a collection
// of nodes. // of nodes.
Expect int BootstrapExpect int
// Datacenter is the datacenter this Consul server represents // Datacenter is the datacenter this Consul server represents
Datacenter string Datacenter string

View File

@ -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 we still expecting to bootstrap, may need to handle this
if s.config.Expect != 0 { if s.config.BootstrapExpect != 0 {
s.maybeBootstrap() s.maybeBootstrap()
} }
} }
@ -170,7 +170,7 @@ func (s *Server) maybeBootstrap() {
// Bootstrap can only be done if there are no committed logs, // Bootstrap can only be done if there are no committed logs,
// remove our expectations of bootstrapping // remove our expectations of bootstrapping
if index != 0 { if index != 0 {
s.config.Expect = 0 s.config.BootstrapExpect = 0
return return
} }
@ -186,7 +186,7 @@ func (s *Server) maybeBootstrap() {
s.logger.Printf("[ERR] consul: Member %v has a conflicting datacenter, ignoring", member) s.logger.Printf("[ERR] consul: Member %v has a conflicting datacenter, ignoring", member)
continue 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) s.logger.Printf("[ERR] consul: Member %v has a conflicting expect value. All nodes should expect the same number.", member)
return return
} }
@ -198,7 +198,7 @@ func (s *Server) maybeBootstrap() {
} }
// Skip if we haven't met the minimum expect count // Skip if we haven't met the minimum expect count
if len(addrs) < s.config.Expect { if len(addrs) < s.config.BootstrapExpect {
return return
} }
@ -209,7 +209,7 @@ func (s *Server) maybeBootstrap() {
} }
// Bootstrapping comlete, don't enter this again // 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 // nodeFailed is used to handle fail events on both the serf clustes

View File

@ -234,8 +234,8 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, w
if s.config.Bootstrap { if s.config.Bootstrap {
conf.Tags["bootstrap"] = "1" conf.Tags["bootstrap"] = "1"
} }
if s.config.Expect != 0 { if s.config.BootstrapExpect != 0 {
conf.Tags["expect"] = fmt.Sprintf("%d", s.config.Expect) conf.Tags["expect"] = fmt.Sprintf("%d", s.config.BootstrapExpect)
} }
conf.MemberlistConfig.LogOutput = s.config.LogOutput conf.MemberlistConfig.LogOutput = s.config.LogOutput
conf.LogOutput = s.config.LogOutput conf.LogOutput = s.config.LogOutput

View File

@ -93,7 +93,7 @@ func testServerDCExpect(t *testing.T, dc string, expect int) (string, *Server) {
dir, config := testServerConfig(t, name) dir, config := testServerConfig(t, name)
config.Datacenter = dc config.Datacenter = dc
config.Bootstrap = false config.Bootstrap = false
config.Expect = expect config.BootstrapExpect = expect
server, err := NewServer(config) server, err := NewServer(config)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)