kv

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned when the targeted key doesn't exist.
	ErrKeyNotFound = errors.New("key not found")

	// ErrKeyAlreadyExists is returned when the targeted key already exists.
	ErrKeyAlreadyExists = errors.New("key already exists")
)

Common errors returned by the engine.

View Source
var DefaultComparer = &pebble.Comparer{
	Compare:        encoding.Compare,
	Equal:          encoding.Equal,
	AbbreviatedKey: encoding.AbbreviatedKey,
	FormatKey:      pebble.DefaultComparer.FormatKey,
	Separator:      encoding.Separator,
	Successor:      encoding.Successor,

	Name: "leveldb.BytewiseComparator",
}

DefaultComparer is the default implementation of the Comparer interface for chai.

Functions

This section is empty.

Types

type BatchSession

type BatchSession struct {
	Store *Store
	DB    *pebble.DB
	Batch *pebble.Batch
	// contains filtered or unexported fields
}

func (*BatchSession) Close

func (s *BatchSession) Close() error

func (*BatchSession) Commit

func (s *BatchSession) Commit() error

func (*BatchSession) Delete

func (s *BatchSession) Delete(k []byte) error

Delete a record by key. If the key doesn't exist, it doesn't do anything.

func (*BatchSession) DeleteRange

func (s *BatchSession) DeleteRange(start []byte, end []byte) error

DeleteRange deletes all keys in the given range. This implementation deletes all keys one by one to simplify the rollback.

func (*BatchSession) Exists

func (s *BatchSession) Exists(k []byte) (bool, error)

Exists returns whether a key exists and is visible by the current session.

func (*BatchSession) Get

func (s *BatchSession) Get(k []byte) ([]byte, error)

Get returns a value associated with the given key. If not found, returns ErrKeyNotFound.

func (*BatchSession) Insert

func (s *BatchSession) Insert(k, v []byte) error

Insert inserts a key-value pair. If it already exists, it returns ErrKeyAlreadyExists.

func (*BatchSession) Iterator

func (s *BatchSession) Iterator(opts *IterOptions) (Iterator, error)

func (*BatchSession) Put

func (s *BatchSession) Put(k, v []byte) error

Put stores a key value pair. If it already exists, it overrides it.

type IterOptions

type IterOptions struct {
	// LowerBound specifies the smallest key (inclusive) that the iterator will
	// return during iteration. If the iterator is seeked or iterated past this
	// boundary the iterator will return Valid()==false. Setting LowerBound
	// effectively truncates the key space visible to the iterator.
	LowerBound []byte
	// UpperBound specifies the largest key (exclusive) that the iterator will
	// return during iteration. If the iterator is seeked or iterated past this
	// boundary the iterator will return Valid()==false. Setting UpperBound
	// effectively truncates the key space visible to the iterator.
	UpperBound []byte
}

type Iterator

type Iterator interface {
	Close() error
	First() bool
	Last() bool
	Valid() bool
	Next() bool
	Prev() bool
	Error() error
	Key() []byte
	Value() ([]byte, error)
}

type Options

type Options struct {
	RollbackSegmentNamespace int64
	MaxBatchSize             int
	MaxTransientBatchSize    int
	MinTransientNamespace    uint64
	MaxTransientNamespace    uint64
}

type RollbackSegment

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

func NewRollbackSegment

func NewRollbackSegment(db *pebble.DB, namespace int64) *RollbackSegment

func (*RollbackSegment) Apply

func (s *RollbackSegment) Apply(b *pebble.Batch) error

func (*RollbackSegment) Clear

func (s *RollbackSegment) Clear(b *pebble.Batch) error

func (*RollbackSegment) Reset

func (s *RollbackSegment) Reset() error

func (*RollbackSegment) Rollback

func (s *RollbackSegment) Rollback() error

type Session

