boltcycle

package
v3.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CycleDB

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

CycleDB allows you to use a bolt.DB as a pseudo-LRU using a cycle of buckets

func New

func New(db *bolt.DB, optionalParameters ...DBConfiguration) (*CycleDB, error)

New creates a CycleDB to use a bolt database that cycles minNumOldBuckets buckets

func (*CycleDB) AsyncWrite

func (c *CycleDB) AsyncWrite(ctx context.Context, towrite []KvPair)

AsyncWrite will enqueue a write into the same chan that moves reads to the last bucket. You must not *ever* change the []byte given to towrite since you can't know when that []byte is finished being used. Note that if the readMovements queue is backed up this operation will block until it has room.

func (*CycleDB) Close

func (c *CycleDB) Close() error

Close ends the goroutine that moves read items to the latest bucket and now closes the DB itself...

func (*CycleDB) CycleNodes

func (c *CycleDB) CycleNodes() error

CycleNodes deletes the first, oldest node in the primary bucket while there are >= minNumOldBuckets and creates a new, empty last node

func (*CycleDB) DB

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

DB exposes raw bolt db

func (*CycleDB) Delete

func (c *CycleDB) Delete(keys [][]byte) ([]bool, error)

Delete all the keys from every bucket that could have the keys. Returns true/false for each key if it exists

func (*CycleDB) Read

func (c *CycleDB) Read(toread [][]byte) ([][]byte, error)

Read bytes from the first available bucket. Do not modify the returned bytes because they are recopied to later cycle databases if needed.

func (*CycleDB) Stats

func (c *CycleDB) Stats() Stats

Stats returns introspection stats about the Database. The members are considered alpha and subject to change or rename.

func (*CycleDB) VerifyBuckets

func (c *CycleDB) VerifyBuckets() error

VerifyBuckets ensures that the cycle of buckets have the correct names (increasing 8 byte integers)

func (*CycleDB) VerifyCompressed

func (c *CycleDB) VerifyCompressed() error

VerifyCompressed checks that no key is repeated in the database

func (*CycleDB) Write

func (c *CycleDB) Write(towrite []KvPair) error

Write a pair of key/value items into the cycle disk

type DBConfiguration

type DBConfiguration func(*CycleDB) error

DBConfiguration are callbacks used as optional vardic parameters in New() to configure DB usage

func AsyncErrors

func AsyncErrors(asyncErrors chan<- error) DBConfiguration

AsyncErrors controls where we log async errors into. If nil, they are silently dropped

func BucketTimesIn

func BucketTimesIn(bucketName []byte) DBConfiguration

BucketTimesIn is the sub bucket we put our cycled hashmap into

func CycleLen

func CycleLen(minNumOldBuckets int) DBConfiguration

CycleLen sets the number of old buckets to keep around

func ReadMovementBacklog

func ReadMovementBacklog(readMovementBacklog int) DBConfiguration

ReadMovementBacklog sets the size of the channel of read operations to rewrite

type KvPair

type KvPair struct {
	// Key to write
	Key []byte
	// Value to write for key
	Value []byte
}

KvPair is a pair of key/value that you want to write during a write call

type Stats

type Stats struct {
	TotalItemsRecopied            int64
	TotalItemsAsyncPut            int64
	RecopyTransactionCount        int64
	TotalItemsDeletedDuringRecopy int64
	TotalReadCount                int64
	TotalWriteCount               int64
	TotalDeleteCount              int64
	TotalCycleCount               int64
	TotalErrorsDuringRecopy       int64
	TotalReadMovementsSkipped     int64
	TotalReadMovementsAdded       int64
	SizeOfBacklogToCopy           int
}

Stats are exported by CycleDB to let users inspect its behavior over time

func (*Stats) AtomicClone

func (s *Stats) AtomicClone() Stats

AtomicClone creates a new stats with somewhat atomically

Jump to

Keyboard shortcuts

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