Skip to content

Commit

Permalink
chore: release failed running piece (#3214)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma committed May 7, 2024
1 parent 328b432 commit c40cba5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,16 @@ func (pt *peerTaskConductor) downloadPiece(workerID int32, request *DownloadPiec
pt.runningPieces.Set(request.piece.PieceNum)
pt.runningPiecesLock.Unlock()

defer func() {
pt.runningPiecesLock.Lock()
pt.runningPieces.Clean(request.piece.PieceNum)
pt.runningPiecesLock.Unlock()
}()
var cleanRunningPieceDone bool
cleanRunningPiece := func() {
if cleanRunningPieceDone {
cleanRunningPieceDone = true
pt.runningPiecesLock.Lock()
pt.runningPieces.Clean(request.piece.PieceNum)
pt.runningPiecesLock.Unlock()
}
}
defer cleanRunningPiece()

ctx, span := tracer.Start(pt.pieceDownloadCtx, fmt.Sprintf(config.SpanDownloadPiece, request.piece.PieceNum))
span.SetAttributes(config.AttributePiece.Int(int(request.piece.PieceNum)))
Expand All @@ -1117,6 +1122,9 @@ func (pt *peerTaskConductor) downloadPiece(workerID int32, request *DownloadPiec
pt.Infof("switch to back source, skip send failed piece")
return result
}

// clean running piece first
cleanRunningPiece()
attempt, success := pt.pieceTaskSyncManager.acquire(
&commonv1.PieceTaskRequest{
Limit: 1,
Expand Down

0 comments on commit c40cba5

Please sign in to comment.