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 4 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
54 changes: 54 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,14 @@ 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.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an inline example would be helpful for "specified amount of time"? (Unless it's super obvious to Vitess operators.) We could steal what's noted here

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”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!!

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 +303,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 +391,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 +456,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