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

vtctldclient OnlineDDL: support throttle, unthrottle #13916

Merged
merged 11 commits into from
Sep 12, 2023
97 changes: 97 additions & 0 deletions go/cmd/vtctldclient/command/onlineddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/vtctl/schematools"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp"

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

Expand Down Expand Up @@ -83,6 +86,22 @@ var (
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLRetry,
}
OnlineDDLThrottle = &cobra.Command{
Use: "throttle <keyspace> <uuid|all>",
Short: "throttles one or all migrations",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these are full sentences with capitalization/punctiuations for some of the others

Copy link
Contributor

Choose a reason for hiding this comment

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

(see Show and Cleanup)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Example: "OnlineDDL throttle all",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLThrottle,
}
OnlineDDLUnthrottle = &cobra.Command{
Use: "unthrottle <keyspace> <uuid|all>",
Short: "unthrottles one or all migrations",
Example: "OnlineDDL unthrottle all",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLUnthrottle,
}
OnlineDDLShow = &cobra.Command{
Use: "show",
Short: "Display information about online DDL operations.",
Expand Down Expand Up @@ -239,6 +258,82 @@ func commandOnlineDDLRetry(cmd *cobra.Command, args []string) error {
return nil
}

// commandOnlineDDLThrottle throttles one or multiple migrations.
// As opposed to *most* OnlineDDL functions, this functionality does not end up calling a gRPC on tablets.
// Instead, it updates Keyspace and SrvKeyspace entries, on which the tablets listen.
func commandOnlineDDLThrottle(cmd *cobra.Command, args []string) error {
rohit-nayak-ps marked this conversation as resolved.
Show resolved Hide resolved
keyspace, uuid, err := analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

throttledAppRule := topodatapb.ThrottledAppRule{
Ratio: throttle.DefaultThrottleRatio,
ExpiresAt: protoutil.TimeToProto(time.Now().Add(throttle.DefaultAppThrottleDuration)),
}
if strings.ToLower(uuid) == AllMigrationsIndicator {
throttledAppRule.Name = throttlerapp.OnlineDDLName.String()
} else {
throttledAppRule.Name = uuid
}

updateThrottlerConfigOptions := vtctldatapb.UpdateThrottlerConfigRequest{
Keyspace: keyspace,
ThrottledApp: &throttledAppRule,
}
resp, err := client.UpdateThrottlerConfig(commandCtx, &updateThrottlerConfigOptions)
if err != nil {
return err
}

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

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

// commandOnlineDDLUnthrottle unthrottles one or multiple migrations.
// As opposed to *most* OnlineDDL functions, this functionality does not end up calling a gRPC on tablets.
// Instead, it updates Keyspace and SrvKeyspace entries, on which the tablets listen.
func commandOnlineDDLUnthrottle(cmd *cobra.Command, args []string) error {
keyspace, uuid, err := analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

unthrottledAppRule := topodatapb.ThrottledAppRule{
Ratio: 0,
ExpiresAt: protoutil.TimeToProto(time.Now()),
}
if strings.ToLower(uuid) == AllMigrationsIndicator {
unthrottledAppRule.Name = throttlerapp.OnlineDDLName.String()
} else {
unthrottledAppRule.Name = uuid
}

updateThrottlerConfigOptions := vtctldatapb.UpdateThrottlerConfigRequest{
Keyspace: keyspace,
ThrottledApp: &unthrottledAppRule,
}
resp, err := client.UpdateThrottlerConfig(commandCtx, &updateThrottlerConfigOptions)
if err != nil {
return err
}

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

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

var onlineDDLShowArgs = struct {
JSON bool
OrderStr string
Expand Down Expand Up @@ -314,6 +409,8 @@ func init() {
OnlineDDL.AddCommand(OnlineDDLComplete)
OnlineDDL.AddCommand(OnlineDDLLaunch)
OnlineDDL.AddCommand(OnlineDDLRetry)
OnlineDDL.AddCommand(OnlineDDLThrottle)
OnlineDDL.AddCommand(OnlineDDLUnthrottle)

OnlineDDLShow.Flags().BoolVar(&onlineDDLShowArgs.JSON, "json", false, "Output JSON instead of human-readable table.")
OnlineDDLShow.Flags().StringVar(&onlineDDLShowArgs.OrderStr, "order", "asc", "Sort the results by `id` property of the Schema migration.")
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vtgate/planbuilder/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
"vitess.io/vitess/go/vt/vtgate/vindexes"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp"
)

Expand All @@ -40,7 +41,7 @@ func validateThrottleParams(alterMigrationType sqlparser.AlterMigrationType, exp
// Unthrottling is like throttling with duration=0
duration = 0
default:
duration = time.Hour * 24 * 365 * 100
duration = throttle.DefaultAppThrottleDuration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to the PR, but I just realized this wasn't using the default expiration, and so was not inline with all other throttle commands.

if expireString != "" {
duration, err = time.ParseDuration(expireString)
if err != nil || duration < 0 {
Expand Down