Skip to content

Commit

Permalink
feat: reduce the scheduler return content of the parent (#3349)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi authored Jun 27, 2024
1 parent 4aa12f8 commit aacf7e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 82 deletions.
52 changes: 0 additions & 52 deletions scheduler/scheduling/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,32 +593,6 @@ func ConstructSuccessNormalTaskResponse(candidateParents []*resource.Peer) *sche
}
}

// Set pieces to parent.
candidateParent.Pieces.Range(func(key, value any) bool {
candidateParentPiece, ok := value.(*resource.Piece)
if !ok {
candidateParent.Log.Errorf("invalid piece %s %#v", key, value)
return true
}

piece := &commonv2.Piece{
Number: uint32(candidateParentPiece.Number),
ParentId: &candidateParentPiece.ParentID,
Offset: candidateParentPiece.Offset,
Length: candidateParentPiece.Length,
TrafficType: &candidateParentPiece.TrafficType,
Cost: durationpb.New(candidateParentPiece.Cost),
CreatedAt: timestamppb.New(candidateParentPiece.CreatedAt),
}

if candidateParentPiece.Digest != nil {
piece.Digest = candidateParentPiece.Digest.String()
}

parent.Pieces = append(parent.Pieces, piece)
return true
})

// Set task to parent.
parent.Task = &commonv2.Task{
Id: candidateParent.Task.ID,
Expand All @@ -644,32 +618,6 @@ func ConstructSuccessNormalTaskResponse(candidateParents []*resource.Peer) *sche
parent.Task.Digest = &dgst
}

// Set pieces to parent task.
candidateParent.Task.Pieces.Range(func(key, value any) bool {
taskPiece, ok := value.(*resource.Piece)
if !ok {
candidateParent.Task.Log.Errorf("invalid piece %s %#v", key, value)
return true
}

piece := &commonv2.Piece{
Number: uint32(taskPiece.Number),
ParentId: &taskPiece.ParentID,
Offset: taskPiece.Offset,
Length: taskPiece.Length,
TrafficType: &taskPiece.TrafficType,
Cost: durationpb.New(taskPiece.Cost),
CreatedAt: timestamppb.New(taskPiece.CreatedAt),
}

if taskPiece.Digest != nil {
piece.Digest = taskPiece.Digest.String()
}

parent.Task.Pieces = append(parent.Task.Pieces, piece)
return true
})

// Set host to parent.
parent.Host = &commonv2.Host{
Id: candidateParent.Host.ID,
Expand Down
36 changes: 6 additions & 30 deletions scheduler/scheduling/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,20 +1648,8 @@ func TestScheduling_ConstructSuccessNormalTaskResponse(t *testing.T) {
Length: uint64(candidateParents[0].Range.Length),
},
Priority: candidateParents[0].Priority,
Pieces: []*commonv2.Piece{
{
Number: uint32(mockPiece.Number),
ParentId: &mockPiece.ParentID,
Offset: mockPiece.Offset,
Length: mockPiece.Length,
Digest: mockPiece.Digest.String(),
TrafficType: &mockPiece.TrafficType,
Cost: durationpb.New(mockPiece.Cost),
CreatedAt: timestamppb.New(mockPiece.CreatedAt),
},
},
Cost: durationpb.New(candidateParents[0].Cost.Load()),
State: candidateParents[0].FSM.Current(),
Cost: durationpb.New(candidateParents[0].Cost.Load()),
State: candidateParents[0].FSM.Current(),
Task: &commonv2.Task{
Id: candidateParents[0].Task.ID,
Type: candidateParents[0].Task.Type,
Expand All @@ -1675,22 +1663,10 @@ func TestScheduling_ConstructSuccessNormalTaskResponse(t *testing.T) {
ContentLength: uint64(candidateParents[0].Task.ContentLength.Load()),
PieceCount: uint32(candidateParents[0].Task.TotalPieceCount.Load()),
SizeScope: candidateParents[0].Task.SizeScope(),
Pieces: []*commonv2.Piece{
{
Number: uint32(mockPiece.Number),
ParentId: &mockPiece.ParentID,
Offset: mockPiece.Offset,
Length: mockPiece.Length,
Digest: mockPiece.Digest.String(),
TrafficType: &mockPiece.TrafficType,
Cost: durationpb.New(mockPiece.Cost),
CreatedAt: timestamppb.New(mockPiece.CreatedAt),
},
},
State: candidateParents[0].Task.FSM.Current(),
PeerCount: uint32(candidateParents[0].Task.PeerCount()),
CreatedAt: timestamppb.New(candidateParents[0].Task.CreatedAt.Load()),
UpdatedAt: timestamppb.New(candidateParents[0].Task.UpdatedAt.Load()),
State: candidateParents[0].Task.FSM.Current(),
PeerCount: uint32(candidateParents[0].Task.PeerCount()),
CreatedAt: timestamppb.New(candidateParents[0].Task.CreatedAt.Load()),
UpdatedAt: timestamppb.New(candidateParents[0].Task.UpdatedAt.Load()),
},
Host: &commonv2.Host{
Id: candidateParents[0].Host.ID,
Expand Down

0 comments on commit aacf7e4

Please sign in to comment.