Skip to content

Commit

Permalink
Minor changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Oct 7, 2024
1 parent d1a7412 commit c59e117
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2140,13 +2140,15 @@ func (s *Server) WorkflowDelete(ctx context.Context, req *vtctldatapb.WorkflowDe
return nil
}

// Multi-tenant migrations delete from the target table in batches and we may not
// be able to complete that work before the timeout. So we only delete the workflow
// after the cleanup work completes successfully so that the workflow can be
// cancelled multiple times if needed.
// Multi-tenant migrations delete only that tenant's records from the target tables
// in batches and we may not be able to complete that work before the timeout. So
// we only delete the workflow after the cleanup work completes successfully so that
// the workflow can be cancelled multiple times if needed in order to full cleanup
// all of the tenant's data that we had copied.
if ts.IsMultiTenantMigration() {
if ts.workflowType != binlogdatapb.VReplicationWorkflowType_MoveTables { // Should never happen
return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "unsupported workflow type %q for multi-tenant migration", ts.workflowType)
return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "unsupported workflow type %q for multi-tenant migration",
ts.workflowType)
}
// We need to delete the rows that the target tables would have for the tenant.
// We don't cleanup other related artifacts since they are not tied to the tenant.
Expand Down Expand Up @@ -2741,7 +2743,8 @@ func (s *Server) DeleteTenantData(ctx context.Context, ts *trafficSwitcher) erro
sw = &switcher{ts: ts, s: s}
)
if ts.workflowType != binlogdatapb.VReplicationWorkflowType_MoveTables {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "unsupported workflow type %q for multi-tenant migration", ts.workflowType)
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "unsupported workflow type %q for multi-tenant migration",
ts.workflowType)
}
if ts.options == nil || strings.TrimSpace(ts.options.TenantId) == "" {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "missing tenant ID in the workflow options")
Expand All @@ -2757,7 +2760,12 @@ func (s *Server) DeleteTenantData(ctx context.Context, ts *trafficSwitcher) erro
return vterrors.Wrapf(lockErr, "failed to lock the %s workflow", lockName)
}
defer workflowUnlock(&err)
lockCtx, targetUnlock, lockErr := sw.lockKeyspace(ctx, ts.TargetKeyspaceName(), "DeleteTenantData")
deadline, ok := ctx.Deadline()
if !ok { // Should never happen
return vterrors.New(vtrpcpb.Code_INTERNAL, "missing deadline in the context")
}
lockCtx, targetUnlock, lockErr := sw.lockKeyspace(ctx, ts.TargetKeyspaceName(), "DeleteTenantData",
topo.WithTTL(time.Duration(deadline.UnixNano())))
if lockErr != nil {
return vterrors.Wrapf(lockErr, "failed to lock the %s keyspace", ts.TargetKeyspaceName())
}
Expand Down Expand Up @@ -2818,10 +2826,11 @@ func (s *Server) DeleteTenantData(ctx context.Context, ts *trafficSwitcher) erro
query := sqlparser.String(del)
log.Errorf("DEBUG: delete query for tenant %s: %s", ts.options.TenantId, sqlparser.String(del))
for {
res, err := s.tmc.ExecuteFetchAsAllPrivs(ctx, target.GetPrimary().Tablet, &tabletmanagerdatapb.ExecuteFetchAsAllPrivsRequest{
Query: []byte(query),
DbName: target.primary.DbName(),
})
res, err := s.tmc.ExecuteFetchAsAllPrivs(ctx, target.GetPrimary().Tablet,
&tabletmanagerdatapb.ExecuteFetchAsAllPrivsRequest{
Query: []byte(query),
DbName: target.primary.DbName(),
})
if err != nil {
return err
}
Expand Down

0 comments on commit c59e117

Please sign in to comment.