[#6] services/object: Simplify local/remote targets

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-01-10 15:10:54 +03:00
parent 339fccde4c
commit 4f14360212
4 changed files with 20 additions and 48 deletions

View file

@ -17,7 +17,6 @@ import (
type preparedObjectTarget interface { type preparedObjectTarget interface {
WriteObject(*objectSDK.Object, object.ContentMeta) error WriteObject(*objectSDK.Object, object.ContentMeta) error
Close() (*transformer.AccessIdentifiers, error)
} }
type distributedTarget struct { type distributedTarget struct {
@ -154,10 +153,9 @@ func (t *distributedTarget) sendObject(node nodeDesc) error {
target := t.nodeTargetInitializer(node) 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) 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 return nil
} }

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
objectCore "github.com/TrueCloudLab/frostfs-node/pkg/core/object" objectCore "github.com/TrueCloudLab/frostfs-node/pkg/core/object"
"github.com/TrueCloudLab/frostfs-node/pkg/services/object_manager/transformer"
"github.com/TrueCloudLab/frostfs-sdk-go/object" "github.com/TrueCloudLab/frostfs-sdk-go/object"
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id" oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
) )
@ -24,40 +23,26 @@ type ObjectStorage interface {
type localTarget struct { type localTarget struct {
storage ObjectStorage storage ObjectStorage
obj *object.Object
meta objectCore.ContentMeta
} }
func (t *localTarget) WriteObject(obj *object.Object, meta objectCore.ContentMeta) error { func (t localTarget) WriteObject(obj *object.Object, meta objectCore.ContentMeta) error {
t.obj = obj switch meta.Type() {
t.meta = meta
return nil
}
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
switch t.meta.Type() {
case object.TypeTombstone: 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 { 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: 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 { 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: default:
// objects that do not change meta storage // objects that do not change meta storage
} }
if err := t.storage.Put(t.obj); err != nil { if err := t.storage.Put(obj); err != nil {
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err) return fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
} }
return nil
id, _ := t.obj.ID()
return new(transformer.AccessIdentifiers).
WithSelfID(id), nil
} }

View file

@ -9,7 +9,6 @@ import (
objectcore "github.com/TrueCloudLab/frostfs-node/pkg/core/object" objectcore "github.com/TrueCloudLab/frostfs-node/pkg/core/object"
internalclient "github.com/TrueCloudLab/frostfs-node/pkg/services/object/internal/client" internalclient "github.com/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
"github.com/TrueCloudLab/frostfs-node/pkg/services/object/util" "github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
"github.com/TrueCloudLab/frostfs-node/pkg/services/object_manager/transformer"
"github.com/TrueCloudLab/frostfs-sdk-go/netmap" "github.com/TrueCloudLab/frostfs-sdk-go/netmap"
"github.com/TrueCloudLab/frostfs-sdk-go/object" "github.com/TrueCloudLab/frostfs-sdk-go/object"
) )
@ -23,8 +22,6 @@ type remoteTarget struct {
nodeInfo clientcore.NodeInfo nodeInfo clientcore.NodeInfo
obj *object.Object
clientConstructor ClientConstructor clientConstructor ClientConstructor
} }
@ -44,12 +41,6 @@ type RemotePutPrm struct {
} }
func (t *remoteTarget) WriteObject(obj *object.Object, _ objectcore.ContentMeta) error { func (t *remoteTarget) WriteObject(obj *object.Object, _ objectcore.ContentMeta) error {
t.obj = obj
return nil
}
func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
var sessionInfo *util.SessionInfo var sessionInfo *util.SessionInfo
if tok := t.commonPrm.SessionToken(); tok != nil { if tok := t.commonPrm.SessionToken(); tok != nil {
@ -61,12 +52,12 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
key, err := t.keyStorage.GetKey(sessionInfo) key, err := t.keyStorage.GetKey(sessionInfo)
if err != nil { if err != nil {
return nil, fmt.Errorf("(%T) could not receive private key: %w", t, err) return fmt.Errorf("(%T) could not receive private key: %w", t, err)
} }
c, err := t.clientConstructor.Get(t.nodeInfo) c, err := t.clientConstructor.Get(t.nodeInfo)
if err != nil { 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 var prm internalclient.PutObjectPrm
@ -77,15 +68,14 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
prm.SetSessionToken(t.commonPrm.SessionToken()) prm.SetSessionToken(t.commonPrm.SessionToken())
prm.SetBearerToken(t.commonPrm.BearerToken()) prm.SetBearerToken(t.commonPrm.BearerToken())
prm.SetXHeaders(t.commonPrm.XHeaders()) prm.SetXHeaders(t.commonPrm.XHeaders())
prm.SetObject(t.obj) prm.SetObject(obj)
res, err := internalclient.PutObject(prm) _, err = internalclient.PutObject(prm)
if err != nil { 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). return nil
WithSelfID(res.ID()), nil
} }
// NewRemoteSender creates, initializes and returns new RemoteSender instance. // NewRemoteSender creates, initializes and returns new RemoteSender instance.
@ -127,9 +117,8 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
return fmt.Errorf("parse client node info: %w", err) return fmt.Errorf("parse client node info: %w", err)
} }
if err := t.WriteObject(p.obj, objectcore.ContentMeta{}); err != nil { err = t.WriteObject(p.obj, objectcore.ContentMeta{})
return fmt.Errorf("(%T) could not send object header: %w", s, err) if err != nil {
} else if _, err := t.Close(); err != nil {
return fmt.Errorf("(%T) could not send object: %w", s, err) return fmt.Errorf("(%T) could not send object: %w", s, err)
} }

View file

@ -220,7 +220,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
getWorkerPool: p.getWorkerPool, getWorkerPool: p.getWorkerPool,
nodeTargetInitializer: func(node nodeDesc) preparedObjectTarget { nodeTargetInitializer: func(node nodeDesc) preparedObjectTarget {
if node.local { if node.local {
return &localTarget{ return localTarget{
storage: p.localStore, storage: p.localStore,
} }
} }