coqdb

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 26 Imported by: 1

README

coqdb

we think the pogreb design is great, and we want to use it deeply in some important projects, sowe have made some targeted improvements.

another reason is that the original author seems to be no longer updated and maintained.

Enhancements

  • support compress

  • support to index key with bplus tree

  • support to store TB size data

  • support to range query

  • optimize some feat

Documentation

Overview

Package coqdb implements an embedded key-value store for read-heavy workloads.

Index

Constants

View Source
const (
	// MaxKeyLength is the maximum size of a key in bytes.
	MaxKeyLength = math.MaxUint16

	// MaxValueLength is the maximum size of a value in bytes.
	MaxValueLength = 512 << 20 // 512 MiB

	// MaxKeys is the maximum numbers of keys in the DB.
	MaxKeys = math.MaxUint32
)

Variables

View Source
var (
	// ErrIterationDone is returned by ItemIterator.Next calls when there are no more items to return.
	ErrIterationDone = errors.New("no more items in iterator")

	ErrNotFound = errors.New("not found")

	ErrNotSupportIter = errors.New("not support b iter because of not set BtreeIndex option")
)

Functions

func NewSegmentIterator added in v0.0.2

func NewSegmentIterator(f *segment) (*segmentIterator, error)

func OpenDatalog added in v0.0.2

func OpenDatalog(opts *Options) (*datalog, error)

func SetLogger

func SetLogger(l *log.Logger)

SetLogger sets the global logger.

Types

type CompactionResult

type CompactionResult struct {
	CompactedSegments int
	ReclaimedRecords  int
	ReclaimedBytes    int
}

CompactionResult holds the compaction result.

type DB

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

DB represents the key-value storage. All DB methods are safe for concurrent use by multiple goroutines.

func Open

func Open(path string, opts *Options) (*DB, error)

Open opens or creates a new DB. The DB must be closed after use, by calling Close method.

func (*DB) Close

func (db *DB) Close() error

Close closes the DB.

func (*DB) Compact

func (db *DB) Compact() (CompactionResult, error)

Compact compacts the DB. Deleted and overwritten items are discarded. Returns an error if compaction is already in progress.

func (*DB) Count

func (db *DB) Count() uint32

Count returns the number of keys in the DB.

func (*DB) Delete

func (db *DB) Delete(key []byte, wo *WriteOption) error

Delete deletes the given key from the DB.

func (*DB) FileSize

func (db *DB) FileSize() (int64, error)

FileSize returns the total size of the disk storage used by the DB.

func (*DB) Get

func (db *DB) Get(key []byte, ro *ReadOption) ([]byte, error)

Get returns the value for the given key stored in the DB or nil if the key doesn't exist.

func (*DB) Has

func (db *DB) Has(key []byte, ro *ReadOption) (bool, error)

Has returns true if the DB contains the given key.

func (*DB) Items

func (db *DB) Items() *ItemIterator

Items returns a new ItemIterator.

func (*DB) Metrics

func (db *DB) Metrics() *Metrics

Metrics returns the DB metrics.

func (*DB) Put

func (db *DB) Put(key []byte, value []byte, wo *WriteOption) error

Put sets the value for the given key. It updates the value for the existing key.

func (*DB) Sync

func (db *DB) Sync() error

Sync commits the contents of the database to the backing FileSystem.

type ItemIterator

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

ItemIterator is an iterator over DB key-value pairs. It iterates the items in an unspecified order.

func (*ItemIterator) Next

func (it *ItemIterator) Next() ([]byte, []byte, error)

Next returns the next key-value pair if available, otherwise it returns ErrIterationDone error.

type Metrics

type Metrics struct {
	Puts           expvar.Int
	Dels           expvar.Int
	Gets           expvar.Int
	HashCollisions expvar.Int
}

Metrics holds the DB metrics.

type Options

type Options struct {
	// BackgroundSyncInterval sets the amount of time between background Sync() calls.
	//
	// Setting the value to 0 disables the automatic background synchronization.
	// Setting the value to -1 makes the DB call Sync() after every write operation.
	BackgroundSyncInterval time.Duration

	// BackgroundCompactionInterval sets the amount of time between background Compact() calls.
	//
	// Setting the value to 0 disables the automatic background compaction.
	BackgroundCompactionInterval time.Duration

	// FileSystem sets the file system implementation.
	//
	// Default: fs.OSMMap.
	FileSystem fs.FileSystem
	// contains filtered or unexported fields
}

Options holds the optional DB parameters.

type ReadOption

type ReadOption struct {
}

type Record added in v0.0.2

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

Binary representation of a segment Record: +---------------+------------------+------------------+-...-+--...--+----------+ | Key Size (2B) | Record Type (1b) | Value Size (31b) | Key | Value | CRC (4B) | +---------------+------------------+------------------+-...-+--...--+----------+

func (*Record) Key added in v0.0.2

func (r *Record) Key() []byte

func (*Record) Type added in v0.0.2

func (r *Record) Type() RecordType

func (*Record) Value added in v0.0.2

func (r *Record) Value() []byte

type RecordType added in v0.0.2

type RecordType int
const (
	RecordTypePut RecordType = iota
	RecordTypeDelete
)

type WriteOption

type WriteOption struct {
	Repeat bool // if true , key exists, then append , not override
}

Directories

Path Synopsis
Package fs provides a file system interface.
Package fs provides a file system interface.

Jump to

Keyboard shortcuts

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