Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vtctldclient missing cmds and remove remaining vtctl[client] usage in e2e tests #17442

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b2c696d
Add missing TopoCp replacement
mattlord Dec 26, 2024
45dd233
Add CopySchemaShard
mattlord Dec 26, 2024
0e3a8e1
Add ValidateSchemaShard
mattlord Dec 27, 2024
851ccac
Add missing permissions commands
mattlord Dec 27, 2024
05c4c1d
Fixups
mattlord Dec 27, 2024
a091042
Remove CopySchemaShard
mattlord Dec 28, 2024
2ef4690
Revert "Remove CopySchemaShard"
mattlord Dec 31, 2024
f5fcd6c
Start work on CopySchemaShard
mattlord Dec 31, 2024
84d5bdd
Testing and fixing
mattlord Jan 1, 2025
6d8ef71
Topology cmd option cleanup
mattlord Jan 1, 2025
f6da213
Correct vtctldclient --help output
mattlord Jan 1, 2025
02f93a2
Align old and new client resp handling
mattlord Jan 1, 2025
065fd01
Remove unneded call
mattlord Jan 1, 2025
f0047fa
Minor changes from self review
mattlord Jan 1, 2025
24fdf41
Changes from further testing
mattlord Jan 2, 2025
64b9576
Merge remote-tracking branch 'origin/main' into vtctldclient_missing_…
mattlord Jan 2, 2025
f75ed39
Remove and replace all remaining vtctl[client] usage
mattlord Jan 2, 2025
d817b3c
Fix cell bootstrapping
mattlord Jan 2, 2025
efdefd7
Replace remaining usage of VtctlProcess
mattlord Jan 2, 2025
4ec0dc1
Fix vtctldclient creation
mattlord Jan 2, 2025
49e70b1
Fix SecureTransport test
mattlord Jan 2, 2025
6e4a4b0
Fix tabletmanager tests
mattlord Jan 2, 2025
ca1064b
Remove "--" args
mattlord Jan 2, 2025
7b213c3
Update --help output
mattlord Jan 2, 2025
0d136d4
Fix migrate tests
mattlord Jan 2, 2025
8d8b3b4
Fix unit test
mattlord Jan 2, 2025
1cb43c5
Fix vtgate/reference test
mattlord Jan 3, 2025
8f66a9f
Fix ERS test
mattlord Jan 3, 2025
e1832b2
Fix backup tests
mattlord Jan 3, 2025
e89ca17
Changes from self review
mattlord Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 1 addition & 48 deletions go/cmd/vtctldclient/command/keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,10 @@ SetKeyspaceDurabilityPolicy --durability-policy='semi_sync' customer`,
Args: cobra.ExactArgs(1),
RunE: commandSetKeyspaceDurabilityPolicy,
}
// ValidateSchemaKeyspace makes a ValidateSchemaKeyspace gRPC call to a vtctld.
ValidateSchemaKeyspace = &cobra.Command{
Use: "ValidateSchemaKeyspace [--exclude-tables=<exclude_tables>] [--include-views] [--skip-no-primary] [--include-vschema] <keyspace>",
Short: "Validates that the schema on the primary tablet for shard 0 matches the schema on all other tablets in the keyspace.",
DisableFlagsInUseLine: true,
Aliases: []string{"validateschemakeyspace"},
Args: cobra.ExactArgs(1),
RunE: commandValidateSchemaKeyspace,
}
// ValidateVersionKeyspace makes a ValidateVersionKeyspace gRPC call to a vtctld.
ValidateVersionKeyspace = &cobra.Command{
Use: "ValidateVersionKeyspace <keyspace>",
Short: "Validates that the version on the primary tablet of shard 0 matches all of the other tablets in the keyspace.",
Short: "Validates that the version on the primary tablet of the first shard matches all of the other tablets in the keyspace.",
DisableFlagsInUseLine: true,
Aliases: []string{"validateversionkeyspace"},
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -350,38 +341,6 @@ func commandSetKeyspaceDurabilityPolicy(cmd *cobra.Command, args []string) error
return nil
}

var validateSchemaKeyspaceOptions = struct {
ExcludeTables []string
IncludeViews bool
SkipNoPrimary bool
IncludeVSchema bool
}{}

func commandValidateSchemaKeyspace(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

ks := cmd.Flags().Arg(0)
resp, err := client.ValidateSchemaKeyspace(commandCtx, &vtctldatapb.ValidateSchemaKeyspaceRequest{
Keyspace: ks,
ExcludeTables: validateSchemaKeyspaceOptions.ExcludeTables,
IncludeVschema: validateSchemaKeyspaceOptions.IncludeVSchema,
SkipNoPrimary: validateSchemaKeyspaceOptions.SkipNoPrimary,
IncludeViews: validateSchemaKeyspaceOptions.IncludeViews,
})

if err != nil {
return err
}

data, err := cli.MarshalJSON(resp)
if err != nil {
return err
}

fmt.Printf("%s\n", data)
return nil
}

func commandValidateVersionKeyspace(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

Expand Down Expand Up @@ -428,11 +387,5 @@ func init() {
SetKeyspaceDurabilityPolicy.Flags().StringVar(&setKeyspaceDurabilityPolicyOptions.DurabilityPolicy, "durability-policy", "none", "Type of durability to enforce for this keyspace. Default is none. Other values include 'semi_sync' and others as dictated by registered plugins.")
Root.AddCommand(SetKeyspaceDurabilityPolicy)

ValidateSchemaKeyspace.Flags().BoolVar(&validateSchemaKeyspaceOptions.IncludeViews, "include-views", false, "Includes views in compared schemas.")
ValidateSchemaKeyspace.Flags().BoolVar(&validateSchemaKeyspaceOptions.IncludeVSchema, "include-vschema", false, "Includes VSchema validation in validation results.")
ValidateSchemaKeyspace.Flags().BoolVar(&validateSchemaKeyspaceOptions.SkipNoPrimary, "skip-no-primary", false, "Skips validation on whether or not a primary exists in shards.")
ValidateSchemaKeyspace.Flags().StringSliceVar(&validateSchemaKeyspaceOptions.ExcludeTables, "exclude-tables", []string{}, "Tables to exclude during schema comparison.")
Root.AddCommand(ValidateSchemaKeyspace)

Root.AddCommand(ValidateVersionKeyspace)
}
114 changes: 114 additions & 0 deletions go/cmd/vtctldclient/command/permissions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Copyright 2024 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package command

import (
"fmt"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/vt/topo/topoproto"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

var (
// GetPermissions makes a GetPermissions gRPC call to a vtctld.
GetPermissions = &cobra.Command{
Use: "GetPermissions <tablet_alias>",
Short: "Displays the permissions for a tablet.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandGetPermissions,
}
// ValidatePermissionsShard makes a ValidatePermissionsKeyspace gRPC call to a
// vtctld with the specified shard to examine in the keyspace.
ValidatePermissionsShard = &cobra.Command{
Use: "ValidatePermissionsShard <keyspace/shard>",
Short: "Validates that the permissions on the primary match all of the replicas.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandValidatePermissionsShard,
}
// ValidatePermissionsKeyspace makes a ValidatePermissionsKeyspace gRPC call to a
// vtctld.
ValidatePermissionsKeyspace = &cobra.Command{
Use: "ValidatePermissionsKeyspace <keyspace name>",
Short: "Validates that the permissions on the primary of the first shard match those of all of the other tablets in the keyspace.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandValidatePermissionsKeyspace,
}
)

func commandGetPermissions(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

resp, err := client.GetPermissions(commandCtx, &vtctldatapb.GetPermissionsRequest{
TabletAlias: alias,
})
if err != nil {
return err
}
p, err := cli.MarshalJSON(resp.Permissions)
if err != nil {
return err
}
fmt.Printf("%s\n", p)

return nil
}

func commandValidatePermissionsKeyspace(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)

cli.FinishedParsing(cmd)

_, err := client.ValidatePermissionsKeyspace(commandCtx, &vtctldatapb.ValidatePermissionsKeyspaceRequest{
Keyspace: keyspace,
})

return err
}

func commandValidatePermissionsShard(cmd *cobra.Command, args []string) error {
keyspace, shard, err := topoproto.ParseKeyspaceShard(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

_, err = client.ValidatePermissionsKeyspace(commandCtx, &vtctldatapb.ValidatePermissionsKeyspaceRequest{
Keyspace: keyspace,
Shards: []string{shard},
})

return err
}

func init() {
Root.AddCommand(GetPermissions)
Root.AddCommand(ValidatePermissionsKeyspace)
Root.AddCommand(ValidatePermissionsShard)
}
9 changes: 0 additions & 9 deletions go/cmd/vtctldclient/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"vitess.io/vitess/go/vt/vtctl/localvtctldclient"
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vttablet/tmclient"

// These imports ensure init()s within them get called and they register their commands/subcommands.
"vitess.io/vitess/go/cmd/vtctldclient/cli"
Expand Down Expand Up @@ -204,14 +203,6 @@ func getClientForCommand(cmd *cobra.Command) (vtctldclient.VtctldClient, error)
}
onTerm = append(onTerm, ts.Close)

// Use internal vtctld server implementation.
// Register a nil grpc handler -- we will not use tmclient at all but
// a factory still needs to be registered.
once.Do(func() {
tmclient.RegisterTabletManagerClientFactory("grpc", func() tmclient.TabletManagerClient {
return nil
})
})
vtctld := grpcvtctldserver.NewVtctldServer(env, ts)
localvtctldclient.SetServer(vtctld)
VtctldClientProtocol = "local"
Expand Down
8 changes: 6 additions & 2 deletions go/cmd/vtctldclient/command/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/vtctl/localvtctldclient"
"vitess.io/vitess/go/vt/vttablet/tmclient"

vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice"
)
Expand Down Expand Up @@ -67,15 +68,18 @@ func TestRootWithInternalVtctld(t *testing.T) {
cell := "zone1"
ts, factory := memorytopo.NewServerAndFactory(ctx, cell)
topo.RegisterFactory("test", factory)
origProtocol := command.VtctldClientProtocol
command.VtctldClientProtocol = "local"
tmclient.RegisterTabletManagerClientFactory("grpc", func() tmclient.TabletManagerClient {
return nil
})
baseArgs := []string{"vtctldclient", "--server", "internal", "--topo-implementation", "test"}

args := append([]string{}, os.Args...)
protocol := command.VtctldClientProtocol
t.Cleanup(func() {
ts.Close()
os.Args = append([]string{}, args...)
command.VtctldClientProtocol = protocol
command.VtctldClientProtocol = origProtocol
})

testCases := []struct {
Expand Down
Loading
Loading