Skip to content

Commit

Permalink
fix: correctly display the disk mount points of tiflash
Browse files Browse the repository at this point in the history
Signed-off-by: mornyx <[email protected]>
  • Loading branch information
mornyx committed Feb 28, 2024
1 parent b7e594c commit 1a8677b
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions pkg/apiserver/clusterinfo/hostinfo/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package hostinfo

import (
"encoding/json"
"strings"

"gorm.io/gorm"
Expand All @@ -24,7 +25,9 @@ func FillInstances(db *gorm.DB, m InfoMap) error {
Where("(`TYPE` = 'tidb' AND `KEY` = 'log.file.filename') " +
"OR (`TYPE` = 'tikv' AND `KEY` = 'storage.data-dir') " +
"OR (`TYPE` = 'pd' AND `KEY` = 'data-dir') " +
"OR (`TYPE` = 'tiflash' AND `KEY` = 'engine-store.path')").
"OR (`TYPE` = 'tiflash' AND (`KEY` = 'engine-store.path' " +
" OR `KEY` = 'engine-store.storage.main.dir' " +
" OR `KEY` = 'engine-store.storage.latest.dir'))").

Check warning on line 30 in pkg/apiserver/clusterinfo/hostinfo/cluster_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/hostinfo/cluster_config.go#L28-L30

Added lines #L28 - L30 were not covered by tests
Find(&rows).Error; err != nil {
return err
}
Expand All @@ -37,9 +40,44 @@ func FillInstances(db *gorm.DB, m InfoMap) error {
if _, ok := m[hostname]; !ok {
m[hostname] = NewHostInfo(hostname)
}
m[hostname].Instances[row.Instance] = &InstanceInfo{
Type: row.Type,
PartitionPathL: strings.ToLower(locateInstanceMountPartition(row.Value, m[hostname].Partitions)),
switch row.Type {
case "tiflash":
if ins, ok := m[hostname].Instances[row.Instance]; ok {
if ins.Type == row.Type && ins.PartitionPathL != "" {
continue

Check warning on line 47 in pkg/apiserver/clusterinfo/hostinfo/cluster_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/hostinfo/cluster_config.go#L43-L47

Added lines #L43 - L47 were not covered by tests
}
} else {
m[hostname].Instances[row.Instance] = &InstanceInfo{
Type: row.Type,
PartitionPathL: "",
}
}
var paths []string
switch row.Key {
case "engine-store.path":
items := strings.Split(row.Value, ",")
for _, path := range items {
paths = append(paths, strings.TrimSpace(path))
}
case "engine-store.storage.main.dir", "engine-store.storage.latest.dir":
if err := json.Unmarshal([]byte(row.Value), &paths); err != nil {
return err
}
default:
paths = []string{row.Value}

Check warning on line 67 in pkg/apiserver/clusterinfo/hostinfo/cluster_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/hostinfo/cluster_config.go#L49-L67

Added lines #L49 - L67 were not covered by tests
}
for _, path := range paths {
mountDir := locateInstanceMountPartition(path, m[hostname].Partitions)
if mountDir != "" {
m[hostname].Instances[row.Instance].PartitionPathL = strings.ToLower(mountDir)
break

Check warning on line 73 in pkg/apiserver/clusterinfo/hostinfo/cluster_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/hostinfo/cluster_config.go#L69-L73

Added lines #L69 - L73 were not covered by tests
}
}
default:
m[hostname].Instances[row.Instance] = &InstanceInfo{
Type: row.Type,
PartitionPathL: strings.ToLower(locateInstanceMountPartition(row.Value, m[hostname].Partitions)),
}

Check warning on line 80 in pkg/apiserver/clusterinfo/hostinfo/cluster_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/clusterinfo/hostinfo/cluster_config.go#L76-L80

Added lines #L76 - L80 were not covered by tests
}
}
return nil
Expand Down

0 comments on commit 1a8677b

Please sign in to comment.