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

[vtctld] sleep/ping tablets #8826

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions go/cmd/vtctldclient/internal/command/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/spf13/cobra"

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

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -81,6 +83,14 @@ Valid output formats are "awk" and "json".`,
Args: cobra.NoArgs,
RunE: commandGetTablets,
}
// PingTablet makes a PingTablet gRPC call to a vtctld.
PingTablet = &cobra.Command{
Use: "PingTablet <alias>",
Short: "Checks that the specified tablet is awake and responding to RPCs. This command can be blocked by other in-flight operations.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandPingTablet,
}
// RefreshState makes a RefreshState gRPC call to a vtctld.
RefreshState = &cobra.Command{
Use: "RefreshState <alias>",
Expand All @@ -105,6 +115,27 @@ Valid output formats are "awk" and "json".`,
Args: cobra.ExactArgs(2),
RunE: commandSetWritable,
}
// SleepTablet makes a SleepTablet gRPC call to a vtctld.
SleepTablet = &cobra.Command{
Use: "SleepTablet <alias> <duration>",
Short: "Blocks the action queue on the specified tablet for the specified amount of time. This is typically used for testing.",
Long: `SleepTablet <alias> <duration>

Blocks the action queue on the specified tablet for the specified duration.
This command is typically only used for testing.

The duration is the amount of time that the action queue should be blocked.
The value is a string that contains a possibly signed sequence of decimal numbers,
each with optional fraction and a unit suffix, such as “300ms” or “1h45m”.
See the definition of the Go language’s ParseDuration[1] function for more details.
Note that, in the SleepTablet implementation, the value should be positively-signed.

[1]: https://pkg.go.dev/time#ParseDuration
`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandSleepTablet,
}
// StartReplication makes a StartReplication gRPC call to a vtctld.
StartReplication = &cobra.Command{
Use: "StartReplication <alias>",
Expand Down Expand Up @@ -285,6 +316,20 @@ func commandGetTablets(cmd *cobra.Command, args []string) error {
return nil
}

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

cli.FinishedParsing(cmd)

_, err = client.PingTablet(commandCtx, &vtctldatapb.PingTabletRequest{
TabletAlias: alias,
})
return err
}

func commandRefreshState(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down Expand Up @@ -359,6 +404,26 @@ func commandSetWritable(cmd *cobra.Command, args []string) error {
return err
}

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

duration, err := time.ParseDuration(cmd.Flags().Arg(1))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

_, err = client.SleepTablet(commandCtx, &vtctldatapb.SleepTabletRequest{
TabletAlias: alias,
Duration: protoutil.DurationToProto(duration),
})
return err
}

func commandStartReplication(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down Expand Up @@ -404,12 +469,14 @@ func init() {
GetTablets.Flags().BoolVar(&getTabletsOptions.Strict, "strict", false, "Require all cells to return successful tablet data. Without --strict, tablet listings may be partial.")
Root.AddCommand(GetTablets)

Root.AddCommand(PingTablet)
Root.AddCommand(RefreshState)

RefreshStateByShard.Flags().StringSliceVarP(&refreshStateByShardOptions.Cells, "cells", "c", nil, "If specified, only call RefreshState on tablets in the specified cells. If empty, all cells are considered.")
Root.AddCommand(RefreshStateByShard)

Root.AddCommand(SetWritable)
Root.AddCommand(SleepTablet)
Root.AddCommand(StartReplication)
Root.AddCommand(StopReplication)
}
Loading