2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
// ObjectStorage is an object storage interface.
|
|
|
|
type ObjectStorage interface {
|
|
|
|
// Put must save passed object
|
|
|
|
// and return any appeared error.
|
2022-11-01 17:32:43 +00:00
|
|
|
Put(*object.Object) error
|
|
|
|
// Delete must delete passed objects
|
|
|
|
// and return any appeared error.
|
|
|
|
Delete(tombstone oid.Address, toDelete []oid.ID) error
|
|
|
|
// Lock must lock passed objects
|
|
|
|
// and return any appeared error.
|
|
|
|
Lock(locker oid.Address, toLock []oid.ID) error
|
2022-03-15 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
type localTarget struct {
|
2022-03-15 19:40:31 +00:00
|
|
|
storage ObjectStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2022-11-01 17:32:43 +00:00
|
|
|
obj *object.Object
|
|
|
|
meta objectCore.ContentMeta
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-01 17:32:43 +00:00
|
|
|
func (t *localTarget) WriteObject(obj *object.Object, meta objectCore.ContentMeta) error {
|
2020-09-21 14:31:31 +00:00
|
|
|
t.obj = obj
|
2022-11-01 17:32:43 +00:00
|
|
|
t.meta = meta
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
|
2022-11-01 17:32:43 +00:00
|
|
|
switch t.meta.Type() {
|
|
|
|
case object.TypeTombstone:
|
|
|
|
err := t.storage.Delete(objectCore.AddressOf(t.obj), t.meta.Objects())
|
|
|
|
if err != nil {
|
|
|
|
return nil, 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())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not lock object from lock objects locally: %w", err)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// objects that do not change meta storage
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
if err := t.storage.Put(t.obj); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := t.obj.ID()
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
return new(transformer.AccessIdentifiers).
|
2022-05-31 17:00:41 +00:00
|
|
|
WithSelfID(id), nil
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|