Repository: matrixorigin/matrixone
Pull request #10725 (2023-07-17 11:14:06)

set hakeeper client default config
## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #

## What this PR does / why we need it:

set hakeeper client default config


Patch:
diff --git a/etc/launch-tae-CN-tae-DN/cn.toml b/etc/launch-tae-CN-tae-DN/cn.toml
index 60afa4f4d..73bd1f461 100644
--- a/etc/launch-tae-CN-tae-DN/cn.toml
+++ b/etc/launch-tae-CN-tae-DN/cn.toml
@@ -6,11 +6,6 @@ level = "info"
 format = "console"
 max-size = 512
 
-[hakeeper-client]
-service-addresses = [
-  "127.0.0.1:32001",
-]
-
 [metacache]
 memory-capacity = "512MB"
 
diff --git a/etc/launch-tae-CN-tae-DN/dn.toml b/etc/launch-tae-CN-tae-DN/dn.toml
index 20e42f24e..b1bbd1677 100644
--- a/etc/launch-tae-CN-tae-DN/dn.toml
+++ b/etc/launch-tae-CN-tae-DN/dn.toml
@@ -6,11 +6,6 @@ level = "info"
 format = "console"
 max-size = 512
 
-[hakeeper-client]
-service-addresses = [
-  "127.0.0.1:32001",
-]
-
 [metacache]
 memory-capacity = "512MB"
 
diff --git a/etc/launch-tae-CN-tae-DN/log.toml b/etc/launch-tae-CN-tae-DN/log.toml
index 7f1f1af92..f47968c0d 100644
--- a/etc/launch-tae-CN-tae-DN/log.toml
+++ b/etc/launch-tae-CN-tae-DN/log.toml
@@ -27,20 +27,9 @@ disk-evict-target = 0.8
 name = "ETL"
 backend = "DISK-ETL"
 
-[hakeeper-client]
-service-addresses = [
-  "127.0.0.1:32001",
-]
-
 [logservice]
 deployment-id = 1
 uuid = "7c4dccb4-4d3c-41f8-b482-5251dc7a41bf"
-raft-address = "127.0.0.1:32000"
-logservice-address = "127.0.0.1:32001"
-gossip-address = "127.0.0.1:32002"
-gossip-seed-addresses = [
-  "127.0.0.1:32002",
-]
 gossip-allow-self-as-seed = true
 
 [logservice.BootstrapConfig]
