[#1590] node: Smart memory allocation in GetRange

Allocate memory only if a node chosen as the forwarded request receiver
has responded with a successful status.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-07-07 18:05:50 +03:00 committed by fyrchik
parent fed5e76e7f
commit 1658242e00
2 changed files with 7 additions and 1 deletions

View file

@ -14,6 +14,7 @@ Changelog for NeoFS Node
- Do not replicate object twice to the same node (#1410) - Do not replicate object twice to the same node (#1410)
- Concurrent object handling by the Policer (#1411) - Concurrent object handling by the Policer (#1411)
- Attaching API version to the forwarded requests (#1581) - Attaching API version to the forwarded requests (#1581)
- Node OOM panics on `GetRange` request with extremely huge range length (#1590)
### Removed ### Removed

View file

@ -250,7 +250,8 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
return nil, fmt.Errorf("could not create Get payload range stream: %w", err) return nil, fmt.Errorf("could not create Get payload range stream: %w", err)
} }
payload := make([]byte, 0, body.GetRange().GetLength()) // allocate memory only after receiving a successful response
var payload []byte
resp := new(objectV2.GetRangeResponse) resp := new(objectV2.GetRangeResponse)
@ -283,6 +284,10 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
case nil: case nil:
return nil, fmt.Errorf("unexpected range type %T", v) return nil, fmt.Errorf("unexpected range type %T", v)
case *objectV2.GetRangePartChunk: case *objectV2.GetRangePartChunk:
if payload == nil {
payload = make([]byte, 0, body.GetRange().GetLength())
}
payload = append(payload, v.GetChunk()...) payload = append(payload, v.GetChunk()...)
case *objectV2.SplitInfo: case *objectV2.SplitInfo:
si := object.NewSplitInfoFromV2(v) si := object.NewSplitInfoFromV2(v)