database

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0, BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrefixPeer defines the prefix of the peer db.
	PrefixPeer byte = iota

	// PrefixLedger defines the storage prefix for the ledger package.
	PrefixLedger

	// PrefixIndexer defines the storage prefix for the indexer package.
	PrefixIndexer
)

Variables

This section is empty.

Functions

func WithBaseDir

func WithBaseDir(baseDir string) options.Option[Manager]

WithBaseDir sets the base directory to store the DB to disk.

func WithDBProvider

func WithDBProvider(provider DBProvider) options.Option[Manager]

WithDBProvider sets the DB provider that is used to create new DB instances.

func WithGranularity

func WithGranularity(granularity int64) options.Option[Manager]

WithGranularity sets the granularity of the DB instances (i.e. how many buckets/slots are stored in one DB). It thus also has an impact on how fine-grained buckets/slots can be pruned.

func WithMaxOpenDBs

func WithMaxOpenDBs(optsMaxOpenDBs int) options.Option[Manager]

WithMaxOpenDBs sets the maximum concurrently open DBs.

Types

type CacheTimeProvider

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

CacheTimeProvider should be always used to get the CacheTime option for storage It wraps around objectstorage.CacheTime() function and may override the input duration.

func NewCacheTimeProvider

func NewCacheTimeProvider(forceCacheTime time.Duration) *CacheTimeProvider

NewCacheTimeProvider creates an instance that forces cache time to always be a certain value. If the given value is negative, hard coded defaults will be used.

func (*CacheTimeProvider) CacheTime

func (m *CacheTimeProvider) CacheTime(duration time.Duration) objectstorage.Option

CacheTime returns a CacheTime option. Duration may be overridden if CacheTimeProvider parameter is a non-negative integer.

type DB

type DB interface {
	// NewStore creates a new KVStore backed by the database.
	NewStore() kvstore.KVStore
	// Close closes a DB.
	Close() error

	// RequiresGC returns whether the database requires a call of GC() to clean deleted items.
	RequiresGC() bool
	// GC runs the garbage collection to clean deleted database items.
	GC() error
}

DB represents a database abstraction.

func NewDB

func NewDB(dirname string) (DB, error)

NewDB returns a new persisting DB object.

func NewMemDB

func NewMemDB(string) (DB, error)

NewMemDB returns a new in-memory (not persisted) DB object.

type DBProvider

type DBProvider func(dirname string) (DB, error)

DBProvider is a function that creates a new DB instance.

type IndexedKey

type IndexedKey[A any] interface {
	slot.IndexedID
	serializer.MarshalablePtr[A]
}

type Manager

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

func NewManager

func NewManager(version Version, opts ...options.Option[Manager]) *Manager

func (*Manager) Flush

func (m *Manager) Flush(index slot.Index)

func (*Manager) Get

func (m *Manager) Get(index slot.Index, realm kvstore.Realm) kvstore.KVStore

func (*Manager) IsTooOld

func (m *Manager) IsTooOld(index slot.Index) (isTooOld bool)

IsTooOld checks if the Block associated with the given id is too old (in a pruned slot).

func (*Manager) MaxPrunedSlot

func (m *Manager) MaxPrunedSlot() slot.Index

func (*Manager) PermanentStorage

func (m *Manager) PermanentStorage() kvstore.KVStore

func (*Manager) PermanentStorageSize

func (m *Manager) PermanentStorageSize() int64

PermanentStorageSize returns the size of the permanent storage.

func (*Manager) PrunableStorageSize

func (m *Manager) PrunableStorageSize() int64

PrunableStorageSize returns the size of the prunable storage containing all db instances.

func (*Manager) PruneUntilSlot

func (m *Manager) PruneUntilSlot(index slot.Index)

func (*Manager) RestoreFromDisk

func (m *Manager) RestoreFromDisk() (latestBucketIndex slot.Index)

func (*Manager) Shutdown

func (m *Manager) Shutdown()

func (*Manager) TotalStorageSize

func (m *Manager) TotalStorageSize() int64

TotalStorageSize returns the combined size of the permanent and prunable storage.

type PersistentSlotStorage

type PersistentSlotStorage[K, V any, KPtr IndexedKey[K], VPtr serializer.MarshalablePtr[V]] struct {
	// contains filtered or unexported fields
}

func NewPersistentSlotStorage

func NewPersistentSlotStorage[K, V any, KPtr IndexedKey[K], VPtr serializer.MarshalablePtr[V]](dbManager *Manager, realm kvstore.Realm) *PersistentSlotStorage[K, V, KPtr, VPtr]

func (*PersistentSlotStorage[K, V, KPtr, VPtr]) Delete

func (p *PersistentSlotStorage[K, V, KPtr, VPtr]) Delete(key K) (success bool)

func (*PersistentSlotStorage[K, V, KPtr, VPtr]) Get

func (p *PersistentSlotStorage[K, V, KPtr, VPtr]) Get(key K) (value V, exists bool)

func (*PersistentSlotStorage[K, V, KPtr, VPtr]) Iterate

func (p *PersistentSlotStorage[K, V, KPtr, VPtr]) Iterate(index slot.Index, callback func(key K, value V) (advance bool), direction ...kvstore.IterDirection) (err error)

func (*PersistentSlotStorage[K, V, KPtr, VPtr]) Set

func (p *PersistentSlotStorage[K, V, KPtr, VPtr]) Set(key K, value V) (err error)

type Version

type Version byte

func (*Version) Bytes

func (v *Version) Bytes() (bytes []byte, err error)

func (*Version) FromBytes

func (v *Version) FromBytes(bytes []byte) (consumedBytes int, err error)

Jump to

Keyboard shortcuts

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