[#277] getsvc: Move headOnly to request params

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-24 10:33:12 +03:00 committed by Evgenii Stratonikov
parent 265d2326a0
commit 591c4e7d50
4 changed files with 29 additions and 43 deletions

View file

@ -123,12 +123,12 @@ func (exec *execCtx) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Ra
p := exec.prm
p.common = p.common.WithLocalOnly(false)
p.objWriter = w
p.SetRange(rng)
p.rng = rng
p.addr.SetContainer(exec.containerID())
p.addr.SetObject(id)
if err := exec.svc.get(ctx, p.commonPrm, withPayloadRange(rng)); err != nil {
if err := exec.svc.get(ctx, p); err != nil {
return nil, err
}
return w.Object(), nil

View file

@ -20,10 +20,16 @@ type statusError struct {
err error
}
type RequestParameters struct {
commonPrm
head bool
rng *objectSDK.Range
}
type execCtx struct {
svc *Service
prm RangePrm
prm RequestParameters
statusError
@ -33,13 +39,9 @@ type execCtx struct {
collectedObject *objectSDK.Object
head bool
curProcEpoch uint64
}
type execOption func(*execCtx)
const (
statusUndefined int = iota
statusOK
@ -48,18 +50,6 @@ const (
statusOutOfRange
)
func headOnly() execOption {
return func(c *execCtx) {
c.head = true
}
}
func withPayloadRange(r *objectSDK.Range) execOption {
return func(c *execCtx) {
c.prm.rng = r
}
}
func (exec *execCtx) setLogger(l *logger.Logger) {
req := "GET"
if exec.headOnly() {
@ -126,7 +116,7 @@ func (exec *execCtx) ctxRange() *objectSDK.Range {
}
func (exec *execCtx) headOnly() bool {
return exec.head
return exec.prm.head
}
func (exec *execCtx) netmapEpoch() uint64 {

View file

@ -11,18 +11,18 @@ import (
// Get serves a request to get an object by address, and returns Streamer instance.
func (s *Service) Get(ctx context.Context, prm Prm) error {
return s.get(ctx, prm.commonPrm)
return s.get(ctx, RequestParameters{
commonPrm: prm.commonPrm,
})
}
// GetRange serves a request to get an object by address, and returns Streamer instance.
func (s *Service) GetRange(ctx context.Context, prm RangePrm) error {
return s.getRange(ctx, prm)
return s.get(ctx, RequestParameters{
commonPrm: prm.commonPrm,
rng: prm.rng,
})
}
func (s *Service) getRange(ctx context.Context, prm RangePrm) error {
return s.get(ctx, prm.commonPrm, withPayloadRange(prm.rng))
}
func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) {
hashes := make([][]byte, 0, len(prm.rngs))
@ -34,16 +34,15 @@ func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHas
// 1. Potential gains are insignificant when operating in the Internet given typical latencies and losses.
// 2. Parallel solution is more complex in terms of code.
// 3. TZ-hash is likely to be disabled in private installations.
rngPrm := RangePrm{
reqPrm := RequestParameters{
commonPrm: prm.commonPrm,
rng: &rng,
}
rngPrm.SetRange(&rng)
rngPrm.SetChunkWriter(&hasherWrapper{
reqPrm.SetChunkWriter(&hasherWrapper{
hash: util.NewSaltingWriter(h, prm.salt),
})
if err := s.getRange(ctx, rngPrm); err != nil {
if err := s.get(ctx, reqPrm); err != nil {
return nil, err
}
@ -60,22 +59,19 @@ func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHas
// Returns ErrNotFound if the header was not received for the call.
// Returns SplitInfoError if object is virtual and raw flag is set.
func (s *Service) Head(ctx context.Context, prm HeadPrm) error {
return s.get(ctx, prm.commonPrm, headOnly())
return s.get(ctx, RequestParameters{
head: true,
commonPrm: prm.commonPrm,
})
}
func (s *Service) get(ctx context.Context, prm commonPrm, opts ...execOption) error {
func (s *Service) get(ctx context.Context, prm RequestParameters) error {
exec := &execCtx{
svc: s,
prm: RangePrm{
commonPrm: prm,
},
prm: prm,
infoSplit: object.NewSplitInfo(),
}
for i := range opts {
opts[i](exec)
}
exec.setLogger(s.log)
exec.execute(ctx)

View file

@ -107,7 +107,7 @@ func (p *Prm) SetObjectWriter(w ObjectWriter) {
}
// SetChunkWriter sets target component to write the object payload range.
func (p *RangePrm) SetChunkWriter(w ChunkWriter) {
func (p *commonPrm) SetChunkWriter(w ChunkWriter) {
p.objWriter = &partWriter{
chunkWriter: w,
}