From 4d4316eda485f01a5f5bce3d8d6716cc592c617a Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 22 Apr 2020 14:38:05 +0200 Subject: [PATCH 01/10] Gather REPLICA tablet types from Vitess only --- go.mod | 1 + go.sum | 4 ++++ pkg/throttle/throttler.go | 5 +++-- pkg/vitess/api_client.go | 24 +++++++++++++++++++++--- pkg/vitess/api_client_test.go | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 pkg/vitess/api_client_test.go diff --git a/go.mod b/go.mod index caafb965..3180f9ee 100644 --- a/go.mod +++ b/go.mod @@ -13,4 +13,5 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed // indirect + vitess.io/vitess v2.1.1+incompatible ) diff --git a/go.sum b/go.sum index 8aff1424..adbaa17f 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= @@ -45,6 +46,9 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cjyFjutgw/Vhan2zLy/A= golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +vitess.io/vitess v2.1.1+incompatible h1:nuuGHiWYWpudD3gOCLeGzol2EJ25e/u5Wer2wV1O130= +vitess.io/vitess v2.1.1+incompatible/go.mod h1:h4qvkyNYTOC0xI+vcidSWoka0gQAZc9ZPHbkHo48gP0= diff --git a/pkg/throttle/throttler.go b/pkg/throttle/throttler.go index ec95ab08..f1670a2f 100644 --- a/pkg/throttle/throttler.go +++ b/pkg/throttle/throttler.go @@ -327,13 +327,14 @@ func (throttler *Throttler) refreshMySQLInventory() error { if err != nil { return log.Errorf("Unable to get vitess hosts from %s, %s/%s: %+v", clusterSettings.VitessSettings.API, keyspace, shard, err) } - log.Debugf("Read %+v hosts from vitess %s, %s/%s", len(tablets), clusterSettings.VitessSettings.API, keyspace, shard) + replicas := vitess.FilterReplicaTablets(tablets) + log.Debugf("Read %+v replica hosts from vitess %s, %s/%s", len(replicas), clusterSettings.VitessSettings.API, keyspace, shard) clusterProbes := &mysql.ClusterProbes{ ClusterName: clusterName, IgnoreHostsCount: clusterSettings.IgnoreHostsCount, InstanceProbes: mysql.NewProbes(), } - for _, tablet := range tablets { + for _, tablet := range replicas { key := mysql.InstanceKey{Hostname: tablet.MysqlHostname, Port: int(tablet.MysqlPort)} addInstanceKey(&key, clusterName, clusterSettings, clusterProbes.InstanceProbes) } diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 49eaa207..aed7aa51 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -7,12 +7,15 @@ import ( "net/http" "strings" "time" + + "vitess.io/vitess/go/vt/proto/topodata" ) // Tablet represents information about a running instance of vttablet. type Tablet struct { - MysqlHostname string `json:"mysql_hostname,omitempty"` - MysqlPort int32 `json:"mysql_port,omitempty"` + MysqlHostname string `json:"mysql_hostname,omitempty"` + MysqlPort int32 `json:"mysql_port,omitempty"` + Type topodata.TabletType `json:"type,omitempty"` } var httpClient = http.Client{ @@ -30,7 +33,7 @@ func constructAPIURL(api string, keyspace string, shard string) (url string) { } // ParseTablets reads from vitess /api/ks_tablets//[shard] and returns a -// tblet (mysql_hostname, mysql_port) listing +// tablet (mysql_hostname, mysql_port) listing func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) { url := constructAPIURL(api, keyspace, shard) resp, err := httpClient.Get(url) @@ -47,3 +50,18 @@ func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err = json.Unmarshal(body, &tablets) return tablets, err } + +func isReplicaTablet(tablet Tablet) bool { + return tablet.Type == topodata.TabletType_REPLICA +} + +// FilterReplicaTablets parses a list of tablets, returning replica tablets only +func FilterReplicaTablets(tablets []Tablet) []Tablet { + replicas := make([]Tablet, 0) + for _, tablet := range tablets { + if isReplicaTablet(tablet) { + replicas = append(replicas, tablet) + } + } + return replicas +} diff --git a/pkg/vitess/api_client_test.go b/pkg/vitess/api_client_test.go new file mode 100644 index 00000000..40a02619 --- /dev/null +++ b/pkg/vitess/api_client_test.go @@ -0,0 +1,35 @@ +package vitess + +import ( + "testing" + + "vitess.io/vitess/go/vt/proto/topodata" +) + +func TestFilterReplicaTablets(t *testing.T) { + replicas := FilterReplicaTablets([]Tablet{ + { + MysqlHostname: t.Name() + "1", + Type: topodata.TabletType_MASTER, + }, + { + MysqlHostname: t.Name() + "2", // this node is valid + Type: topodata.TabletType_REPLICA, + }, + { + MysqlHostname: t.Name() + "3", + Type: topodata.TabletType_BACKUP, + }, + { + + MysqlHostname: t.Name() + "4", + Type: topodata.TabletType_RESTORE, + }, + }) + if len(replicas) != 1 { + t.Fatalf("Expected 1 replica, got %v", replicas) + } + if replicas[0].MysqlHostname != t.Name()+"2" { + t.Fatalf("Expected hostname %q, got %q", t.Name()+"2", replicas[0].MysqlHostname) + } +} From 7b41a7fcc91005a107ddd4695c924273022783ac Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 22 Apr 2020 20:16:12 +0200 Subject: [PATCH 02/10] Make IsReplica() struct func --- pkg/vitess/api_client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index aed7aa51..9d0ae739 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -18,6 +18,11 @@ type Tablet struct { Type topodata.TabletType `json:"type,omitempty"` } +// IsReplica returns a bool reflecting if a tablet type is REPLICA +func (t Tablet) IsReplica() bool { + return t.Type == topodata.TabletType_REPLICA +} + var httpClient = http.Client{ Timeout: 1 * time.Second, } @@ -51,15 +56,11 @@ func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, return tablets, err } -func isReplicaTablet(tablet Tablet) bool { - return tablet.Type == topodata.TabletType_REPLICA -} - // FilterReplicaTablets parses a list of tablets, returning replica tablets only func FilterReplicaTablets(tablets []Tablet) []Tablet { replicas := make([]Tablet, 0) for _, tablet := range tablets { - if isReplicaTablet(tablet) { + if tablet.IsReplica() { replicas = append(replicas, tablet) } } From 41485088e696c5cac710e8979b9c303d31c3693e Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 22 Apr 2020 20:18:39 +0200 Subject: [PATCH 03/10] IsReplica() -> isReplica() --- pkg/vitess/api_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 9d0ae739..87008005 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -18,8 +18,8 @@ type Tablet struct { Type topodata.TabletType `json:"type,omitempty"` } -// IsReplica returns a bool reflecting if a tablet type is REPLICA -func (t Tablet) IsReplica() bool { +// isReplica returns a bool reflecting if a tablet type is REPLICA +func (t Tablet) isReplica() bool { return t.Type == topodata.TabletType_REPLICA } @@ -60,7 +60,7 @@ func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, func FilterReplicaTablets(tablets []Tablet) []Tablet { replicas := make([]Tablet, 0) for _, tablet := range tablets { - if tablet.IsReplica() { + if tablet.isReplica() { replicas = append(replicas, tablet) } } From 5467764e8b9409777ac604458d6eef18e8df87a2 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 22 Apr 2020 20:29:17 +0200 Subject: [PATCH 04/10] Match code style --- pkg/vitess/api_client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 87008005..302734bb 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -57,8 +57,7 @@ func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, } // FilterReplicaTablets parses a list of tablets, returning replica tablets only -func FilterReplicaTablets(tablets []Tablet) []Tablet { - replicas := make([]Tablet, 0) +func FilterReplicaTablets(tablets []Tablet) (replicas []Tablet) { for _, tablet := range tablets { if tablet.isReplica() { replicas = append(replicas, tablet) From 57e43a65fc99ea86b5381c3ae975238b5b51bfab Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 23 Apr 2020 00:09:54 +0200 Subject: [PATCH 05/10] Move filter func to ParseTablets --- pkg/throttle/throttler.go | 5 ++--- pkg/vitess/api_client.go | 22 +++++++++++----------- pkg/vitess/api_client_test.go | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/throttle/throttler.go b/pkg/throttle/throttler.go index f1670a2f..ec95ab08 100644 --- a/pkg/throttle/throttler.go +++ b/pkg/throttle/throttler.go @@ -327,14 +327,13 @@ func (throttler *Throttler) refreshMySQLInventory() error { if err != nil { return log.Errorf("Unable to get vitess hosts from %s, %s/%s: %+v", clusterSettings.VitessSettings.API, keyspace, shard, err) } - replicas := vitess.FilterReplicaTablets(tablets) - log.Debugf("Read %+v replica hosts from vitess %s, %s/%s", len(replicas), clusterSettings.VitessSettings.API, keyspace, shard) + log.Debugf("Read %+v hosts from vitess %s, %s/%s", len(tablets), clusterSettings.VitessSettings.API, keyspace, shard) clusterProbes := &mysql.ClusterProbes{ ClusterName: clusterName, IgnoreHostsCount: clusterSettings.IgnoreHostsCount, InstanceProbes: mysql.NewProbes(), } - for _, tablet := range replicas { + for _, tablet := range tablets { key := mysql.InstanceKey{Hostname: tablet.MysqlHostname, Port: int(tablet.MysqlPort)} addInstanceKey(&key, clusterName, clusterSettings, clusterProbes.InstanceProbes) } diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 302734bb..8f8f803e 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -37,6 +37,16 @@ func constructAPIURL(api string, keyspace string, shard string) (url string) { return url } +// filterReplicaTablets parses a list of tablets, returning replica tablets only +func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) { + for _, tablet := range tablets { + if tablet.isReplica() { + replicas = append(replicas, tablet) + } + } + return replicas +} + // ParseTablets reads from vitess /api/ks_tablets//[shard] and returns a // tablet (mysql_hostname, mysql_port) listing func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) { @@ -53,15 +63,5 @@ func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, } err = json.Unmarshal(body, &tablets) - return tablets, err -} - -// FilterReplicaTablets parses a list of tablets, returning replica tablets only -func FilterReplicaTablets(tablets []Tablet) (replicas []Tablet) { - for _, tablet := range tablets { - if tablet.isReplica() { - replicas = append(replicas, tablet) - } - } - return replicas + return filterReplicaTablets(tablets), err } diff --git a/pkg/vitess/api_client_test.go b/pkg/vitess/api_client_test.go index 40a02619..4bd08fd4 100644 --- a/pkg/vitess/api_client_test.go +++ b/pkg/vitess/api_client_test.go @@ -7,7 +7,7 @@ import ( ) func TestFilterReplicaTablets(t *testing.T) { - replicas := FilterReplicaTablets([]Tablet{ + replicas := filterReplicaTablets([]Tablet{ { MysqlHostname: t.Name() + "1", Type: topodata.TabletType_MASTER, From fcdc2237e765a613f2482b2da835e7a6e0727e02 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 23 Apr 2020 00:11:18 +0200 Subject: [PATCH 06/10] Fix comment --- pkg/vitess/api_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 8f8f803e..3e646f23 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -48,7 +48,7 @@ func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) { } // ParseTablets reads from vitess /api/ks_tablets//[shard] and returns a -// tablet (mysql_hostname, mysql_port) listing +// listing (mysql_hostname, mysql_port) of REPLICA tablets func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) { url := constructAPIURL(api, keyspace, shard) resp, err := httpClient.Get(url) From 716ede20756c68a4f5ea6082549f763b443c9878 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 23 Apr 2020 00:13:48 +0200 Subject: [PATCH 07/10] Test for SPARE type --- pkg/vitess/api_client_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/vitess/api_client_test.go b/pkg/vitess/api_client_test.go index 4bd08fd4..26b7c4f1 100644 --- a/pkg/vitess/api_client_test.go +++ b/pkg/vitess/api_client_test.go @@ -18,11 +18,15 @@ func TestFilterReplicaTablets(t *testing.T) { }, { MysqlHostname: t.Name() + "3", + Type: topodata.TabletType_SPARE, + }, + { + MysqlHostname: t.Name() + "4", Type: topodata.TabletType_BACKUP, }, { - MysqlHostname: t.Name() + "4", + MysqlHostname: t.Name() + "5", Type: topodata.TabletType_RESTORE, }, }) From 779c612d27422637969a49df188f7dc313dc7294 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 23 Apr 2020 13:51:04 +0200 Subject: [PATCH 08/10] Use real http test --- pkg/vitess/api_client_test.go | 96 ++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 29 deletions(-) diff --git a/pkg/vitess/api_client_test.go b/pkg/vitess/api_client_test.go index 26b7c4f1..9ff6fcf8 100644 --- a/pkg/vitess/api_client_test.go +++ b/pkg/vitess/api_client_test.go @@ -1,39 +1,77 @@ package vitess import ( + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" "testing" "vitess.io/vitess/go/vt/proto/topodata" ) -func TestFilterReplicaTablets(t *testing.T) { - replicas := filterReplicaTablets([]Tablet{ - { - MysqlHostname: t.Name() + "1", - Type: topodata.TabletType_MASTER, - }, - { - MysqlHostname: t.Name() + "2", // this node is valid - Type: topodata.TabletType_REPLICA, - }, - { - MysqlHostname: t.Name() + "3", - Type: topodata.TabletType_SPARE, - }, - { - MysqlHostname: t.Name() + "4", - Type: topodata.TabletType_BACKUP, - }, - { - - MysqlHostname: t.Name() + "5", - Type: topodata.TabletType_RESTORE, - }, +func TestParseTablets(t *testing.T) { + vitessApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.String() { + case "/api/keyspace/test/tablets/00": + data, _ := json.Marshal([]Tablet{ + { + MysqlHostname: "master", + Type: topodata.TabletType_MASTER, + }, + { + MysqlHostname: "replica", + Type: topodata.TabletType_REPLICA, + }, + { + MysqlHostname: "spare", + Type: topodata.TabletType_SPARE, + }, + { + MysqlHostname: "batch", + Type: topodata.TabletType_BATCH, + }, + { + MysqlHostname: "backup", + Type: topodata.TabletType_BACKUP, + }, + { + + MysqlHostname: "restore", + Type: topodata.TabletType_RESTORE, + }, + }) + fmt.Fprint(w, string(data)) + default: + w.WriteHeader(http.StatusNotFound) + fmt.Fprint(w, "[]") + } + })) + defer vitessApi.Close() + + t.Run("not-found", func(t *testing.T) { + tablets, err := ParseTablets(vitessApi.URL, "not-found", "00") + if err != nil { + t.Fatalf("Expected no error, got %q", err) + } + + if len(tablets) > 0 { + t.Fatalf("Expected 0 tablets, got %d", len(tablets)) + } + }) + + t.Run("success", func(t *testing.T) { + tablets, err := ParseTablets(vitessApi.URL, "test", "00") + if err != nil { + t.Fatalf("Expected no error, got %q", err) + } + + if len(tablets) != 1 { + t.Fatalf("Expected 1 tablet, got %d", len(tablets)) + } + + if tablets[0].MysqlHostname != "replica" { + t.Fatalf("Expected hostname %q, got %q", "replica", tablets[0].MysqlHostname) + } }) - if len(replicas) != 1 { - t.Fatalf("Expected 1 replica, got %v", replicas) - } - if replicas[0].MysqlHostname != t.Name()+"2" { - t.Fatalf("Expected hostname %q, got %q", t.Name()+"2", replicas[0].MysqlHostname) - } } From 8415d242a846bdac6d2f2ef91ef9bebc5b290eaf Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 23 Apr 2020 23:52:27 +0200 Subject: [PATCH 09/10] add test for conn failure --- pkg/vitess/api_client_test.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/vitess/api_client_test.go b/pkg/vitess/api_client_test.go index 9ff6fcf8..ebf188fc 100644 --- a/pkg/vitess/api_client_test.go +++ b/pkg/vitess/api_client_test.go @@ -49,29 +49,37 @@ func TestParseTablets(t *testing.T) { })) defer vitessApi.Close() - t.Run("not-found", func(t *testing.T) { - tablets, err := ParseTablets(vitessApi.URL, "not-found", "00") + t.Run("success", func(t *testing.T) { + tablets, err := ParseTablets(vitessApi.URL, "test", "00") if err != nil { t.Fatalf("Expected no error, got %q", err) } - if len(tablets) > 0 { - t.Fatalf("Expected 0 tablets, got %d", len(tablets)) + if len(tablets) != 1 { + t.Fatalf("Expected 1 tablet, got %d", len(tablets)) + } + + if tablets[0].MysqlHostname != "replica" { + t.Fatalf("Expected hostname %q, got %q", "replica", tablets[0].MysqlHostname) } }) - t.Run("success", func(t *testing.T) { - tablets, err := ParseTablets(vitessApi.URL, "test", "00") + t.Run("not-found", func(t *testing.T) { + tablets, err := ParseTablets(vitessApi.URL, "not-found", "00") if err != nil { t.Fatalf("Expected no error, got %q", err) } - if len(tablets) != 1 { - t.Fatalf("Expected 1 tablet, got %d", len(tablets)) + if len(tablets) > 0 { + t.Fatalf("Expected 0 tablets, got %d", len(tablets)) } + }) - if tablets[0].MysqlHostname != "replica" { - t.Fatalf("Expected hostname %q, got %q", "replica", tablets[0].MysqlHostname) + t.Run("failed", func(t *testing.T) { + vitessApi.Close() // kill the mock vitess API + _, err := ParseTablets(vitessApi.URL, "fail", "00") + if err == nil { + t.Fatal("Expected error, got nil") } }) } From 6b90452c9f4320cf17dc2cd31ddcbb1f42f98c66 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 24 Apr 2020 13:30:47 +0200 Subject: [PATCH 10/10] More cleanup --- pkg/vitess/api_client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/vitess/api_client.go b/pkg/vitess/api_client.go index 3e646f23..6155e74a 100644 --- a/pkg/vitess/api_client.go +++ b/pkg/vitess/api_client.go @@ -18,8 +18,8 @@ type Tablet struct { Type topodata.TabletType `json:"type,omitempty"` } -// isReplica returns a bool reflecting if a tablet type is REPLICA -func (t Tablet) isReplica() bool { +// IsValidReplica returns a bool reflecting if a tablet type is REPLICA +func (t Tablet) IsValidReplica() bool { return t.Type == topodata.TabletType_REPLICA } @@ -40,7 +40,7 @@ func constructAPIURL(api string, keyspace string, shard string) (url string) { // filterReplicaTablets parses a list of tablets, returning replica tablets only func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) { for _, tablet := range tablets { - if tablet.isReplica() { + if tablet.IsValidReplica() { replicas = append(replicas, tablet) } } @@ -48,7 +48,7 @@ func filterReplicaTablets(tablets []Tablet) (replicas []Tablet) { } // ParseTablets reads from vitess /api/ks_tablets//[shard] and returns a -// listing (mysql_hostname, mysql_port) of REPLICA tablets +// listing (mysql_hostname, mysql_port, type) of REPLICA tablets func ParseTablets(api string, keyspace string, shard string) (tablets []Tablet, err error) { url := constructAPIURL(api, keyspace, shard) resp, err := httpClient.Get(url)