Skip to content

Commit

Permalink
consul: Avoid name conflict on WAN ring. Fixes #158.
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed May 16, 2014
1 parent 9832cce commit 1611d98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ func NewServer(config *Config) (*Server, error) {

// Initialize the lan Serf
s.serfLAN, err = s.setupSerf(config.SerfLANConfig,
s.eventChLAN, serfLANSnapshot)
s.eventChLAN, serfLANSnapshot, false)
if err != nil {
s.Shutdown()
return nil, fmt.Errorf("Failed to start lan serf: %v", err)
}

// Initialize the wan Serf
s.serfWAN, err = s.setupSerf(config.SerfWANConfig,
s.eventChWAN, serfWANSnapshot)
s.eventChWAN, serfWANSnapshot, true)
if err != nil {
s.Shutdown()
return nil, fmt.Errorf("Failed to start wan serf: %v", err)
Expand All @@ -197,10 +197,14 @@ func NewServer(config *Config) (*Server, error) {
}

// setupSerf is used to setup and initialize a Serf
func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string) (*serf.Serf, error) {
func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, wan bool) (*serf.Serf, error) {
addr := s.rpcListener.Addr().(*net.TCPAddr)
conf.Init()
conf.NodeName = s.config.NodeName
if wan {
conf.NodeName = fmt.Sprintf("%s.%s", s.config.NodeName, s.config.Datacenter)
} else {
conf.NodeName = s.config.NodeName
}
conf.Tags["role"] = "consul"
conf.Tags["dc"] = s.config.Datacenter
conf.Tags["vsn"] = fmt.Sprintf("%d", s.config.ProtocolVersion)
Expand Down
2 changes: 1 addition & 1 deletion consul/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestServer_StartStop(t *testing.T) {
}

config.RPCAdvertise = &net.TCPAddr{
IP: private.IP,
IP: private,
Port: 8300,
}

Expand Down

0 comments on commit 1611d98

Please sign in to comment.