Skip to content

Commit aacf7e4

Browse files
authored
feat: reduce the scheduler return content of the parent (#3349)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 4aa12f8 commit aacf7e4

File tree

2 files changed

+6
-82
lines changed

2 files changed

+6
-82
lines changed

scheduler/scheduling/scheduling.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -593,32 +593,6 @@ func ConstructSuccessNormalTaskResponse(candidateParents []*resource.Peer) *sche
593593
}
594594
}
595595

596-
// Set pieces to parent.
597-
candidateParent.Pieces.Range(func(key, value any) bool {
598-
candidateParentPiece, ok := value.(*resource.Piece)
599-
if !ok {
600-
candidateParent.Log.Errorf("invalid piece %s %#v", key, value)
601-
return true
602-
}
603-
604-
piece := &commonv2.Piece{
605-
Number: uint32(candidateParentPiece.Number),
606-
ParentId: &candidateParentPiece.ParentID,
607-
Offset: candidateParentPiece.Offset,
608-
Length: candidateParentPiece.Length,
609-
TrafficType: &candidateParentPiece.TrafficType,
610-
Cost: durationpb.New(candidateParentPiece.Cost),
611-
CreatedAt: timestamppb.New(candidateParentPiece.CreatedAt),
612-
}
613-
614-
if candidateParentPiece.Digest != nil {
615-
piece.Digest = candidateParentPiece.Digest.String()
616-
}
617-
618-
parent.Pieces = append(parent.Pieces, piece)
619-
return true
620-
})
621-
622596
// Set task to parent.
623597
parent.Task = &commonv2.Task{
624598
Id: candidateParent.Task.ID,
@@ -644,32 +618,6 @@ func ConstructSuccessNormalTaskResponse(candidateParents []*resource.Peer) *sche
644618
parent.Task.Digest = &dgst
645619
}
646620

647-
// Set pieces to parent task.
648-
candidateParent.Task.Pieces.Range(func(key, value any) bool {
649-
taskPiece, ok := value.(*resource.Piece)
650-
if !ok {
651-
candidateParent.Task.Log.Errorf("invalid piece %s %#v", key, value)
652-
return true
653-
}
654-
655-
piece := &commonv2.Piece{
656-
Number: uint32(taskPiece.Number),
657-
ParentId: &taskPiece.ParentID,
658-
Offset: taskPiece.Offset,
659-
Length: taskPiece.Length,
660-
TrafficType: &taskPiece.TrafficType,
661-
Cost: durationpb.New(taskPiece.Cost),
662-
CreatedAt: timestamppb.New(taskPiece.CreatedAt),
663-
}
664-
665-
if taskPiece.Digest != nil {
666-
piece.Digest = taskPiece.Digest.String()
667-
}
668-
669-
parent.Task.Pieces = append(parent.Task.Pieces, piece)
670-
return true
671-
})
672-
673621
// Set host to parent.
674622
parent.Host = &commonv2.Host{
675623
Id: candidateParent.Host.ID,

scheduler/scheduling/scheduling_test.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,20 +1648,8 @@ func TestScheduling_ConstructSuccessNormalTaskResponse(t *testing.T) {
16481648
Length: uint64(candidateParents[0].Range.Length),
16491649
},
16501650
Priority: candidateParents[0].Priority,
1651-
Pieces: []*commonv2.Piece{
1652-
{
1653-
Number: uint32(mockPiece.Number),
1654-
ParentId: &mockPiece.ParentID,
1655-
Offset: mockPiece.Offset,
1656-
Length: mockPiece.Length,
1657-
Digest: mockPiece.Digest.String(),
1658-
TrafficType: &mockPiece.TrafficType,
1659-
Cost: durationpb.New(mockPiece.Cost),
1660-
CreatedAt: timestamppb.New(mockPiece.CreatedAt),
1661-
},
1662-
},
1663-
Cost: durationpb.New(candidateParents[0].Cost.Load()),
1664-
State: candidateParents[0].FSM.Current(),
1651+
Cost: durationpb.New(candidateParents[0].Cost.Load()),
1652+
State: candidateParents[0].FSM.Current(),
16651653
Task: &commonv2.Task{
16661654
Id: candidateParents[0].Task.ID,
16671655
Type: candidateParents[0].Task.Type,
@@ -1675,22 +1663,10 @@ func TestScheduling_ConstructSuccessNormalTaskResponse(t *testing.T) {
16751663
ContentLength: uint64(candidateParents[0].Task.ContentLength.Load()),
16761664
PieceCount: uint32(candidateParents[0].Task.TotalPieceCount.Load()),
16771665
SizeScope: candidateParents[0].Task.SizeScope(),
1678-
Pieces: []*commonv2.Piece{
1679-
{
1680-
Number: uint32(mockPiece.Number),
1681-
ParentId: &mockPiece.ParentID,
1682-
Offset: mockPiece.Offset,
1683-
Length: mockPiece.Length,
1684-
Digest: mockPiece.Digest.String(),
1685-
TrafficType: &mockPiece.TrafficType,
1686-
Cost: durationpb.New(mockPiece.Cost),
1687-
CreatedAt: timestamppb.New(mockPiece.CreatedAt),
1688-
},
1689-
},
1690-
State: candidateParents[0].Task.FSM.Current(),
1691-
PeerCount: uint32(candidateParents[0].Task.PeerCount()),
1692-
CreatedAt: timestamppb.New(candidateParents[0].Task.CreatedAt.Load()),
1693-
UpdatedAt: timestamppb.New(candidateParents[0].Task.UpdatedAt.Load()),
1666+
State: candidateParents[0].Task.FSM.Current(),
1667+
PeerCount: uint32(candidateParents[0].Task.PeerCount()),
1668+
CreatedAt: timestamppb.New(candidateParents[0].Task.CreatedAt.Load()),
1669+
UpdatedAt: timestamppb.New(candidateParents[0].Task.UpdatedAt.Load()),
16941670
},
16951671
Host: &commonv2.Host{
16961672
Id: candidateParents[0].Host.ID,

0 commit comments

Comments
 (0)