Skip to content

Commit 5f2bf56

Browse files
austenLacyshanth96
authored andcommitted
Bug fix: Use target tablet from health stats cache when checking replication status (vitessio#14436) (#128)
Signed-off-by: Austen Lacy <[email protected]> Co-authored-by: Austen Lacy <[email protected]>
1 parent 6587ffd commit 5f2bf56

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

go/test/endtoend/cluster/cluster_process.go

+5
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ func (cluster *LocalProcessCluster) VtctlclientGetTablet(tablet *Vttablet) (*top
896896
return &ti, nil
897897
}
898898

899+
func (cluster *LocalProcessCluster) VtctlclientChangeTabletType(tablet *Vttablet, tabletType topodatapb.TabletType) error {
900+
_, err := cluster.VtctlclientProcess.ExecuteCommandWithOutput("ChangeTabletType", "--", tablet.Alias, tabletType.String())
901+
return err
902+
}
903+
899904
// Teardown brings down the cluster by invoking teardown for individual processes
900905
func (cluster *LocalProcessCluster) Teardown() {
901906
PanicHandler(nil)

go/test/endtoend/tabletgateway/vtgate_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"time"
3030

3131
"vitess.io/vitess/go/test/endtoend/utils"
32+
"vitess.io/vitess/go/vt/proto/topodata"
3233

3334
"github.com/stretchr/testify/assert"
3435
"github.com/stretchr/testify/require"
@@ -69,6 +70,34 @@ func TestVtgateReplicationStatusCheck(t *testing.T) {
6970
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))
7071
}
7172

73+
func TestVtgateReplicationStatusCheckWithTabletTypeChange(t *testing.T) {
74+
defer cluster.PanicHandler(t)
75+
// Healthcheck interval on tablet is set to 1s, so sleep for 2s
76+
time.Sleep(2 * time.Second)
77+
verifyVtgateVariables(t, clusterInstance.VtgateProcess.VerifyURL)
78+
ctx := context.Background()
79+
conn, err := mysql.Connect(ctx, &vtParams)
80+
require.NoError(t, err)
81+
defer conn.Close()
82+
83+
// Only returns rows for REPLICA and RDONLY tablets -- so should be 2 of them
84+
qr := utils.Exec(t, conn, "show vitess_replication_status like '%'")
85+
expectNumRows := 2
86+
numRows := len(qr.Rows)
87+
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))
88+
89+
// change the RDONLY tablet to SPARE
90+
rdOnlyTablet := clusterInstance.Keyspaces[0].Shards[0].Rdonly()
91+
err = clusterInstance.VtctlclientChangeTabletType(rdOnlyTablet, topodata.TabletType_SPARE)
92+
require.NoError(t, err)
93+
94+
// Only returns rows for REPLICA and RDONLY tablets -- so should be 1 of them since we updated 1 to spare
95+
qr = utils.Exec(t, conn, "show vitess_replication_status like '%'")
96+
expectNumRows = 1
97+
numRows = len(qr.Rows)
98+
assert.Equal(t, expectNumRows, numRows, fmt.Sprintf("wrong number of results from show vitess_replication_status. Expected %d, got %d", expectNumRows, numRows))
99+
}
100+
72101
func verifyVtgateVariables(t *testing.T, url string) {
73102
resp, err := http.Get(url)
74103
require.NoError(t, err)

go/vt/vtgate/executor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -848,14 +848,14 @@ func (e *Executor) showVitessReplicationStatus(ctx context.Context, filter *sqlp
848848
for _, s := range status {
849849
for _, ts := range s.TabletsStats {
850850
// We only want to show REPLICA and RDONLY tablets
851-
if ts.Tablet.Type != topodatapb.TabletType_REPLICA && ts.Tablet.Type != topodatapb.TabletType_RDONLY {
851+
if ts.Target.TabletType != topodatapb.TabletType_REPLICA && ts.Target.TabletType != topodatapb.TabletType_RDONLY {
852852
continue
853853
}
854854

855855
// Allow people to filter by Keyspace and Shard using a LIKE clause
856856
if filter != nil {
857857
ksFilterRegex := sqlparser.LikeToRegexp(filter.Like)
858-
keyspaceShardStr := fmt.Sprintf("%s/%s", ts.Tablet.Keyspace, ts.Tablet.Shard)
858+
keyspaceShardStr := fmt.Sprintf("%s/%s", ts.Target.Keyspace, ts.Target.Shard)
859859
if !ksFilterRegex.MatchString(keyspaceShardStr) {
860860
continue
861861
}

0 commit comments

Comments
 (0)