Documentation ¶
Index ¶
- Constants
- Variables
- func CloseAll() error
- func ConvertDB(dst, src DBer, fn ConvertFn) error
- func DefaultSegmentByKey(key string) uint64
- func ForEachTx[T any](tx *Tx, bucket string, fn func(key []byte, val T) error, ...) error
- func FramesToString(frs *runtime.Frames) string
- func GetAny[T any](db *DB, bucket, key string, unmarshalFn UnmarshalFn) (out T, err error)
- func GetTxAny[T any](tx *Tx, bucket, key string, unmarshalFn UnmarshalFn) (out T, err error)
- func SegDBUpdateOne[T any](s *SegDB, bucket, key string, fn func(v T) (T, error)) error
- type BBoltDB
- type BBoltTx
- type Bucket
- type Cache
- func (c *Cache[T]) Delete(key string) (err error)
- func (c *Cache[T]) ForEach(fn func(k string, v T) error) (err error)
- func (c *Cache[T]) Get(key string) (v T, err error)
- func (c *Cache[T]) Put(key string, v T) (err error)
- func (c *Cache[T]) Stats() (hits, misses int64)
- func (c *Cache[T]) Sync()
- func (c *Cache[T]) Update(fn func(tx *Tx) (key string, v T, err error)) (err error)
- type ConvertFn
- type Cursor
- type DB
- func (db *DB) Backup(w io.Writer) (n int64, err error)
- func (db *DB) BackupToFile(fp string) (n int64, err error)
- func (db *DB) Batch(fn func(*Tx) error) error
- func (db *DB) Begin(writable bool) (*Tx, error)
- func (db *DB) Buckets() (out []string)
- func (db *DB) Close() error
- func (db *DB) CreateBucket(bucket string) error
- func (db *DB) CreateBucketWithIndex(bucket string, idx uint64) error
- func (db *DB) CreateBucketWithIndexBig(bucket string, idx *big.Int) error
- func (db *DB) CurrentIndex(bucket string) (idx uint64)
- func (db *DB) Delete(bucket, key string) error
- func (db *DB) ForEachBytes(bucket string, fn func(k, v []byte) error) (err error)
- func (db *DB) Get(bucket, key string, out any) (err error)
- func (db *DB) GetAny(bucket, key string, out any, unmarshalFn UnmarshalFn) error
- func (db *DB) GetBytes(bucket, key string) (out []byte, err error)
- func (db *DB) NextIndex(bucket string) (idx uint64, err error)
- func (db *DB) OnSlowUpdate(minDuration time.Duration, fn OnSlowUpdateFn)
- func (db *DB) Path() string
- func (db *DB) Put(bucket, key string, val any) error
- func (db *DB) PutAny(bucket, key string, val any, marshalFn MarshalFn) error
- func (db *DB) PutBytes(bucket, key string, val []byte) error
- func (db *DB) Raw() *BBoltDB
- func (db *DB) SetMarshaler(marshalFn MarshalFn, unmarshalFn UnmarshalFn)
- func (db *DB) SetNextIndex(bucket string, seq uint64) error
- func (db *DB) Update(fn func(*Tx) error) error
- func (db *DB) UseBatch(v bool) (old bool)
- func (db *DB) View(fn func(*Tx) error) error
- type DBer
- type MarshalFn
- type MultiDB
- func (mdb *MultiDB) Backup(w io.Writer, filter func(name string, db *DB) bool) (n int64, err error)
- func (mdb *MultiDB) BackupToDir(dir string, filter func(name string, db *DB) bool) (n int64, err error)
- func (mdb *MultiDB) BackupToFile(fp string, filter func(name string, db *DB) bool) (n int64, err error)
- func (mdb *MultiDB) Close() error
- func (mdb *MultiDB) CloseDB(name string) (err error)
- func (mdb *MultiDB) ForEachDB(fn func(name string, db *DB) error) error
- func (mdb *MultiDB) Get(ctx context.Context, name string, opts *Options) (db *DB, err error)
- func (mdb *MultiDB) MustGet(ctx context.Context, name string, opts *Options) *DB
- func (mdb *MultiDB) Restore(ctx context.Context, r io.ReaderAt) (err error)
- func (mdb *MultiDB) RestoreFromFile(ctx context.Context, fp string) (err error)
- type OnSlowUpdateFn
- type Options
- type SegDB
- func (s *SegDB) Backup(w io.Writer) (int64, error)
- func (s *SegDB) Buckets() []string
- func (s *SegDB) Close() error
- func (s *SegDB) CurrentIndex(bucket string) (idx uint64)
- func (s *SegDB) CurrentIndexByKey(bucket, key string) (idx uint64)
- func (s *SegDB) Delete(bucket, key string) error
- func (s *SegDB) ForEachBytes(bucket string, fn func(k, v []byte) error) error
- func (s *SegDB) ForEachDB(fn func(db *DB) error) error
- func (s *SegDB) Get(bucket, key string, v any) error
- func (s *SegDB) NextIndex(bucket string) (seq uint64, err error)
- func (s *SegDB) NextIndexByKey(bucket, key string) (seq uint64, err error)
- func (s *SegDB) Put(bucket, key string, v any) error
- func (s *SegDB) Restore(ctx context.Context, r io.ReaderAt) error
- func (s *SegDB) RestoreFromFile(ctx context.Context, fp string) error
- func (s *SegDB) SetMarshaler(marshalFn MarshalFn, unmarshalFn UnmarshalFn)
- func (s *SegDB) SetNextIndex(bucket string, seq uint64) error
- func (s *SegDB) SetNextIndexByKey(bucket, key string, seq uint64) error
- func (s *SegDB) UseBatch(v bool) (old bool)
- type Tx
- func (tx *Tx) Bucket(bucket string) *Bucket
- func (tx *Tx) CreateBucketIfNotExists(bucket string) (*Bucket, error)
- func (tx *Tx) Delete(bucket, key string) error
- func (tx *Tx) DeleteBucket(bucket string) error
- func (tx *Tx) ForEachBytes(bucket string, fn func(k, v []byte) error) error
- func (tx *Tx) ForEachUpdate(bucket string, fn func(k, v []byte, setValue func(k, nv []byte)) (err error)) (err error)
- func (tx *Tx) GetAny(bucket, key string, out any, unmarshalFn UnmarshalFn) error
- func (tx *Tx) GetBytes(bucket, key string, clone bool) (out []byte)
- func (tx *Tx) GetValue(bucket, key string, out any) error
- func (tx *Tx) MustBucket(bucket string) *Bucket
- func (tx *Tx) NextIndex(bucket string) (uint64, error)
- func (tx *Tx) NextIndexBig(bucket string) (*big.Int, error)
- func (tx *Tx) PutAny(bucket, key string, val any, marshalFn MarshalFn) error
- func (tx *Tx) PutBytes(bucket, key string, val []byte) error
- func (tx *Tx) PutValue(bucket, key string, val any) error
- func (tx *Tx) Range(bucket string, start []byte, fn func(cursor *Cursor, k, v []byte) error, ...) (err error)
- func (tx *Tx) SetNextIndex(bucket string, idx uint64) error
- type TxBase
- type TxStats
- type TypedDB
- type TypedTx
- type UnmarshalFn
Constants ¶
View Source
const DefaultMMapFlags = syscall.MAP_POPULATE
View Source
const ErrDeleteKey = oerrs.String("delete")
Variables ¶
View Source
var ( DefaultMarshalFn = json.Marshal DefaultUnmarshalFn = json.Unmarshal ErrBucketNotFound = bbolt.ErrBucketNotFound )
View Source
var DefaultOptions = &Options{ Timeout: time.Second, NoFreelistSync: true, NoGrowSync: false, FreelistType: bbolt.FreelistMapType, MaxBatchSize: 512, MaxBatchDelay: time.Millisecond * 10, MmapFlags: DefaultMMapFlags, InitialMmapSize: 1 << 29, }
Functions ¶
func DefaultSegmentByKey ¶
func FramesToString ¶
func GetAny ¶
func GetAny[T any](db *DB, bucket, key string, unmarshalFn UnmarshalFn) (out T, err error)
Types ¶
type Cache ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CreateBucket ¶
func (*DB) CreateBucketWithIndex ¶
func (*DB) CreateBucketWithIndexBig ¶
func (*DB) CurrentIndex ¶
func (*DB) ForEachBytes ¶
func (*DB) GetAny ¶
func (db *DB) GetAny(bucket, key string, out any, unmarshalFn UnmarshalFn) error
func (*DB) OnSlowUpdate ¶
func (db *DB) OnSlowUpdate(minDuration time.Duration, fn OnSlowUpdateFn)
func (*DB) SetMarshaler ¶
func (db *DB) SetMarshaler(marshalFn MarshalFn, unmarshalFn UnmarshalFn)
type DBer ¶
type DBer interface { CurrentIndex(bucket string) uint64 NextIndex(bucket string) (uint64, error) SetNextIndex(bucket string, index uint64) error Buckets() []string Get(bucket, key string, v any) error ForEachBytes(bucket string, fn func(k, v []byte) error) error Put(bucket, key string, v any) error Delete(bucket, key string) error }
type MultiDB ¶
type MultiDB struct {
// contains filtered or unexported fields
}
func NewMultiDB ¶
func (*MultiDB) BackupToDir ¶
func (*MultiDB) BackupToFile ¶
type OnSlowUpdateFn ¶
bbolt type aliases
type Options ¶
type Options struct { // OpenFile is used to open files. It defaults to os.OpenFile. This option // is useful for writing hermetic tests. OpenFile func(string, int, os.FileMode) (*os.File, error) // InitDB gets called on initial db open InitDB func(db *DB) error // FreelistType sets the backend freelist type. There are two options. Array which is simple but endures // dramatic performance degradation if database is large and framentation in freelist is common. // The alternative one is using hashmap, it is faster in almost all circumstances // but it doesn't guarantee that it offers the smallest page id available. In normal case it is safe. // The default type is array FreelistType bbolt.FreelistType // InitialBuckets will create the given slice of buckets on initial db open InitialBuckets []string // Sets the DB.MmapFlags flag before memory mapping the file. MmapFlags int // InitialMmapSize is the initial mmap size of the database // in bytes. Read transactions won't block write transaction // if the InitialMmapSize is large enough to hold database mmap // size. (See DB.Begin for more information) // // If <=0, the initial map size is 0. // If initialMmapSize is smaller than the previous database size, // it takes no effect. InitialMmapSize int // PageSize overrides the default OS page size. PageSize int // Timeout is the amount of time to wait to obtain a file lock. // When set to zero it will wait indefinitely. This option is only // available on Darwin and Linux. Timeout time.Duration // Sets the DB.NoGrowSync flag before memory mapping the file. NoGrowSync bool // Do not sync freelist to disk. This improves the database write performance // under normal operation, but requires a full database re-sync during recovery. NoFreelistSync bool // Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to // grab a shared lock (UNIX). ReadOnly bool // NoSync sets the initial value of DB.NoSync. Normally this can just be // set directly on the DB itself when returned from Open(), but this option // is useful in APIs which expose Options but not the underlying DB. NoSync bool // Mlock locks database file in memory when set to true. // It prevents potential page faults, however // used memory can't be reclaimed. (UNIX only) Mlock bool // MaxBatchSize is the maximum size of a batch. Default value is // copied from DefaultMaxBatchSize in Open. // // If <=0, disables batching. MaxBatchSize int // MaxBatchDelay is the maximum delay before a batch starts. // Default value is copied from DefaultMaxBatchDelay in Open. // // If <=0, effectively disables batching. MaxBatchDelay time.Duration MarshalFn MarshalFn UnmarshalFn UnmarshalFn // AutoRetry will keep retrying to open the db instead of returning a timeout error AutoRetry bool }
type SegDB ¶
func NewSegDB ¶
NewSegDB creates a new segmented database. SegDB uses msgpack by default. WARNING WARNING, if numSegments changes between calls, the keys will be out of sync
func NewSegDBFromFile ¶
func (*SegDB) CurrentIndex ¶
func (*SegDB) CurrentIndexByKey ¶
func (*SegDB) ForEachBytes ¶
func (*SegDB) NextIndexByKey ¶
func (*SegDB) RestoreFromFile ¶
func (*SegDB) SetMarshaler ¶
func (s *SegDB) SetMarshaler(marshalFn MarshalFn, unmarshalFn UnmarshalFn)
func (*SegDB) SetNextIndexByKey ¶
type Tx ¶
type Tx struct { *BBoltTx // contains filtered or unexported fields }
func (*Tx) CreateBucketIfNotExists ¶
func (*Tx) DeleteBucket ¶
func (*Tx) ForEachBytes ¶
func (*Tx) ForEachUpdate ¶
func (tx *Tx) ForEachUpdate(bucket string, fn func(k, v []byte, setValue func(k, nv []byte)) (err error)) (err error)
ForEachUpdate passes a func to the loop func to allow you to set values inside the loop, this is a workaround seting values inside a foreach loop which isn't allowed.
func (*Tx) GetAny ¶
func (tx *Tx) GetAny(bucket, key string, out any, unmarshalFn UnmarshalFn) error
func (*Tx) MustBucket ¶
type UnmarshalFn ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.