-
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
LookupVindex: Implement internalize
command for lookup vindexes
#17429
base: main
Are you sure you want to change the base?
Changes from 4 commits
3ab44c3
944c39c
7038c78
128198d
983a415
ee296d2
f11a0a7
f6f42ba
f63d9f3
18b7de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,14 @@ var ( | |
Keyspace string | ||
}{} | ||
|
||
internalizeOptions = struct { | ||
Keyspace string | ||
}{} | ||
|
||
completeOptions = struct { | ||
Keyspace string | ||
}{} | ||
|
||
parseAndValidateCreate = func(cmd *cobra.Command, args []string) error { | ||
if createOptions.TableName == "" { // Use vindex name | ||
createOptions.TableName = baseOptions.Name | ||
|
@@ -142,6 +150,18 @@ var ( | |
RunE: commandCancel, | ||
} | ||
|
||
// complete makes a LookupVindexComplete call to a vtctld. | ||
complete = &cobra.Command{ | ||
Use: "complete", | ||
Short: "Complete the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be deleted.", | ||
Example: `vtctldclient --server localhost:15999 LookupVindex --name corder_lookup_vdx --table-keyspace customer complete`, | ||
SilenceUsage: true, | ||
DisableFlagsInUseLine: true, | ||
Aliases: []string{"Complete"}, | ||
Args: cobra.NoArgs, | ||
RunE: commandComplete, | ||
} | ||
|
||
// create makes a LookupVindexCreate call to a vtctld. | ||
create = &cobra.Command{ | ||
Use: "create", | ||
|
@@ -158,7 +178,7 @@ var ( | |
// externalize makes a LookupVindexExternalize call to a vtctld. | ||
externalize = &cobra.Command{ | ||
Use: "externalize", | ||
Short: "Externalize the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be deleted.", | ||
Short: "Externalize the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be stopped.", | ||
Example: `vtctldclient --server localhost:15999 LookupVindex --name corder_lookup_vdx --table-keyspace customer externalize`, | ||
SilenceUsage: true, | ||
DisableFlagsInUseLine: true, | ||
|
@@ -167,6 +187,18 @@ var ( | |
RunE: commandExternalize, | ||
} | ||
|
||
// internalize makes a LookupVindexInternalize call to a vtctld. | ||
internalize = &cobra.Command{ | ||
Use: "internalize", | ||
Short: "Internalize the Lookup Vindex. If the Vindex has an owner the VReplication workflow will also be started.", | ||
Example: `vtctldclient --server localhost:15999 LookupVindex --name corder_lookup_vdx --table-keyspace customer internalize`, | ||
SilenceUsage: true, | ||
DisableFlagsInUseLine: true, | ||
Aliases: []string{"Internalize"}, | ||
Args: cobra.NoArgs, | ||
RunE: commandInternalize, | ||
} | ||
|
||
// show makes a GetWorkflows call to a vtctld. | ||
show = &cobra.Command{ | ||
Use: "show", | ||
|
@@ -199,6 +231,33 @@ func commandCancel(cmd *cobra.Command, args []string) error { | |
return nil | ||
} | ||
|
||
func commandComplete(cmd *cobra.Command, args []string) error { | ||
if completeOptions.Keyspace == "" { | ||
completeOptions.Keyspace = baseOptions.TableKeyspace | ||
} | ||
cli.FinishedParsing(cmd) | ||
|
||
resp, err := common.GetClient().LookupVindexComplete(common.GetCommandCtx(), &vtctldatapb.LookupVindexCompleteRequest{ | ||
Keyspace: completeOptions.Keyspace, | ||
// The name of the workflow and lookup vindex. | ||
Name: baseOptions.Name, | ||
// Where the lookup table and VReplication workflow were created. | ||
TableKeyspace: baseOptions.TableKeyspace, | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
output := fmt.Sprintf("LookupVindex %s has been completed", baseOptions.Name) | ||
if resp.WorkflowDeleted { | ||
output = output + fmt.Sprintf(" and the %s VReplication workflow has been deleted", baseOptions.Name) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would also be nice to note when it was NOT deleted and why as the user is likely going to want to follow-up on this at some point. Nit, but I don't think we need to specify the name yet again here, we can instead say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done 👍 |
||
fmt.Println(output) | ||
|
||
return nil | ||
} | ||
|
||
func commandCreate(cmd *cobra.Command, args []string) error { | ||
tsp := common.GetTabletSelectionPreference(cmd) | ||
cli.FinishedParsing(cmd) | ||
|
@@ -243,8 +302,35 @@ func commandExternalize(cmd *cobra.Command, args []string) error { | |
} | ||
|
||
output := fmt.Sprintf("LookupVindex %s has been externalized", baseOptions.Name) | ||
if resp.WorkflowDeleted { | ||
output = output + fmt.Sprintf(" and the %s VReplication workflow has been deleted", baseOptions.Name) | ||
if resp.WorkflowStopped { | ||
output = output + fmt.Sprintf(" and the %s VReplication workflow has been stopped", baseOptions.Name) | ||
} | ||
fmt.Println(output) | ||
|
||
return nil | ||
} | ||
|
||
func commandInternalize(cmd *cobra.Command, args []string) error { | ||
if internalizeOptions.Keyspace == "" { | ||
internalizeOptions.Keyspace = baseOptions.TableKeyspace | ||
} | ||
cli.FinishedParsing(cmd) | ||
|
||
resp, err := common.GetClient().LookupVindexInternalize(common.GetCommandCtx(), &vtctldatapb.LookupVindexInternalizeRequest{ | ||
Keyspace: internalizeOptions.Keyspace, | ||
// The name of the workflow and lookup vindex. | ||
Name: baseOptions.Name, | ||
// Where the lookup table and VReplication workflow were created. | ||
TableKeyspace: baseOptions.TableKeyspace, | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
output := fmt.Sprintf("LookupVindex %s has been internalized", baseOptions.Name) | ||
if resp.WorkflowStarted { | ||
output = output + fmt.Sprintf(" and the %s VReplication workflow has been started", baseOptions.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here from the complete command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
fmt.Println(output) | ||
|
||
|
@@ -304,12 +390,18 @@ func registerCommands(root *cobra.Command) { | |
// for the VReplication workflow used. | ||
base.AddCommand(show) | ||
|
||
// This will also delete the VReplication workflow if the | ||
// This will also stop the VReplication workflow if the | ||
// vindex has an owner as the lookup vindex will then be | ||
// managed by VTGate. | ||
externalize.Flags().StringVar(&externalizeOptions.Keyspace, "keyspace", "", "The keyspace containing the Lookup Vindex. If no value is specified then the table-keyspace will be used.") | ||
base.AddCommand(externalize) | ||
|
||
internalize.Flags().StringVar(&internalizeOptions.Keyspace, "keyspace", "", "The keyspace containing the Lookup Vindex. If no value is specified then the table-keyspace will be used.") | ||
base.AddCommand(internalize) | ||
|
||
complete.Flags().StringVar(&completeOptions.Keyspace, "keyspace", "", "The keyspace containing the Lookup Vindex. If no value is specified then the table-keyspace will be used.") | ||
base.AddCommand(complete) | ||
|
||
// The cancel command deletes the VReplication workflow used | ||
// to backfill the lookup vindex. It ends up making a | ||
// WorkflowDelete VtctldServer call. | ||
|
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.
Would it be challenging or problematic to add a
--delete
flag for externalize for those that want to retain the old behavior? Then we can continue using theWorkflowDeleted
response field too.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.
done 👍