forked from TrueCloudLab/frostfs-node
[#1064] putsvc: Refactor distributed target
Extract object builder. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
92569b9bbf
commit
39da643354
3 changed files with 60 additions and 48 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
|
||||
)
|
||||
|
||||
type preparedObjectTarget interface {
|
||||
|
@ -15,16 +14,13 @@ type preparedObjectTarget interface {
|
|||
}
|
||||
|
||||
type distributedTarget struct {
|
||||
placementOpts []placement.Option
|
||||
extraBroadcastEnabled bool
|
||||
placementOpts []placement.Option
|
||||
|
||||
obj *objectSDK.Object
|
||||
objMeta object.ContentMeta
|
||||
|
||||
*cfg
|
||||
|
||||
payload *payload
|
||||
|
||||
nodeTargetInitializer func(nodeDesc) preparedObjectTarget
|
||||
|
||||
relay func(context.Context, nodeDesc) error
|
||||
|
@ -91,36 +87,6 @@ func (x errIncompletePut) Error() string {
|
|||
return commonMsg
|
||||
}
|
||||
|
||||
func (t *distributedTarget) WriteHeader(_ context.Context, obj *objectSDK.Object) error {
|
||||
t.obj = obj
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *distributedTarget) Write(_ context.Context, p []byte) (n int, err error) {
|
||||
t.payload.Data = append(t.payload.Data, p...)
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (t *distributedTarget) Close(ctx context.Context) (*transformer.AccessIdentifiers, error) {
|
||||
defer func() {
|
||||
putPayload(t.payload)
|
||||
t.payload = nil
|
||||
}()
|
||||
|
||||
t.obj.SetPayload(t.payload.Data)
|
||||
|
||||
if err := t.WriteObject(ctx, t.obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, _ := t.obj.ID()
|
||||
return &transformer.AccessIdentifiers{
|
||||
SelfID: id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WriteObject implements the transformer.ObjectWriter interface.
|
||||
func (t *distributedTarget) WriteObject(ctx context.Context, obj *objectSDK.Object) error {
|
||||
t.obj = obj
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue