archivedb

package
v1.11.12-rc.12 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("feature not implemented")
	ErrInvalidValue   = errors.New("invalid data value")
)
View Source
var (
	ErrParsingKeyLength   = errors.New("failed reading key length")
	ErrIncorrectKeyLength = errors.New("incorrect key length")
)

Functions

This section is empty.

Types

type Database

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

Database implements an ArchiveDB on top of a database.Database. An ArchiveDB is an append only database which stores all state changes happening at every height. Each record is stored in such way to perform both fast insertions and lookups.

The API is quite simple, it has two main functions, one to create a Batch write with a given height, inside this batch entries can be added with a given value or they can be deleted.

The way it works is as follows:
	- NewBatch(10)
		batch.Put(foo, "foo's value is bar")
		batch.Put(bar, "bar's value is bar")
	- NewBatch(100)
		batch.Put(foo, "updatedfoo's value is bar")
	- NewBatch(1000)
		batch.Put(bar, "updated bar's value is bar")
		batch.Delete(foo)

The other primary function is to read data at a given height.

The way it works is as follows:
	- Open(10)
		reader.Get(foo)
		reader.Get(bar)
	- Open(99)
		reader.GetHeight(foo)
	- Open(100)
		reader.Get(foo)
	- Open(1000)
		reader.Get(foo)

Requesting `reader.Get(foo)` at height 1000 will return ErrNotFound because foo was deleted at height 1000. When calling `reader.GetHeight(foo)` at height 99 it will return a tuple `("foo's value is bar", 10)` returning the value of `foo` at height 99 (which was set at height 10).

func New

func New(db database.Database) *Database

func (*Database) Close

func (db *Database) Close() error

func (*Database) Compact

func (db *Database) Compact(start []byte, limit []byte) error

func (*Database) HealthCheck

func (db *Database) HealthCheck(ctx context.Context) (interface{}, error)

func (*Database) Height

func (db *Database) Height() (uint64, error)

Height returns the last written height.

func (*Database) NewBatch

func (db *Database) NewBatch(height uint64) *batch

NewBatch creates a write batch to perform changes at a given height.

Note: Committing multiple batches at the same height, or at a lower height than the currently committed height will not error. It is left up to the caller to enforce any guarantees they need around height consistency.

func (*Database) Open

func (db *Database) Open(height uint64) *Reader

Open returns a reader for the state at the given height.

type Reader

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

func (*Reader) Get

func (r *Reader) Get(key []byte) ([]byte, error)

func (*Reader) GetEntry

func (r *Reader) GetEntry(key []byte) ([]byte, uint64, bool, error)

GetEntry retrieves the value of the provided key, the height it was last modified at, and a boolean to indicate if the last modification was an insertion. If the key has never been modified, ErrNotFound will be returned.

func (*Reader) Has

func (r *Reader) Has(key []byte) (bool, error)

Jump to

Keyboard shortcuts

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