forked from TrueCloudLab/frostfs-node
[#277] getsvc: Move headOnly to request params
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
265d2326a0
commit
591c4e7d50
4 changed files with 29 additions and 43 deletions
|
@ -123,12 +123,12 @@ func (exec *execCtx) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Ra
|
||||||
p := exec.prm
|
p := exec.prm
|
||||||
p.common = p.common.WithLocalOnly(false)
|
p.common = p.common.WithLocalOnly(false)
|
||||||
p.objWriter = w
|
p.objWriter = w
|
||||||
p.SetRange(rng)
|
p.rng = rng
|
||||||
|
|
||||||
p.addr.SetContainer(exec.containerID())
|
p.addr.SetContainer(exec.containerID())
|
||||||
p.addr.SetObject(id)
|
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 nil, err
|
||||||
}
|
}
|
||||||
return w.Object(), nil
|
return w.Object(), nil
|
||||||
|
|
|
@ -20,10 +20,16 @@ type statusError struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestParameters struct {
|
||||||
|
commonPrm
|
||||||
|
head bool
|
||||||
|
rng *objectSDK.Range
|
||||||
|
}
|
||||||
|
|
||||||
type execCtx struct {
|
type execCtx struct {
|
||||||
svc *Service
|
svc *Service
|
||||||
|
|
||||||
prm RangePrm
|
prm RequestParameters
|
||||||
|
|
||||||
statusError
|
statusError
|
||||||
|
|
||||||
|
@ -33,13 +39,9 @@ type execCtx struct {
|
||||||
|
|
||||||
collectedObject *objectSDK.Object
|
collectedObject *objectSDK.Object
|
||||||
|
|
||||||
head bool
|
|
||||||
|
|
||||||
curProcEpoch uint64
|
curProcEpoch uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type execOption func(*execCtx)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
statusUndefined int = iota
|
statusUndefined int = iota
|
||||||
statusOK
|
statusOK
|
||||||
|
@ -48,18 +50,6 @@ const (
|
||||||
statusOutOfRange
|
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) {
|
func (exec *execCtx) setLogger(l *logger.Logger) {
|
||||||
req := "GET"
|
req := "GET"
|
||||||
if exec.headOnly() {
|
if exec.headOnly() {
|
||||||
|
@ -126,7 +116,7 @@ func (exec *execCtx) ctxRange() *objectSDK.Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) headOnly() bool {
|
func (exec *execCtx) headOnly() bool {
|
||||||
return exec.head
|
return exec.prm.head
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) netmapEpoch() uint64 {
|
func (exec *execCtx) netmapEpoch() uint64 {
|
||||||
|
|
|
@ -11,18 +11,18 @@ import (
|
||||||
|
|
||||||
// Get serves a request to get an object by address, and returns Streamer instance.
|
// Get serves a request to get an object by address, and returns Streamer instance.
|
||||||
func (s *Service) Get(ctx context.Context, prm Prm) error {
|
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.
|
// GetRange serves a request to get an object by address, and returns Streamer instance.
|
||||||
func (s *Service) GetRange(ctx context.Context, prm RangePrm) error {
|
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) {
|
func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) {
|
||||||
hashes := make([][]byte, 0, len(prm.rngs))
|
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.
|
// 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.
|
// 2. Parallel solution is more complex in terms of code.
|
||||||
// 3. TZ-hash is likely to be disabled in private installations.
|
// 3. TZ-hash is likely to be disabled in private installations.
|
||||||
rngPrm := RangePrm{
|
reqPrm := RequestParameters{
|
||||||
commonPrm: prm.commonPrm,
|
commonPrm: prm.commonPrm,
|
||||||
|
rng: &rng,
|
||||||
}
|
}
|
||||||
|
reqPrm.SetChunkWriter(&hasherWrapper{
|
||||||
rngPrm.SetRange(&rng)
|
|
||||||
rngPrm.SetChunkWriter(&hasherWrapper{
|
|
||||||
hash: util.NewSaltingWriter(h, prm.salt),
|
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
|
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 ErrNotFound if the header was not received for the call.
|
||||||
// Returns SplitInfoError if object is virtual and raw flag is set.
|
// Returns SplitInfoError if object is virtual and raw flag is set.
|
||||||
func (s *Service) Head(ctx context.Context, prm HeadPrm) error {
|
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{
|
exec := &execCtx{
|
||||||
svc: s,
|
svc: s,
|
||||||
prm: RangePrm{
|
prm: prm,
|
||||||
commonPrm: prm,
|
|
||||||
},
|
|
||||||
infoSplit: object.NewSplitInfo(),
|
infoSplit: object.NewSplitInfo(),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range opts {
|
|
||||||
opts[i](exec)
|
|
||||||
}
|
|
||||||
|
|
||||||
exec.setLogger(s.log)
|
exec.setLogger(s.log)
|
||||||
|
|
||||||
exec.execute(ctx)
|
exec.execute(ctx)
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (p *Prm) SetObjectWriter(w ObjectWriter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetChunkWriter sets target component to write the object payload range.
|
// 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{
|
p.objWriter = &partWriter{
|
||||||
chunkWriter: w,
|
chunkWriter: w,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue