Skip to content

Commit

Permalink
fix: client miss failed piece (#1194)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma authored and gaius-qi committed Jun 28, 2023
1 parent 1939cef commit d45bffe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ loop:
break loop
}

pt.Debugf("receive peerPacket %v for peer %s", peerPacket, pt.peerID)
pt.Debugf("receive peerPacket %v", peerPacket)
if peerPacket.Code != base.Code_Success {
if peerPacket.Code == base.Code_SchedNeedBackSource {
pt.needBackSource.Store(true)
Expand Down Expand Up @@ -783,6 +783,7 @@ loop:
default:
}

retry:
// 2, try to get pieces
pt.Debugf("try to get pieces, number: %d, limit: %d", num, limit)
piecePacket, err := pt.pieceTaskPoller.preparePieceTasks(
Expand Down Expand Up @@ -823,6 +824,7 @@ loop:
}
// just need one piece
limit = 1
goto retry
}
}

Expand Down Expand Up @@ -978,6 +980,7 @@ func (pt *peerTaskConductor) waitFailedPiece() (int32, bool) {
if pt.isCompleted() {
return -1, false
}
wait:
// use no default branch select to wait failed piece or exit
select {
case <-pt.successCh:
Expand All @@ -989,6 +992,17 @@ func (pt *peerTaskConductor) waitFailedPiece() (int32, bool) {
case failed := <-pt.failedPieceCh:
pt.Warnf("download piece/%d failed, retry", failed)
return failed, true
case _, ok := <-pt.peerPacketReady:
if ok {
// preparePieceTasksByPeer func already send piece result with error
pt.Infof("new peer client ready, but all pieces are already downloading, just wait failed pieces")
goto wait
}
// when scheduler says base.Code_SchedNeedBackSource, receivePeerPacket will close pt.peerPacketReady
pt.Infof("start download from source due to base.Code_SchedNeedBackSource")
pt.span.AddEvent("back source due to scheduler says need back source")
pt.backSource()
return -1, false
}
}

Expand Down Expand Up @@ -1056,6 +1070,7 @@ func (pt *peerTaskConductor) downloadPiece(workerID int32, request *DownloadPiec
StartNum: uint32(request.piece.PieceNum),
Limit: 1,
})
// Deprecated
// send to fail chan and retry
// try to send directly first, if failed channel is busy, create a new goroutine to do this
select {
Expand Down

0 comments on commit d45bffe

Please sign in to comment.