From c59e117e5d1df3c5f9b57bf1b5f24272347464f9 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Mon, 7 Oct 2024 12:18:19 -0400 Subject: [PATCH] Minor changes from review Signed-off-by: Matt Lord --- go/vt/vtctl/workflow/server.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index c5ba9a4c729..b8eaad3e718 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -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. @@ -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") @@ -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()) } @@ -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 }