2021-04-06 10:56:06 +00:00
|
|
|
package writecache
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2023-06-22 11:55:30 +00:00
|
|
|
"errors"
|
2021-04-06 10:56:06 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-08-09 12:54:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2023-06-22 11:55:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
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"
|
2021-04-06 10:56:06 +00:00
|
|
|
)
|
|
|
|
|
2021-12-20 10:03:06 +00:00
|
|
|
// Info groups the information about write-cache.
|
|
|
|
type Info struct {
|
|
|
|
// Full path to the write-cache.
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
2024-08-06 10:20:33 +00:00
|
|
|
type SealPrm struct {
|
|
|
|
IgnoreErrors bool
|
|
|
|
RestoreMode bool
|
2024-08-06 12:45:53 +00:00
|
|
|
Shrink bool
|
2024-08-06 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
// Cache represents write-cache for objects.
|
|
|
|
type Cache interface {
|
2023-07-06 12:36:41 +00:00
|
|
|
Get(ctx context.Context, address oid.Address) (*objectSDK.Object, error)
|
|
|
|
Head(context.Context, oid.Address) (*objectSDK.Object, error)
|
2022-10-28 10:55:21 +00:00
|
|
|
// Delete removes object referenced by the given oid.Address from the
|
|
|
|
// Cache. Returns any error encountered that prevented the object to be
|
|
|
|
// removed.
|
|
|
|
//
|
|
|
|
// Returns apistatus.ObjectNotFound if object is missing in the Cache.
|
|
|
|
// Returns ErrReadOnly if the Cache is currently in the read-only mode.
|
2023-04-12 14:01:29 +00:00
|
|
|
Delete(context.Context, oid.Address) error
|
|
|
|
Put(context.Context, common.PutPrm) (common.PutRes, error)
|
2024-10-21 08:56:38 +00:00
|
|
|
SetMode(context.Context, mode.Mode) error
|
2022-09-28 07:41:01 +00:00
|
|
|
SetLogger(*logger.Logger)
|
2021-12-20 10:03:06 +00:00
|
|
|
DumpInfo() Info
|
2023-12-27 05:20:15 +00:00
|
|
|
Flush(context.Context, bool, bool) error
|
2024-08-06 10:20:33 +00:00
|
|
|
Seal(context.Context, SealPrm) error
|
2021-04-06 10:56:06 +00:00
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
Init(context.Context) error
|
2024-02-09 06:17:17 +00:00
|
|
|
Open(ctx context.Context, mode mode.Mode) error
|
2024-10-21 13:27:28 +00:00
|
|
|
Close(context.Context) error
|
2024-02-13 06:09:47 +00:00
|
|
|
GetMetrics() Metrics
|
2021-04-06 10:56:06 +00:00
|
|
|
}
|
|
|
|
|
2023-08-09 12:54:08 +00:00
|
|
|
// MainStorage is the interface of the underlying storage of Cache implementations.
|
|
|
|
type MainStorage interface {
|
|
|
|
Compressor() *compression.Config
|
|
|
|
Exists(context.Context, common.ExistsPrm) (common.ExistsRes, error)
|
|
|
|
Put(context.Context, common.PutPrm) (common.PutRes, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metabase is the interface of the metabase used by Cache implementations.
|
|
|
|
type Metabase interface {
|
2023-10-13 11:01:14 +00:00
|
|
|
UpdateStorageID(context.Context, meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error)
|
2023-08-09 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
var (
|
2023-06-22 11:55:30 +00:00
|
|
|
// ErrReadOnly is returned when Put/Write is performed in a read-only mode.
|
|
|
|
ErrReadOnly = logicerr.New("write-cache is in read-only mode")
|
2024-02-20 14:24:57 +00:00
|
|
|
// ErrDegraded is returned when writecache is in degraded mode.
|
|
|
|
ErrDegraded = logicerr.New("write-cache is in degraded mode")
|
2023-06-22 11:55:30 +00:00
|
|
|
// ErrNotInitialized is returned when write-cache is initializing.
|
|
|
|
ErrNotInitialized = logicerr.New("write-cache is not initialized yet")
|
|
|
|
// ErrBigObject is returned when object is too big to be placed in cache.
|
|
|
|
ErrBigObject = errors.New("too big object")
|
|
|
|
// ErrOutOfSpace is returned when there is no space left to put a new object.
|
|
|
|
ErrOutOfSpace = errors.New("no space left in the write cache")
|
2021-04-06 10:56:06 +00:00
|
|
|
)
|