Skip to content

Commit

Permalink
Testing and fixing
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 1, 2025
1 parent 9e87209 commit 6021859
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion go/cmd/vtctldclient/command/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ func commandCopySchemaShard(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
sourceTabletAlias = res.GetTablets()[0].Alias
tablets := res.GetTablets()
if len(tablets) == 0 {
return fmt.Errorf("no primary tablet found in source shard %s/%s", sourceKeyspace, sourceShard)
}
sourceTabletAlias = tablets[0].Alias
} else {
sourceTabletAlias, err = topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions go/test/endtoend/sharded/sharded_keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func TestShardedKeyspace(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, `[[INT64(1) VARCHAR("test 1")]]`, fmt.Sprintf("%v", rows.Rows))

err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidateSchemaShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ValidateSchemaShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
require.Nil(t, err)

err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidateSchemaShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ValidateSchemaShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
require.Nil(t, err)

output, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("ValidateSchemaKeyspace", keyspaceName)
output, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("ValidateSchemaKeyspace", keyspaceName)
require.Error(t, err)
// We should assert that there is a schema difference and that both the shard primaries are involved in it.
// However, we cannot assert in which order the two primaries will occur since the underlying function does not guarantee that
Expand All @@ -166,9 +166,9 @@ func TestShardedKeyspace(t *testing.T) {
require.Nil(t, err)
err = clusterInstance.VtctldClientProcess.ExecuteCommand("GetPermissions", shard1.Vttablets[1].Alias)
require.Nil(t, err)
err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidatePermissionsShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ValidatePermissionsShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
require.Nil(t, err)
err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidatePermissionsKeyspace", keyspaceName)
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ValidatePermissionsKeyspace", keyspaceName)
require.Nil(t, err)

rows, err = shard1Primary.VttabletProcess.QueryTablet("select id, msg from vt_select_test order by id", keyspaceName, true)
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/vtgate/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func testCopySchemaShards(t *testing.T, source string, shard int) {
checkTablesCount(t, clusterInstance.Keyspaces[0].Shards[shard].Vttablets[1], 0)
// Run the command twice to make sure it's idempotent.
for i := 0; i < 2; i++ {
err := clusterInstance.VtctlclientProcess.ExecuteCommand("CopySchemaShard", source, fmt.Sprintf("%s/%d", keyspaceName, shard))
err := clusterInstance.VtctldClientProcess.ExecuteCommand("CopySchemaShard", source, fmt.Sprintf("%s/%d", keyspaceName, shard))
require.Nil(t, err)
}
// shard2 primary should look the same as the replica we copied from
Expand Down Expand Up @@ -329,7 +329,7 @@ func testCopySchemaShardWithDifferentDB(t *testing.T, shard int) {
err = clusterInstance.VtctldClientProcess.ExecuteCommand("ExecuteFetchAsDBA", "--json", tabletAlias, "ALTER DATABASE vt_ks CHARACTER SET latin1")
require.Nil(t, err)

output, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("CopySchemaShard", source, fmt.Sprintf("%s/%d", keyspaceName, shard))
output, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("CopySchemaShard", source, fmt.Sprintf("%s/%d", keyspaceName, shard))
require.Error(t, err)
assert.True(t, strings.Contains(output, "schemas are different"))

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4725,7 +4725,7 @@ func (s *VtctldServer) ValidatePermissionsKeyspace(ctx context.Context, req *vtc
// If the user has specified a list of specific shards, we'll use that.
shards = req.Shards
} else {
// Validate all the shards
// Validate all of the shards.
shards, err = s.ts.GetShardNames(ctx, req.Keyspace)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6021859

Please sign in to comment.