Skip to content

Commit

Permalink
feat: delete the host after host leave peers during host manager gc
Browse files Browse the repository at this point in the history
Signed-off-by: BruceAko <[email protected]>
  • Loading branch information
BruceAko committed Jul 5, 2024
1 parent 8153e57 commit 2ed4d07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions scheduler/resource/host_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (h *hostManager) RunGC() error {
if host.AnnounceInterval > 0 && elapsed > host.AnnounceInterval*2 {
host.Log.Info("host elapsed exceeds twice the announce interval, causing the host to leave peers")
host.LeavePeers()
// Directly reclaim the host,
// as host's ConcurrentUploadCount may not be 0 when the host exits abnormally.
host.Log.Info("host has been reclaimed")
h.Delete(host.ID)
return true
}

Expand Down
5 changes: 2 additions & 3 deletions scheduler/resource/host_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ func TestHostManager_RunGC(t *testing.T) {
return true
})

host, loaded := hostManager.Load(mockHost.ID)
assert.Equal(loaded, true)
assert.Equal(host.ID, mockHost.ID)
_, loaded := hostManager.Load(mockHost.ID)
assert.Equal(loaded, false)
},
},
}
Expand Down

0 comments on commit 2ed4d07

Please sign in to comment.