From 8ba4a12fcdcb734a4565e70277acdd5a2fdf1c57 Mon Sep 17 00:00:00 2001 From: Gaius Date: Wed, 2 Mar 2022 20:49:59 +0800 Subject: [PATCH] feat: when peer downloads finished, peer deletes parent (#1116) Signed-off-by: Gaius --- scheduler/resource/peer.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/scheduler/resource/peer.go b/scheduler/resource/peer.go index 869237a1a74..e414b195f2f 100644 --- a/scheduler/resource/peer.go +++ b/scheduler/resource/peer.go @@ -90,9 +90,6 @@ const ( // Peer downloaded failed PeerEventDownloadFailed = "DownloadFailed" - // Peer back to initial pending state - PeerEventRestart = "Restart" - // Peer leaves PeerEventLeave = "Leave" ) @@ -173,7 +170,6 @@ func NewPeer(id string, task *Task, host *Host) *Peer { PeerStatePending, PeerStateReceivedTiny, PeerStateReceivedSmall, PeerStateReceivedNormal, PeerStateRunning, PeerStateBackToSource, PeerStateSucceeded, }, Dst: PeerStateFailed}, - {Name: PeerEventRestart, Src: []string{PeerStateSucceeded}, Dst: PeerStatePending}, {Name: PeerEventLeave, Src: []string{PeerStateFailed, PeerStateSucceeded}, Dst: PeerEventLeave}, }, fsm.Callbacks{ @@ -195,6 +191,7 @@ func NewPeer(id string, task *Task, host *Host) *Peer { }, PeerEventDownloadFromBackToSource: func(e *fsm.Event) { p.Task.BackToSourcePeers.Add(p) + p.DeleteParent() p.UpdateAt.Store(time.Now()) p.Log.Infof("peer state is %s", e.FSM.Current()) }, @@ -212,14 +209,12 @@ func NewPeer(id string, task *Task, host *Host) *Peer { p.Task.BackToSourcePeers.Delete(p) } - p.UpdateAt.Store(time.Now()) - p.Log.Infof("peer state is %s", e.FSM.Current()) - }, - PeerEventRestart: func(e *fsm.Event) { + p.DeleteParent() p.UpdateAt.Store(time.Now()) p.Log.Infof("peer state is %s", e.FSM.Current()) }, PeerEventLeave: func(e *fsm.Event) { + p.DeleteParent() p.Log.Infof("peer state is %s", e.FSM.Current()) }, },