From 49ba8ffebf3626440e9ad77184efb48a8159781b Mon Sep 17 00:00:00 2001 From: jaime Date: Wed, 11 Dec 2024 17:46:06 +0800 Subject: [PATCH] fix: sync task still running after DataNode has stopped Signed-off-by: jaime --- internal/datanode/syncmgr/sync_manager.go | 3 +++ internal/datanode/syncmgr/sync_manager_test.go | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/datanode/syncmgr/sync_manager.go b/internal/datanode/syncmgr/sync_manager.go index 3c1896400fb1a..84915f4575797 100644 --- a/internal/datanode/syncmgr/sync_manager.go +++ b/internal/datanode/syncmgr/sync_manager.go @@ -47,6 +47,9 @@ type SyncMeta struct { type SyncManager interface { // SyncData is the method to submit sync task. SyncData(ctx context.Context, task Task, callbacks ...func(error) error) (*conc.Future[struct{}], error) + + // Close waits for the task to finish and then shuts down the sync manager. + Close() error } type syncManager struct { diff --git a/internal/datanode/syncmgr/sync_manager_test.go b/internal/datanode/syncmgr/sync_manager_test.go index d2908b923e844..919ec39dad129 100644 --- a/internal/datanode/syncmgr/sync_manager_test.go +++ b/internal/datanode/syncmgr/sync_manager_test.go @@ -285,7 +285,8 @@ func (s *SyncManagerSuite) TestUnexpectedError() { task.EXPECT().Run().Return(merr.WrapErrServiceInternal("mocked")).Once() task.EXPECT().HandleError(mock.Anything) - f, _ := manager.SyncData(context.Background(), task) + f, err := manager.SyncData(context.Background(), task) + s.NoError(err) _, err = f.Await() s.Error(err) } @@ -300,7 +301,9 @@ func (s *SyncManagerSuite) TestTargetUpdateSameID() { task.EXPECT().Run().Return(errors.New("mock err")).Once() task.EXPECT().HandleError(mock.Anything) - f, _ := manager.SyncData(context.Background(), task) + f, err := manager.SyncData(context.Background(), task) + s.NoError(err) + _, err = f.Await() s.Error(err) }