Documentation
¶
Index ¶
- Constants
- type Config
- type Database
- func (d *Database) Backup(w io.Writer, since uint64) (uint64, error)
- func (d *Database) Close() error
- func (d *Database) Compact(start []byte, limit []byte) error
- func (d *Database) Delete(key []byte) error
- func (d *Database) Empty() (bool, error)
- func (d *Database) Get(key []byte) ([]byte, error)
- func (d *Database) GetSnapshot() (database.Database, error)
- func (d *Database) Has(key []byte) (bool, error)
- func (d *Database) HealthCheck(ctx context.Context) (interface{}, error)
- func (d *Database) Len() (int, error)
- func (d *Database) Load(r io.Reader) error
- func (d *Database) NewBatch() database.Batch
- func (d *Database) NewIterator() database.Iterator
- func (d *Database) NewIteratorWithPrefix(prefix []byte) database.Iterator
- func (d *Database) NewIteratorWithStart(start []byte) database.Iterator
- func (d *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator
- func (d *Database) Put(key []byte, value []byte) error
- func (d *Database) StartReplicator(ctx context.Context) error
- func (d *Database) Sync() error
- type GPUCacheConfig
Constants ¶
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) Empty ¶
Empty returns true if the database doesn't contain any keys (but not deleted keys)
func (*Database) GetSnapshot ¶
GetSnapshot implements the database.Database interface
func (*Database) HealthCheck ¶
HealthCheck returns nil if the database is healthy, non-nil otherwise.
func (*Database) NewIterator ¶
NewIterator implements the Database interface
func (*Database) NewIteratorWithPrefix ¶
NewIteratorWithPrefix implements the Database interface
func (*Database) NewIteratorWithStart ¶
NewIteratorWithStart implements the Database interface
func (*Database) NewIteratorWithStartAndPrefix ¶
NewIteratorWithStartAndPrefix implements the Database interface
func (*Database) StartReplicator ¶ added in v1.17.47
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.
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.