2024-08-30 09:09:14 +00:00
|
|
|
package writer
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-03 11:23:53 +00:00
|
|
|
"context"
|
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"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
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.
|
2023-07-06 12:36:41 +00:00
|
|
|
Put(context.Context, *objectSDK.Object) error
|
2022-11-01 17:32:43 +00:00
|
|
|
// Delete must delete passed objects
|
|
|
|
// and return any appeared error.
|
2023-04-04 11:40:01 +00:00
|
|
|
Delete(ctx context.Context, tombstone oid.Address, toDelete []oid.ID) error
|
2022-11-01 17:32:43 +00:00
|
|
|
// Lock must lock passed objects
|
|
|
|
// and return any appeared error.
|
2023-04-12 14:01:29 +00:00
|
|
|
Lock(ctx context.Context, locker oid.Address, toLock []oid.ID) error
|
2023-03-15 01:07:27 +00:00
|
|
|
// IsLocked must clarify object's lock status.
|
2023-04-12 14:01:29 +00:00
|
|
|
IsLocked(context.Context, oid.Address) (bool, error)
|
2022-03-15 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 09:09:14 +00:00
|
|
|
type LocalTarget struct {
|
|
|
|
Storage ObjectStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 09:09:14 +00:00
|
|
|
func (t LocalTarget) WriteObject(ctx context.Context, obj *objectSDK.Object, meta objectCore.ContentMeta) error {
|
2023-01-10 12:10:54 +00:00
|
|
|
switch meta.Type() {
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeTombstone:
|
2024-08-30 09:09:14 +00:00
|
|
|
err := t.Storage.Delete(ctx, objectCore.AddressOf(obj), meta.Objects())
|
2022-11-01 17:32:43 +00:00
|
|
|
if err != nil {
|
2023-01-10 12:10:54 +00:00
|
|
|
return fmt.Errorf("could not delete objects from tombstone locally: %w", err)
|
2022-11-01 17:32:43 +00:00
|
|
|
}
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeLock:
|
2024-08-30 09:09:14 +00:00
|
|
|
err := t.Storage.Lock(ctx, objectCore.AddressOf(obj), meta.Objects())
|
2022-11-01 17:32:43 +00:00
|
|
|
if err != nil {
|
2023-01-10 12:10:54 +00:00
|
|
|
return fmt.Errorf("could not lock object from lock objects locally: %w", err)
|
2022-11-01 17:32:43 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
// objects that do not change meta storage
|
|
|
|
}
|
|
|
|
|
2024-08-30 09:09:14 +00:00
|
|
|
if err := t.Storage.Put(ctx, obj); err != nil {
|
2023-01-10 12:10:54 +00:00
|
|
|
return fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
2023-01-10 12:10:54 +00:00
|
|
|
return nil
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|