chore: release failed running piece (#3214)

Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
Jim Ma 2024-05-07 13:01:26 +08:00 committed by GitHub
parent 328b43268c
commit c40cba5208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 5 deletions

View File

@ -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)))
@ -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,