Skip to content

Commit

Permalink
fix: calculate piece MD5 sign when last piece download (dragonflyoss#…
Browse files Browse the repository at this point in the history
…1006)

* fix: calculate piece md5 sign when last piece download

Signed-off-by: sunwp <[email protected]>
  • Loading branch information
244372610 authored Jan 18, 2022
1 parent 641a65e commit ac7e8dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cdn/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"d7y.io/dragonfly/v2/pkg/rpc/base"
"d7y.io/dragonfly/v2/pkg/rpc/cdnsystem"
cdnserver "d7y.io/dragonfly/v2/pkg/rpc/cdnsystem/server"
"d7y.io/dragonfly/v2/pkg/util/digestutils"
"d7y.io/dragonfly/v2/pkg/util/hostutils"
)

Expand Down Expand Up @@ -200,14 +201,23 @@ func (css *Server) GetPieceTasks(ctx context.Context, req *base.PieceTaskRequest
count++
}
}
pieceMd5Sign := seedTask.PieceMd5Sign
if len(seedTask.Pieces) == int(seedTask.TotalPieceCount) && pieceMd5Sign == "" {
taskPieces := seedTask.Pieces
var pieceMd5s []string
for i := 0; i < len(taskPieces); i++ {
pieceMd5s = append(pieceMd5s, taskPieces[uint32(i)].PieceMd5)
}
pieceMd5Sign = digestutils.Sha256(pieceMd5s...)
}
pp := &base.PiecePacket{
TaskId: req.TaskId,
DstPid: req.DstPid,
DstAddr: fmt.Sprintf("%s:%d", css.config.AdvertiseIP, css.config.DownloadPort),
PieceInfos: pieceInfos,
TotalPiece: seedTask.TotalPieceCount,
ContentLength: seedTask.SourceFileLength,
PieceMd5Sign: seedTask.PieceMd5Sign,
PieceMd5Sign: pieceMd5Sign,
}
span.SetAttributes(constants.AttributePiecePacketResult.String(pp.String()))
return pp, nil
Expand Down
4 changes: 4 additions & 0 deletions cdn/supervisor/cdn/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (cm *manager) TriggerCDN(ctx context.Context, seedTask *task.SeedTask) (*ta
// todo source not reach error SOURCE_ERROR
updateTaskInfo = getUpdateTaskInfoWithStatusOnly(seedTask, task.StatusFailed)
}
if !updateTaskInfo.IsDone() {
seedTask.Log().Errorf("task status is not final state, current is %s", updateTaskInfo.CdnStatus)
updateTaskInfo = getUpdateTaskInfoWithStatusOnly(seedTask, task.StatusFailed)
}
err = cm.progressManager.PublishTask(ctx, seedTask.ID, updateTaskInfo)
return updateTaskInfo, err
}
Expand Down

0 comments on commit ac7e8dd

Please sign in to comment.