zapdb

package
v1.17.47 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: BSD-3-Clause Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const Name = "zapdb"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SyncWrites           bool    `json:"syncWrites"`
	NumCompactors        int     `json:"numCompactors"`
	NumMemtables         int     `json:"numMemtables"`
	MemTableSize         int64   `json:"memTableSize"`
	ValueLogFileSize     int64   `json:"valueLogFileSize"`
	ValueLogMaxEntries   uint32  `json:"valueLogMaxEntries"`
	BlockCacheSize       int64   `json:"blockCacheSize"`
	IndexCacheSize       int64   `json:"indexCacheSize"`
	BloomFalsePositive   float64 `json:"bloomFalsePositive"`
	ValueThreshold       int     `json:"valueThreshold"`
	Compression          string  `json:"compression"`
	ZSTDCompressionLevel int     `json:"zstdCompressionLevel"`
}

Config represents BadgerDB configuration

type Database

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

Database is a badgerdb backed database

func New

func New(file string, configBytes []byte, namespace string, metrics metric.Registerer) (*Database, error)

New returns a new badgerdb-backed database

func (*Database) Backup

func (d *Database) Backup(w io.Writer, since uint64) (uint64, error)

Backup implements the database.Database interface

func (*Database) Close

func (d *Database) Close() error

Close implements the Database interface

func (*Database) Compact

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

Compact implements the Database interface

func (*Database) Delete

func (d *Database) Delete(key []byte) error

Delete implements the Database interface

func (*Database) Empty

func (d *Database) Empty() (bool, error)

Empty returns true if the database doesn't contain any keys (but not deleted keys)

func (*Database) Get

func (d *Database) Get(key []byte) ([]byte, error)

Get implements the Database interface

func (*Database) GetSnapshot

func (d *Database) GetSnapshot() (database.Database, error)

GetSnapshot implements the database.Database interface

func (*Database) Has

func (d *Database) Has(key []byte) (bool, error)

Has implements the Database interface

func (*Database) HealthCheck

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

HealthCheck returns nil if the database is healthy, non-nil otherwise.

func (*Database) Len

func (d *Database) Len() (int, error)

Len returns the number of keys in the database

func (*Database) Load

func (d *Database) Load(r io.Reader) error

Load implements the database.Database interface

func (*Database) NewBatch

func (d *Database) NewBatch() database.Batch

NewBatch implements the Database interface

func (*Database) NewIterator

func (d *Database) NewIterator() database.Iterator

NewIterator implements the Database interface

func (*Database) NewIteratorWithPrefix

func (d *Database) NewIteratorWithPrefix(prefix []byte) database.Iterator

NewIteratorWithPrefix implements the Database interface

func (*Database) NewIteratorWithStart

func (d *Database) NewIteratorWithStart(start []byte) database.Iterator

NewIteratorWithStart implements the Database interface

func (*Database) NewIteratorWithStartAndPrefix

func (d *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator

NewIteratorWithStartAndPrefix implements the Database interface

func (*Database) Put

func (d *Database) Put(key []byte, value []byte) error

Put implements the Database interface

func (*Database) StartReplicator added in v1.17.47

func (d *Database) StartReplicator(ctx context.Context) error

StartReplicator starts encrypted streaming replication to S3 if configured. Reads config from REPLICATE_* env vars. No-op if REPLICATE_S3_ENDPOINT is not set. Implements database.Replicatable.

func (*Database) Sync

func (d *Database) Sync() error

Sync implements the database.Syncer interface It flushes all buffered writes to persistent storage.

type GPUCacheConfig added in v1.17.47

type GPUCacheConfig struct {
	// GPUMemoryBudget is the maximum GPU memory to use for caching in bytes.
	// Set to 0 to disable GPU caching (default).
	// Typical values: 256MB for light use, 1-4GB for consensus/DEX workloads.
	GPUMemoryBudget uint64 `json:"gpuMemoryBudget,omitempty"`

	// Backend selects the GPU backend: "auto", "metal", "cuda", "webgpu", "cpu".
	// Default: "auto" (best available).
	Backend string `json:"gpuBackend,omitempty"`

	// DeviceIndex selects which GPU device to use (-1 for default).
	DeviceIndex int `json:"gpuDeviceIndex,omitempty"`

	// InitialCapacity is the initial number of hash table slots (power of 2).
	// Default: 1048576 (1M slots). Each slot is 64 bytes.
	InitialCapacity uint32 `json:"gpuInitialCapacity,omitempty"`

	// EvictionThreshold triggers cache eviction when load factor exceeds this.
	// Default: 0.90. Range: 0.5 to 0.95.
	EvictionThreshold float32 `json:"gpuEvictionThreshold,omitempty"`

	// PromoteOnMiss controls whether disk reads are promoted into GPU cache.
	// Default: true. Set to false for write-heavy workloads where reads are rare.
	PromoteOnMiss bool `json:"gpuPromoteOnMiss,omitempty"`

	// WriteThrough ensures every Put is immediately persisted to disk.
	// Default: true. Set to false for higher write throughput at risk of
	// data loss on crash (dirty entries are flushed periodically).
	WriteThrough bool `json:"gpuWriteThrough,omitempty"`

	// MaxKeySize is the maximum key size in bytes. Default: 1024.
	MaxKeySize uint32 `json:"gpuMaxKeySize,omitempty"`

	// MaxValueSize is the maximum value size in bytes. Default: 65536.
	MaxValueSize uint32 `json:"gpuMaxValueSize,omitempty"`
}

GPUCacheConfig configures opt-in GPU-accelerated caching for ZapDB. When GPUMemoryBudget > 0, the database keeps hot key-value pairs in GPU memory for fast access. Reads check GPU first, writes go through to disk.

Set GPUMemoryBudget to 0 (default) to disable GPU caching entirely.

func DefaultGPUCacheConfig added in v1.17.47

func DefaultGPUCacheConfig() GPUCacheConfig

DefaultGPUCacheConfig returns a GPUCacheConfig with GPU caching disabled. To enable, set GPUMemoryBudget > 0.

func ParseGPUConfig added in v1.17.47

func ParseGPUConfig(configBytes []byte) GPUCacheConfig

ParseGPUConfig extracts GPU cache configuration from the database config JSON bytes. If the config contains gpuMemoryBudget > 0, GPU caching is enabled. This allows GPU mode to be activated via the standard database config mechanism (--db-config-content or --db-config-file).

Example config JSON:

{
  "syncWrites": false,
  "gpuMemoryBudget": 536870912,
  "gpuBackend": "auto",
  "gpuPromoteOnMiss": true
}

func (*GPUCacheConfig) Enabled added in v1.17.47

func (c *GPUCacheConfig) Enabled() bool

Enabled returns true if GPU caching is configured.

Jump to

Keyboard shortcuts

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