Skip to content

Commit

Permalink
rewrite with vtctldclient command
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <andrew@planetscale.com>
  • Loading branch information
Andrew Mason committed Feb 29, 2024
1 parent 5be7ffd commit b1375de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
13 changes: 13 additions & 0 deletions go/test/endtoend/cluster/vtctldclient_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ func (vtctldclient *VtctldClientProcess) ChangeTabletType(tablet *Vttablet, tabl
)
}

// GetShardReplication returns a mapping of cell to shard replication for the given keyspace and shard.
func (vtctldclient *VtctldClientProcess) GetShardReplication(keyspace string, shard string, cells ...string) (replication map[string]*topodatapb.ShardReplication, err error) {
args := append([]string{"GetShardReplication", keyspace + "/" + shard}, cells...)
out, err := vtctldclient.ExecuteCommandWithOutput(args...)
if err != nil {
return nil, err
}

replication = map[string]*topodatapb.ShardReplication{}
err = json2.Unmarshal([]byte(out), &replication)
return replication, err
}

// GetSrvKeyspaces returns a mapping of cell to srv keyspace for the given keyspace.
func (vtctldclient *VtctldClientProcess) GetSrvKeyspaces(keyspace string, cells ...string) (ksMap map[string]*topodatapb.SrvKeyspace, err error) {
args := append([]string{"GetSrvKeyspaces", keyspace}, cells...)
Expand Down
5 changes: 2 additions & 3 deletions go/test/endtoend/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package sequence

import (
"context"
"encoding/binary"
"encoding/json"
"flag"
Expand Down Expand Up @@ -262,7 +261,7 @@ func TestDeleteKeyspace(t *testing.T) {
// Create the serving/replication entries and check that they exist,
// so we can later check they're deleted.
_ = clusterForKSTest.VtctldClientProcess.ExecuteCommand("RebuildKeyspaceGraph", "test_delete_keyspace")
_, _ = clusterForKSTest.TopoProcess.Server.GetShardReplication(context.Background(), cell, "test_delete_keyspace", "0")
_, _ = clusterForKSTest.VtctldClientProcess.GetShardReplication("test_delete_keyspace/0", cell)
_ = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetSrvKeyspace", cell, "test_delete_keyspace")

// Recursive DeleteKeyspace
Expand All @@ -275,7 +274,7 @@ func TestDeleteKeyspace(t *testing.T) {
require.Error(t, err)
err = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetTablet", "zone1-0000000100")
require.Error(t, err)
_, err = clusterForKSTest.TopoProcess.Server.GetShardReplication(context.Background(), cell, "test_delete_keyspace", "0")
_, err = clusterForKSTest.VtctldClientProcess.GetShardReplication("test_delete_keyspace/0", cell)
require.Error(t, err)
err = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetSrvKeyspace", cell, "test_delete_keyspace")
require.Error(t, err)
Expand Down
7 changes: 4 additions & 3 deletions go/test/endtoend/reparent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,13 @@ func CheckReplicaStatus(ctx context.Context, t *testing.T, tablet *cluster.Vttab

// CheckReparentFromOutside checks that cluster was reparented from outside
func CheckReparentFromOutside(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tablet *cluster.Vttablet, downPrimary bool, baseTime int64) {
result, err := clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell1, KeyspaceName, ShardName)
result, err := clusterInstance.VtctldClientProcess.GetShardReplication(KeyspaceName, ShardName, cell1)
require.Nil(t, err, "error should be Nil")
require.NotNil(t, result[cell1], "result should not be nil")
if !downPrimary {
assert.Len(t, result.Nodes, 3)
assert.Len(t, result[cell1].Nodes, 3)
} else {
assert.Len(t, result.Nodes, 2)
assert.Len(t, result[cell1].Nodes, 2)
}

// make sure the primary status page says it's the primary
Expand Down
15 changes: 9 additions & 6 deletions go/test/endtoend/tabletmanager/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,26 @@ func runHookAndAssert(t *testing.T, params []string, expectedStatus int64, expec
func TestShardReplicationFix(t *testing.T) {
// make sure the replica is in the replication graph, 2 nodes: 1 primary, 1 replica
defer cluster.PanicHandler(t)
result, err := clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName)
result, err := clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell)
require.Nil(t, err, "error should be Nil")
assert.Len(t, result.Nodes, 3)
require.NotNil(t, result[cell], "result should not be Nil")
assert.Len(t, result[cell].Nodes, 3)

// Manually add a bogus entry to the replication graph, and check it is removed by ShardReplicationFix
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ShardReplicationAdd", keyspaceShard, fmt.Sprintf("%s-9000", cell))
require.Nil(t, err, "error should be Nil")

result, err = clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName)
result, err = clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell)
require.Nil(t, err, "error should be Nil")
assert.Len(t, result.Nodes, 4)
require.NotNil(t, result[cell], "result should not be Nil")
assert.Len(t, result[cell].Nodes, 4)

err = clusterInstance.VtctldClientProcess.ExecuteCommand("ShardReplicationFix", cell, keyspaceShard)
require.Nil(t, err, "error should be Nil")
result, err = clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName)
result, err = clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell)
require.Nil(t, err, "error should be Nil")
assert.Len(t, result.Nodes, 3)
require.NotNil(t, result[cell], "result should not be Nil")
assert.Len(t, result[cell].Nodes, 3)
}

func TestGetSchema(t *testing.T) {
Expand Down

0 comments on commit b1375de

Please sign in to comment.