Skip to content

Commit

Permalink
feat: when peer downloads finished, peer deletes parent (#1116)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 28, 2023
1 parent a95edf5 commit 8ba4a12
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions scheduler/resource/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ const (
// Peer downloaded failed
PeerEventDownloadFailed = "DownloadFailed"

// Peer back to initial pending state
PeerEventRestart = "Restart"

// Peer leaves
PeerEventLeave = "Leave"
)
Expand Down Expand Up @@ -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{
Expand All @@ -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())
},
Expand All @@ -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())
},
},
Expand Down

0 comments on commit 8ba4a12

Please sign in to comment.