-
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
VReplication: Properly support cancel and delete for multi-tenant MoveTables #16906
VReplication: Properly support cancel and delete for multi-tenant MoveTables #16906
Conversation
Signed-off-by: Matt Lord <mattalord@gmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16906 +/- ##
==========================================
+ Coverage 67.13% 67.16% +0.02%
==========================================
Files 1571 1571
Lines 251868 252060 +192
==========================================
+ Hits 169091 169284 +193
+ Misses 82777 82776 -1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Matt Lord <mattalord@gmail.com>
c59e117
to
435ff92
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
399cb1f
to
ab22f0d
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
ab22f0d
to
68d28b9
Compare
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
1. Stop the workflow so that it doesn't do anymore work 2. Delete the related artifacts 3. Delete the workflow itself This allows for repeated cancel/delete attempts if the cleanup work fails to complete succesfully. Signed-off-by: Matt Lord <mattalord@gmail.com>
…es_cleanup Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
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.
Nice work! I do think it's important for flag help to be consistent. I can approve once that is fixed.
@@ -60,6 +61,7 @@ func registerCommands(root *cobra.Command) { | |||
delete.MarkFlagRequired("workflow") | |||
delete.Flags().BoolVar(&deleteOptions.KeepData, "keep-data", false, "Keep the partially copied table data from the workflow in the target keyspace.") | |||
delete.Flags().BoolVar(&deleteOptions.KeepRoutingRules, "keep-routing-rules", false, "Keep the routing rules created for the workflow.") | |||
delete.Flags().Int64Var(&deleteOptions.DeleteBatchSize, "delete-batch-size", movetables.DefaultDeleteBatchSize, "The batch size to use when deleting a subset of data from the migrated tables. This is only used with multi-tenant MoveTables workflows.") |
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.
Should this description not be consistent with that given for the same flag in moveables.go for the Cancel sub-command?
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.
Nice catch! However, this is a bit of an exception in that the context is different for MoveTables cancel
and Workflow delete
. It was intentional:
go/cmd/vtctldclient/command/vreplication/movetables/movetables.go: cancel.Flags().Int64Var(&common.CancelOptions.DeleteBatchSize, "delete-batch-size", DefaultDeleteBatchSize, "When cleaning up the migrated data in tables moved as part of a mult-tenant workflow, delete the records in batches of this size.")
go/cmd/vtctldclient/command/vreplication/workflow/workflow.go: delete.Flags().Int64Var(&deleteOptions.DeleteBatchSize, "delete-batch-size", movetables.DefaultDeleteBatchSize, "The batch size to use when deleting a subset of data from the migrated tables. This is only used with multi-tenant MoveTables workflows.")
But I'm good tweaking them if you have any suggestions or preference?
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.
I don't understand how they are different. As long as they are both consistent, either way of wording the flag help is fine.
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.
On second thought, this is somewhat misleading
The batch size to use when deleting a subset of data from the migrated tables
It makes it sound as if there's some general capability to delete a subset of data from migrated tables. So the other version is preferable.
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.
You need them to be exactly the same? That would be a little odd as MoveTables cancel
is obviously for MoveTables
. What about:
go/cmd/vtctldclient/command/vreplication/movetables/movetables.go: cancel.Flags().Int64Var(&common.CancelOptions.DeleteBatchSize, "delete-batch-size", DefaultDeleteBatchSize, "When cleaning up the migrated data in tables moved as part of a multi-tenant workflow, delete the records in batches of this size.")
go/cmd/vtctldclient/command/vreplication/workflow/workflow.go: delete.Flags().Int64Var(&deleteOptions.DeleteBatchSize, "delete-batch-size", movetables.DefaultDeleteBatchSize, "When cleaning up the migrated data in tables moved as part of a multi-tenant MoveTables workflow, delete the records in batches of this size.")
The only difference being we note that it's for a multi-tenant MoveTables workflow
in the Workflow delete
help output.
And I just realized a misspelling in there mult-tenant
that I corrected above. :)
…es_cleanup Signed-off-by: Matt Lord <mattalord@gmail.com>
if len(res) == 0 { | ||
return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "the %s workflow does not exist in the %s keyspace", req.Workflow, req.Keyspace) | ||
} |
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.
Is this check no longer necessary? Or was it redundant in the first place?
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.
We now delete the actual workflow at the end, and by this time we've already read the workflow details. Followed by cleaning up all related artifacts. And we now hold the workflow lock throughout all of it. So at this point if the workflow itself is gone that's not an error condition.
// Lock the workflow while we complete it. | ||
lockName := fmt.Sprintf("%s/%s", ts.TargetKeyspaceName(), ts.WorkflowName()) | ||
ctx, workflowUnlock, lockErr := s.ts.LockName(ctx, lockName, "MoveTablesComplete") | ||
if lockErr != nil { | ||
ts.Logger().Errorf("Locking the workflow %s failed: %v", lockName, lockErr) | ||
return nil, vterrors.Wrapf(lockErr, "failed to lock the %s workflow", lockName) | ||
} | ||
defer workflowUnlock(&err) | ||
|
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.
The locking code seems to have been moved. Is there a consistent rule that we now follow for where we lock? We seem to call each lower level function (dropSources / DropTargets / DeleteTenantData) only in one place, so in practice we acquire/release the lock once regardless of where we do it.
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.
The keyspace locks were not moved. The workflow locks were moved so that the workflow is locked while the larger operation is happening. For example we hold it throughout the WorkflowDelete
operation, which ends with deleting the workflow (and us releasing the workflow lock at the end). The keyspace locks we take only when needed and release ASAP as there's contention for those (e.g. schema changes). Remember that the workflow locks are pretty new. When I initially added them I added them in the same spot we took the keyspace locks. But on further thought, it makes sense to hold them longer. That became clear when I moved the workflow deletion to AFTER we cleanup the other related artifacts and data (where the workflow lock was previously taken and released).
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
* Document changes from vitessio/vitess#16906 Signed-off-by: Matt Lord <mattalord@gmail.com> * Bring v22 docs up-to-date with main after PR merged Signed-off-by: Matt Lord <mattalord@gmail.com> * Add two new files Signed-off-by: Matt Lord <mattalord@gmail.com> * Update v21 docs as well Signed-off-by: Matt Lord <mattalord@gmail.com> --------- Signed-off-by: Matt Lord <mattalord@gmail.com>
Description
This PR fixes #16919 by taking a different execution path when cleaning up a multi-tenant MoveTables workflow (one created with the
--tenant-id
flag):--delete-batch-size
flag forcancel
— to prevent performance issues on the target keyspace (the target is most likely serving production traffic from this table for already migrated tenants)Manual test
Results on this PR branch:
Related Issue(s)
Checklist