From 6021859ede0075cefd75248cbd540c87db6d447d Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Wed, 1 Jan 2025 14:21:12 -0500 Subject: [PATCH] Testing and fixing Signed-off-by: Matt Lord --- go/cmd/vtctldclient/command/schema.go | 6 +++++- go/test/endtoend/sharded/sharded_keyspace_test.go | 10 +++++----- go/test/endtoend/vtgate/schema/schema_test.go | 4 ++-- go/vt/vtctl/grpcvtctldserver/server.go | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/go/cmd/vtctldclient/command/schema.go b/go/cmd/vtctldclient/command/schema.go index 5094a2da752..4715835d66b 100644 --- a/go/cmd/vtctldclient/command/schema.go +++ b/go/cmd/vtctldclient/command/schema.go @@ -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 { diff --git a/go/test/endtoend/sharded/sharded_keyspace_test.go b/go/test/endtoend/sharded/sharded_keyspace_test.go index 3e5f2b3add7..dba369a2539 100644 --- a/go/test/endtoend/sharded/sharded_keyspace_test.go +++ b/go/test/endtoend/sharded/sharded_keyspace_test.go @@ -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 @@ -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) diff --git a/go/test/endtoend/vtgate/schema/schema_test.go b/go/test/endtoend/vtgate/schema/schema_test.go index 4c28e29ca0d..fd84b5b2793 100644 --- a/go/test/endtoend/vtgate/schema/schema_test.go +++ b/go/test/endtoend/vtgate/schema/schema_test.go @@ -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 @@ -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")) diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index 97df4e30b9d..275437343ea 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -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