Skip to content

Commit

Permalink
slicer: Reuse stub object
Browse files Browse the repository at this point in the history
Updated after benchmark. During object slicing we recreate object on each part, we may reuse it, just reset some fields.

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Jul 27, 2023
1 parent d2d2b7f commit 4a5f2ee
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
17 changes: 17 additions & 0 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func (o *Object) SetID(v oid.ID) {
SetObjectID(&v2)
}

// ResetID removes object identifier.
//
// See also [Object.SetID].
func (o *Object) ResetID() {
(*object.Object)(o).
SetObjectID(nil)
}

// Signature returns signature of the object identifier.
//
// See also [Object.SetSignature].
Expand Down Expand Up @@ -536,6 +544,15 @@ func (o *Object) SetParentID(v oid.ID) {
})
}

// ResetParentID removes identifier of the parent object.
//
// See also [Object.SetParentID].
func (o *Object) ResetParentID() {
o.setSplitFields(func(split *object.SplitHeader) {
split.SetParent(nil)
})
}

// Parent returns parent object w/o payload.
//
// See also [Object.SetParent].
Expand Down
32 changes: 20 additions & 12 deletions object/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ func initPayloadStream(ctx context.Context, ow ObjectWriter, header object.Objec
currentVersion := version.Current()
header.SetVersion(&currentVersion)

var stubObject object.Object
stubObject.SetVersion(&currentVersion)
stubObject.SetContainerID(containerID)
stubObject.SetCreationEpoch(opts.currentNeoFSEpoch)
stubObject.SetType(object.TypeRegular)
stubObject.SetOwnerID(&owner)
stubObject.SetSessionToken(opts.sessionToken)

res := &PayloadWriter{
ctx: ctx,
isHeaderWriteStep: true,
Expand All @@ -246,6 +254,7 @@ func initPayloadStream(ctx context.Context, ow ObjectWriter, header object.Objec
rootMeta: newDynamicObjectMetadata(opts.withHomoChecksum),
childMeta: newDynamicObjectMetadata(opts.withHomoChecksum),
prmObjectPutInit: prm,
stubObject: &stubObject,
}

maxObjSize := childPayloadSizeLimit(opts)
Expand Down Expand Up @@ -284,6 +293,7 @@ type PayloadWriter struct {

writtenChildren []oid.ID
prmObjectPutInit client.PrmObjectPutInit
stubObject *object.Object
}

// Write writes next chunk of the object data. Concatenation of all chunks forms
Expand Down Expand Up @@ -365,19 +375,14 @@ func (x *PayloadWriter) writeLastChild(ctx context.Context, meta dynamicObjectMe
}

func (x *PayloadWriter) _writeChild(ctx context.Context, meta dynamicObjectMetadata, last bool, rootIDHandler func(id oid.ID)) error {
currentVersion := version.Current()

fCommon := func(obj *object.Object) {
obj.SetVersion(&currentVersion)
obj.SetContainerID(x.container)
obj.SetCreationEpoch(x.currentEpoch)
obj.SetType(object.TypeRegular)
obj.SetOwnerID(&x.owner)
obj.SetSessionToken(x.sessionToken)
}
obj := *x.stubObject
obj.SetSplitID(nil)
obj.ResetPreviousID()
obj.SetParent(nil)
obj.ResetParentID()
obj.SetSignature(nil)
obj.ResetID()

var obj object.Object
fCommon(&obj)
if x.withSplit {
obj.SetSplitID(x.splitID)
}
Expand Down Expand Up @@ -421,6 +426,9 @@ func (x *PayloadWriter) _writeChild(ctx context.Context, meta dynamicObjectMetad
meta.reset()
obj.ResetPreviousID()
obj.SetChildren(x.writtenChildren...)
// we reuse already written object, we should reset these fields, to eval them one more time in writeInMemObject.
obj.ResetID()
obj.SetSignature(nil)

_, err = writeInMemObject(ctx, x.signer, x.stream, obj, nil, meta, x.prmObjectPutInit)
if err != nil {
Expand Down

0 comments on commit 4a5f2ee

Please sign in to comment.