From b8e8e1e80daf931cd8c1c2ca3b58d28056698bff Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 2 Dec 2020 11:29:51 +0300 Subject: [PATCH] [#227] transformer: Do not inherit attribute in generated objects In previous implementation child objects inherited parent attributes after split-transformation, which was redundant. From now attributes are not inherited. Signed-off-by: Leonard Lyubich --- .../object_manager/transformer/transformer.go | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/services/object_manager/transformer/transformer.go b/pkg/services/object_manager/transformer/transformer.go index ceb6d6584..0f14eff28 100644 --- a/pkg/services/object_manager/transformer/transformer.go +++ b/pkg/services/object_manager/transformer/transformer.go @@ -29,6 +29,8 @@ type payloadSizeLimiter struct { chunkWriter io.Writer splitID *objectSDK.SplitID + + parAttrs []*objectSDK.Attribute } type payloadChecksumHasher struct { @@ -78,10 +80,7 @@ func (s *payloadSizeLimiter) initialize() { if ln := len(s.previous); ln > 0 { // initialize parent object once (after 1st object) if ln == 1 { - s.parent = s.current - s.current = fromObject(s.parent) - s.parent.ResetRelations() - s.parentHashers = s.currentHashers + s.detachParent() } // set previous object to the last previous identifier @@ -228,9 +227,7 @@ func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { // statement is true if the previous write of bytes reached exactly the boundary. if s.written > 0 && s.written%s.maxSize == 0 { if s.written == s.maxSize { - // initialize split header with split ID on first object in chain - s.current.InitRelations() - s.current.SetSplitID(s.splitID) + s.prepareFirstChild() } // we need to release current object @@ -267,3 +264,25 @@ func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { return nil } + +func (s *payloadSizeLimiter) prepareFirstChild() { + // initialize split header with split ID on first object in chain + s.current.InitRelations() + s.current.SetSplitID(s.splitID) + + // cut source attributes + s.parAttrs = s.current.Attributes() + s.current.SetAttributes() + + // attributes will be added to parent in detachParent +} + +func (s *payloadSizeLimiter) detachParent() { + s.parent = s.current + s.current = fromObject(s.parent) + s.parent.ResetRelations() + s.parentHashers = s.currentHashers + + // return source attributes + s.parent.SetAttributes(s.parAttrs...) +}