[#532] object/hash: Fix NPE during request forwarding

In current implementation `Object.GetRangeHash` RPC handler forwards range
requests for payload data. Missing request forwarder of the original request
caused NPE during execution.

Do not call request forwarder if payload range hash is requested.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-18 15:13:40 +03:00 committed by Alex Vanin
parent 5e9513e008
commit 72e2bc8fb6
3 changed files with 18 additions and 4 deletions

View file

@ -38,7 +38,7 @@ type execCtx struct {
curOff uint64 curOff uint64
head bool head, hash bool
curProcEpoch uint64 curProcEpoch uint64
@ -71,6 +71,12 @@ func withPayloadRange(r *objectSDK.Range) execOption {
} }
} }
func hashOnly() execOption {
return func(c *execCtx) {
c.hash = true
}
}
func (exec *execCtx) setLogger(l *logger.Logger) { func (exec *execCtx) setLogger(l *logger.Logger) {
req := "GET" req := "GET"
if exec.headOnly() { if exec.headOnly() {
@ -146,6 +152,10 @@ func (exec *execCtx) headOnly() bool {
return exec.head return exec.head
} }
func (exec *execCtx) hashOnly() bool {
return exec.hash
}
func (exec *execCtx) netmapEpoch() uint64 { func (exec *execCtx) netmapEpoch() uint64 {
return exec.prm.common.NetmapEpoch() return exec.prm.common.NetmapEpoch()
} }

View file

@ -15,7 +15,11 @@ func (s *Service) Get(ctx context.Context, prm Prm) error {
// 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.get(ctx, prm.commonPrm, withPayloadRange(prm.rng)).err return s.getRange(ctx, prm)
}
func (s *Service) getRange(ctx context.Context, prm RangePrm, opts ...execOption) error {
return s.get(ctx, prm.commonPrm, append(opts, withPayloadRange(prm.rng))...).err
} }
func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) { func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHashRes, error) {
@ -37,7 +41,7 @@ func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHas
hash: util.NewSaltingWriter(h, prm.salt), hash: util.NewSaltingWriter(h, prm.salt),
}) })
if err := s.GetRange(ctx, rngPrm); err != nil { if err := s.getRange(ctx, rngPrm, hashOnly()); err != nil {
return nil, err return nil, err
} }

View file

@ -80,7 +80,7 @@ func (c *clientCacheWrapper) get(addr string) (getClient, error) {
} }
func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) { func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) {
if !exec.assembling { if !exec.assembling && !exec.hashOnly() {
return exec.prm.forwarder(c.client) return exec.prm.forwarder(c.client)
} }