[#6] services/object: Simplify local/remote targets
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
c5c7e8e759
commit
076e44ad5a
4 changed files with 19 additions and 47 deletions
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
type preparedObjectTarget interface {
|
||||
WriteObject(*objectSDK.Object, object.ContentMeta) error
|
||||
Close() (*transformer.AccessIdentifiers, error)
|
||||
}
|
||||
|
||||
type distributedTarget struct {
|
||||
|
@ -154,10 +153,9 @@ func (t *distributedTarget) sendObject(node nodeDesc) error {
|
|||
|
||||
target := t.nodeTargetInitializer(node)
|
||||
|
||||
if err := target.WriteObject(t.obj, t.objMeta); err != nil {
|
||||
err := target.WriteObject(t.obj, t.objMeta)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not write header: %w", err)
|
||||
} else if _, err := target.Close(); err != nil {
|
||||
return fmt.Errorf("could not close object stream: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/transformer"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
)
|
||||
|
@ -24,40 +23,26 @@ type ObjectStorage interface {
|
|||
|
||||
type localTarget struct {
|
||||
storage ObjectStorage
|
||||
|
||||
obj *object.Object
|
||||
meta objectCore.ContentMeta
|
||||
}
|
||||
|
||||
func (t *localTarget) WriteObject(obj *object.Object, meta objectCore.ContentMeta) error {
|
||||
t.obj = obj
|
||||
t.meta = meta
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||
switch t.meta.Type() {
|
||||
func (t localTarget) WriteObject(obj *object.Object, meta objectCore.ContentMeta) error {
|
||||
switch meta.Type() {
|
||||
case object.TypeTombstone:
|
||||
err := t.storage.Delete(objectCore.AddressOf(t.obj), t.meta.Objects())
|
||||
err := t.storage.Delete(objectCore.AddressOf(obj), meta.Objects())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not delete objects from tombstone locally: %w", err)
|
||||
return fmt.Errorf("could not delete objects from tombstone locally: %w", err)
|
||||
}
|
||||
case object.TypeLock:
|
||||
err := t.storage.Lock(objectCore.AddressOf(t.obj), t.meta.Objects())
|
||||
err := t.storage.Lock(objectCore.AddressOf(obj), meta.Objects())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not lock object from lock objects locally: %w", err)
|
||||
return fmt.Errorf("could not lock object from lock objects locally: %w", err)
|
||||
}
|
||||
default:
|
||||
// objects that do not change meta storage
|
||||
}
|
||||
|
||||
if err := t.storage.Put(t.obj); err != nil {
|
||||
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
||||
if err := t.storage.Put(obj); err != nil {
|
||||
return fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
||||
}
|
||||
|
||||
id, _ := t.obj.ID()
|
||||
|
||||
return new(transformer.AccessIdentifiers).
|
||||
WithSelfID(id), nil
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/transformer"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
)
|
||||
|
@ -24,8 +23,6 @@ type remoteTarget struct {
|
|||
|
||||
nodeInfo clientcore.NodeInfo
|
||||
|
||||
obj *object.Object
|
||||
|
||||
clientConstructor ClientConstructor
|
||||
}
|
||||
|
||||
|
@ -45,15 +42,9 @@ type RemotePutPrm struct {
|
|||
}
|
||||
|
||||
func (t *remoteTarget) WriteObject(obj *object.Object, _ objectcore.ContentMeta) error {
|
||||
t.obj = obj
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||
c, err := t.clientConstructor.Get(t.nodeInfo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("(%T) could not create SDK client %s: %w", t, t.nodeInfo, err)
|
||||
return fmt.Errorf("(%T) could not create SDK client %s: %w", t, t.nodeInfo, err)
|
||||
}
|
||||
|
||||
var prm internalclient.PutObjectPrm
|
||||
|
@ -64,15 +55,14 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
|||
prm.SetSessionToken(t.commonPrm.SessionToken())
|
||||
prm.SetBearerToken(t.commonPrm.BearerToken())
|
||||
prm.SetXHeaders(t.commonPrm.XHeaders())
|
||||
prm.SetObject(t.obj)
|
||||
prm.SetObject(obj)
|
||||
|
||||
res, err := internalclient.PutObject(prm)
|
||||
_, err = internalclient.PutObject(prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("(%T) could not put object to %s: %w", t, t.nodeInfo.AddressGroup(), err)
|
||||
return fmt.Errorf("(%T) could not put object to %s: %w", t, t.nodeInfo.AddressGroup(), err)
|
||||
}
|
||||
|
||||
return new(transformer.AccessIdentifiers).
|
||||
WithSelfID(res.ID()), nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRemoteSender creates, initializes and returns new RemoteSender instance.
|
||||
|
@ -119,9 +109,8 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
|
|||
return fmt.Errorf("parse client node info: %w", err)
|
||||
}
|
||||
|
||||
if err := t.WriteObject(p.obj, objectcore.ContentMeta{}); err != nil {
|
||||
return fmt.Errorf("(%T) could not send object header: %w", s, err)
|
||||
} else if _, err := t.Close(); err != nil {
|
||||
err = t.WriteObject(p.obj, objectcore.ContentMeta{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("(%T) could not send object: %w", s, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
|||
getWorkerPool: p.getWorkerPool,
|
||||
nodeTargetInitializer: func(node nodeDesc) preparedObjectTarget {
|
||||
if node.local {
|
||||
return &localTarget{
|
||||
return localTarget{
|
||||
storage: p.localStore,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue