Skip to content

Commit

Permalink
refactor: scheduler end and begin of piece (#1189)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 28, 2023
1 parent 9d41cee commit 1939cef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ func (pt *peerTaskConductor) done() {

// send EOF piece result to scheduler
err := pt.peerPacketStream.Send(
scheduler.NewEndPieceResult(pt.taskID, pt.peerID, pt.readyPieces.Settled()))
schedulerclient.NewEndOfPiece(pt.taskID, pt.peerID, pt.readyPieces.Settled()))
pt.Debugf("end piece result sent: %v, peer task finished", err)

err = pt.schedulerClient.ReportPeerResult(
Expand Down Expand Up @@ -1362,7 +1362,7 @@ func (pt *peerTaskConductor) fail() {

// send EOF piece result to scheduler
err := pt.peerPacketStream.Send(
scheduler.NewEndPieceResult(pt.taskID, pt.peerID, pt.readyPieces.Settled()))
schedulerclient.NewEndOfPiece(pt.taskID, pt.peerID, pt.readyPieces.Settled()))
pt.Debugf("end piece result sent: %v, peer task finished", err)

ctx := trace.ContextWithSpan(context.Background(), trace.SpanFromContext(pt.ctx))
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/scheduler/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (sc *schedulerClient) ReportPieceResult(ctx context.Context, taskID string,
logger.With("peerId", ptr.PeerId, "errMsg", err).Infof("start to report piece result for taskID: %s", taskID)

// trigger scheduling
return pps, pps.Send(scheduler.NewZeroPieceResult(taskID, ptr.PeerId))
return pps, pps.Send(NewBeginOfPiece(taskID, ptr.PeerId))
}

func (sc *schedulerClient) ReportPeerResult(ctx context.Context, pr *scheduler.PeerResult, opts ...grpc.CallOption) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,31 @@
* limitations under the License.
*/

package scheduler
package client

import (
"d7y.io/dragonfly/v2/pkg/rpc/base"
"d7y.io/dragonfly/v2/pkg/rpc/base/common"
"d7y.io/dragonfly/v2/pkg/rpc/scheduler"
)

func NewZeroPieceResult(taskID, peerID string) *PieceResult {
return &PieceResult{
func NewBeginOfPiece(taskID, peerID string) *scheduler.PieceResult {
return &scheduler.PieceResult{
TaskId: taskID,
SrcPid: peerID,
PieceInfo: &base.PieceInfo{
PieceNum: common.BeginOfPiece,
RangeStart: 0,
RangeSize: 0,
PieceMd5: "",
PieceOffset: 0,
PieceStyle: 0,
PieceNum: common.BeginOfPiece,
},
}
}

func NewEndPieceResult(taskID, peerID string, finishedCount int32) *PieceResult {
return &PieceResult{
func NewEndOfPiece(taskID, peerID string, finishedCount int32) *scheduler.PieceResult {
return &scheduler.PieceResult{
TaskId: taskID,
SrcPid: peerID,
FinishedCount: finishedCount,
PieceInfo: &base.PieceInfo{
PieceNum: common.EndOfPiece,
RangeStart: 0,
RangeSize: 0,
PieceMd5: "",
PieceOffset: 0,
PieceStyle: 0,
PieceNum: common.EndOfPiece,
},
}
}

0 comments on commit 1939cef

Please sign in to comment.