Skip to content

Commit

Permalink
feat: report bad parents and add bad parents to block parent set (#3010)
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 Jan 10, 2024
1 parent 67d5dd0 commit 6586489
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module d7y.io/dragonfly/v2
go 1.21

require (
d7y.io/api/v2 v2.0.73
d7y.io/api/v2 v2.0.74
github.com/MysteriousPotato/go-lockable v1.0.0
github.com/RichardKnop/machinery v1.10.6
github.com/Showmax/go-fqdn v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
d7y.io/api/v2 v2.0.73 h1:ZzqErswvYeurqmsXVy4i5sUL8CfSq6n+A/r0UP9wI+M=
d7y.io/api/v2 v2.0.73/go.mod h1:hiZRuNTy1Tiv7+peJkYloDPm0Sq9GlPTVaiKb2UOhhU=
d7y.io/api/v2 v2.0.74 h1:GKfaQloPemF9zJr5FZ1XJL0VKmB8sjCy5Do9xcUtW0Q=
d7y.io/api/v2 v2.0.74/go.mod h1:hiZRuNTy1Tiv7+peJkYloDPm0Sq9GlPTVaiKb2UOhhU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
Expand Down
12 changes: 9 additions & 3 deletions scheduler/service/service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func (v *V2) AnnouncePeer(stream schedulerv2.Scheduler_AnnouncePeerServer) error
return err
}
case *schedulerv2.AnnouncePeerRequest_RescheduleRequest:
log.Infof("receive RescheduleRequest, description: %s", announcePeerRequest.RescheduleRequest.GetDescription())
if err := v.handleRescheduleRequest(ctx, req.GetPeerId()); err != nil {
rescheduleRequest := announcePeerRequest.RescheduleRequest
log.Infof("receive RescheduleRequest, candidate parent ids: %v, description: %s", rescheduleRequest.GetCandidateParentIds(), rescheduleRequest.GetDescription())
if err := v.handleRescheduleRequest(ctx, req.GetPeerId(), rescheduleRequest.GetCandidateParentIds()); err != nil {
log.Error(err)
return err
}
Expand Down Expand Up @@ -959,12 +960,17 @@ func (v *V2) handleDownloadPeerBackToSourceStartedRequest(ctx context.Context, p
}

// handleRescheduleRequest handles RescheduleRequest of AnnouncePeerRequest.
func (v *V2) handleRescheduleRequest(ctx context.Context, peerID string) error {
func (v *V2) handleRescheduleRequest(ctx context.Context, peerID string, candidateParentIDs []string) error {
peer, loaded := v.resource.PeerManager().Load(peerID)
if !loaded {
return status.Errorf(codes.NotFound, "peer %s not found", peerID)
}

// Add candidate parent ids to block parents.
for _, candidateParentID := range candidateParentIDs {
peer.BlockParents.Add(candidateParentID)
}

if err := v.scheduling.ScheduleCandidateParents(ctx, peer, peer.BlockParents); err != nil {
return status.Error(codes.FailedPrecondition, err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions scheduler/service/service_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ func TestServiceV2_handleRescheduleRequest(t *testing.T) {
)

assert := assert.New(t)
assert.ErrorIs(svc.handleRescheduleRequest(context.Background(), peer.ID), status.Errorf(codes.NotFound, "peer %s not found", peer.ID))
assert.ErrorIs(svc.handleRescheduleRequest(context.Background(), peer.ID, []string{mockPeerID}), status.Errorf(codes.NotFound, "peer %s not found", peer.ID))
},
},
{
Expand All @@ -1937,7 +1937,7 @@ func TestServiceV2_handleRescheduleRequest(t *testing.T) {
)

assert := assert.New(t)
assert.ErrorIs(svc.handleRescheduleRequest(context.Background(), peer.ID), status.Error(codes.FailedPrecondition, "foo"))
assert.ErrorIs(svc.handleRescheduleRequest(context.Background(), peer.ID, []string{mockPeerID}), status.Error(codes.FailedPrecondition, "foo"))
},
},
{
Expand All @@ -1951,7 +1951,7 @@ func TestServiceV2_handleRescheduleRequest(t *testing.T) {
)

assert := assert.New(t)
assert.NoError(svc.handleRescheduleRequest(context.Background(), peer.ID))
assert.NoError(svc.handleRescheduleRequest(context.Background(), peer.ID, []string{mockPeerID}))
},
},
}
Expand Down

0 comments on commit 6586489

Please sign in to comment.