From 268ea0477d85bfecacb2c4c85065b1fbb25372c6 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 30 May 2019 13:58:46 +0800 Subject: [PATCH] ddl: address comments --- ddl/ddl_worker.go | 5 +++++ ddl/syncer.go | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index 558eb10a5cfe8..98788084dcbd0 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -631,6 +631,11 @@ func (w *worker) waitSchemaChanged(ctx context.Context, d *ddlCtx, waitTime time return } d.schemaSyncer.NotifyCleanExpiredPaths() + // Wait until timeout. + select { + case <-ctx.Done(): + return + } } logutil.Logger(w.logCtx).Info("[ddl] wait latest schema version changed", zap.Int64("ver", latestSchemaVersion), zap.Duration("takeTime", time.Since(timeStart)), zap.String("job", job.String())) } diff --git a/ddl/syncer.go b/ddl/syncer.go index 495ccbe316eb4..e832ee37aa3aa 100644 --- a/ddl/syncer.go +++ b/ddl/syncer.go @@ -428,8 +428,7 @@ func (s *schemaVersionSyncer) StartCleanWork() { continue } - isFinished := s.doCleanExpirePaths(resp.Leases) - if isFinished { + if isFinished := s.doCleanExpirePaths(resp.Leases); isFinished { break } time.Sleep(opRetryInterval) @@ -458,7 +457,6 @@ func (s *schemaVersionSyncer) NotifyCleanExpiredPaths() { } func (s *schemaVersionSyncer) doCleanExpirePaths(leases []clientv3.LeaseStatus) bool { - ctx := context.Background() failedGetIDs := 0 failedRevokeIDs := 0 startTime := time.Now() @@ -471,7 +469,7 @@ func (s *schemaVersionSyncer) doCleanExpirePaths(leases []clientv3.LeaseStatus) // The DDL owner key uses '%x', so here print it too. leaseID := fmt.Sprintf("%x, %d", lease.ID, lease.ID) childCtx, cancelFunc := context.WithTimeout(context.Background(), opDefaultTimeout) - ttlResp, err := s.etcdCli.TimeToLive(ctx, lease.ID) + ttlResp, err := s.etcdCli.TimeToLive(childCtx, lease.ID) cancelFunc() if err != nil { logutil.Logger(ddlLogCtx).Info("[ddl] syncer clean expired paths, failed to get TTL.", zap.String("leaseID", leaseID), zap.Error(err))