Skip to content

Commit 977db88

Browse files
Support many cells
1 parent cfbcea7 commit 977db88

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

pkg/config/mysql_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type MySQLConfigurationSettings struct {
5858
HttpCheckPort int // port for HTTP check. -1 to disable.
5959
HttpCheckPath string // If non-empty, requires HttpCheckPort
6060
IgnoreHosts []string // If non empty, substrings to indicate hosts to be ignored/skipped
61-
VitessCell string // Name of the Vitess cell for polling tablet hosts
61+
VitessCells []string // Name of the Vitess cells for polling tablet hosts
6262

6363
Clusters map[string](*MySQLClusterConfigurationSettings) // cluster name -> cluster config
6464
}
@@ -115,8 +115,8 @@ func (settings *MySQLConfigurationSettings) postReadAdjustments() error {
115115
if len(clusterSettings.IgnoreHosts) == 0 {
116116
clusterSettings.IgnoreHosts = settings.IgnoreHosts
117117
}
118-
if !clusterSettings.VitessSettings.IsEmpty() && clusterSettings.VitessSettings.Cell == "" {
119-
clusterSettings.VitessSettings.Cell = settings.VitessCell
118+
if !clusterSettings.VitessSettings.IsEmpty() && len(clusterSettings.VitessSettings.Cells) < 1 {
119+
clusterSettings.VitessSettings.Cells = settings.VitessCells
120120
}
121121
}
122122
return nil

pkg/config/vitess_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package config
66

77
type VitessConfigurationSettings struct {
88
API string
9-
Cell string
9+
Cells []string
1010
Keyspace string
1111
Shard string
1212
TimeoutSecs uint

pkg/vitess/api_client.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ type Tablet struct {
2222
Type topodata.TabletType `json:"type,omitempty"`
2323
}
2424

25+
// IsValidCell returns a bool reflecting if a tablet type is in a valid cell
26+
func (t Tablet) HasValidCell(validCells []string) bool {
27+
if len(validCells) == 0 {
28+
return true
29+
}
30+
for _, cell := range validCells {
31+
if t.Alias.GetCell() == strings.TrimSpace(cell) {
32+
return true
33+
}
34+
}
35+
return false
36+
}
37+
2538
// IsValidReplica returns a bool reflecting if a tablet type is REPLICA
2639
func (t Tablet) IsValidReplica() bool {
2740
return t.Type == topodata.TabletType_REPLICA
@@ -44,11 +57,7 @@ func constructAPIURL(settings config.VitessConfigurationSettings) (url string) {
4457
// filterReplicaTablets parses a list of tablets, returning replica tablets only
4558
func filterReplicaTablets(settings config.VitessConfigurationSettings, tablets []Tablet) (replicas []Tablet) {
4659
for _, tablet := range tablets {
47-
expectedCell := strings.TrimSpace(settings.Cell)
48-
if expectedCell != "" && tablet.Alias.GetCell() != expectedCell {
49-
continue
50-
}
51-
if tablet.IsValidReplica() {
60+
if tablet.HasValidCell(settings.Cells) && tablet.IsValidReplica() {
5261
replicas = append(replicas, tablet)
5362
}
5463
}

pkg/vitess/api_client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestParseTablets(t *testing.T) {
9191
t.Run("with-cell", func(t *testing.T) {
9292
tablets, err := ParseTablets(config.VitessConfigurationSettings{
9393
API: vitessApi.URL,
94-
Cell: "cell2",
94+
Cells: []string{"cell2"},
9595
Keyspace: "test",
9696
Shard: "00",
9797
})
@@ -109,7 +109,6 @@ func TestParseTablets(t *testing.T) {
109109
if tablets[0].Alias.Cell != "cell2" {
110110
t.Fatalf("Expected vitess cell %s, got %s", "cell2", tablets[0].Alias.Cell)
111111
}
112-
113112
})
114113

115114
t.Run("not-found", func(t *testing.T) {

0 commit comments

Comments
 (0)