Skip to content

Commit

Permalink
fix: small size task failed due to digest error (#886)
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 6866ecc commit 5b016d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client/daemon/peer/peertask_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
dfclient "d7y.io/dragonfly/v2/pkg/rpc/dfdaemon/client"
"d7y.io/dragonfly/v2/pkg/rpc/scheduler"
schedulerclient "d7y.io/dragonfly/v2/pkg/rpc/scheduler/client"
"d7y.io/dragonfly/v2/pkg/util/digestutils"
)

const (
Expand Down Expand Up @@ -347,7 +348,7 @@ func (pt *peerTask) pullSinglePiece(cleanUnfinishedFunc func()) {

pt.contentLength.Store(int64(pt.singlePiece.PieceInfo.RangeSize))
pt.SetTotalPieces(1)
pt.SetPieceMd5Sign(pt.singlePiece.PieceInfo.PieceMd5)
pt.SetPieceMd5Sign(digestutils.Sha256(pt.singlePiece.PieceInfo.PieceMd5))
if err := pt.callback.Init(pt); err != nil {
pt.failedReason = err.Error()
pt.failedCode = base.Code_ClientError
Expand Down
2 changes: 1 addition & 1 deletion client/daemon/peer/piece_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func (pm *pieceManager) DownloadSource(ctx context.Context, pt Task, request *sc
// last piece, piece size maybe 0
if n < int64(size) {
contentLength = int64(pieceNum)*int64(pieceSize) + n
pt.SetTotalPieces(int32(math.Ceil(float64(contentLength) / float64(pieceSize))))
if err := pm.storageManager.UpdateTask(ctx,
&storage.UpdateTaskRequest{
PeerTaskMetadata: storage.PeerTaskMetadata{
Expand All @@ -416,7 +417,6 @@ func (pm *pieceManager) DownloadSource(ctx context.Context, pt Task, request *sc
}); err != nil {
log.Errorf("update task failed %s", err)
}
pt.SetTotalPieces(pieceNum + 1)
return pt.SetContentLength(contentLength)
}
}
Expand Down

0 comments on commit 5b016d9

Please sign in to comment.