[#6] services/object: Simplify local/remote targets
Some checks failed
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests (1.19) (pull_request) Successful in 14m18s
Vulncheck / Vulncheck (pull_request) Failing after 2m23s
Tests and linters / Staticcheck (pull_request) Successful in 4m8s
Build / Build Components (1.19) (pull_request) Successful in 3m26s
Build / Build Components (1.20) (pull_request) Successful in 2m56s
Tests and linters / Tests with -race (pull_request) Successful in 21m39s
Tests and linters / Tests (1.20) (pull_request) Successful in 22m36s
Tests and linters / Lint (pull_request) Successful in 1m39s
ci/woodpecker/push/pre-commit Pipeline was successful
Some checks failed
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests (1.19) (pull_request) Successful in 14m18s
Vulncheck / Vulncheck (pull_request) Failing after 2m23s
Tests and linters / Staticcheck (pull_request) Successful in 4m8s
Build / Build Components (1.19) (pull_request) Successful in 3m26s
Build / Build Components (1.20) (pull_request) Successful in 2m56s
Tests and linters / Tests with -race (pull_request) Successful in 21m39s
Tests and linters / Tests (1.20) (pull_request) Successful in 22m36s
Tests and linters / Lint (pull_request) Successful in 1m39s
ci/woodpecker/push/pre-commit Pipeline was successful
We do not use the return result from Close() and we always execute both methods in succession. It makes sense to unite them. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
448b48287c
commit
5ff82ff04f
4 changed files with 27 additions and 58 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
|
||||
)
|
||||
|
||||
// ObjectStorage is an object storage interface.
|
||||
|
@ -27,41 +26,26 @@ type ObjectStorage interface {
|
|||
|
||||
type localTarget struct {
|
||||
storage ObjectStorage
|
||||
|
||||
obj *objectSDK.Object
|
||||
meta objectCore.ContentMeta
|
||||
}
|
||||
|
||||
func (t *localTarget) WriteObject(obj *objectSDK.Object, meta objectCore.ContentMeta) error {
|
||||
t.obj = obj
|
||||
t.meta = meta
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *localTarget) Close(ctx context.Context) (*transformer.AccessIdentifiers, error) {
|
||||
switch t.meta.Type() {
|
||||
func (t localTarget) WriteObject(ctx context.Context, obj *objectSDK.Object, meta objectCore.ContentMeta) error {
|
||||
switch meta.Type() {
|
||||
case objectSDK.TypeTombstone:
|
||||
err := t.storage.Delete(ctx, objectCore.AddressOf(t.obj), t.meta.Objects())
|
||||
err := t.storage.Delete(ctx, 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 objectSDK.TypeLock:
|
||||
err := t.storage.Lock(ctx, objectCore.AddressOf(t.obj), t.meta.Objects())
|
||||
err := t.storage.Lock(ctx, 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(ctx, t.obj); err != nil { //TODO
|
||||
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
||||
if err := t.storage.Put(ctx, obj); err != nil {
|
||||
return fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
||||
}
|
||||
|
||||
id, _ := t.obj.ID()
|
||||
|
||||
return &transformer.AccessIdentifiers{
|
||||
SelfID: id,
|
||||
}, nil
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue