fix: scheduler success event (#891)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2021-12-08 10:33:56 +08:00
parent dc50bd31d5
commit 04a3550925
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 21 additions and 20 deletions

View File

@ -175,27 +175,28 @@ func (e peerDownloadPieceSuccessEvent) apply(s *state) {
var candidates []*supervisor.Peer
parentPeer, ok := s.peerManager.Get(e.pr.DstPid)
if ok {
if parentPeer.IsLeave() {
e.peer.Log().Warnf("peerDownloadPieceSuccessEvent: need reschedule parent for peer because it's parent is already left")
e.peer.ReplaceParent(nil)
var hasParent bool
parentPeer, candidates, hasParent = s.sched.ScheduleParent(e.peer, sets.NewString(parentPeer.ID))
if !hasParent {
e.peer.Log().Warnf("peerDownloadPieceSuccessEvent: no parent node is currently available, " +
"reschedule it later")
s.waitScheduleParentPeerQueue.AddAfter(&rsPeer{peer: e.peer, blankParents: sets.NewString(parentPeer.ID)}, time.Second)
return
}
}
if oldParent, ok := e.peer.GetParent(); e.pr.DstPid != e.peer.ID && (!ok || oldParent.ID != e.pr.DstPid) {
logger.WithTaskAndPeerID(e.peer.Task.ID, e.peer.ID).Debugf("parent peerID is not same as DestPid, replace it's parent node with %s",
e.pr.DstPid)
e.peer.ReplaceParent(parentPeer)
}
} else {
if !ok {
e.peer.Log().Warnf("parent peer %s not found", e.pr.DstPid)
return
}
if parentPeer.IsLeave() {
e.peer.Log().Warnf("peerDownloadPieceSuccessEvent: need reschedule parent for peer because it's parent is already left")
e.peer.ReplaceParent(nil)
var hasParent bool
parentPeer, candidates, hasParent = s.sched.ScheduleParent(e.peer, sets.NewString(parentPeer.ID))
if !hasParent {
e.peer.Log().Warnf("peerDownloadPieceSuccessEvent: no parent node is currently available, " +
"reschedule it later")
s.waitScheduleParentPeerQueue.AddAfter(&rsPeer{peer: e.peer, blankParents: sets.NewString(parentPeer.ID)}, time.Second)
return
}
}
if oldParent, ok := e.peer.GetParent(); e.pr.DstPid != e.peer.ID && (!ok || oldParent.ID != e.pr.DstPid) {
logger.WithTaskAndPeerID(e.peer.Task.ID, e.peer.ID).Debugf("parent peerID is not same as DestPid, replace it's parent node with %s",
e.pr.DstPid)
e.peer.ReplaceParent(parentPeer)
}
parentPeer.Touch()