Skip to content

Commit

Permalink
Add a function to check task existence in cdn (#570)
Browse files Browse the repository at this point in the history
* fix: replace get with exist in gc

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* fix: no error in the if branch

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* fix: move accessTimeMap.Add from getTask into Get

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* fix: change return value

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* fix: remove log error for Exist don't return error

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* chore: use mockgen

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>

* chore: merge submodule

Signed-off-by: zzy987 <67889264+zzy987@users.noreply.github.com>
  • Loading branch information
zzy987 authored Aug 24, 2021
1 parent 2621b5e commit f180bd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
5 changes: 1 addition & 4 deletions cdnsystem/supervisor/cdn/storage/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ func (s *diskStorageMgr) GC() error {
for _, taskID := range gcTaskIDs {
synclock.Lock(taskID, false)
// try to ensure the taskID is not using again
if _, err := s.taskMgr.Get(taskID); err == nil || !cdnerrors.IsDataNotFound(err) {
if err != nil {
logger.GcLogger.With("type", "disk").Errorf("failed to get taskID(%s): %v", taskID, err)
}
if s.taskMgr.Exist(taskID) {
synclock.UnLock(taskID, false)
continue
}
Expand Down
14 changes: 14 additions & 0 deletions cdnsystem/supervisor/mock/mock_task_mgr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions cdnsystem/supervisor/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ func (tm *Manager) getTask(taskID string) (*types.SeedTask, error) {
}
return nil, err
}
// update accessTime for taskID
if err := tm.accessTimeMap.Add(taskID, time.Now()); err != nil {
logger.WithTaskID(taskID).Warnf("failed to update accessTime: %v", err)
}
// type assertion
if info, ok := v.(*types.SeedTask); ok {
return info, nil
Expand All @@ -177,7 +173,17 @@ func (tm *Manager) getTask(taskID string) (*types.SeedTask, error) {
}

func (tm Manager) Get(taskID string) (*types.SeedTask, error) {
return tm.getTask(taskID)
task, err := tm.getTask(taskID)
// update accessTime for taskID
if err := tm.accessTimeMap.Add(taskID, time.Now()); err != nil {
logger.WithTaskID(taskID).Warnf("failed to update accessTime: %v", err)
}
return task, err
}

func (tm Manager) Exist(taskID string) bool {
_, err := tm.taskStore.Get(taskID)
return err == nil || !cdnerrors.IsDataNotFound(err)
}

func (tm Manager) GetAccessTime() (*syncmap.SyncMap, error) {
Expand Down
3 changes: 3 additions & 0 deletions cdnsystem/supervisor/task_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type SeedTaskMgr interface {
// Get get task Info with specified taskId.
Get(string) (*types.SeedTask, error)

// Exist check task existence with specified taskId.
Exist(string) bool

// GetAccessTime get all tasks accessTime.
GetAccessTime() (*syncmap.SyncMap, error)

Expand Down

0 comments on commit f180bd1

Please sign in to comment.