Repository: matrixorigin/matrixone
Pull request #10770 (2023-07-19 12:03:22)

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


Patch:
diff --git a/cmd/mo-service/config.go b/cmd/mo-service/config.go
index 90a314e0a..84c063bed 100644
--- a/cmd/mo-service/config.go
+++ b/cmd/mo-service/config.go
@@ -116,7 +116,14 @@ type Config struct {
 // NewConfig return Config with default values.
 func NewConfig() *Config {
 	return &Config{
+		HAKeeperClient: logservice.HAKeeperClientConfig{
+			DiscoveryAddress: "",
+			ServiceAddresses: []string{logservice.DefaultServiceAddress},
+			AllocateIDBatch:  100,
+			EnableCompress:   false,
+		},
 		Observability: *config.NewObservabilityParameters(),
+		LogService:    logservice.DefaultConfig(),
 	}
 }
 
diff --git a/etc/launch-tae-CN-tae-DN/log.toml b/etc/launch-tae-CN-tae-DN/log.toml
index f47968c0d..68a3dcba8 100644
--- a/etc/launch-tae-CN-tae-DN/log.toml
+++ b/etc/launch-tae-CN-tae-DN/log.toml
@@ -26,17 +26,3 @@ disk-evict-target = 0.8
 [[fileservice]]
 name = "ETL"
 backend = "DISK-ETL"
-
-[logservice]
-deployment-id = 1
-uuid = "7c4dccb4-4d3c-41f8-b482-5251dc7a41bf"
-gossip-allow-self-as-seed = true
-
-[logservice.BootstrapConfig]
-bootstrap-cluster = true
-num-of-log-shards = 1
-num-of-dn-shards = 1
-num-of-log-shard-replicas = 1
-init-hakeeper-members = [
-  "131072:7c4dccb4-4d3c-41f8-b482-5251dc7a41bf",
-]
diff --git a/etc/launch-tae-compose/config/log.toml b/etc/launch-tae-compose/config/log.toml
index 4c9a7f0a4..7ce8e6373 100644
--- a/etc/launch-tae-compose/config/log.toml
+++ b/etc/launch-tae-compose/config/log.toml
@@ -38,27 +38,3 @@ key-prefix = "server/etl"
 
 [observability]
 statusPort = 7001
-
-[hakeeper-client]
-discovery-address = "logservice:32001"
-
-[logservice]
-deployment-id = 1
-uuid = "7c4dccb4-4d3c-41f8-b482-5251dc7a41bf"
-raft-address = "logservice:32000"
-logservice-address = "logservice:32001"
-gossip-address-v2 = "logservice:32002"
-logservice-listen-address = "0.0.0.0:32001"
-gossip-seed-addresses = [
-  "logservice:32002",
-]
-gossip-allow-self-as-seed = true
-
-[logservice.BootstrapConfig]
-bootstrap-cluster = true
-num-of-log-shards = 1
-num-of-dn-shards = 1
-num-of-log-shard-replicas = 1
-init-hakeeper-members = [
-  "131072:7c4dccb4-4d3c-41f8-b482-5251dc7a41bf",
-]
diff --git a/etc/launch-tae-multi-CN-tae-DN/log.toml b/etc/launch-tae-multi-CN-tae-DN/log.toml
index 888bc038f..9d717d78e 100644
--- a/etc/launch-tae-multi-CN-tae-DN/log.toml
+++ b/etc/launch-tae-multi-CN-tae-DN/log.toml
@@ -29,28 +29,3 @@ backend = "DISK-ETL"
 
 [observability]
 statusPort = 7001
-
-[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]
-bootstrap-cluster = true
-num-of-log-shards = 1
-num-of-dn-shards = 1
-num-of-log-shard-replicas = 1
-init-hakeeper-members = [
-  "131072:7c4dccb4-4d3c-41f8-b482-5251dc7a41bf",
-]
diff --git a/etc/launch-with-proxy/log.toml b/etc/launch-with-proxy/log.toml
index a387d2fb3..5fddf9a7b 100644
--- a/etc/launch-with-proxy/log.toml
+++ b/etc/launch-with-proxy/log.toml
@@ -27,28 +27,3 @@ backend = "DISK-ETL"
 
 [observability]
 statusPort = 7001
-
-[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]
-bootstrap-cluster = true
-num-of-log-shards = 1
-num-of-dn-shards = 1
-num-of-log-shard-replicas = 1
-init-hakeeper-members = [
-  "131072:7c4dccb4-4d3c-41f8-b482-5251dc7a41bf",
-]
diff --git a/pkg/logservice/config.go b/pkg/logservice/config.go
index 92360c132..83b26f4f7 100644
--- a/pkg/logservice/config.go
+++ b/pkg/logservice/config.go
@@ -29,6 +29,7 @@ import (
 )
 
 const (
+	defaultDeploymentID      = 1
 	defaultDataDir           = "mo-data/logservice"
 	defaultSnapshotExportDir = "exported-snapshot"
 	defaultRaftAddress       = "0.0.0.0:32000"
@@ -44,6 +45,9 @@ const (
 	defaultMaxMessageSize      = 1024 * 1024 * 100
 	// The default value for HAKeeper truncate interval.
 	defaultHAKeeperTruncateInterval = 24 * time.Hour
+
+	// DefaultServiceAddress is exported.
+	DefaultServiceAddress = defaultServiceAddress
 )
 
 // Config defines the Configurations supported by the Log Service.
@@ -330,22 +334,93 @@ func (c *Config) Validate() error {
 	return nil
 }
 
-func (c *Config) Fill() {
-	if c.FS == nil {
-		c.FS = vfs.Default
-	}
-	if c.RTTMillisecond == 0 {
-		c.RTTMillisecond = 200
-	}
-	if len(c.DataDir) == 0 {
-		c.DataDir = defaultDataDir
-	}
-	if len(c.SnapshotExportDir) == 0 {
-		c.SnapshotExportDir = defaultSnapshotExportDir
-	}
-	if c.MaxExportedSnapshot == 0 {
-		c.MaxExportedSnapshot = defaultMaxExportedSnapshot
+func DefaultConfig() Config {
+	uid := "7c4dccb4-4d3c-41f8-b482-5251dc7a41bf"
+	return Config{
+		FS:                       vfs.Default,
+		DeploymentID:             defaultDeploymentID,
+		UUID:                     uid,
+		RTTMillisecond:           200,
+		DataDir:                  defaultDataDir,
+		SnapshotExportDir:        defaultSnapshotExportDir,
+		MaxExportedSnapshot:      defaultMaxExportedSnapshot,
+		ServiceAddress:           defaultServiceAddress,
+		RaftAddress:              defaultRaftAddress,
+		UseTeeLogDB:              false,
+		LogDBBufferSize:          defaultLogDBBufferSize,
+		GossipAddress:            defaultGossipAddress,
+		GossipSeedAddresses:      []string{defaultGossipSeedAddress},
+		GossipProbeInterval:      toml.Duration{Duration: defaultGossipProbeInterval},
+		GossipAllowSelfAsSeed:    true,
+		HeartbeatInterval:        toml.Duration{Duration: defaultHeartbeatInterval},
+		HAKeeperTickInterval:     toml.Duration{Duration: time.Second / hakeeper.DefaultTickPerSecond},
+		HAKeeperCheckInterval:    toml.Duration{Duration: hakeeper.CheckDuration},
+		TruncateInterval:         toml.Duration{Duration: defaultTruncateInterval},
+		HAKeeperTruncateInterval: toml.Duration{Duration: defaultHAKeeperTruncateInterval},
+		RPC: struct {
+			MaxMessageSize toml.ByteSize `toml:"max-message-size"`
+			EnableCompress bool          `toml:"enable-compress"`
+		}(struct {
+			MaxMessageSize toml.ByteSize
+			EnableCompress bool
+		}{
+			MaxMessageSize: toml.ByteSize(defaultMaxMessageSize),
+			EnableCompress: false,
+		}),
+		BootstrapConfig: struct {
+			BootstrapCluster      bool     `toml:"bootstrap-cluster"`
+			NumOfLogShards        uint64   `toml:"num-of-log-shards"`
+			NumOfDNShards         uint64   `toml:"num-of-dn-shards"`
+			NumOfLogShardReplicas uint64   `toml:"num-of-log-shard-replicas"`
+			InitHAKeeperMembers   []string `toml:"init-hakeeper-members"`
+		}(struct {
+			BootstrapCluster      bool
+			NumOfLogShards        uint64
+			NumOfDNShards         uint64
+			NumOfLogShardReplicas uint64
+			InitHAKeeperMembers   []string
+		}{
+			BootstrapCluster:      true,
+			NumOfLogShards:        1,
+			NumOfDNShards:         1,
+			NumOfLogShardReplicas: 1,
+			InitHAKeeperMembers:   []string{"131072:" + uid}}),
+		HAKeeperConfig: struct {
+			TickPerSecond   int           `toml:"tick-per-second"`
+			LogStoreTimeout toml.Duration `toml:"log-store-timeout"`
+			DNStoreTimeout  toml.Duration `toml:"dn-store-timeout"`
+			CNStoreTimeout  toml.Duration `toml:"cn-store-timeout"`
+		}(struct {
+			TickPerSecond   int
+			LogStoreTimeout toml.Duration
+			DNStoreTimeout  toml.Duration
+			CNStoreTimeout  toml.Duration
+		}{
+			TickPerSecond:   hakeeper.DefaultTickPerSecond,
+			LogStoreTimeout: toml.Duration{Duration: hakeeper.DefaultLogStoreTimeout},
+			DNStoreTimeout:  toml.Duration{Duration: hakeeper.DefaultDNStoreTimeout},
+			CNStoreTimeout:  toml.Duration{Duration: hakeeper.DefaultCNStoreTimeout},
+		}),
+		HAKeeperClientConfig: HAKeeperClientConfig{
+			DiscoveryAddress: "",
+			ServiceAddresses: []string{defaultServiceAddress},
+			AllocateIDBatch:  100,
+			EnableCompress:   false,
+		},
+		DisableWorkers: false,
+		// Not used for now.
+		Ctl: struct {
+			ListenAddress  string `toml:"listen-address"`
+			ServiceAddress string `toml:"service-address"`
+		}(struct {
+			ListenAddress  string
+			ServiceAddress string
+		}{ListenAddress: "", ServiceAddress: ""}),
 	}
+}
+
+// Fill just fills the listen addresses.
+func (c *Config) Fill() {
 	if len(c.ServiceAddress) == 0 {
 		c.ServiceAddress = defaultServiceAddress
 		c.ServiceListenAddress = defaultServiceAddress
@@ -358,9 +433,6 @@ func (c *Config) Fill() {
 	} else if len(c.RaftAddress) != 0 && len(c.RaftListenAddress) == 0 {
 		c.RaftListenAddress = c.RaftAddress
 	}
-	if c.LogDBBufferSize == 0 {
-		c.LogDBBufferSize = defaultLogDBBufferSize
-	}
 	// If GossipAddressV2 is set, we use it as gossip address, and GossipAddress
 	// will be overridden by it.
 	if len(c.GossipAddressV2) != 0 {
@@ -375,45 +447,6 @@ func (c *Config) Fill() {
 	if len(c.GossipSeedAddresses) == 0 {
 		c.GossipSeedAddresses = []string{defaultGossipSeedAddress}
 	}
-	if c.HAKeeperConfig.TickPerSecond == 0 {
-		c.HAKeeperConfig.TickPerSecond = hakeeper.DefaultTickPerSecond
-	}
-	if c.HAKeeperConfig.LogStoreTimeout.Duration == 0 {
-		c.HAKeeperConfig.LogStoreTimeout.Duration = hakeeper.DefaultLogStoreTimeout
-	}
-	if c.HAKeeperConfig.DNStoreTimeout.Duration == 0 {
-		c.HAKeeperConfig.DNStoreTimeout.Duration = hakeeper.DefaultDNStoreTimeout
-	}
-	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
-	}
-	if c.HAKeeperTickInterval.Duration == 0 {
-		c.HAKeeperTickInterval.Duration = time.Second / time.Duration(c.HAKeeperConfig.TickPerSecond)
-	}
-	if c.HAKeeperCheckInterval.Duration == 0 {
-		c.HAKeeperCheckInterval.Duration = hakeeper.CheckDuration
-	}
-	if c.GossipProbeInterval.Duration == 0 {
-		c.GossipProbeInterval.Duration = defaultGossipProbeInterval
-	}
-	if c.TruncateInterval.Duration == 0 {
-		c.TruncateInterval.Duration = defaultTruncateInterval
-	}
-	if c.HAKeeperTruncateInterval.Duration == 0 {
-		c.HAKeeperTruncateInterval.Duration = defaultHAKeeperTruncateInterval
-	}
-	if c.RPC.MaxMessageSize == 0 {
-		c.RPC.MaxMessageSize = toml.ByteSize(defaultMaxMessageSize)
-	}
 }
 
 // HAKeeperClientConfig is the config for HAKeeper clients.


Test patch:
diff --git a/pkg/logservice/config_test.go b/pkg/logservice/config_test.go
index 368187755..69eece40e 100644
--- a/pkg/logservice/config_test.go
+++ b/pkg/logservice/config_test.go
@@ -25,18 +25,17 @@ import (
 )
 
 func getTestConfig() Config {
-	c := Config{
-		UUID:                 "uuid",
-		DeploymentID:         100,
-		DataDir:              "/mydata/dir",
-		ServiceAddress:       "localhost:9000",
-		ServiceListenAddress: "localhost:9000",
-		RaftAddress:          "localhost:9001",
-		RaftListenAddress:    "localhost:9001",
-		GossipAddress:        "localhost:9002",
-		GossipListenAddress:  "localhost:9002",
-		GossipSeedAddresses:  []string{"localhost:9002"},
-	}
+	c := DefaultConfig()
+	c.UUID = "uuid"
+	c.DeploymentID = 100
+	c.DataDir = "/mydata/dir"
+	c.ServiceAddress = "localhost:9000"
+	c.ServiceListenAddress = "localhost:9000"
+	c.RaftAddress = "localhost:9001"
+	c.RaftListenAddress = "localhost:9001"
+	c.GossipAddress = "localhost:9002"
+	c.GossipListenAddress = "localhost:9002"
+	c.GossipSeedAddresses = []string{"localhost:9002"}
 	c.Fill()
 	return c
 }
@@ -170,10 +169,9 @@ func TestBootstrapConfigCanBeValidated(t *testing.T) {
 }
 
 func TestFillConfig(t *testing.T) {
-	c := Config{}
+	c := DefaultConfig()
 	c.Fill()
-
-	assert.Equal(t, uint64(0), c.DeploymentID)
+	assert.Equal(t, uint64(1), c.DeploymentID)
 	assert.Equal(t, defaultDataDir, c.DataDir)
 	assert.Equal(t, defaultSnapshotExportDir, c.SnapshotExportDir)
 	assert.Equal(t, defaultMaxExportedSnapshot, c.MaxExportedSnapshot)
@@ -276,10 +274,9 @@ func TestHAKeeperClientConfigValidate(t *testing.T) {
 }
 
 func TestGossipAddressV2IsUsed(t *testing.T) {
-	cfg := Config{
-		GossipAddress:   "127.0.0.1:9001",
-		GossipAddressV2: "localhost:9002",
-	}
+	cfg := DefaultConfig()
+	cfg.GossipAddress = "127.0.0.1:9001"
+	cfg.GossipAddressV2 = "localhost:9002"
 	cfg.Fill()
 	assert.Equal(t, cfg.GossipAddress, cfg.GossipAddressV2)
 	assert.Equal(t, cfg.GossipAddress, cfg.GossipListenAddress)
diff --git a/pkg/logservice/hakeeper_client_test.go b/pkg/logservice/hakeeper_client_test.go
index 8681a6cb8..6c0dfa203 100644
--- a/pkg/logservice/hakeeper_client_test.go
+++ b/pkg/logservice/hakeeper_client_test.go
@@ -283,31 +283,34 @@ func TestHAKeeperClientSendLogHeartbeat(t *testing.T) {
 
 func testNotHAKeeperErrorIsHandled(t *testing.T, fn func(*testing.T, *managedHAKeeperClient)) {
 	defer leaktest.AfterTest(t)()
-	cfg1 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-1",
-		ServiceAddress:      "127.0.0.1:9002",
-		RaftAddress:         "127.0.0.1:9000",
-		GossipAddress:       "127.0.0.1:9001",
-		GossipSeedAddresses: []string{"127.0.0.1:9011"},
-		DisableWorkers:      true,
-	}
-	cfg2 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-2",
-		ServiceAddress:      "127.0.0.1:9012",
-		RaftAddress:         "127.0.0.1:9010",
-		GossipAddress:       "127.0.0.1:9011",
-		GossipSeedAddresses: []string{"127.0.0.1:9001"},
-		DisableWorkers:      true,
-	}
+	cfg1 := DefaultConfig()
+	cfg1.UUID = uuid.New().String()
+	cfg1.FS = vfs.NewStrictMem()
+	cfg1.DeploymentID = 1
+	cfg1.RTTMillisecond = 5
+	cfg1.DataDir = "data-1"
+	cfg1.ServiceAddress = "127.0.0.1:9002"
+	cfg1.RaftAddress = "127.0.0.1:9000"
+	cfg1.GossipAddress = "127.0.0.1:9001"
+	cfg1.GossipSeedAddresses = []string{"127.0.0.1:9011"}
+	cfg1.DisableWorkers = true
 	cfg1.Fill()
+	cfg2 := DefaultConfig()
+	cfg2.UUID = uuid.New().String()
+	cfg2.FS = vfs.NewStrictMem()
+	cfg2.DeploymentID = 1
+	cfg2.RTTMillisecond = 5
+	cfg2.DataDir = "data-2"
+	cfg2.ServiceAddress = "127.0.0.1:9012"
+	cfg2.ServiceListenAddress = cfg2.ServiceAddress
+	cfg2.RaftAddress = "127.0.0.1:9010"
+	cfg2.RaftListenAddress = cfg2.RaftAddress
+	cfg2.GossipAddress = "127.0.0.1:9011"
+	cfg2.GossipAddressV2 = cfg2.GossipAddress
+	cfg2.GossipListenAddress = cfg2.GossipAddress
+	cfg2.GossipSeedAddresses = []string{"127.0.0.1:9001"}
+	cfg2.DisableWorkers = true
+	cfg2.Fill()
 	service1, err := NewService(cfg1,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
@@ -318,7 +321,6 @@ func testNotHAKeeperErrorIsHandled(t *testing.T, fn func(*testing.T, *managedHAK
 	defer func() {
 		assert.NoError(t, service1.Close())
 	}()
-	cfg2.Fill()
 	service2, err := NewService(cfg2,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
diff --git a/pkg/logservice/service_commands_test.go b/pkg/logservice/service_commands_test.go
index 6392cadf7..a620f6012 100644
--- a/pkg/logservice/service_commands_test.go
+++ b/pkg/logservice/service_commands_test.go
@@ -32,18 +32,17 @@ import (
 
 func TestBackgroundTickAndHeartbeat(t *testing.T) {
 	defer leaktest.AfterTest(t)()
-	cfg := Config{
-		UUID:           uuid.New().String(),
-		FS:             vfs.NewStrictMem(),
-		DeploymentID:   1,
-		RTTMillisecond: 5,
-		DataDir:        "data-1",
-		ServiceAddress: "127.0.0.1:9002",
-		RaftAddress:    "127.0.0.1:9000",
-		GossipAddress:  "127.0.0.1:9001",
-		// below is an unreachable address intentionally set
-		GossipSeedAddresses: []string{"127.0.0.1:9010"},
-	}
+	cfg := DefaultConfig()
+	cfg.UUID = uuid.New().String()
+	cfg.FS = vfs.NewStrictMem()
+	cfg.DeploymentID = 1
+	cfg.RTTMillisecond = 5
+	cfg.DataDir = "data-1"
+	cfg.ServiceAddress = "127.0.0.1:9002"
+	cfg.RaftAddress = "127.0.0.1:9000"
+	cfg.GossipAddress = "127.0.0.1:9001"
+	// below is an unreachable address intentionally set
+	cfg.GossipSeedAddresses = []string{"127.0.0.1:9010"}
 	cfg.HeartbeatInterval.Duration = 5 * time.Millisecond
 	cfg.HAKeeperTickInterval.Duration = 5 * time.Millisecond
 	cfg.HAKeeperClientConfig.ServiceAddresses = []string{"127.0.0.1:9002"}
diff --git a/pkg/logservice/service_test.go b/pkg/logservice/service_test.go
index 3f44779a7..54db57120 100644
--- a/pkg/logservice/service_test.go
+++ b/pkg/logservice/service_test.go
@@ -43,19 +43,18 @@ const (
 )
 
 func getServiceTestConfig() Config {
-	c := Config{
-		UUID:                 uuid.New().String(),
-		RTTMillisecond:       10,
-		GossipAddress:        testGossipAddress,
-		GossipListenAddress:  testGossipAddress,
-		GossipSeedAddresses:  []string{testGossipAddress, dummyGossipSeedAddress},
-		DeploymentID:         1,
-		FS:                   vfs.NewStrictMem(),
-		ServiceListenAddress: testServiceAddress,
-		ServiceAddress:       testServiceAddress,
-		DisableWorkers:       true,
-		UseTeeLogDB:          true,
-	}
+	c := DefaultConfig()
+	c.UUID = uuid.New().String()
+	c.RTTMillisecond = 10
+	c.GossipAddress = testGossipAddress
+	c.GossipListenAddress = testGossipAddress
+	c.GossipSeedAddresses = []string{testGossipAddress, dummyGossipSeedAddress}
+	c.DeploymentID = 1
+	c.FS = vfs.NewStrictMem()
+	c.ServiceListenAddress = testServiceAddress
+	c.ServiceAddress = testServiceAddress
+	c.DisableWorkers = true
+	c.UseTeeLogDB = true
 	c.RPC.MaxMessageSize = testServerMaxMsgSize
 	c.Fill()
 	return c
@@ -514,30 +513,29 @@ func TestServiceCheckHAKeeper(t *testing.T) {
 
 func TestShardInfoCanBeQueried(t *testing.T) {
 	defer leaktest.AfterTest(t)()
-	cfg1 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-1",
-		ServiceAddress:      "127.0.0.1:9002",
-		RaftAddress:         "127.0.0.1:9000",
-		GossipAddress:       "127.0.0.1:9001",
-		GossipSeedAddresses: []string{"127.0.0.1:9011"},
-		DisableWorkers:      true,
-	}
-	cfg2 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-2",
-		ServiceAddress:      "127.0.0.1:9012",
-		RaftAddress:         "127.0.0.1:9010",
-		GossipAddress:       "127.0.0.1:9011",
-		GossipSeedAddresses: []string{"127.0.0.1:9001"},
-		DisableWorkers:      true,
-	}
+	cfg1 := DefaultConfig()
+	cfg1.UUID = uuid.New().String()
+	cfg1.FS = vfs.NewStrictMem()
+	cfg1.DeploymentID = 1
+	cfg1.RTTMillisecond = 5
+	cfg1.DataDir = "data-1"
+	cfg1.ServiceAddress = "127.0.0.1:9002"
+	cfg1.RaftAddress = "127.0.0.1:9000"
+	cfg1.GossipAddress = "127.0.0.1:9001"
+	cfg1.GossipSeedAddresses = []string{"127.0.0.1:9011"}
+	cfg1.DisableWorkers = true
+	cfg1.Fill()
+	cfg2 := DefaultConfig()
+	cfg2.UUID = uuid.New().String()
+	cfg2.FS = vfs.NewStrictMem()
+	cfg2.DeploymentID = 1
+	cfg2.RTTMillisecond = 5
+	cfg2.DataDir = "data-2"
+	cfg2.ServiceAddress = "127.0.0.1:9012"
+	cfg2.RaftAddress = "127.0.0.1:9010"
+	cfg2.GossipAddress = "127.0.0.1:9011"
+	cfg2.GossipSeedAddresses = []string{"127.0.0.1:9001"}
+	cfg2.DisableWorkers = true
 	cfg1.Fill()
 	service1, err := NewService(cfg1,
 		newFS(),
@@ -552,7 +550,6 @@ func TestShardInfoCanBeQueried(t *testing.T) {
 	peers1 := make(map[uint64]dragonboat.Target)
 	peers1[1] = service1.ID()
 	assert.NoError(t, service1.store.startReplica(1, 1, peers1, false))
-	cfg2.Fill()
 	service2, err := NewService(cfg2,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
@@ -644,30 +641,29 @@ func TestGossipInSimulatedCluster(t *testing.T) {
 	configs := make([]Config, 0)
 	services := make([]*Service, 0)
 	for i := 0; i < nodeCount; i++ {
-		cfg := Config{
-			FS:             vfs.NewStrictMem(),
-			UUID:           uuid.New().String(),
-			DeploymentID:   1,
-			RTTMillisecond: 200,
-			DataDir:        fmt.Sprintf("data-%d", i),
-			ServiceAddress: fmt.Sprintf("127.0.0.1:%d", 26000+10*i),
-			RaftAddress:    fmt.Sprintf("127.0.0.1:%d", 26000+10*i+1),
-			GossipAddress:  fmt.Sprintf("127.0.0.1:%d", 26000+10*i+2),
-			GossipSeedAddresses: []string{
-				"127.0.0.1:26002",
-				"127.0.0.1:26012",
-				"127.0.0.1:26022",
-				"127.0.0.1:26032",
-				"127.0.0.1:26042",
-				"127.0.0.1:26052",
-				"127.0.0.1:26062",
-				"127.0.0.1:26072",
-				"127.0.0.1:26082",
-				"127.0.0.1:26092",
-			},
-			DisableWorkers:  true,
-			LogDBBufferSize: 1024 * 16,
-		}
+		cfg := DefaultConfig()
+		cfg.FS = vfs.NewStrictMem()
+		cfg.UUID = uuid.New().String()
+		cfg.DeploymentID = 1
+		cfg.RTTMillisecond = 200
+		cfg.DataDir = fmt.Sprintf("data-%d", i)
+		cfg.ServiceAddress = fmt.Sprintf("127.0.0.1:%d", 26000+10*i)
+		cfg.RaftAddress = fmt.Sprintf("127.0.0.1:%d", 26000+10*i+1)
+		cfg.GossipAddress = fmt.Sprintf("127.0.0.1:%d", 26000+10*i+2)
+		cfg.GossipSeedAddresses = []string{
+			"127.0.0.1:26002",
+			"127.0.0.1:26012",
+			"127.0.0.1:26022",
+			"127.0.0.1:26032",
+			"127.0.0.1:26042",
+			"127.0.0.1:26052",
+			"127.0.0.1:26062",
+			"127.0.0.1:26072",
+			"127.0.0.1:26082",
+			"127.0.0.1:26092",
+		}
+		cfg.DisableWorkers = true
+		cfg.LogDBBufferSize = 1024 * 16
 		cfg.GossipProbeInterval.Duration = 350 * time.Millisecond
 		configs = append(configs, cfg)
 		service, err := NewService(cfg,
diff --git a/pkg/logservice/store_hakeeper_check_test.go b/pkg/logservice/store_hakeeper_check_test.go
index 227727860..32b1f8bd5 100644
--- a/pkg/logservice/store_hakeeper_check_test.go
+++ b/pkg/logservice/store_hakeeper_check_test.go
@@ -158,71 +158,70 @@ func runHakeeperTaskServiceTest(t *testing.T, fn func(*testing.T, *store, taskse
 
 func runHAKeeperClusterTest(t *testing.T, fn func(*testing.T, []*Service)) {
 	defer leaktest.AfterTest(t)()
-	cfg1 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-1",
-		ServiceAddress:      "127.0.0.1:9002",
-		RaftAddress:         "127.0.0.1:9000",
-		GossipAddress:       "127.0.0.1:9001",
-		GossipSeedAddresses: []string{"127.0.0.1:9011", "127.0.0.1:9021", "127.0.0.1:9031"},
-		DisableWorkers:      true,
-	}
+	cfg1 := DefaultConfig()
+	cfg1.UUID = uuid.New().String()
+	cfg1.FS = vfs.NewStrictMem()
+	cfg1.DeploymentID = 1
+	cfg1.RTTMillisecond = 5
+	cfg1.DataDir = "data-1"
+	cfg1.ServiceAddress = "127.0.0.1:9002"
+	cfg1.RaftAddress = "127.0.0.1:9000"
+	cfg1.GossipAddress = "127.0.0.1:9001"
+	cfg1.GossipSeedAddresses = []string{"127.0.0.1:9011", "127.0.0.1:9021", "127.0.0.1:9031"}
+	cfg1.DisableWorkers = true
 	cfg1.HAKeeperConfig.TickPerSecond = 10
 	cfg1.HAKeeperConfig.LogStoreTimeout.Duration = 5 * time.Second
 	cfg1.HAKeeperConfig.DNStoreTimeout.Duration = 10 * time.Second
 	cfg1.HAKeeperConfig.CNStoreTimeout.Duration = 5 * time.Second
-	cfg2 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-2",
-		ServiceAddress:      "127.0.0.1:9012",
-		RaftAddress:         "127.0.0.1:9010",
-		GossipAddress:       "127.0.0.1:9011",
-		GossipSeedAddresses: []string{"127.0.0.1:9001", "127.0.0.1:9021", "127.0.0.1:9031"},
-		DisableWorkers:      true,
-	}
+	cfg1.Fill()
+	cfg2 := DefaultConfig()
+	cfg2.UUID = uuid.New().String()
+	cfg2.FS = vfs.NewStrictMem()
+	cfg2.DeploymentID = 1
+	cfg2.RTTMillisecond = 5
+	cfg2.DataDir = "data-2"
+	cfg2.ServiceAddress = "127.0.0.1:9012"
+	cfg2.RaftAddress = "127.0.0.1:9010"
+	cfg2.GossipAddress = "127.0.0.1:9011"
+	cfg2.GossipSeedAddresses = []string{"127.0.0.1:9001", "127.0.0.1:9021", "127.0.0.1:9031"}
+	cfg2.DisableWorkers = true
 	cfg2.HAKeeperConfig.TickPerSecond = 10
 	cfg2.HAKeeperConfig.LogStoreTimeout.Duration = 5 * time.Second
 	cfg2.HAKeeperConfig.DNStoreTimeout.Duration = 10 * time.Second
 	cfg2.HAKeeperConfig.CNStoreTimeout.Duration = 5 * time.Second
-	cfg3 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-3",
-		ServiceAddress:      "127.0.0.1:9022",
-		RaftAddress:         "127.0.0.1:9020",
-		GossipAddress:       "127.0.0.1:9021",
-		GossipSeedAddresses: []string{"127.0.0.1:9001", "127.0.0.1:9011", "127.0.0.1:9031"},
-		DisableWorkers:      true,
-	}
+	cfg2.Fill()
+	cfg3 := DefaultConfig()
+	cfg3.UUID = uuid.New().String()
+	cfg3.FS = vfs.NewStrictMem()
+	cfg3.DeploymentID = 1
+	cfg3.RTTMillisecond = 5
+	cfg3.DataDir = "data-3"
+	cfg3.ServiceAddress = "127.0.0.1:9022"
+	cfg3.RaftAddress = "127.0.0.1:9020"
+	cfg3.GossipAddress = "127.0.0.1:9021"
+	cfg3.GossipSeedAddresses = []string{"127.0.0.1:9001", "127.0.0.1:9011", "127.0.0.1:9031"}
+	cfg3.DisableWorkers = true
 	cfg3.HAKeeperConfig.TickPerSecond = 10
 	cfg3.HAKeeperConfig.LogStoreTimeout.Duration = 5 * time.Second
 	cfg3.HAKeeperConfig.DNStoreTimeout.Duration = 10 * time.Second
 	cfg3.HAKeeperConfig.CNStoreTimeout.Duration = 5 * time.Second
-	cfg4 := Config{
-		UUID:                uuid.New().String(),
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-4",
-		ServiceAddress:      "127.0.0.1:9032",
-		RaftAddress:         "127.0.0.1:9030",
-		GossipAddress:       "127.0.0.1:9031",
-		GossipSeedAddresses: []string{"127.0.0.1:9001", "127.0.0.1:9011", "127.0.0.1:9021"},
-		DisableWorkers:      true,
-	}
+	cfg3.Fill()
+	cfg4 := DefaultConfig()
+	cfg4.UUID = uuid.New().String()
+	cfg4.FS = vfs.NewStrictMem()
+	cfg4.DeploymentID = 1
+	cfg4.RTTMillisecond = 5
+	cfg4.DataDir = "data-4"
+	cfg4.ServiceAddress = "127.0.0.1:9032"
+	cfg4.RaftAddress = "127.0.0.1:9030"
+	cfg4.GossipAddress = "127.0.0.1:9031"
+	cfg4.GossipSeedAddresses = []string{"127.0.0.1:9001", "127.0.0.1:9011", "127.0.0.1:9021"}
+	cfg4.DisableWorkers = true
 	cfg4.HAKeeperConfig.TickPerSecond = 10
 	cfg4.HAKeeperConfig.LogStoreTimeout.Duration = 5 * time.Second
 	cfg4.HAKeeperConfig.DNStoreTimeout.Duration = 10 * time.Second
 	cfg4.HAKeeperConfig.CNStoreTimeout.Duration = 5 * time.Second
-	cfg1.Fill()
+	cfg4.Fill()
 	service1, err := NewService(cfg1,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
@@ -233,7 +232,6 @@ func runHAKeeperClusterTest(t *testing.T, fn func(*testing.T, []*Service)) {
 	defer func() {
 		assert.NoError(t, service1.Close())
 	}()
-	cfg2.Fill()
 	service2, err := NewService(cfg2,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
@@ -244,7 +242,6 @@ func runHAKeeperClusterTest(t *testing.T, fn func(*testing.T, []*Service)) {
 	defer func() {
 		assert.NoError(t, service2.Close())
 	}()
-	cfg3.Fill()
 	service3, err := NewService(cfg3,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
@@ -255,7 +252,6 @@ func runHAKeeperClusterTest(t *testing.T, fn func(*testing.T, []*Service)) {
 	defer func() {
 		assert.NoError(t, service3.Close())
 	}()
-	cfg4.Fill()
 	service4, err := NewService(cfg4,
 		newFS(),
 		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
diff --git a/pkg/logservice/store_metadata_test.go b/pkg/logservice/store_metadata_test.go
index b03b1f0ad..d32e45d0b 100644
--- a/pkg/logservice/store_metadata_test.go
+++ b/pkg/logservice/store_metadata_test.go
@@ -30,7 +30,6 @@ import (
 func TestHasMetadataRec(t *testing.T) {
 	cfg := getStoreTestConfig()
 	defer vfs.ReportLeakedFD(cfg.FS, t)
-	cfg.Fill()
 	s := store{cfg: cfg}
 	s.addMetadata(10, 1)
 	has, err := hasMetadataRec(s.cfg.DataDir, logMetadataFilename, 10, 1, s.cfg.FS)
@@ -44,7 +43,6 @@ func TestHasMetadataRec(t *testing.T) {
 func TestAddMetadata(t *testing.T) {
 	cfg := getStoreTestConfig()
 	defer vfs.ReportLeakedFD(cfg.FS, t)
-	cfg.Fill()
 	s := store{cfg: cfg}
 	require.NoError(t, mkdirAll(s.cfg.DataDir, cfg.FS))
 	s.addMetadata(10, 1)
@@ -59,7 +57,6 @@ func TestAddMetadata(t *testing.T) {
 func TestAddMetadataRejectDupl(t *testing.T) {
 	cfg := getStoreTestConfig()
 	defer vfs.ReportLeakedFD(cfg.FS, t)
-	cfg.Fill()
 	s := store{cfg: cfg, runtime: runtime.DefaultRuntime()}
 	require.NoError(t, mkdirAll(s.cfg.DataDir, cfg.FS))
 	s.addMetadata(10, 1)
@@ -71,7 +68,6 @@ func TestAddMetadataRejectDupl(t *testing.T) {
 func TestRemoveMetadata(t *testing.T) {
 	cfg := getStoreTestConfig()
 	defer vfs.ReportLeakedFD(cfg.FS, t)
-	cfg.Fill()
 	s := store{cfg: cfg, runtime: runtime.DefaultRuntime()}
 	require.NoError(t, mkdirAll(s.cfg.DataDir, cfg.FS))
 	s.addMetadata(10, 1)
@@ -88,7 +84,6 @@ func TestRemoveMetadata(t *testing.T) {
 func TestStartReplicas(t *testing.T) {
 	cfg := getStoreTestConfig()
 	defer vfs.ReportLeakedFD(cfg.FS, t)
-	cfg.Fill()
 	require.NoError(t, mkdirAll(cfg.DataDir, cfg.FS))
 	func() {
 		store, err := getTestStore(cfg, false, nil)
diff --git a/pkg/logservice/store_test.go b/pkg/logservice/store_test.go
index 975f36713..532ec48cf 100644
--- a/pkg/logservice/store_test.go
+++ b/pkg/logservice/store_test.go
@@ -53,11 +53,10 @@ var (
 )
 
 func TestNodeHostConfig(t *testing.T) {
-	cfg := Config{
-		DeploymentID: 1234,
-		DataDir:      "lalala",
-	}
+	cfg := DefaultConfig()
 	cfg.Fill()
+	cfg.DeploymentID = 1234
+	cfg.DataDir = "lalala"
 	nhConfig := getNodeHostConfig(cfg)
 	assert.Equal(t, cfg.DeploymentID, nhConfig.DeploymentID)
 	assert.Equal(t, cfg.DataDir, nhConfig.NodeHostDir)
@@ -71,15 +70,16 @@ func TestRaftConfig(t *testing.T) {
 }
 
 func getStoreTestConfig() Config {
-	cfg := Config{
-		UUID:                uuid.New().String(),
-		RTTMillisecond:      10,
-		GossipAddress:       testGossipAddress,
-		GossipSeedAddresses: []string{testGossipAddress, dummyGossipSeedAddress},
-		DeploymentID:        1,
-		FS:                  vfs.NewStrictMem(),
-		UseTeeLogDB:         true,
-	}
+	cfg := DefaultConfig()
+	cfg.UUID = uuid.New().String()
+	cfg.RTTMillisecond = 10
+	cfg.GossipAddress = testGossipAddress
+	cfg.GossipAddressV2 = testGossipAddress
+	cfg.GossipListenAddress = testGossipAddress
+	cfg.GossipSeedAddresses = []string{testGossipAddress, dummyGossipSeedAddress}
+	cfg.DeploymentID = 1
+	cfg.FS = vfs.NewStrictMem()
+	cfg.UseTeeLogDB = true
 	cfg.Fill()
 	return cfg
 }
@@ -524,31 +524,31 @@ func TestAddReplica(t *testing.T) {
 }
 
 func getTestStores() (*store, *store, error) {
-	cfg1 := Config{
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-1",
-		ServiceAddress:      "127.0.0.1:9001",
-		RaftAddress:         "127.0.0.1:9002",
-		GossipAddress:       "127.0.0.1:9011",
-		GossipSeedAddresses: []string{"127.0.0.1:9011", "127.0.0.1:9012"},
-	}
+	cfg1 := DefaultConfig()
+	cfg1.UUID = uuid.NewString()
+	cfg1.FS = vfs.NewStrictMem()
+	cfg1.DeploymentID = 1
+	cfg1.RTTMillisecond = 5
+	cfg1.DataDir = "data-1"
+	cfg1.ServiceAddress = "127.0.0.1:9001"
+	cfg1.RaftAddress = "127.0.0.1:9002"
+	cfg1.GossipAddress = "127.0.0.1:9011"
+	cfg1.GossipSeedAddresses = []string{"127.0.0.1:9011", "127.0.0.1:9012"}
 	cfg1.Fill()
 	store1, err := newLogStore(cfg1, nil, runtime.DefaultRuntime())
 	if err != nil {
 		return nil, nil, err
 	}
-	cfg2 := Config{
-		FS:                  vfs.NewStrictMem(),
-		DeploymentID:        1,
-		RTTMillisecond:      5,
-		DataDir:             "data-1",
-		ServiceAddress:      "127.0.0.1:9006",
-		RaftAddress:         "127.0.0.1:9007",
-		GossipAddress:       "127.0.0.1:9012",
-		GossipSeedAddresses: []string{"127.0.0.1:9011", "127.0.0.1:9012"},
-	}
+	cfg2 := DefaultConfig()
+	cfg2.UUID = uuid.NewString()
+	cfg2.FS = vfs.NewStrictMem()
+	cfg2.DeploymentID = 1
+	cfg2.RTTMillisecond = 5
+	cfg2.DataDir = "data-1"
+	cfg2.ServiceAddress = "127.0.0.1:9006"
+	cfg2.RaftAddress = "127.0.0.1:9007"
+	cfg2.GossipAddress = "127.0.0.1:9012"
+	cfg2.GossipSeedAddresses = []string{"127.0.0.1:9011", "127.0.0.1:9012"}
 	cfg2.Fill()
 	store2, err := newLogStore(cfg2, nil, runtime.DefaultRuntime())
 	if err != nil {
diff --git a/pkg/logservice/testclient.go b/pkg/logservice/testclient.go
index 7e6531d00..c6ca70c73 100644
--- a/pkg/logservice/testclient.go
+++ b/pkg/logservice/testclient.go
@@ -25,16 +25,15 @@ import (
 
 func NewTestService(fs vfs.FS) (*Service, ClientConfig, error) {
 	addr := []string{"localhost:9000"}
-	cfg := Config{
-		UUID:                 uuid.New().String(),
-		RTTMillisecond:       10,
-		GossipSeedAddresses:  []string{defaultGossipSeedAddress},
-		DeploymentID:         1,
-		FS:                   fs,
-		ServiceListenAddress: addr[0],
-		ServiceAddress:       addr[0],
-		DisableWorkers:       true,
-	}
+	cfg := DefaultConfig()
+	cfg.UUID = uuid.New().String()
+	cfg.RTTMillisecond = 10
+	cfg.GossipSeedAddresses = []string{defaultGossipSeedAddress}
+	cfg.DeploymentID = 1
+	cfg.FS = fs
+	cfg.ServiceListenAddress = addr[0]
+	cfg.ServiceAddress = addr[0]
+	cfg.DisableWorkers = true
 	cfg.Fill()
 	service, err := NewService(cfg,
 		newFS(),