file

package
v0.1.1-experimental.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func ExtractIndex

func ExtractIndex(prefixedKey []byte) (uint64, error)

ExtractIndex extracts the index from a prefixed key.

Types

type DB

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

DB represents a filesystem backed key-value store. It is useful for storing amounts of data that exceed what is performant to store in a traditional key-value database.

func NewDB

func NewDB(opts ...Option) *DB

NewDB creates a new instance of the DB.

func (*DB) Delete

func (db *DB) Delete(key []byte) error

Delete removes the value for a key.

func (*DB) Get

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

Get retrieves the value for a key.

func (*DB) Has

func (db *DB) Has(key []byte) (bool, error)

Has returns true if the key exists in the database.

func (*DB) Set

func (db *DB) Set(key []byte, value []byte) error

Set stores the value for a key.

type Option

type Option func(*DB) error

func WithAferoFS

func WithAferoFS(fs afero.Fs) Option

WithAferoFS sets the filesystem for the database. NOTE: Should only be used for testing.

func WithDirectoryPermissions

func WithDirectoryPermissions(permissions os.FileMode) Option

WithDirectoryPermissions sets the permissions for the directory.

func WithFileExtension

func WithFileExtension(extension string) Option

WithFileExtension sets the file extension for the database.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger for the database.

func WithRootDirectory

func WithRootDirectory(rootDir string) Option

WithRootDirectory sets the root directory for the database.

type RangeDB

type RangeDB struct {
	db.DB
}

RangeDB is a database that stores versioned data. It prefixes keys with an index.

func NewRangeDB

func NewRangeDB(db db.DB) *RangeDB

NewRangeDB creates a new RangeDB.

func (*RangeDB) Delete

func (db *RangeDB) Delete(index uint64, key []byte) error

Delete removes the value associated with the given index and key from the database. It prefixes the key with the index and a slash before deleting it from the underlying database.

func (*RangeDB) DeleteRange

func (db *RangeDB) DeleteRange(from, to uint64) error

DeleteRange removes all values associated with the given index from the filesystem. It is INCLUSIVE of the `from` index and EXCLUSIVE of the `to“ index.

func (*RangeDB) Get

func (db *RangeDB) Get(index uint64, key []byte) ([]byte, error)

Get retrieves the value associated with the given index and key. It prefixes the key with the index and a slash before querying the underlying database.

func (*RangeDB) Has

func (db *RangeDB) Has(index uint64, key []byte) (bool, error)

Has checks if the given index and key exist in the database. It prefixes the key with the index and a slash before querying the underlying database.

func (*RangeDB) Set

func (db *RangeDB) Set(index uint64, key []byte, value []byte) error

Set stores the value with the given index and key in the database. It prefixes the key with the index and a slash before storing it in the underlying database.

type RangeDBPruner

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

RangeDBPruner prunes old indexes from the range DB.

func NewRangeDBPruner

func NewRangeDBPruner(
	db *RangeDB,
	pruneWindow uint64,
	notifyNewIndex chan uint64,
) *RangeDBPruner

func (*RangeDBPruner) Start

func (p *RangeDBPruner) Start(ctx context.Context)

Start starts a goroutine that listens for new indices to prune.

Jump to

Keyboard shortcuts

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