Repository: matrixorigin/matrixone
Pull request #4653 (2022-08-24 05:56:12)

logservice: added UseTeeLogDB option
## 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:

Added a new UseTeeLogDB option to Log Service config. This allows selected tests to enable tee based LogDB for testing while making sure that it is not used in standalone mode testing. 


Patch:
diff --git a/pkg/logservice/config.go b/pkg/logservice/config.go
index 38d502ddd..7a571bc29 100644
--- a/pkg/logservice/config.go
+++ b/pkg/logservice/config.go
@@ -71,6 +71,10 @@ type Config struct {
 	RaftAddress string `toml:"raft-address"`
 	// RaftListenAddress is the local listen address of the RaftAddress.
 	RaftListenAddress string `toml:"raft-listen-address"`
+	// UseTeeLogDB enables the log service to use tee based LogDB which is backed
+	// by both a pebble and a tan based LogDB. This field should only be set to
+	// true during testing.
+	UseTeeLogDB bool `toml:"use-tee-logdb"`
 	// LogDBBufferSize is the size of the logdb buffer in bytes.
 	LogDBBufferSize uint64 `toml:"logdb-buffer-size"`
 	// GossipAddress is the address used for accepting gossip communication.
diff --git a/pkg/logservice/store.go b/pkg/logservice/store.go
index 781e7e371..8242ea621 100644
--- a/pkg/logservice/store.go
+++ b/pkg/logservice/store.go
@@ -24,6 +24,7 @@ import (
 	"github.com/lni/dragonboat/v4"
 	cli "github.com/lni/dragonboat/v4/client"
 	"github.com/lni/dragonboat/v4/config"
+	"github.com/lni/dragonboat/v4/plugin/tan"
 	"github.com/lni/dragonboat/v4/plugin/tee"
 	"github.com/lni/dragonboat/v4/raftpb"
 	sm "github.com/lni/dragonboat/v4/statemachine"
@@ -74,6 +75,12 @@ func getNodeHostConfig(cfg Config) config.NodeHostConfig {
 	}
 	logdb := config.GetTinyMemLogDBConfig()
 	logdb.KVWriteBufferSize = cfg.LogDBBufferSize
+	logdbFactory := (config.LogDBFactory)(nil)
+	logdbFactory = tan.Factory
+	if cfg.UseTeeLogDB {
+		plog.Warningf("using tee based logdb backed by pebble and tan, for testing purposes only")
+		logdbFactory = tee.TanPebbleLogDBFactory
+	}
 	return config.NodeHostConfig{
 		DeploymentID:        cfg.DeploymentID,
 		NodeHostID:          cfg.UUID,
@@ -84,7 +91,7 @@ func getNodeHostConfig(cfg Config) config.NodeHostConfig {
 		ListenAddress:       cfg.RaftListenAddress,
 		Expert: config.ExpertConfig{
 			FS:           cfg.FS,
-			LogDBFactory: tee.TanPebbleLogDBFactory,
+			LogDBFactory: logdbFactory,
 			// FIXME: dragonboat need to be updated to make this field a first class
 			// citizen
 			TestGossipProbeInterval: cfg.GossipProbeInterval.Duration,


Test patch:
diff --git a/pkg/logservice/service_test.go b/pkg/logservice/service_test.go
index c85255249..3be861072 100644
--- a/pkg/logservice/service_test.go
+++ b/pkg/logservice/service_test.go
@@ -47,6 +47,7 @@ func getServiceTestConfig() Config {
 		ServiceListenAddress: testServiceAddress,
 		ServiceAddress:       testServiceAddress,
 		DisableWorkers:       true,
+		UseTeeLogDB:          true,
 	}
 	c.Fill()
 	return c
diff --git a/pkg/logservice/store_test.go b/pkg/logservice/store_test.go
index 9100d59c3..a180c5695 100644
--- a/pkg/logservice/store_test.go
+++ b/pkg/logservice/store_test.go
@@ -62,6 +62,7 @@ func getStoreTestConfig() Config {
 		GossipSeedAddresses: []string{"127.0.0.1:9000"},
 		DeploymentID:        1,
 		FS:                  vfs.NewStrictMem(),
+		UseTeeLogDB:         true,
 	}
 	cfg.Fill()
 	return cfg