@@ -24,17 +24,10 @@ type Tablet struct {
24
24
25
25
// HasValidCell returns a bool reflecting if a tablet is in a valid Vitess cell
26
26
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 {
35
28
return true
36
29
}
37
- for _ , cell := range cells {
30
+ for _ , cell := range validCells {
38
31
if t .Alias .GetCell () == cell {
39
32
return true
40
33
}
@@ -61,10 +54,22 @@ func constructAPIURL(settings config.VitessConfigurationSettings) (url string) {
61
54
return url
62
55
}
63
56
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
+
64
68
// filterReplicaTablets parses a list of tablets, returning replica tablets only
65
69
func filterReplicaTablets (settings config.VitessConfigurationSettings , tablets []Tablet ) (replicas []Tablet ) {
70
+ validCells := ParseCells (settings )
66
71
for _ , tablet := range tablets {
67
- if tablet .HasValidCell (settings . Cells ) && tablet .IsValidReplica () {
72
+ if tablet .HasValidCell (validCells ) && tablet .IsValidReplica () {
68
73
replicas = append (replicas , tablet )
69
74
}
70
75
}
0 commit comments