writecache

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package writecache implements write-cache for objects.

It contains in-memory cache of fixed size and underlying database (usually on SSD) for storing small objects. There are 3 places where object can be: 1. In-memory cache. 2. On-disk cache DB. 3. Main storage (blobstor).

There are 2 types of background jobs:

  1. Persisting objects from in-memory cache to database.
  2. Flushing objects from database to blobstor. On flushing object address is put in in-memory LRU cache. The actual deletion from the DB is done when object is evicted from this cache.

Putting objects to the main storage is done by multiple workers. Some of them prioritize flushing items, others prioritize putting new objects. The current ration is 50/50. This helps to make some progress even under load.

Index

Constants

This section is empty.

Variables

View Source
var ErrBigObject = errors.New("too big object")

ErrBigObject is returned when object is too big to be placed in cache.

View Source
var ErrNoDefaultBucket = errors.New("no default bucket")

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

View Source
var ErrReadOnly = errors.New("write-cache is in read-only mode")

ErrReadOnly is returned when Put/Write is performed in a read-only mode.

Functions

func Get added in v0.26.0

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 requested object is missing in db.

func IsErrNotFound added in v0.28.0

func IsErrNotFound(err error) bool

IsErrNotFound checks if error returned by Cache Get/Head/Delete method corresponds to missing object.

func IterateDB added in v0.26.0

func IterateDB(db *bbolt.DB, f func(*addressSDK.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 added in v0.26.0

func OpenDB(p string, ro bool) (*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(*addressSDK.Address) (*object.Object, error)
	Head(*addressSDK.Address) (*object.Object, error)
	Delete(*addressSDK.Address) error
	Iterate(*IterationPrm) error
	Put(*object.Object) error
	SetMode(Mode)
	DumpInfo() Info

	Init() error
	Open() error
	Close() error
}

Cache represents write-cache for objects.

func New

func New(opts ...Option) Cache

New creates new writecache instance.

type Info added in v0.27.2

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

Info groups the information about write-cache.

type IterationPrm added in v0.27.5

type IterationPrm struct {
	// contains filtered or unexported fields
}

IterationPrm contains iteration parameters.

func (*IterationPrm) WithHandler added in v0.27.5

func (p *IterationPrm) WithHandler(f func([]byte) error) *IterationPrm

WithHandler sets a callback to be executed on every object.

func (*IterationPrm) WithIgnoreErrors added in v0.27.5

func (p *IterationPrm) WithIgnoreErrors(ignore bool) *IterationPrm

WithIgnoreErrors sets a flag indicating that errors should be ignored.

type Mode added in v0.27.5

type Mode uint32

Mode represents write-cache mode of operation.

const (
	// ModeReadWrite is a default mode allowing objects to be flushed.
	ModeReadWrite Mode = iota

	// ModeReadOnly is a mode in which write-cache doesn't flush anything to a metabase.
	ModeReadOnly

	// ModeDegraded is similar to a shard's degraded mode.
	ModeDegraded
)

type ObjectCounters added in v0.25.0

type ObjectCounters interface {
	// Increments number of objects saved in DB.
	IncDB()
	// Decrements number of objects saved in DB.
	DecDB()
	// Returns number of objects saved in DB.
	DB() uint64

	// Increments number of objects saved in FSTree.
	IncFS()
	// Decrements number of objects saved in FSTree.
	DecFS()
	// Returns number of objects saved in FSTree.
	FS() uint64

	// Reads number of objects saved in write-cache. It is called on write-cache initialization step.
	Read() error
	// Flushes the values and closes the storage. It is called on write-cache shutdown.
	FlushAndClose()
}

ObjectCounters is an interface of the storage of cached object amount.

type Option

type Option func(*options)

Option represents write-cache configuration option.

func WithBlobstor

func WithBlobstor(bs *blobstor.BlobStor) Option

WithBlobstor sets main object storage.

func WithFlushWorkersCount

func WithFlushWorkersCount(c int) Option

func WithLogger

func WithLogger(log *zap.Logger) Option

WithLogger sets logger.

func WithMaxCacheSize added in v0.25.0

func WithMaxCacheSize(sz uint64) Option

WithMaxCacheSize sets maximum write-cache size in bytes.

func WithMaxMemSize

func WithMaxMemSize(sz uint64) Option

WithMaxMemSize sets maximum size for in-memory DB.

func WithMaxObjectSize

func WithMaxObjectSize(sz uint64) Option

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

func WithMetabase

func WithMetabase(db *meta.DB) Option

WithMetabase sets metabase.

func WithObjectCounters added in v0.25.0

func WithObjectCounters(v ObjectCounters) Option

WithObjectCounters sets ObjectCounters instance needed for cache write-cache size estimation.

func WithPath

func WithPath(path string) Option

WithPath sets path to writecache db.

func WithSmallObjectSize

func WithSmallObjectSize(sz uint64) Option

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

Jump to

Keyboard shortcuts

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