From 1611d986d66c8c7bb50d8b61f9298dc7a6495f88 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 16 May 2014 14:07:50 -0700 Subject: [PATCH] consul: Avoid name conflict on WAN ring. Fixes #158. --- consul/server.go | 12 ++++++++---- consul/server_test.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/consul/server.go b/consul/server.go index 32c38f7d4a..282c0be9c3 100644 --- a/consul/server.go +++ b/consul/server.go @@ -179,7 +179,7 @@ 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) @@ -187,7 +187,7 @@ func NewServer(config *Config) (*Server, error) { // 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) @@ -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) diff --git a/consul/server_test.go b/consul/server_test.go index 45edac53d9..7c7864344a 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -98,7 +98,7 @@ func TestServer_StartStop(t *testing.T) { } config.RPCAdvertise = &net.TCPAddr{ - IP: private.IP, + IP: private, Port: 8300, }