fix: unregister task from scheduler in storage.deleteTask (#2100)

On graceful shutdown we will call forceGC() to delete all cached tasks
if 'keepStorage' is false. And we rely on deleteTask() to delete the
given task from both local storage and scheduler.

But commit 86a6030c8f ("feat: unregister failed task storage (#1717)")
changed MarkReclaim() to MarkInvalid() in deleteTask(), and resulted in
task leak in scheduler.

Fix it by calling MarkReclaim() in deleteTask().

Fixes: 86a6030c8f ("feat: unregister failed task storage (#1717)")

Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
This commit is contained in:
Eryu Guan 2023-02-21 17:07:21 +08:00 committed by Gaius
parent f8098799c7
commit 3352deff39
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 3 additions and 1 deletions

View File

@ -886,6 +886,7 @@ func (s *storageManager) TryGC() (bool, error) {
return true, nil
}
// delete the given task from local storage and unregister it from scheduler.
func (s *storageManager) deleteTask(meta PeerTaskMetadata) error {
task, ok := s.LoadAndDeleteTask(meta)
if !ok {
@ -899,7 +900,8 @@ func (s *storageManager) deleteTask(meta PeerTaskMetadata) error {
} else {
s.cleanSubIndex(meta.TaskID, meta.PeerID)
}
task.(Reclaimer).MarkInvalid()
// MarkReclaim() will call gcCallback, which will unregister task from scheduler
task.(Reclaimer).MarkReclaim()
return task.(Reclaimer).Reclaim()
}