dbkernel

package
v0.0.0-...-028e620 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CustomEpochMs is a Sentinel Value for Jan 1, 2025 @ 00:00:00 UTC.
	CustomEpochMs = 1735689600000
)

Variables

View Source
var (
	// ErrKeyNotFound is a sentinel error for missing keys.
	ErrKeyNotFound     = kvdrivers.ErrKeyNotFound
	ErrBucketNotFound  = kvdrivers.ErrBucketNotFound
	ErrRecordCorrupted = kvdrivers.ErrRecordCorrupted
	ErrUseGetColumnAPI = kvdrivers.ErrUseGetColumnAPI

	ErrInCloseProcess   = errors.New("in-Close process")
	ErrDatabaseDirInUse = errors.New("pid.lock is held by another process")
	ErrInternalError    = errors.New("internal error")
	ErrMisMatchKeyType  = errors.New("mismatch key type with existing value")
)
View Source
var (
	ErrInvalidLSN    = errors.New("invalid LSN")
	ErrInvalidOffset = errors.New("appendLog: offset does not match record")
)
View Source
var (
	ErrTxnAlreadyCommitted      = errors.New("txn already committed")
	ErrKeyChangedForChunkedType = errors.New("chunked txn type cannot change key from first value")
	ErrUnsupportedTxnType       = errors.New("unsupported txn type")
	ErrEmptyColumns             = errors.New("empty column set")
)
View Source
var (
	// ErrWaitTimeoutExceeded is a sentinel error to denotes sync.cond expired due to timeout.
	ErrWaitTimeoutExceeded = errors.New("wait timeout exceeded")
)

Functions

func HLCDecode

func HLCDecode(encodedHLC uint64) (uint64, uint32)

HLCDecode Extract lastTime and counter from the encoded HLC.

func HLCNow

func HLCNow() uint64

HLCNow returns an encoded hybrid logical clock. 41 bits = ms timestamp since custom epoch and 23 bits = logical counter.

func IsConcurrent

func IsConcurrent(hlc1, hlc2 uint64) bool

IsConcurrent return true if the two hybrid logical clock have happened at the same time but are distinct events within a millisecond interval.

Types

type DBEngine

type DBEngine string

DBEngine : which bTreeStore engine to use for the underlying persistence storage.

const (
	BoltDBEngine DBEngine = "BOLT"
	LMDBEngine   DBEngine = "LMDB"
)

type Engine

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

Engine manages WAL, MemTable (SkipList), and BtreeStore for a given namespace.

func NewStorageEngine

func NewStorageEngine(dataDir, namespace string, conf *EngineConfig) (*Engine, error)

NewStorageEngine initializes WAL, MemTable, and BtreeStore and returns an initialized Engine for a namespace.

func (*Engine) BatchDelete

func (e *Engine) BatchDelete(keys [][]byte) error

BatchDelete removes all the key and its value pair.

func (*Engine) BatchDeleteRows

func (e *Engine) BatchDeleteRows(rowKeys [][]byte) error

func (*Engine) BatchPut

func (e *Engine) BatchPut(key, value [][]byte) error

BatchPut insert the associated Key Value Pair.

func (*Engine) BtreeSnapshot

func (e *Engine) BtreeSnapshot(w io.Writer) (int64, error)

BtreeSnapshot returns the snapshot of the current btree store.

func (*Engine) Close

func (e *Engine) Close(ctx context.Context) error

Close all the associated resource.

func (*Engine) CurrentOffset

func (e *Engine) CurrentOffset() *Offset

CurrentOffset returns the current offset that it has seen.

func (*Engine) Delete

func (e *Engine) Delete(key []byte) error

Delete removes a key and its value pair.

func (*Engine) DeleteColumnsForRow

func (e *Engine) DeleteColumnsForRow(rowKey []byte, columnEntries map[string][]byte) error

DeleteColumnsForRow removes the specified columns from the given row key.

func (*Engine) DeleteColumnsForRows

func (e *Engine) DeleteColumnsForRows(rowKeys [][]byte, columnEntries []map[string][]byte) error

DeleteColumnsForRows removes specified columns from multiple rows.

func (*Engine) DeleteRow

func (e *Engine) DeleteRow(rowKey []byte) error

DeleteRow removes an entire row and all its associated column entries.

func (*Engine) Get

func (e *Engine) Get(key []byte) ([]byte, error)

Get retrieves the value associated with the given key.

func (*Engine) GetRowColumns

func (e *Engine) GetRowColumns(rowKey string, predicate func(columnKey string) bool) (map[string][]byte, error)

GetRowColumns returns all the column value associated with the row. It's filters columns if predicate function is provided and only returns those columns for which predicate return true.

func (*Engine) GetWalCheckPoint

func (e *Engine) GetWalCheckPoint() (*internal.Metadata, error)

GetWalCheckPoint returns the last checkpoint metadata saved in the database.

func (*Engine) Namespace

func (e *Engine) Namespace() string

func (*Engine) NewReader

func (e *Engine) NewReader() (*Reader, error)

NewReader return a reader that reads from the beginning, until EOF is encountered. It returns io.EOF when it reaches end of file.

func (*Engine) NewReaderWithStart

func (e *Engine) NewReaderWithStart(startPos *Offset) (*Reader, error)

NewReaderWithStart return a reader that reads from provided offset, until EOF is encountered. It returns io.EOF when it reaches end of file.

func (*Engine) NewTxn

func (e *Engine) NewTxn(txnType logrecord.LogOperationType, valueType logrecord.LogEntryType) (*Txn, error)

NewTxn returns a new initialized batch Txn.

func (*Engine) OpsFlushedCount

func (e *Engine) OpsFlushedCount() uint64

OpsFlushedCount returns the total number of Put and Delete operations flushed to BtreeStore.

func (*Engine) OpsReceivedCount

func (e *Engine) OpsReceivedCount() uint64

OpsReceivedCount returns the total number of Put and Delete operations received.

func (*Engine) Put

func (e *Engine) Put(key, value []byte) error

Put inserts a key-value pair.

func (*Engine) PutColumnsForRow

func (e *Engine) PutColumnsForRow(rowKey []byte, columnEntries map[string][]byte) error

PutColumnsForRow inserts or updates the provided column entries.

It's an upsert operation: - existing column value will get updated to newer value, else a new column entry will be created for the given row.

func (*Engine) PutColumnsForRows

func (e *Engine) PutColumnsForRows(rowKeys [][]byte, columnEntriesPerRow []map[string][]byte) error

func (*Engine) RecoveredWALCount

func (e *Engine) RecoveredWALCount() int

RecoveredWALCount returns the number of WAL entries successfully recovered.

func (*Engine) WaitForAppend

func (e *Engine) WaitForAppend(ctx context.Context, timeout time.Duration, lastSeen *Offset) error

WaitForAppend blocks until a put/delete operation occurs or timeout happens or context cancelled is done.

type EngineConfig

type EngineConfig struct {
	ArenaSize   int64            `toml:"arena_size"`
	WalConfig   wal.Config       `toml:"wal_config"`
	BtreeConfig kvdrivers.Config `toml:"btree_config"`
	DBEngine    DBEngine         `toml:"db_engine"`
}

EngineConfig embeds all the config needed for Engine.

func NewDefaultEngineConfig

func NewDefaultEngineConfig() *EngineConfig

NewDefaultEngineConfig returns an initialized default config for engine.

type Offset

type Offset = wal.Offset

Offset represents the offset in the wal.

func DecodeOffset

func DecodeOffset(b []byte) *Offset

DecodeOffset decodes the offset position from a byte slice.

type Reader

type Reader = wal.Reader

type ReplicaWALHandler

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

ReplicaWALHandler processes and applies incoming WAL records during replication.

func NewReplicaWALHandler

func NewReplicaWALHandler(engine *Engine) *ReplicaWALHandler

func (*ReplicaWALHandler) ApplyRecord

func (wh *ReplicaWALHandler) ApplyRecord(encodedWal []byte, receivedOffset []byte) error

ApplyRecord validates and applies a WAL record to the mem table which later get flushed to Btree Store.

type Txn

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

Txn ensures atomicity at WAL. Writes/Deletes/Chunks wouldn't be visible that are part of the batch until commited.

func (*Txn) AppendColumnTxn

func (t *Txn) AppendColumnTxn(rowKey []byte, columnEntries map[string][]byte) error

AppendColumnTxn appends the Columns update type Txn to wal for the provided rowKey. Update/Delete Ops for column is decided by the Log Operation type. Single Txn Cannot contain both update and delete ops. Caller can set the Columns Key to empty value, if deleted needs to be part of same Txn.

func (*Txn) AppendKVTxn

func (t *Txn) AppendKVTxn(key []byte, value []byte) error

AppendKVTxn append a key, value to the WAL as part of a Txn.

func (*Txn) Checksum

func (t *Txn) Checksum() uint32

func (*Txn) ChunkedValueChecksum

func (t *Txn) ChunkedValueChecksum() uint32

func (*Txn) Commit

func (t *Txn) Commit() error

Commit the Txn.

func (*Txn) CommitOffset

func (t *Txn) CommitOffset() *Offset

func (*Txn) TxnID

func (t *Txn) TxnID() []byte

Directories

Path Synopsis
wal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