Skip to content

Commit acea623

Browse files
Add func for parsing cell names
1 parent fb0040a commit acea623

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pkg/throttle/throttler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func (throttler *Throttler) refreshMySQLInventory() error {
328328
return log.Errorf("Unable to get vitess hosts from %s, %s/%s: %+v", clusterSettings.VitessSettings.API, keyspace, shard, err)
329329
}
330330
log.Debugf("Read %+v hosts from vitess %s, %s/%s, cells=%s", len(tablets), clusterSettings.VitessSettings.API,
331-
keyspace, shard, strings.Join(clusterSettings.VitessSettings.Cells, ","),
331+
keyspace, shard, strings.Join(vitess.ParseCells(clusterSettings.VitessSettings), ","),
332332
)
333333
clusterProbes := &mysql.ClusterProbes{
334334
ClusterName: clusterName,

pkg/vitess/api_client.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ type Tablet struct {
2424

2525
// HasValidCell returns a bool reflecting if a tablet is in a valid Vitess cell
2626
func (t Tablet) HasValidCell(validCells []string) bool {
27-
cells := make([]string, 0)
28-
for _, cell := range validCells {
29-
cell = strings.TrimSpace(cell)
30-
if cell != "" {
31-
cells = append(cells, cell)
32-
}
33-
}
34-
if len(cells) == 0 {
27+
if len(validCells) == 0 {
3528
return true
3629
}
37-
for _, cell := range cells {
30+
for _, cell := range validCells {
3831
if t.Alias.GetCell() == cell {
3932
return true
4033
}
@@ -61,10 +54,22 @@ func constructAPIURL(settings config.VitessConfigurationSettings) (url string) {
6154
return url
6255
}
6356

57+
// ParseCells returns a slice of non-empty Vitess cell names
58+
func ParseCells(settings config.VitessConfigurationSettings) (cells []string) {
59+
for _, cell := range settings.Cells {
60+
cell = strings.TrimSpace(cell)
61+
if cell != "" {
62+
cells = append(cells, cell)
63+
}
64+
}
65+
return cells
66+
}
67+
6468
// filterReplicaTablets parses a list of tablets, returning replica tablets only
6569
func filterReplicaTablets(settings config.VitessConfigurationSettings, tablets []Tablet) (replicas []Tablet) {
70+
validCells := ParseCells(settings)
6671
for _, tablet := range tablets {
67-
if tablet.HasValidCell(settings.Cells) && tablet.IsValidReplica() {
72+
if tablet.HasValidCell(validCells) && tablet.IsValidReplica() {
6873
replicas = append(replicas, tablet)
6974
}
7075
}

0 commit comments

Comments
 (0)