Add a function to check task existence in cdn (#570)

* 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>
This commit is contained in:
zzy987 2021-08-24 11:07:35 +08:00 committed by Gaius
parent 92ebd103e7
commit 22ad61b7f6
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
4 changed files with 29 additions and 9 deletions

View File

@ -131,10 +131,7 @@ func (s *diskStorageMgr) GC() error {
for _, taskID := range gcTaskIDs { for _, taskID := range gcTaskIDs {
synclock.Lock(taskID, false) synclock.Lock(taskID, false)
// try to ensure the taskID is not using again // try to ensure the taskID is not using again
if _, err := s.taskMgr.Get(taskID); err == nil || !cdnerrors.IsDataNotFound(err) { if s.taskMgr.Exist(taskID) {
if err != nil {
logger.GcLogger.With("type", "disk").Errorf("failed to get taskID(%s): %v", taskID, err)
}
synclock.UnLock(taskID, false) synclock.UnLock(taskID, false)
continue continue
} }

View File

@ -50,6 +50,20 @@ func (mr *MockSeedTaskMgrMockRecorder) Delete(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockSeedTaskMgr)(nil).Delete), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockSeedTaskMgr)(nil).Delete), arg0)
} }
// Exist mocks base method.
func (m *MockSeedTaskMgr) Exist(arg0 string) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Exist", arg0)
ret0, _ := ret[0].(bool)
return ret0
}
// Exist indicates an expected call of Exist.
func (mr *MockSeedTaskMgrMockRecorder) Exist(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exist", reflect.TypeOf((*MockSeedTaskMgr)(nil).Exist), arg0)
}
// Get mocks base method. // Get mocks base method.
func (m *MockSeedTaskMgr) Get(arg0 string) (*types.SeedTask, error) { func (m *MockSeedTaskMgr) Get(arg0 string) (*types.SeedTask, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -165,10 +165,6 @@ func (tm *Manager) getTask(taskID string) (*types.SeedTask, error) {
} }
return nil, err 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 // type assertion
if info, ok := v.(*types.SeedTask); ok { if info, ok := v.(*types.SeedTask); ok {
return info, nil return info, nil
@ -177,7 +173,17 @@ func (tm *Manager) getTask(taskID string) (*types.SeedTask, error) {
} }
func (tm Manager) Get(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) { func (tm Manager) GetAccessTime() (*syncmap.SyncMap, error) {

View File

@ -35,6 +35,9 @@ type SeedTaskMgr interface {
// Get get task Info with specified taskId. // Get get task Info with specified taskId.
Get(string) (*types.SeedTask, error) Get(string) (*types.SeedTask, error)
// Exist check task existence with specified taskId.
Exist(string) bool
// GetAccessTime get all tasks accessTime. // GetAccessTime get all tasks accessTime.
GetAccessTime() (*syncmap.SyncMap, error) GetAccessTime() (*syncmap.SyncMap, error)