[#539] getsvc: Use buffer to assemble object
To reduce memory consumption. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
32c77f3a23
commit
286242cad0
4 changed files with 20 additions and 7 deletions
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
type objectGetter interface {
|
||||
GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Range) (*objectSDK.Object, error)
|
||||
GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Range, buffer []byte) (*objectSDK.Object, error)
|
||||
HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error)
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ func (a *assembler) getLastPartOrLinkObjectID() (oid.ID, bool) {
|
|||
}
|
||||
|
||||
func (a *assembler) initializeFromSourceObjectID(ctx context.Context, id oid.ID) (*oid.ID, []oid.ID, error) {
|
||||
sourceObject, err := a.getChildObject(ctx, id, nil, true)
|
||||
sourceObject, err := a.getChildObject(ctx, id, nil, true, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ func (a *assembler) initializeFromSourceObjectID(ctx context.Context, id oid.ID)
|
|||
return nil, sourceObject.Children(), nil
|
||||
}
|
||||
|
||||
func (a *assembler) getChildObject(ctx context.Context, id oid.ID, rng *objectSDK.Range, verifyIsChild bool) (*objectSDK.Object, error) {
|
||||
obj, err := a.objGetter.GetObject(ctx, id, rng)
|
||||
func (a *assembler) getChildObject(ctx context.Context, id oid.ID, rng *objectSDK.Range, verifyIsChild bool, payloadBuffer []byte) (*objectSDK.Object, error) {
|
||||
obj, err := a.objGetter.GetObject(ctx, id, rng, payloadBuffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -176,13 +176,14 @@ func (a *assembler) assemleObjectByPreviousIDInReverse(ctx context.Context, prev
|
|||
func (a *assembler) assemblePayloadByObjectIDs(ctx context.Context, writer ObjectWriter, partIDs []oid.ID, partRanges []objectSDK.Range, verifyIsChild bool) error {
|
||||
withRng := len(partRanges) > 0 && a.rng != nil
|
||||
|
||||
var buffer []byte
|
||||
for i := range partIDs {
|
||||
var r *objectSDK.Range
|
||||
if withRng {
|
||||
r = &partRanges[i]
|
||||
}
|
||||
|
||||
child, err := a.getChildObject(ctx, partIDs[i], r, verifyIsChild)
|
||||
child, err := a.getChildObject(ctx, partIDs[i], r, verifyIsChild, buffer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -190,6 +191,8 @@ func (a *assembler) assemblePayloadByObjectIDs(ctx context.Context, writer Objec
|
|||
if err := writer.WriteChunk(ctx, child.Payload()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buffer = child.Payload()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue