Help us shape the future of Go! Take the 2026 Go Developer Survey

bolt

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultProbeInterval is how often the background prober probes the
	// bolt DB. Picked to give /health callers near-fresh results without
	// adding meaningful load to bolt.
	DefaultProbeInterval = 1 * time.Second
	// DefaultProbeStaleness is the default staleness budget on the
	// freshness wrapper. After this much time without a successful probe
	// update, /health reports fail with a "stale" message. Sized at 5x
	// DefaultProbeInterval so a single skipped tick does not flip the
	// status, but a wedged or dead prober goroutine becomes visible
	// within a small multiple of the probe interval.
	DefaultProbeStaleness = 5 * DefaultProbeInterval
)
View Source
const DefaultFilename = "influxd.bolt"

Variables

This section is empty.

Functions

func NewPluginMetricsCollector added in v2.0.5

func NewPluginMetricsCollector(tickDuration time.Duration) *pluginMetricsCollector

func WithNoSync

func WithNoSync(s *KVStore)

WithNoSync WARNING: this is useful for tests only this skips fsyncing on every commit to improve write performance in exchange for no guarantees that the db will persist.

Types

type Bucket

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

Bucket implements kv.Bucket.

func (*Bucket) Cursor

func (b *Bucket) Cursor(opts ...kv.CursorHint) (kv.Cursor, error)

Cursor retrieves a cursor for iterating through the entries in the key value store.

func (*Bucket) Delete

func (b *Bucket) Delete(key []byte) error

Delete removes the provided key.

func (*Bucket) ForwardCursor

func (b *Bucket) ForwardCursor(seek []byte, opts ...kv.CursorOption) (kv.ForwardCursor, error)

ForwardCursor retrieves a cursor for iterating through the entries in the key value store in a given direction (ascending / descending).

func (*Bucket) Get

func (b *Bucket) Get(key []byte) ([]byte, error)

Get retrieves the value at the provided key.

func (*Bucket) GetBatch

func (b *Bucket) GetBatch(keys ...[]byte) ([][]byte, error)

GetBatch retrieves the values for the provided keys.

func (*Bucket) Put

func (b *Bucket) Put(key []byte, value []byte) error

Put sets the value at the provided key.

type Client

type Client struct {
	Path string

	IDGenerator    platform2.IDGenerator
	TokenGenerator platform.TokenGenerator
	platform.TimeGenerator
	// contains filtered or unexported fields
}

Client is a client for the boltDB data store.

func NewClient

func NewClient(log *zap.Logger) *Client

NewClient returns an instance of a Client.

func (*Client) Close

func (c *Client) Close() error

Close the connection to the bolt database

func (*Client) Collect

func (c *Client) Collect(ch chan<- prometheus.Metric)

Collect returns the current state of all metrics of the collector.

func (*Client) DB

func (c *Client) DB() *bolt.DB

DB returns the clients DB.

func (*Client) Describe

func (c *Client) Describe(ch chan<- *prometheus.Desc)

Describe returns all descriptions of the collector.

func (*Client) ID

func (c *Client) ID() platform2.ID

ID retrieves the unique ID for this influx instance.

func (*Client) Open

func (c *Client) Open(ctx context.Context) error

Open / create boltDB file.

type Cursor

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

Cursor is a struct for iterating through the entries in the key value store.

func (*Cursor) Close

func (c *Cursor) Close() error

Close sets the closed to closed

func (*Cursor) Err

func (c *Cursor) Err() error

Err always returns nil as nothing can go wrong™ during iteration

func (*Cursor) First

func (c *Cursor) First() ([]byte, []byte)

First retrieves the first key value pair in the bucket.

func (*Cursor) Last

func (c *Cursor) Last() ([]byte, []byte)

Last retrieves the last key value pair in the bucket.

func (*Cursor) Next

func (c *Cursor) Next() (k []byte, v []byte)

Next retrieves the next key in the bucket.

func (*Cursor) Prev

func (c *Cursor) Prev() (k []byte, v []byte)

Prev retrieves the previous key in the bucket.

func (*Cursor) Seek

func (c *Cursor) Seek(prefix []byte) ([]byte, []byte)

Seek seeks for the first key that matches the prefix provided.

type KVOption

type KVOption func(*KVStore)

func WithCheckName added in v2.10.0

func WithCheckName(name string) KVOption

WithCheckName sets the name reported by Check and CheckName. Required for callers that register the store with a kit/check.Check registry; other callers can omit it and leave CheckName empty.

func WithProbeInterval added in v2.10.0

func WithProbeInterval(d time.Duration) KVOption

WithProbeInterval overrides the period of the background prober's ticker. Intended for tests that need probes to run more frequently than DefaultProbeInterval; production callers should accept the default. Callers that raise this above DefaultProbeInterval should also raise the staleness budget via WithStaleness, since the budget defaults to a small multiple of DefaultProbeInterval.

func WithStaleness added in v2.10.0

func WithStaleness(d time.Duration) KVOption

WithStaleness overrides the staleness budget used when the probe state's FreshnessResponse is constructed. Intended for tests that need to observe staleness quickly; production callers should accept the default.

type KVStore

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

KVStore is a kv.Store backed by boltdb.

func NewKVStore

func NewKVStore(log *zap.Logger, path string, opts ...KVOption) *KVStore

NewKVStore returns an instance of KVStore with the file at the provided path.

func (*KVStore) Backup

func (s *KVStore) Backup(ctx context.Context, w io.Writer) error

Backup copies all K:Vs to a writer, in BoltDB format.

func (*KVStore) Check added in v2.10.0

func (s *KVStore) Check(_ context.Context) check.Response

Check returns the live freshness-aware probe state. It is non-blocking: a background prober (started by Open / WithDB) periodically probes the underlying bolt database via runOneProbe, which calls Update on the wrapper. The wrapper's Status/Message derive from the cached snapshot's age vs. configured staleness at the moment they're read, so a wedged or dead prober flips /health to fail once the snapshot ages past the budget. ctx is unused; it is retained to satisfy the check.Checker interface.

func (*KVStore) CheckName added in v2.10.0

func (s *KVStore) CheckName() string

CheckName satisfies check.NamedChecker so the store can be passed to AddNamedHealthCheck without an extra wrapper. Returns the name configured by WithCheckName, or "" if unset, which registration rejects.

func (*KVStore) Close

func (s *KVStore) Close() error

Close signals the background prober (if any) to exit and closes the underlying bolt database. Close does not wait for the prober: the prober simply stops updating the freshness wrapper, which ages out to a fail status within DefaultProbeStaleness. There is a window after Close returns where Check may still report the last probe's result; once staleness elapses, /health flips to fail.

func (*KVStore) CreateBucket

func (s *KVStore) CreateBucket(ctx context.Context, name []byte) error

CreateBucket creates a bucket in the underlying boltdb store if it does not already exist

func (*KVStore) DB

func (s *KVStore) DB() *bolt.DB

DB returns a reference to the current Bolt database.

func (*KVStore) DeleteBucket

func (s *KVStore) DeleteBucket(ctx context.Context, name []byte) error

DeleteBucket creates a bucket in the underlying boltdb store if it does not already exist

func (*KVStore) Flush

func (s *KVStore) Flush(ctx context.Context)

Flush removes all bolt keys within each bucket.

func (*KVStore) Open

func (s *KVStore) Open(ctx context.Context) error

Open creates boltDB file it doesn't exists and opens it otherwise.

func (*KVStore) RLock added in v2.1.0

func (s *KVStore) RLock()

func (*KVStore) RUnlock added in v2.1.0

func (s *KVStore) RUnlock()

func (*KVStore) Restore

func (s *KVStore) Restore(ctx context.Context, r io.Reader) error

Restore replaces the underlying database with the data from r.

func (*KVStore) StopProber added in v2.10.0

func (s *KVStore) StopProber()

StopProber signals the background prober (if any) to exit. It does not close the underlying *bolt.DB. Idempotent and safe to call concurrently. Intended for callers that own the DB lifecycle separately (e.g. constructed the store via WithDB) and need to stop the prober without closing the DB they own.

func (*KVStore) Update

func (s *KVStore) Update(ctx context.Context, fn func(tx kv.Tx) error) error

Update opens up an update transaction against the store.

func (*KVStore) View

func (s *KVStore) View(ctx context.Context, fn func(tx kv.Tx) error) error

View opens up a view transaction against the store.

func (*KVStore) WithDB

func (s *KVStore) WithDB(db *bolt.DB)

WithDB sets the boltdb on the store and starts the background health prober if it has not yet been started.

type Tx

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

Tx is a light wrapper around a boltdb transaction. It implements kv.Tx.

func (*Tx) Bucket

func (tx *Tx) Bucket(b []byte) (kv.Bucket, error)

Bucket retrieves the bucket named b.

func (*Tx) Context

func (tx *Tx) Context() context.Context

Context returns the context for the transaction.

func (*Tx) WithContext

func (tx *Tx) WithContext(ctx context.Context)

WithContext sets the context for the transaction.

Jump to

Keyboard shortcuts

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