Skip to content

Commit

Permalink
feat: remove unused context and update api version (#3412)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Aug 6, 2024
1 parent 9698903 commit a35517c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/compatibility-e2e-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ jobs:
include:
- module: manager
image: manager
image-tag: v2.1.46
image-tag: v2.1.53
chart-name: manager
- module: scheduler
image: scheduler
image-tag: v2.1.46
image-tag: v2.1.53
chart-name: scheduler
- module: client
image: client
image-tag: v0.1.76
image-tag: v0.1.95
chart-name: client
- module: seed-client
image: client
image-tag: v0.1.76
image-tag: v0.1.95
chart-name: seed-client

steps:
Expand Down
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.141
d7y.io/api/v2 v2.0.142
github.com/MysteriousPotato/go-lockable v1.0.0
github.com/RichardKnop/machinery v1.10.8
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 @@ -53,8 +53,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
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=
d7y.io/api/v2 v2.0.141 h1:pRGCLKcNtBB026b/sJXMBVeh1Ik0/7nxHN7YFXi1uhU=
d7y.io/api/v2 v2.0.141/go.mod h1:IakrltEphFvcLIQs3NVeb9PAe66MGDnd2/HMs9DKYu8=
d7y.io/api/v2 v2.0.142 h1:u1gQZwCKJODdJB883J9e5SRK9VmOTmApX13FX/bR0Vk=
d7y.io/api/v2 v2.0.142/go.mod h1:IakrltEphFvcLIQs3NVeb9PAe66MGDnd2/HMs9DKYu8=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
Expand Down
10 changes: 10 additions & 0 deletions pkg/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"hash"
"hash/crc32"
"io"
"os"
"strings"
Expand All @@ -34,6 +35,9 @@ import (
)

const (
// AlgorithmCRC32 is crc32 algorithm name of hash.
AlgorithmCRC32 = "crc32"

// AlgorithmBlake3 is blake3 algorithm name of hash.
AlgorithmBlake3 = "blake3"

Expand Down Expand Up @@ -82,6 +86,8 @@ func HashFile(path string, algorithm string) (string, error) {

var h hash.Hash
switch algorithm {
case AlgorithmCRC32:
h = crc32.NewIEEE()
case AlgorithmBlake3:
h = blake3.New()
case AlgorithmSHA1:
Expand Down Expand Up @@ -116,6 +122,10 @@ func Parse(digest string) (*Digest, error) {
encoded := values[1]

switch algorithm {
case AlgorithmCRC32:
if len(encoded) != 8 {
return nil, errors.New("invalid encoded")
}
case AlgorithmBlake3:
if len(encoded) != 64 {
return nil, errors.New("invalid encoded")
Expand Down
30 changes: 15 additions & 15 deletions pkg/objectstorage/mocks/objectstorage_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scheduler/service/service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (v *V2) AnnouncePeer(stream schedulerv2.Scheduler_AnnouncePeerServer) error
case *schedulerv2.AnnouncePeerRequest_DownloadPieceFinishedRequest:
piece := announcePeerRequest.DownloadPieceFinishedRequest.Piece
log.Infof("receive DownloadPieceFinishedRequest, piece number: %d, piece length: %d, traffic type: %s, cost: %s, parent id: %s", piece.GetNumber(), piece.GetLength(), piece.GetTrafficType(), piece.GetCost().AsDuration().String(), piece.GetParentId())
if err := v.handleDownloadPieceFinishedRequest(ctx, req.GetPeerId(), announcePeerRequest.DownloadPieceFinishedRequest); err != nil {
if err := v.handleDownloadPieceFinishedRequest(req.GetPeerId(), announcePeerRequest.DownloadPieceFinishedRequest); err != nil {
log.Error(err)
return err
}
Expand Down Expand Up @@ -1154,7 +1154,7 @@ func (v *V2) handleDownloadPeerBackToSourceFailedRequest(ctx context.Context, pe
}

// handleDownloadPieceFinishedRequest handles DownloadPieceFinishedRequest of AnnouncePeerRequest.
func (v *V2) handleDownloadPieceFinishedRequest(ctx context.Context, peerID string, req *schedulerv2.DownloadPieceFinishedRequest) error {
func (v *V2) handleDownloadPieceFinishedRequest(peerID string, req *schedulerv2.DownloadPieceFinishedRequest) error {
// Construct piece.
piece := &resource.Piece{
Number: int32(req.Piece.GetNumber()),
Expand Down
8 changes: 4 additions & 4 deletions scheduler/service/service_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ func TestServiceV2_handleDownloadPieceFinishedRequest(t *testing.T) {
},
run: func(t *testing.T, svc *V2, req *schedulerv2.DownloadPieceFinishedRequest, peer *resource.Peer, peerManager resource.PeerManager, mr *resource.MockResourceMockRecorder, mp *resource.MockPeerManagerMockRecorder) {
assert := assert.New(t)
assert.ErrorIs(svc.handleDownloadPieceFinishedRequest(context.Background(), peer.ID, req), status.Error(codes.InvalidArgument, "invalid digest"))
assert.ErrorIs(svc.handleDownloadPieceFinishedRequest(peer.ID, req), status.Error(codes.InvalidArgument, "invalid digest"))
},
},
{
Expand All @@ -2501,7 +2501,7 @@ func TestServiceV2_handleDownloadPieceFinishedRequest(t *testing.T) {
)

assert := assert.New(t)
assert.ErrorIs(svc.handleDownloadPieceFinishedRequest(context.Background(), peer.ID, req), status.Errorf(codes.NotFound, "peer %s not found", peer.ID))
assert.ErrorIs(svc.handleDownloadPieceFinishedRequest(peer.ID, req), status.Errorf(codes.NotFound, "peer %s not found", peer.ID))
},
},
{
Expand All @@ -2527,7 +2527,7 @@ func TestServiceV2_handleDownloadPieceFinishedRequest(t *testing.T) {
)

assert := assert.New(t)
assert.NoError(svc.handleDownloadPieceFinishedRequest(context.Background(), peer.ID, req))
assert.NoError(svc.handleDownloadPieceFinishedRequest(peer.ID, req))

piece, loaded := peer.LoadPiece(int32(req.Piece.Number))
assert.True(loaded)
Expand Down Expand Up @@ -2569,7 +2569,7 @@ func TestServiceV2_handleDownloadPieceFinishedRequest(t *testing.T) {
)

assert := assert.New(t)
assert.NoError(svc.handleDownloadPieceFinishedRequest(context.Background(), peer.ID, req))
assert.NoError(svc.handleDownloadPieceFinishedRequest(peer.ID, req))

piece, loaded := peer.LoadPiece(int32(req.Piece.Number))
assert.True(loaded)
Expand Down

0 comments on commit a35517c

Please sign in to comment.