From e8211df9c3a402b5ff506ed45aa671eef116f20e Mon Sep 17 00:00:00 2001 From: Austen Lacy Date: Thu, 2 Nov 2023 15:40:36 +0000 Subject: [PATCH 1/3] use target tablet from health stats cache when checking replication status Signed-off-by: Austen Lacy --- go/vt/vtgate/executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index c7843e26bbf..8465b92944c 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -901,7 +901,7 @@ func (e *Executor) showVitessReplicationStatus(ctx context.Context, filter *sqlp for _, s := range status { for _, ts := range s.TabletsStats { // We only want to show REPLICA and RDONLY tablets - if ts.Tablet.Type != topodatapb.TabletType_REPLICA && ts.Tablet.Type != topodatapb.TabletType_RDONLY { + if ts.Target.TabletType != topodatapb.TabletType_REPLICA && ts.Target.TabletType != topodatapb.TabletType_RDONLY { continue } From f4920fee5172494878eb9ca21dea1bcdc8042ec6 Mon Sep 17 00:00:00 2001 From: Austen Lacy Date: Thu, 2 Nov 2023 19:03:16 +0000 Subject: [PATCH 2/3] added test in vtgate for show vitess_replication_status to support tablets changing type Signed-off-by: Austen Lacy --- go/test/endtoend/cluster/cluster_process.go | 9 ++++++ go/test/endtoend/tabletgateway/vtgate_test.go | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index f74a031f4d8..1087037a6ac 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -985,6 +985,15 @@ func (cluster *LocalProcessCluster) VtctlclientGetTablet(tablet *Vttablet) (*top return &ti, nil } +func (cluster *LocalProcessCluster) VtctlclientChangeTabletType(tablet *Vttablet, tabletType topodatapb.TabletType) error { + _, err := cluster.VtctlclientProcess.ExecuteCommandWithOutput("ChangeTabletType", "--", tablet.Alias, tabletType.String()) + if err != nil { + return err + } + + return nil +} + // Teardown brings down the cluster by invoking teardown for individual processes func (cluster *LocalProcessCluster) Teardown() { PanicHandler(nil) diff --git a/go/test/endtoend/tabletgateway/vtgate_test.go b/go/test/endtoend/tabletgateway/vtgate_test.go index a3876b259f3..be227927981 100644 --- a/go/test/endtoend/tabletgateway/vtgate_test.go +++ b/go/test/endtoend/tabletgateway/vtgate_test.go @@ -29,6 +29,7 @@ import ( "time" "vitess.io/vitess/go/test/endtoend/utils" + "vitess.io/vitess/go/vt/proto/topodata" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -69,6 +70,34 @@ func TestVtgateReplicationStatusCheck(t *testing.T) { assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows)) } +func TestVtgateReplicationStatusCheckWithTabletTypeChange(t *testing.T) { + defer cluster.PanicHandler(t) + // Healthcheck interval on tablet is set to 1s, so sleep for 2s + time.Sleep(2 * time.Second) + verifyVtgateVariables(t, clusterInstance.VtgateProcess.VerifyURL) + ctx := context.Background() + conn, err := mysql.Connect(ctx, &vtParams) + require.NoError(t, err) + defer conn.Close() + + // Only returns rows for REPLICA and RDONLY tablets -- so should be 2 of them + qr := utils.Exec(t, conn, "show vitess_replication_status like '%'") + expectNumRows := 2 + numRows := len(qr.Rows) + assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows)) + + // change the RDONLY tablet to SPARE + rdOnlyTablet := clusterInstance.Keyspaces[0].Shards[0].Rdonly() + err = clusterInstance.VtctlclientChangeTabletType(rdOnlyTablet, topodata.TabletType_SPARE) + require.NoError(t, err) + + // Only returns rows for REPLICA and RDONLY tablets -- so should be 1 of them since we updated 1 to spare + qr = utils.Exec(t, conn, "show vitess_replication_status like '%'") + expectNumRows = 1 + numRows = len(qr.Rows) + assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows)) +} + func verifyVtgateVariables(t *testing.T, url string) { resp, err := http.Get(url) require.NoError(t, err) From d7a46654101a8d123f59570a1ade1a1797c2706d Mon Sep 17 00:00:00 2001 From: Austen Lacy Date: Fri, 3 Nov 2023 13:33:12 +0000 Subject: [PATCH 3/3] simplify VtctlclientChangeTabletType and use target tablet in executor#showVitessReplicationStatus Signed-off-by: Austen Lacy --- go/test/endtoend/cluster/cluster_process.go | 6 +----- go/vt/vtgate/executor.go | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index 1087037a6ac..28a8807cf08 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -987,11 +987,7 @@ func (cluster *LocalProcessCluster) VtctlclientGetTablet(tablet *Vttablet) (*top func (cluster *LocalProcessCluster) VtctlclientChangeTabletType(tablet *Vttablet, tabletType topodatapb.TabletType) error { _, err := cluster.VtctlclientProcess.ExecuteCommandWithOutput("ChangeTabletType", "--", tablet.Alias, tabletType.String()) - if err != nil { - return err - } - - return nil + return err } // Teardown brings down the cluster by invoking teardown for individual processes diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 8465b92944c..152533f2c0d 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -908,7 +908,7 @@ func (e *Executor) showVitessReplicationStatus(ctx context.Context, filter *sqlp // Allow people to filter by Keyspace and Shard using a LIKE clause if filter != nil { ksFilterRegex := sqlparser.LikeToRegexp(filter.Like) - keyspaceShardStr := fmt.Sprintf("%s/%s", ts.Tablet.Keyspace, ts.Tablet.Shard) + keyspaceShardStr := fmt.Sprintf("%s/%s", ts.Target.Keyspace, ts.Target.Shard) if !ksFilterRegex.MatchString(keyspaceShardStr) { continue }