pogreb

package
v0.0.0-...-379a0d7 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownAction = errors.New("unknown action")
	ErrBogusStore    = errors.New("bogus store backend")
	ErrBadOptions    = errors.New("invalid pogreb options")
	ErrStoreExists   = errors.New("store name already exists")
	ErrNoStores      = errors.New("no stores initialized")
)
View Source
var ErrInvalidOptions = errors.New("invalid pogreb options")
View Source
var OptionAllowRecovery = func(opts *WrappedOptions) {
	opts.AllowRecovery = true
}

Functions

func SetDefaultPogrebOptions

func SetDefaultPogrebOptions(pogrebopts ...any) (err error)

SetDefaultPogrebOptions options will set the options used for all subsequent pogreb stores that are initialized.

Types

type CombinedMetrics

type CombinedMetrics struct {
	Puts           int64 `json:"puts"`
	Dels           int64 `json:"dels"`
	Gets           int64 `json:"gets"`
	HashCollisions int64 `json:"hash_collisions"`
}

func CombineMetrics

func CombineMetrics(metrics ...*pogreb.Metrics) *CombinedMetrics

func (*CombinedMetrics) Equal

func (cm *CombinedMetrics) Equal(other *CombinedMetrics) bool

type DB

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

DB is a mapper of a Filer and Searcher implementation using pogreb.

func OpenDB

func OpenDB(path string) *DB

OpenDB will either open an existing set of pogreb datastores at the given directory, or it will create a new one.

func (*DB) AllStores

func (db *DB) AllStores() map[string]encryptdb.Filer

AllStores returns a map of the names of all pogreb datastores and the corresponding Filers.

func (*DB) BackupAll

func (db *DB) BackupAll(archivePath string) (models.Backup, error)

func (*DB) Close

func (db *DB) Close(storeName string) error

Close is a simple shim for pogreb's Close function.

func (*DB) CloseAll

func (db *DB) CloseAll() error

CloseAll closes all bitcask datastores.

func (*DB) Destroy

func (db *DB) Destroy(name string) error

Destroy will remove a pogreb store and all data associated with it.

func (*DB) Discover

func (db *DB) Discover() ([]string, error)

Discover will discover and initialize all existing bitcask stores at the path opened by OpenDB.

func (*DB) Init

func (db *DB) Init(storeName string, opts ...any) error

Init opens a pogreb store at the given path to be referenced by storeName.

func (*DB) Meta

func (db *DB) Meta() models.Metadata

Meta returns the metadata for the pogreb database.

func (*DB) Path

func (db *DB) Path() string

Path returns the base path where we store our pogreb "stores".

func (*DB) RestoreAll

func (db *DB) RestoreAll(archivePath string) error

func (*DB) Sync

func (db *DB) Sync(storeName string) error

Sync is a simple shim for pogreb's Sync function.

func (*DB) SyncAll

func (db *DB) SyncAll() error

SyncAll syncs all pogreb datastores. TODO: investigate locking here, right now if we try to hold a lock during a backup we'll hang :^)

func (*DB) SyncAndCloseAll

func (db *DB) SyncAndCloseAll() error

SyncAndCloseAll implements the method from Keeper to sync and close all bitcask stores.

func (*DB) Type

func (db *DB) Type() string

func (*DB) UpdateMetrics

func (db *DB) UpdateMetrics()

func (*DB) With

func (db *DB) With(storeName string) encryptdb.Filer

With calls the given underlying pogreb instance.

func (*DB) WithNew

func (db *DB) WithNew(storeName string, opts ...any) encryptdb.Filer

WithNew calls the given underlying pogreb instance, if it doesn't exist, it creates it.

type Metrics

type Metrics struct {
	Puts           int64 `json:"puts"`
	Dels           int64 `json:"dels"`
	Gets           int64 `json:"gets"`
	HashCollisions int64 `json:"hash_collisions"`
}

type Option

type Option func(*WrappedOptions)

func AllowRecovery

func AllowRecovery() Option

func SetPogrebOptions

func SetPogrebOptions(options pogreb.Options) Option

type Store

type Store struct {
	*pogreb.DB
	// contains filtered or unexported fields
}

Store is an implmentation of a Filer and a Searcher using Bitcask.

func (*Store) Backend

func (pstore *Store) Backend() any

Backend returns the underlying pogren instance.

func (*Store) Close

func (pstore *Store) Close() error

Close is a simple shim for pogreb's Close function.

func (*Store) Get

func (pstore *Store) Get(key []byte) ([]byte, error)

Get is a wrapper for pogreb's Get function to regularize errors when keys do not exist.

func (*Store) Has

func (pstore *Store) Has(key []byte) bool

func (*Store) Keys

func (pstore *Store) Keys() [][]byte

func (*Store) Len

func (pstore *Store) Len() int

func (*Store) PrefixScan

func (pstore *Store) PrefixScan(prefixs string) (<-chan keyvalue.KeyValue, chan error)

PrefixScan will scan a Store for all keys that have a matching prefix of the given string and return a map of keys and values. (map[Key]Value) error channel will block, so be sure to read from it.

func (*Store) Search

func (pstore *Store) Search(query string) (<-chan keyvalue.KeyValue, chan error)

Search will search for a given string within all values inside of a Store. Note, type casting will be necessary. (e.g: []byte or string)

func (*Store) ValueExists

func (pstore *Store) ValueExists(value []byte) (key []byte, ok bool)

ValueExists will check for the existence of a Value anywhere within the keyspace; returning the first Key found, true if found || nil and false if not found.

type WrappedOptions

type WrappedOptions struct {
	*pogreb.Options `json:"options"`
	// AllowRecovery allows the database to be recovered if a lockfile is detected upon running Init.
	AllowRecovery bool `json:"allow_recovery,omitempty"`
}

func (*WrappedOptions) MarshalJSON

func (w *WrappedOptions) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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