diff --git a/pkg/logservice/config.go b/pkg/logservice/config.go
index d756e206f..92360c132 100644
--- a/pkg/logservice/config.go
+++ b/pkg/logservice/config.go
@@ -31,8 +31,8 @@ import (
 const (
 	defaultDataDir           = "mo-data/logservice"
 	defaultSnapshotExportDir = "exported-snapshot"
-	defaultServiceAddress    = "0.0.0.0:32000"
-	defaultRaftAddress       = "0.0.0.0:32001"
+	defaultRaftAddress       = "0.0.0.0:32000"
+	defaultServiceAddress    = "0.0.0.0:32001"
 	defaultGossipAddress     = "0.0.0.0:32002"
 	defaultGossipSeedAddress = "127.0.0.1:32002"
 
@@ -372,6 +372,9 @@ func (c *Config) Fill() {
 	} else if len(c.GossipAddress) != 0 && len(c.GossipListenAddress) == 0 {
 		c.GossipListenAddress = c.GossipAddress
 	}
+	if len(c.GossipSeedAddresses) == 0 {
+		c.GossipSeedAddresses = []string{defaultGossipSeedAddress}
+	}
 	if c.HAKeeperConfig.TickPerSecond == 0 {
 		c.HAKeeperConfig.TickPerSecond = hakeeper.DefaultTickPerSecond
 	}
@@ -384,6 +387,12 @@ func (c *Config) Fill() {
 	if c.HAKeeperConfig.CNStoreTimeout.Duration == 0 {
 		c.HAKeeperConfig.CNStoreTimeout.Duration = hakeeper.DefaultCNStoreTimeout
 	}
+	if c.HAKeeperClientConfig.DiscoveryAddress == "" && len(c.HAKeeperClientConfig.ServiceAddresses) == 0 {
+		c.HAKeeperClientConfig.ServiceAddresses = []string{defaultServiceAddress}
+	}
+	if c.HAKeeperClientConfig.AllocateIDBatch == 0 {
+		c.HAKeeperClientConfig.AllocateIDBatch = 100
+	}
 	if c.HeartbeatInterval.Duration == 0 {
 		c.HeartbeatInterval.Duration = defaultHeartbeatInterval
 	}
@@ -423,7 +432,7 @@ type HAKeeperClientConfig struct {
 // Validate validates the HAKeeperClientConfig.
 func (c *HAKeeperClientConfig) Validate() error {
 	if len(c.DiscoveryAddress) == 0 && len(c.ServiceAddresses) == 0 {
-		return moerr.NewBadConfigNoCtx("HAKeeperClientConfig not set")
+		c.ServiceAddresses = []string{defaultServiceAddress}
 	}
 	if c.AllocateIDBatch == 0 {
 		c.AllocateIDBatch = 100
@@ -461,7 +470,7 @@ func (c *ClientConfig) Validate() error {
 		return moerr.NewBadConfigNoCtx("DNReplicaID value cannot be 0")
 	}
 	if len(c.DiscoveryAddress) == 0 && len(c.ServiceAddresses) == 0 {
-		return moerr.NewBadConfigNoCtx("ServiceAddresses not set")
+		c.ServiceAddresses = []string{defaultServiceAddress}
 	}
 	return nil
 }


Test patch:
diff --git a/pkg/logservice/config_test.go b/pkg/logservice/config_test.go
index 94c0955ca..368187755 100644
--- a/pkg/logservice/config_test.go
+++ b/pkg/logservice/config_test.go
@@ -183,7 +183,7 @@ func TestFillConfig(t *testing.T) {
 	assert.Equal(t, defaultRaftAddress, c.RaftListenAddress)
 	assert.Equal(t, defaultGossipAddress, c.GossipAddress)
 	assert.Equal(t, defaultGossipAddress, c.GossipListenAddress)
-	assert.Equal(t, 0, len(c.GossipSeedAddresses))
+	assert.Equal(t, 1, len(c.GossipSeedAddresses))
 	assert.Equal(t, hakeeper.DefaultTickPerSecond, c.HAKeeperConfig.TickPerSecond)
 	assert.Equal(t, hakeeper.DefaultLogStoreTimeout, c.HAKeeperConfig.LogStoreTimeout.Duration)
 	assert.Equal(t, hakeeper.DefaultDNStoreTimeout, c.HAKeeperConfig.DNStoreTimeout.Duration)
@@ -249,7 +249,7 @@ func TestHAKeeperClientConfigValidate(t *testing.T) {
 		ok  bool
 	}{
 		{
-			HAKeeperClientConfig{}, false,
+			HAKeeperClientConfig{}, true,
 		},
 		{
 			HAKeeperClientConfig{DiscoveryAddress: "localhost:9090"}, true,
diff --git a/pkg/logservice/hakeeper_client_test.go b/pkg/logservice/hakeeper_client_test.go
index 0724180d0..8681a6cb8 100644
--- a/pkg/logservice/hakeeper_client_test.go
+++ b/pkg/logservice/hakeeper_client_test.go
@@ -38,13 +38,13 @@ func TestHAKeeperClientConfigIsValidated(t *testing.T) {
 	cfg := HAKeeperClientConfig{}
 	cc1, err := NewCNHAKeeperClient(context.TODO(), cfg)
 	assert.Nil(t, cc1)
-	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBadConfig))
+	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBackendCannotConnect))
 	cc2, err := NewDNHAKeeperClient(context.TODO(), cfg)
 	assert.Nil(t, cc2)
-	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBadConfig))
+	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBackendCannotConnect))
 	cc3, err := NewLogHAKeeperClient(context.TODO(), cfg)
 	assert.Nil(t, cc3)
-	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBadConfig))
+	assert.True(t, moerr.IsMoErrCode(err, moerr.ErrBackendCannotConnect))
 }
 
 func TestHAKeeperClientsCanBeCreated(t *testing.T) {