Repository: matrixorigin/matrixone
Pull request #4224 (2022-07-26 15:53:15)

logservice: fixed some issues that prevented logservice from starting
**What type of PR is this?**

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

**Which issue(s) this PR fixes:**

issue #

**What this PR does / why we need it:**

fixed some issues that prevented logservice from starting

**Special notes for your reviewer:**

Not Available

**Additional documentation (e.g. design docs, usage docs, etc.):**

Not Available



Patch:
diff --git a/.gitignore b/.gitignore
index 9b4220b18..3eaa74340 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,8 +16,10 @@ vendor/
 gen_config
 main
 mo-server
+mo-service
 cube*/
 store/
+mo-data/
 pkg/catalog/test/
 pkg/config/system_vars.go
 pkg/config/system_vars_test.go
diff --git a/go.mod b/go.mod
index b55b37fab..5e1c4a2f7 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
 	github.com/google/btree v1.0.1
 	github.com/google/gofuzz v1.2.0
 	github.com/google/uuid v1.3.0
-	github.com/lni/dragonboat/v4 v4.0.0-20220724134658-ed44d312daa2
+	github.com/lni/dragonboat/v4 v4.0.0-20220726132939-e3950119af4e
 	github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4
 	github.com/matrixorigin/matrixcube v0.3.1-0.20220606032431-c944d801f1e5
 	github.com/matrixorigin/simdcsv v0.0.0-20210926114300-591bf748a770
diff --git a/go.sum b/go.sum
index 0c0d3e2c9..2a935831f 100644
--- a/go.sum
+++ b/go.sum
@@ -380,8 +380,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
 github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y=
 github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
-github.com/lni/dragonboat/v4 v4.0.0-20220724134658-ed44d312daa2 h1:cPICPrExab17TUc6v40REOfhLh7L/LKlV380+bZTEyE=
-github.com/lni/dragonboat/v4 v4.0.0-20220724134658-ed44d312daa2/go.mod h1:bR6ZGoUwApH4/P4+AezNGT0xehljg+j+Z/Q2Fz+Y4a0=
+github.com/lni/dragonboat/v4 v4.0.0-20220726132939-e3950119af4e h1:NuxzjkmVkxO/ImCRKW9GmWxKA49NVKbN/adVVPG6Nr0=
+github.com/lni/dragonboat/v4 v4.0.0-20220726132939-e3950119af4e/go.mod h1:bR6ZGoUwApH4/P4+AezNGT0xehljg+j+Z/Q2Fz+Y4a0=
 github.com/lni/goutils v1.3.0/go.mod h1:PUPtBAnZlRPUKWUXCsYkIRWubJbtNHpTAee0sczhlf4=
 github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4 h1:6gzI38ZJmbzZ7oZebXz6jII0uVK+MZ3+ds+7mIt1ioI=
 github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4/go.mod h1:LIHvF0fflR+zyXUQFQOiHPpKANf3UIr7DFIv5CBPOoU=
diff --git a/pkg/logservice/commands.go b/pkg/logservice/commands.go
index fad35a2fb..1b76b4b11 100644
--- a/pkg/logservice/commands.go
+++ b/pkg/logservice/commands.go
@@ -137,10 +137,6 @@ func (s *Service) heartbeat(ctx context.Context) {
 	cb, err := s.haClient.SendLogHeartbeat(ctx2, hb)
 	if err != nil {
 		plog.Errorf("failed to send log service heartbeat, %v", err)
-		if err := s.haClient.Close(); err != nil {
-			plog.Errorf("failed to close hakeeper client %v", err)
-		}
-		s.haClient = nil
 		return
 	}
 	s.handleCommands(cb.Commands)
diff --git a/pkg/logservice/config.go b/pkg/logservice/config.go
index 220104b1a..4bf9867c7 100644
--- a/pkg/logservice/config.go
+++ b/pkg/logservice/config.go
@@ -180,6 +180,9 @@ func (c *Config) Validate() error {
 }
 
 func (c *Config) Fill() {
+	if c.FS == nil {
+		c.FS = vfs.Default
+	}
 	if c.HeartbeatInterval.Duration == 0 {
 		c.HeartbeatInterval.Duration = defaultHeartbeatInterval
 	}
@@ -228,7 +231,10 @@ func splitAddresses(v string) []string {
 	results := make([]string, 0)
 	parts := strings.Split(v, ";")
 	for _, v := range parts {
-		results = append(results, strings.TrimSpace(v))
+		t := strings.TrimSpace(v)
+		if len(t) > 0 {
+			results = append(results, t)
+		}
 	}
 	return results
 }
diff --git a/pkg/logservice/service.go b/pkg/logservice/service.go
index 4422a64aa..ece5bcbfa 100644
--- a/pkg/logservice/service.go
+++ b/pkg/logservice/service.go
@@ -67,10 +67,10 @@ type Service struct {
 }
 
 func NewService(cfg Config) (*Service, error) {
+	cfg.Fill()
 	if err := cfg.Validate(); err != nil {
 		return nil, err
 	}
-	cfg.Fill()
 	store, err := newLogStore(cfg)
 	if err != nil {
 		plog.Errorf("failed to create log store %v", err)


Test patch:
diff --git a/etc/log-minimal-test.toml b/etc/log-minimal-test.toml
new file mode 100644
index 000000000..bc041eca4
--- /dev/null
+++ b/etc/log-minimal-test.toml
@@ -0,0 +1,12 @@
+# service node type, [DN|CN|LOG]
+service-type = "LOG"
+
+[log]
+level = "debug"
+format = "json"
+max-size = 512
+
+[logservice]
+deployment-id = 1
+uuid = "9c4dccb4-4d3c-41f8-b482-5251dc7a41bf"
+gossip-seed-addresses = "127.0.0.1:32002"
diff --git a/pkg/logservice/config_test.go b/pkg/logservice/config_test.go
index e6fe43301..5a16cb01a 100644
--- a/pkg/logservice/config_test.go
+++ b/pkg/logservice/config_test.go
@@ -40,6 +40,28 @@ func getTestConfig() Config {
 	return c
 }
 
+func TestSplitAddress(t *testing.T) {
+	tests := []struct {
+		input  string
+		output []string
+	}{
+		{"", []string{}},
+		{" ; ", []string{}},
+		{" ;; ", []string{}},
+		{";", []string{}},
+		{"localhost:1000;localhost:1001", []string{"localhost:1000", "localhost:1001"}},
+		{" localhost:1000 ; localhost:1001\t\n", []string{"localhost:1000", "localhost:1001"}},
+		{"localhost:1000 \n", []string{"localhost:1000"}},
+		{"localhost:1000;", []string{"localhost:1000"}},
+		{";localhost:1000", []string{"localhost:1000"}},
+	}
+
+	for _, tt := range tests {
+		v := splitAddresses(tt.input)
+		assert.Equal(t, tt.output, v)
+	}
+}
+
 func TestGetGossipSeedAddresses(t *testing.T) {
 	cfg := Config{
 		GossipSeedAddresses: "localhost:9000;localhost:9001 ; localhost:9002 ",