diff --git a/dm/dm/master/election_test.go b/dm/dm/master/election_test.go index 11a6c62aa8e..6ef2dfef063 100644 --- a/dm/dm/master/election_test.go +++ b/dm/dm/master/election_test.go @@ -41,6 +41,7 @@ func (t *testElectionSuite) TestFailToStartLeader(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -60,6 +61,7 @@ func (t *testElectionSuite) TestFailToStartLeader(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster diff --git a/dm/dm/master/etcd.go b/dm/dm/master/etcd.go index bd7762cc4b7..a10b53af54b 100644 --- a/dm/dm/master/etcd.go +++ b/dm/dm/master/etcd.go @@ -97,7 +97,7 @@ func prepareJoinEtcd(cfg *Config) error { } // try to join self, invalid - if cfg.Join == cfg.MasterAddr { + if cfg.Join == cfg.AdvertiseAddr { return terror.ErrMasterJoinEmbedEtcdFail.Generate(fmt.Sprintf("join self %s is forbidden", cfg.Join)) } diff --git a/dm/dm/master/etcd_test.go b/dm/dm/master/etcd_test.go index e3a8a8b1572..402396e0e40 100644 --- a/dm/dm/master/etcd_test.go +++ b/dm/dm/master/etcd_test.go @@ -69,7 +69,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgCluster.Name = "dm-master-1" cfgCluster.DataDir = c.MkDir() cfgCluster.MasterAddr = tempurl.Alloc()[len("http://"):] - cfgCluster.AdvertiseAddr = tempurl.Alloc()[len("http://"):] + cfgCluster.AdvertiseAddr = cfgCluster.MasterAddr cfgCluster.PeerUrls = tempurl.Alloc() c.Assert(cfgCluster.adjust(), check.IsNil) cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info") @@ -79,6 +79,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgBefore := t.cloneConfig(cfgCluster) // before `prepareJoinEtcd` applied cfgBefore.DataDir = c.MkDir() // overwrite some config items cfgBefore.MasterAddr = tempurl.Alloc()[len("http://"):] + cfgBefore.AdvertiseAddr = cfgBefore.MasterAddr cfgBefore.PeerUrls = tempurl.Alloc() cfgBefore.AdvertisePeerUrls = cfgBefore.PeerUrls c.Assert(cfgBefore.adjust(), check.IsNil) @@ -172,6 +173,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgAfter2.Name = "dm-master-3" // overwrite some items cfgAfter2.DataDir = c.MkDir() cfgAfter2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfgAfter2.AdvertiseAddr = cfgAfter2.MasterAddr cfgAfter2.PeerUrls = tempurl.Alloc() cfgAfter2.AdvertisePeerUrls = cfgAfter2.PeerUrls err = prepareJoinEtcd(cfgAfter2) @@ -229,6 +231,7 @@ func (t *testEtcdSuite) TestEtcdAutoCompaction(c *check.C) { cfg.DataDir = c.MkDir() cfg.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg.AdvertiseAddr = cfg.MasterAddr cfg.AutoCompactionRetention = "1s" ctx, cancel := context.WithCancel(context.Background()) diff --git a/dm/dm/master/openapi_test.go b/dm/dm/master/openapi_test.go index de038b3df72..ab4745c906a 100644 --- a/dm/dm/master/openapi_test.go +++ b/dm/dm/master/openapi_test.go @@ -85,6 +85,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -105,6 +106,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster @@ -138,6 +140,7 @@ func (t *openAPISuite) TestOpenAPIWillNotStartInDefaultConfig(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) diff --git a/dm/dm/master/server.go b/dm/dm/master/server.go index 47d7508fa9a..42309798856 100644 --- a/dm/dm/master/server.go +++ b/dm/dm/master/server.go @@ -208,7 +208,7 @@ func (s *Server) Start(ctx context.Context) (err error) { // create an etcd client used in the whole server instance. // NOTE: we only use the local member's address now, but we can use all endpoints of the cluster if needed. - s.etcdClient, err = etcdutil.CreateClient([]string{withHost(s.cfg.MasterAddr)}, tls.TLSConfig()) + s.etcdClient, err = etcdutil.CreateClient([]string{withHost(s.cfg.AdvertiseAddr)}, tls.TLSConfig()) if err != nil { return } diff --git a/dm/dm/master/server_test.go b/dm/dm/master/server_test.go index 842f9283221..d3dd2db1521 100644 --- a/dm/dm/master/server_test.go +++ b/dm/dm/master/server_test.go @@ -1311,6 +1311,7 @@ func (t *testMaster) TestServer(c *check.C) { cfg.PeerUrls = "http://127.0.0.1:8294" cfg.DataDir = c.MkDir() cfg.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg.AdvertiseAddr = cfg.MasterAddr s := NewServer(cfg) @@ -1534,6 +1535,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -1553,6 +1555,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster @@ -1587,6 +1590,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg3.Name = "dm-master-3" cfg3.DataDir = c.MkDir() cfg3.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg3.AdvertiseAddr = cfg3.MasterAddr cfg3.PeerUrls = tempurl.Alloc() cfg3.AdvertisePeerUrls = cfg3.PeerUrls cfg3.Join = cfg1.MasterAddr // join to an existing cluster @@ -1629,7 +1633,7 @@ func (t *testMaster) TestOperateSource(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] - cfg1.AdvertiseAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls)