diff --git a/internal/datacoord/garbage_collector.go b/internal/datacoord/garbage_collector.go index 2fb177d1d5..c6ca192c22 100644 --- a/internal/datacoord/garbage_collector.go +++ b/internal/datacoord/garbage_collector.go @@ -174,7 +174,7 @@ func (gc *garbageCollector) work(ctx context.Context) { } // startControlLoop start a control loop for garbageCollector. -func (gc *garbageCollector) startControlLoop(ctx context.Context) { +func (gc *garbageCollector) startControlLoop(_ context.Context) { for { select { case cmd := <-gc.cmdCh: @@ -203,7 +203,7 @@ func (gc *garbageCollector) startControlLoop(ctx context.Context) { // runRecycleTaskWithPauser is a helper function to create a task with pauser func (gc *garbageCollector) runRecycleTaskWithPauser(ctx context.Context, name string, interval time.Duration, task func(ctx context.Context)) { logger := log.With(zap.String("gcType", name)).With(zap.Duration("interval", interval)) - timer := time.NewTimer(interval) + timer := time.NewTicker(interval) defer timer.Stop() for { diff --git a/internal/datacoord/garbage_collector_test.go b/internal/datacoord/garbage_collector_test.go index a33b258d16..e6ed9878f5 100644 --- a/internal/datacoord/garbage_collector_test.go +++ b/internal/datacoord/garbage_collector_test.go @@ -1614,6 +1614,26 @@ func (s *GarbageCollectorSuite) TestPauseResume() { }) } +func (s *GarbageCollectorSuite) TestRunRecycleTaskWithPauser() { + gc := newGarbageCollector(s.meta, newMockHandler(), GcOption{ + cli: s.cli, + enabled: true, + checkInterval: time.Millisecond * 10, + scanInterval: time.Hour * 7 * 24, + missingTolerance: time.Hour * 24, + dropTolerance: time.Hour * 24, + }) + + ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*2500) + defer cancel() + + cnt := 0 + gc.runRecycleTaskWithPauser(ctx, "test", time.Second, func(ctx context.Context) { + cnt++ + }) + s.Equal(cnt, 2) +} + func TestGarbageCollector(t *testing.T) { suite.Run(t, new(GarbageCollectorSuite)) }