Skip to content

Commit

Permalink
[vtctldclient] Add GetShardReplication (#15389)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
vitess-bot[bot] committed Feb 29, 2024
1 parent 977b585 commit aad6ebc
Show file tree
Hide file tree
Showing 14 changed files with 4,924 additions and 3,151 deletions.
39 changes: 39 additions & 0 deletions go/cmd/vtctldclient/command/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ that shard.`,
Args: cobra.ExactArgs(1),
RunE: commandGetShard,
}
// GetShardReplication makes a GetShardReplication gRPC request to a vtctld.
GetShardReplication = &cobra.Command{
Use: "GetShardReplication <keyspace/shard> [cell1 [cell2...]]",
Short: "Returns information about the replication relationships for a shard in the given cell(s).",
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
RunE: commandGetShardReplication,
}
// RemoveShardCell makes a RemoveShardCell gRPC request to a vtctld.
RemoveShardCell = &cobra.Command{
Use: "RemoveShardCell [--force|-f] [--recursive|-r] <keyspace/shard> <cell>",
Expand Down Expand Up @@ -286,6 +294,36 @@ func commandGetShard(cmd *cobra.Command, args []string) error {
return nil
}

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

Check warning on line 300 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L297-L300

Added lines #L297 - L300 were not covered by tests
}

cells := cmd.Flags().Args()[1:]

Check warning on line 303 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L303

Added line #L303 was not covered by tests

cli.FinishedParsing(cmd)

Check warning on line 305 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L305

Added line #L305 was not covered by tests

resp, err := client.GetShardReplication(commandCtx, &vtctldatapb.GetShardReplicationRequest{
Keyspace: keyspace,
Shard: shard,
Cells: cells,
})
if err != nil {
return err

Check warning on line 313 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L307-L313

Added lines #L307 - L313 were not covered by tests
}

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

Check warning on line 318 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L316-L318

Added lines #L316 - L318 were not covered by tests
}

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

Check warning on line 321 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L321

Added line #L321 was not covered by tests

return nil

Check warning on line 323 in go/cmd/vtctldclient/command/shards.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/shards.go#L323

Added line #L323 was not covered by tests

}

var removeShardCellOptions = struct {
Force bool
Recursive bool
Expand Down Expand Up @@ -624,6 +662,7 @@ func init() {
Root.AddCommand(DeleteShards)

Root.AddCommand(GetShard)
Root.AddCommand(GetShardReplication)
Root.AddCommand(GenerateShardRanges)

RemoveShardCell.Flags().BoolVarP(&removeShardCellOptions.Force, "force", "f", false, "Proceed even if the cell's topology server cannot be reached. The assumption is that you turned down the entire cell, and just need to update the global topo data.")
Expand Down
1 change: 1 addition & 0 deletions go/flags/endtoend/vtctldclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Available Commands:
GetRoutingRules Displays the VSchema routing rules.
GetSchema Displays the full schema for a tablet, optionally restricted to the specified tables/views.
GetShard Returns information about a shard in the topology.
GetShardReplication Returns information about the replication relationships for a shard in the given cell(s).
GetShardRoutingRules Displays the currently active shard routing rules as a JSON document.
GetSrvKeyspaceNames Outputs a JSON mapping of cell=>keyspace names served in that cell. Omit to query all cells.
GetSrvKeyspaces Returns the SrvKeyspaces for the given keyspace in one or more cells.
Expand Down
Loading

0 comments on commit aad6ebc

Please sign in to comment.