writecache

package
v0.43.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrReadOnly is returned when Put/Write is performed in a read-only mode.
	ErrReadOnly = logicerr.New("write-cache is in read-only mode")
	// ErrDegraded is returned when writecache is in degraded mode.
	ErrDegraded = logicerr.New("write-cache is in degraded mode")
	// 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")
)
View Source
var ErrNoDefaultBucket = errors.New("no default bucket")

ErrNoDefaultBucket is returned by IterateDB when default bucket for objects is missing.

Functions

func Get

func Get(db *bbolt.DB, key []byte) ([]byte, error)

Get fetches object from the underlying database. Key should be a stringified address.

Returns an error of type apistatus.ObjectNotFound if the requested object is missing in db.

func IterateDB

func IterateDB(db *bbolt.DB, f func(oid.Address) error) error

IterateDB iterates over all objects stored in bbolt.DB instance and passes them to f until error return. It is assumed that db is an underlying database of some WriteCache instance.

Returns ErrNoDefaultBucket if there is no default bucket in db.

DB must not be nil and should be opened.

func OpenDB

func OpenDB(p string, ro bool, openFile func(string, int, fs.FileMode) (*os.File, error)) (*bbolt.DB, error)

OpenDB opens BoltDB instance for write-cache. Opens in read-only mode if ro is true.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, address oid.Address) (*objectSDK.Object, error)
	Head(context.Context, oid.Address) (*objectSDK.Object, error)
	// 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.
	Delete(context.Context, oid.Address) error
	Put(context.Context, common.PutPrm) (common.PutRes, error)
	SetMode(mode.Mode) error
	SetLogger(*logger.Logger)
	DumpInfo() Info
	Flush(context.Context, bool, bool) error
	Seal(context.Context, SealPrm) error

	Init() error
	Open(ctx context.Context, mode mode.Mode) error
	Close() error
	GetMetrics() Metrics
}

Cache represents write-cache for objects.

func New

func New(opts ...Option) Cache

New creates new writecache instance.

type Info

type Info struct {
	// Full path to the write-cache.
	Path string
}

Info groups the information about write-cache.

type MainStorage added in v0.37.0

type MainStorage interface {
	Compressor() *compression.Config
	Exists(context.Context, common.ExistsPrm) (common.ExistsRes, error)
	Put(context.Context, common.PutPrm) (common.PutRes, error)
}

MainStorage is the interface of the underlying storage of Cache implementations.

type Metabase added in v0.37.0

type Metabase interface {
	UpdateStorageID(context.Context, meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error)
}

Metabase is the interface of the metabase used by Cache implementations.

type Metrics added in v0.37.0

type Metrics interface {
	SetShardID(string)
	Get(d time.Duration, success bool, st StorageType)
	Delete(d time.Duration, success bool, st StorageType)
	Put(d time.Duration, success bool, st StorageType)
	Flush(success bool, st StorageType)
	Evict(st StorageType)

	SetEstimateSize(uint64)
	SetMode(m mode.ComponentMode)
	SetActualCounters(uint64)
	SetPath(path string)
	Close()
}

func DefaultMetrics added in v0.37.0

func DefaultMetrics() Metrics

type Option

type Option func(*options)

Option represents write-cache configuration option.

func WithBlobstor

func WithBlobstor(bs MainStorage) Option

WithBlobstor sets main object storage.

func WithDisableBackgroundFlush added in v0.38.0

func WithDisableBackgroundFlush() Option

WithDisableBackgroundFlush disables background flush, for testing purposes only.

func WithFlushSizeLimit added in v0.43.0

func WithFlushSizeLimit(v uint64) Option

WithFlushSizeLimit sets flush size limit.

func WithFlushWorkersCount

func WithFlushWorkersCount(c int) Option

func WithLogger

func WithLogger(log *logger.Logger) Option

WithLogger sets logger.

func WithMaxCacheCount added in v0.43.0

func WithMaxCacheCount(v uint64) Option

WithMaxCacheCount sets maximum write-cache objects count.

func WithMaxCacheSize

func WithMaxCacheSize(sz uint64) Option

WithMaxCacheSize sets maximum write-cache size in bytes.

func WithMaxObjectSize

func WithMaxObjectSize(sz uint64) Option

WithMaxObjectSize sets maximum object size to be stored in write-cache.

func WithMetabase

func WithMetabase(db Metabase) Option

WithMetabase sets metabase.

func WithMetrics added in v0.38.0

func WithMetrics(metrics Metrics) Option

WithMetrics sets metrics implementation.

func WithNoSync

func WithNoSync(noSync bool) Option

WithNoSync sets an option to allow returning to caller on PUT before write is persisted. Note, that we use this flag for FSTree only and DO NOT use it for a bolt DB because we cannot yet properly handle the corrupted database during the startup. This SHOULD NOT be relied upon and may be changed in future.

func WithPath

func WithPath(path string) Option

WithPath sets path to writecache db.

func WithReportErrorFunc

func WithReportErrorFunc(f func(string, error)) Option

WithReportErrorFunc sets error reporting function.

type SealPrm added in v0.43.0

type SealPrm struct {
	IgnoreErrors bool
	RestoreMode  bool
	Shrink       bool
}

type StorageType added in v0.37.0

type StorageType string
const (
	StorageTypeUndefined StorageType = "null"
	StorageTypeDB        StorageType = "db"
	StorageTypeFSTree    StorageType = "fstree"
)

func (StorageType) String added in v0.37.0

func (t StorageType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL