From c40cba5208d7e9568edabfff992f6198448cb596 Mon Sep 17 00:00:00 2001 From: Jim Ma Date: Tue, 7 May 2024 13:01:26 +0800 Subject: [PATCH] chore: release failed running piece (#3214) Signed-off-by: Jim Ma --- client/daemon/peer/peertask_conductor.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/daemon/peer/peertask_conductor.go b/client/daemon/peer/peertask_conductor.go index 49009e6cb..baff9032f 100644 --- a/client/daemon/peer/peertask_conductor.go +++ b/client/daemon/peer/peertask_conductor.go @@ -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,