Skip to content

Commit

Permalink
services/object: Inline intermediate GET/RANGE/HEAD services
Browse files Browse the repository at this point in the history
Continues 068d746. All these ops are
very similar, so refactored in one scope.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 26, 2024
1 parent 9c3a3b9 commit be24078
Show file tree
Hide file tree
Showing 7 changed files with 663 additions and 842 deletions.
16 changes: 9 additions & 7 deletions cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ type objectSvc struct {

search *searchsvc.Service

get *getsvcV2.Service
get *getsvcV2.Service
get_ *getsvc.Service

delete *deletesvc.Service
}
Expand All @@ -69,24 +70,24 @@ func (s *objectSvc) Put(ctx context.Context) (*putsvc.Streamer, error) {
return s.put.Put(ctx)
}

func (s *objectSvc) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
return s.get.Head(ctx, req)
func (s *objectSvc) Head(ctx context.Context, prm getsvc.HeadPrm) error {
return s.get_.Head(ctx, prm)
}

func (s *objectSvc) Search(ctx context.Context, prm searchsvc.Prm) error {
return s.search.Search(ctx, prm)
}

func (s *objectSvc) Get(req *object.GetRequest, stream objectService.GetObjectStream) error {
return s.get.Get(req, stream)
func (s *objectSvc) Get(ctx context.Context, prm getsvc.Prm) error {
return s.get_.Get(ctx, prm)
}

func (s *objectSvc) Delete(ctx context.Context, prm deletesvc.Prm) error {
return s.delete.Delete(ctx, prm)
}

func (s *objectSvc) GetRange(req *object.GetRangeRequest, stream objectService.GetObjectRangeStream) error {
return s.get.GetRange(req, stream)
func (s *objectSvc) GetRange(ctx context.Context, prm getsvc.RangePrm) error {
return s.get_.GetRange(ctx, prm)
}

func (s *objectSvc) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
Expand Down Expand Up @@ -279,6 +280,7 @@ func initObjectService(c *cfg) {
put: sPut,
search: sSearch,
get: sGetV2,
get_: sGet,
delete: sDelete,
}

Expand Down
63 changes: 0 additions & 63 deletions pkg/services/object/get/v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package getsvc

import (
"context"
"errors"

objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/nspcc-dev/neofs-sdk-go/object"
)

// Service implements Get operation of Object service v2.
Expand Down Expand Up @@ -38,44 +35,6 @@ func NewService(opts ...Option) *Service {
}
}

// Get calls internal service and returns v2 object stream.
func (s *Service) Get(req *objectV2.GetRequest, stream objectSvc.GetObjectStream) error {
p, err := s.toPrm(req, stream)
if err != nil {
return err
}

err = s.svc.Get(stream.Context(), *p)

var splitErr *object.SplitInfoError

switch {
case errors.As(err, &splitErr):
return stream.Send(splitInfoResponse(splitErr.SplitInfo()))
default:
return err
}
}

// GetRange calls internal service and returns v2 payload range stream.
func (s *Service) GetRange(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) error {
p, err := s.toRangePrm(req, stream)
if err != nil {
return err
}

err = s.svc.GetRange(stream.Context(), *p)

var splitErr *object.SplitInfoError

switch {
case errors.As(err, &splitErr):
return stream.Send(splitInfoRangeResponse(splitErr.SplitInfo()))
default:
return err
}
}

// GetRangeHash calls internal service and returns v2 response.
func (s *Service) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) {
p, err := s.toHashRangePrm(req)
Expand All @@ -91,28 +50,6 @@ func (s *Service) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashRe
return toHashResponse(req.GetBody().GetType(), res), nil
}

// Head serves NeoFS API v2 compatible HEAD requests.
func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
resp := new(objectV2.HeadResponse)
resp.SetBody(new(objectV2.HeadResponseBody))

p, err := s.toHeadPrm(ctx, req, resp)
if err != nil {
return nil, err
}

err = s.svc.Head(ctx, *p)

var splitErr *object.SplitInfoError

if errors.As(err, &splitErr) {
setSplitInfoHeadResponse(splitErr.SplitInfo(), resp)
err = nil
}

return resp, err
}

func WithInternalService(v *getsvc.Service) Option {
return func(c *cfg) {
c.svc = v
Expand Down
62 changes: 0 additions & 62 deletions pkg/services/object/get/v2/streamer.go

This file was deleted.

Loading

0 comments on commit be24078

Please sign in to comment.