type Session interface {
	Commit() error
	Close() error
	// Insert inserts a key-value pair. If it already exists, it returns ErrKeyAlreadyExists.
	Insert(k, v []byte) error
	// Put stores a key-value pair. If it already exists, it overrides it.
	Put(k, v []byte) error
	// Get returns a value associated with the given key. If not found, returns ErrKeyNotFound.
	Get(k []byte) ([]byte, error)
	// Exists returns whether a key exists and is visible by the current session.
	Exists(k []byte) (bool, error)
	// Delete a record by key. If not found, returns ErrKeyNotFound.
	Delete(k []byte) error
	DeleteRange(start []byte, end []byte) error
	Iterator(opts *IterOptions) (Iterator, error)
}

type SnapshotSession

type SnapshotSession struct {
	Store    *Store
	Snapshot *snapshot
	// contains filtered or unexported fields
}

func (*SnapshotSession) Close

func (s *SnapshotSession) Close() error

func (*SnapshotSession) Commit

func (s *SnapshotSession) Commit() error

func (*SnapshotSession) Delete

func (s *SnapshotSession) Delete(k []byte) error

Delete a record by key. If not found, returns ErrKeyNotFound.

func (*SnapshotSession) DeleteRange

func (s *SnapshotSession) DeleteRange(start []byte, end []byte) error

func (*SnapshotSession) Exists

func (s *SnapshotSession) Exists(k []byte) (bool, error)

Exists returns whether a key exists and is visible by the current session.

func (*SnapshotSession) Get

func (s *SnapshotSession) Get(k []byte) ([]byte, error)

Get returns a value associated with the given key. If not found, returns ErrKeyNotFound.

func (*SnapshotSession) Insert

func (s *SnapshotSession) Insert(k, v []byte) error

func (*SnapshotSession) Iterator

func (s *SnapshotSession) Iterator(opts *IterOptions) (Iterator, error)

func (*SnapshotSession) Put

func (s *SnapshotSession) Put(k, v []byte) error

type Store

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

func NewEngine

func NewEngine(path string, opts Options) (*Store, error)

func NewEngineWith

func NewEngineWith(path string, opts Options, popts *pebble.Options) (*Store, error)

func NewStore

func NewStore(db *pebble.DB, opts Options) *Store

func (*Store) CleanupTransientNamespaces

func (s *Store) CleanupTransientNamespaces() error

func (*Store) Close

func (s *Store) Close() error

func (*Store) DB

func (s *Store) DB() *pebble.DB

func (*Store) LockSharedSnapshot

func (s *Store) LockSharedSnapshot()

func (*Store) NewBatchSession

func (s *Store) NewBatchSession() *BatchSession

func (*Store) NewSnapshotSession

func (s *Store) NewSnapshotSession() *SnapshotSession

func (*Store) NewTransientSession

func (s *Store) NewTransientSession() *TransientSession

func (*Store) ResetRollbackSegment

func (s *Store) ResetRollbackSegment() error

func (*Store) Rollback

func (s *Store) Rollback() error

func (*Store) UnlockSharedSnapshot

func (s *Store) UnlockSharedSnapshot()

type TransientSession

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

func (*TransientSession) Close

func (s *TransientSession) Close() error

func (*TransientSession) Commit

func (s *TransientSession) Commit() error

func (*TransientSession) Delete

func (s *TransientSession) Delete(k []byte) error

Delete a record by key. If not found, returns ErrKeyNotFound.

func (*TransientSession) DeleteRange

func (s *TransientSession) DeleteRange(start []byte, end []byte) error

func (*TransientSession) Exists

func (s *TransientSession) Exists(k []byte) (bool, error)

Exists returns whether a key exists and is visible by the current session.

func (*TransientSession) Get

func (s *TransientSession) Get(k []byte) ([]byte, error)

Get returns a value associated with the given key. If not found, returns ErrKeyNotFound.

func (*TransientSession) Insert

func (s *TransientSession) Insert(k, v []byte) error

func (*TransientSession) Iterator

func (s *TransientSession) Iterator(opts *IterOptions) (Iterator, error)

func (*TransientSession) Put

func (s *TransientSession) Put(k, v []byte) error

Put stores a key value pair. If it already exists, it overrides it.

Jump to

Keyboard shortcuts

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