diff --git a/satellite/audit/disqualification_test.go b/satellite/audit/disqualification_test.go index 9ab677d2b..5002af0b6 100644 --- a/satellite/audit/disqualification_test.go +++ b/satellite/audit/disqualification_test.go @@ -140,7 +140,7 @@ func TestDisqualifiedNodesGetNoDownload(t *testing.T) { err = satellitePeer.Reputation.Service.TestDisqualifyNode(ctx, disqualifiedNode, overlay.DisqualificationReasonUnknown) require.NoError(t, err) - limits, _, err := satellitePeer.Orders.Service.CreateGetOrderLimits(ctx, bucket, segment, 0) + limits, _, err := satellitePeer.Orders.Service.CreateGetOrderLimits(ctx, bucket, segment, 0, 0) require.NoError(t, err) notNilLimits := []*pb.AddressedOrderLimit{} diff --git a/satellite/metainfo/endpoint_object.go b/satellite/metainfo/endpoint_object.go index a202ee14e..4cbd3a531 100644 --- a/satellite/metainfo/endpoint_object.go +++ b/satellite/metainfo/endpoint_object.go @@ -543,7 +543,7 @@ func (endpoint *Endpoint) DownloadObject(ctx context.Context, req *pb.ObjectDown }}, nil } - limits, privateKey, err := endpoint.orders.CreateGetOrderLimits(ctx, object.Location().Bucket(), segment, downloadSizes.orderLimit) + limits, privateKey, err := endpoint.orders.CreateGetOrderLimits(ctx, object.Location().Bucket(), segment, req.GetDesiredNodes(), downloadSizes.orderLimit) if err != nil { if orders.ErrDownloadFailedNotEnoughPieces.Has(err) { endpoint.log.Error("Unable to create order limits.", diff --git a/satellite/metainfo/endpoint_segment.go b/satellite/metainfo/endpoint_segment.go index d244f8046..29fec085a 100644 --- a/satellite/metainfo/endpoint_segment.go +++ b/satellite/metainfo/endpoint_segment.go @@ -703,7 +703,7 @@ func (endpoint *Endpoint) DownloadSegment(ctx context.Context, req *pb.SegmentDo } // Remote segment - limits, privateKey, err := endpoint.orders.CreateGetOrderLimits(ctx, bucket, segment, 0) + limits, privateKey, err := endpoint.orders.CreateGetOrderLimits(ctx, bucket, segment, req.GetDesiredNodes(), 0) if err != nil { if orders.ErrDownloadFailedNotEnoughPieces.Has(err) { endpoint.log.Error("Unable to create order limits.", diff --git a/satellite/orders/service.go b/satellite/orders/service.go index f28c9faed..3289b1c74 100644 --- a/satellite/orders/service.go +++ b/satellite/orders/service.go @@ -126,7 +126,7 @@ func (service *Service) updateBandwidth(ctx context.Context, bucket metabase.Buc } // CreateGetOrderLimits creates the order limits for downloading the pieces of a segment. -func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabase.BucketLocation, segment metabase.Segment, overrideLimit int64) (_ []*pb.AddressedOrderLimit, privateKey storj.PiecePrivateKey, err error) { +func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabase.BucketLocation, segment metabase.Segment, desiredNodes int32, overrideLimit int64) (_ []*pb.AddressedOrderLimit, privateKey storj.PiecePrivateKey, err error) { defer mon.Task()(&ctx)(&err) redundancy, err := eestream.NewRedundancyStrategyFromStorj(segment.Redundancy) @@ -155,7 +155,10 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabas } neededLimits := segment.Redundancy.DownloadNodes() + if desiredNodes > neededLimits { + neededLimits = desiredNodes + } pieces := segment.Pieces for _, pieceIndex := range service.perm(len(pieces)) { piece := pieces[pieceIndex] diff --git a/satellite/orders/service_integration_test.go b/satellite/orders/service_integration_test.go index 539ec9f37..ab44094b7 100644 --- a/satellite/orders/service_integration_test.go +++ b/satellite/orders/service_integration_test.go @@ -38,7 +38,7 @@ func TestOrderLimitsEncryptedMetadata(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, len(segments)) - limits, _, err := satellitePeer.Orders.Service.CreateGetOrderLimits(ctx, bucket, segments[0], 0) + limits, _, err := satellitePeer.Orders.Service.CreateGetOrderLimits(ctx, bucket, segments[0], 0, 0) require.NoError(t, err) require.Equal(t, 3, len(limits)) diff --git a/satellite/orders/service_test.go b/satellite/orders/service_test.go index 9753b94a3..cdc2bd017 100644 --- a/satellite/orders/service_test.go +++ b/satellite/orders/service_test.go @@ -81,8 +81,8 @@ func TestGetOrderLimits(t *testing.T) { RootPieceID: testrand.PieceID(), } - checkExpectedLimits := func(received int) { - limits, _, err := service.CreateGetOrderLimits(ctx, bucket, segment, 0) + checkExpectedLimits := func(requested int32, received int) { + limits, _, err := service.CreateGetOrderLimits(ctx, bucket, segment, requested, 0) require.NoError(t, err) realLimits := 0 for _, limit := range limits { @@ -94,7 +94,19 @@ func TestGetOrderLimits(t *testing.T) { } t.Run("Do not request any specific number", func(t *testing.T) { - checkExpectedLimits(6) + checkExpectedLimits(0, 6) + }) + + t.Run("Request less than the optimal", func(t *testing.T) { + checkExpectedLimits(2, 6) + }) + + t.Run("Request more than the optimal", func(t *testing.T) { + checkExpectedLimits(8, 8) + }) + + t.Run("Request more than the replication", func(t *testing.T) { + checkExpectedLimits(1000, 8) }) }