-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 OnlineDDL show support #13738
Merged
ajm188
merged 26 commits into
vitessio:main
from
planetscale:andrew/vtctldserver-onlineddl-show
Aug 21, 2023
Merged
Add OnlineDDL show support #13738
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4da799d
Add OnlineDDL show support
b2bf58f
finish defining SchemaMigrations protobuf message
2a11c41
commentary
d67a012
named row, so nice
3bdfb6f
unit test row conversion
3a68dbc
minor tweaks
98f6fcf
unit tests
d11adfd
update help text
c13e65f
fix indentation
bcc4dac
add additional sqltypes constructors
3f3ede7
add reflection-based marshalling of structs into result objects
1c8df07
wrap schemamigration to marshal it
eec7f87
better NULL handling
73c485a
support marshalling multiple migrations into one result
8ab6696
add SQL table format
3addca0
Merge branch 'main' into andrew/vtctldserver-onlineddl-show
d37da34
show takes at least one arg
495ee03
update flag testdata
56271d2
PR feedback (nitpicks and wordings)
ef39e58
PR feedback (TODO comments)
9472588
concurrent fetches
0677d9c
remove unsafe cast
22d6c13
nit
370aa09
remove deprecation warnings that are unneeded
8e58aec
standard ghost/ptosc names
0785e2c
fix marshal to handle null_type
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
Copyright 2023 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" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/vtctldclient/cli" | ||
"vitess.io/vitess/go/protoutil" | ||
"vitess.io/vitess/go/sqltypes" | ||
"vitess.io/vitess/go/vt/schema" | ||
"vitess.io/vitess/go/vt/vtctl/schematools" | ||
|
||
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" | ||
) | ||
|
||
var ( | ||
OnlineDDL = &cobra.Command{ | ||
Use: "OnlineDDL <cmd> <keyspace> [args]", | ||
Short: "Operates on online DDL (schema migrations).", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.MinimumNArgs(2), | ||
} | ||
OnlineDDLShow = &cobra.Command{ | ||
Use: "show", | ||
Short: "Display information about online DDL operations.", | ||
Example: `OnlineDDL show test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90 | ||
OnlineDDL show test_keyspace all | ||
OnlineDDL show --order descending test_keyspace all | ||
OnlineDDL show --limit 10 test_keyspace all | ||
OnlineDDL show --skip 5 --limit 10 test_keyspace all | ||
OnlineDDL show test_keyspace running | ||
OnlineDDL show test_keyspace complete | ||
OnlineDDL show test_keyspace failed`, | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.RangeArgs(1, 2), | ||
RunE: commandOnlineDDLShow, | ||
} | ||
) | ||
|
||
var onlineDDLShowArgs = struct { | ||
JSON bool | ||
OrderStr string | ||
Limit uint64 | ||
Skip uint64 | ||
}{ | ||
OrderStr: "ascending", | ||
} | ||
|
||
func commandOnlineDDLShow(cmd *cobra.Command, args []string) error { | ||
var order vtctldatapb.QueryOrdering | ||
switch strings.ToLower(onlineDDLShowArgs.OrderStr) { | ||
case "": | ||
order = vtctldatapb.QueryOrdering_NONE | ||
case "asc", "ascending": | ||
order = vtctldatapb.QueryOrdering_ASCENDING | ||
case "desc", "descending": | ||
order = vtctldatapb.QueryOrdering_DESCENDING | ||
default: | ||
return fmt.Errorf("invalid ordering %s (choices are 'asc', 'ascending', 'desc', 'descending')", onlineDDLShowArgs.OrderStr) | ||
} | ||
|
||
cli.FinishedParsing(cmd) | ||
|
||
req := &vtctldatapb.GetSchemaMigrationsRequest{ | ||
Keyspace: cmd.Flags().Arg(0), | ||
Order: order, | ||
Limit: onlineDDLShowArgs.Limit, | ||
Skip: onlineDDLShowArgs.Skip, | ||
} | ||
|
||
switch arg := cmd.Flags().Arg(1); arg { | ||
case "", "all": | ||
case "recent": | ||
req.Recent = protoutil.DurationToProto(7 * 24 * time.Hour) | ||
default: | ||
if status, err := schematools.ParseSchemaMigrationStatus(arg); err == nil { | ||
// Argument is a status name. | ||
req.Status = status | ||
} else if schema.IsOnlineDDLUUID(arg) { | ||
req.Uuid = arg | ||
} else { | ||
req.MigrationContext = arg | ||
} | ||
} | ||
|
||
resp, err := client.GetSchemaMigrations(commandCtx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch { | ||
case onlineDDLShowArgs.JSON: | ||
data, err := cli.MarshalJSON(resp) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s\n", data) | ||
default: | ||
res, err := sqltypes.MarshalResult(schematools.MarshallableSchemaMigrations(resp.Migrations)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.WriteQueryResultTable(os.Stdout, res) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
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.") | ||
OnlineDDLShow.Flags().Uint64Var(&onlineDDLShowArgs.Limit, "limit", 0, "Limit number of rows returned in output.") | ||
OnlineDDLShow.Flags().Uint64Var(&onlineDDLShowArgs.Skip, "skip", 0, "Skip specified number of rows returned in output.") | ||
|
||
OnlineDDL.AddCommand(OnlineDDLShow) | ||
Root.AddCommand(OnlineDDL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately cobra won't support a positional argument before the subcommand name (or at least i couldn't see an easy/obvious way)