writecache

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package writecache implements write-cache for objects.

Write-cache has 2 components: 1. Key-value (bbolt) database for storing small objects. 2. Filesystem tree for storing big objects.

Flushing from the writecache to the main storage is done in the background. To make it possible to serve Read requests after the object was flushed, we maintain an LRU cache containing addresses of all the objects that could be safely deleted. The actual deletion is done during eviction from this cache.

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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.

View Source
var ErrReadOnly = logicerr.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 the requested object is missing in db.

func IterateDB added in v0.26.0

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 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(address oid.Address) (*object.Object, error)
	// GetBytes reads object from the Cache by address into memory buffer in a
	// canonical NeoFS binary format. Returns [apistatus.ObjectNotFound] if object
	// is missing.
	GetBytes(oid.Address) ([]byte, error)
	Head(oid.Address) (*object.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(oid.Address) error
	Iterate(IterationPrm) error
	Put(common.PutPrm) (common.PutRes, error)
	SetMode(mode.Mode) error
	SetLogger(*zap.Logger)
	DumpInfo() Info
	Flush(bool) error

	Init() error
	Open(readOnly bool) error
	Close() error
	ObjectStatus(address oid.Address) (ObjectStatus, 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)

WithHandler sets a callback to be executed on every object.

func (*IterationPrm) WithIgnoreErrors added in v0.27.5

func (p *IterationPrm) WithIgnoreErrors(ignore bool)

WithIgnoreErrors sets a flag indicating that errors should be ignored.

type ObjectStatus added in v0.39.0

type ObjectStatus struct {
	PathDB     string
	PathFSTree string
}

ObjectStatus represents the status of the object in the Writecache.

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 WithMaxBatchDelay added in v0.29.0

func WithMaxBatchDelay(d time.Duration) Option

WithMaxBatchDelay sets max batch delay for the small object database.

func WithMaxBatchSize added in v0.29.0

func WithMaxBatchSize(sz int) Option

WithMaxBatchSize sets max batch size for the small object database.

func WithMaxCacheSize added in v0.25.0

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 *meta.DB) Option

WithMetabase sets metabase.

func WithNoSync added in v0.36.0

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 added in v0.36.0

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

WithReportErrorFunc sets error reporting function.

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