keydb: github.com/robaho/keydb Index | Files | Directories

package keydb

import "github.com/robaho/keydb"

Index

Package Files

database.go diskio.go disksegment.go errors.go memorysegment.go merger.go multisegment.go segment.go transaction.go tree.go

Variables

var DatabaseClosed = errors.New("database closed")
var DatabaseHasOpenTransactions = errors.New("database has open transactions")
var DatabaseInUse = errors.New("database in use")
var EmptyKey = errors.New("key is empty")
var EndOfIterator = errors.New("end of iterator")
var KeyNotFound = errors.New("key not found")
var KeyTooLong = errors.New("key too long, max 1024")
var NoDatabaseFound = errors.New("no database found")
var NotADirectory = errors.New("path is not a directory")
var NotValidDatabase = errors.New("path is not a valid database")
var ReadOnlySegment = errors.New("read only segment")
var TransactionClosed = errors.New("transaction closed")

func FindNodes Uses

func FindNodes(node *node, lower []byte, upper []byte, fn func(*node))

The functions finds all nodes within the provided key range, call function fn on each found node

func IsValidDatabase Uses

func IsValidDatabase(path string) error

returns nil if the path points to a valid database or empty directory

func Remove Uses

func Remove(path string) error

remove the database, deleting all files. the caller must be able to gain exclusive multi to the database

type Database Uses

type Database struct {
    sync.Mutex
    // contains filtered or unexported fields
}

a Database reference is obtained via Open()

func Open Uses

func Open(path string, createIfNeeded bool) (*Database, error)

open a database. The database can only be opened by a single process, but the *Database reference can be shared across Go routines. The path is a directory name. if createIfNeeded is true, them if the db doesn't exist it will be created Additional tables can be added on subsequent opens, but there is no current way to delete a table, except for deleting the table related files from the directory

func (*Database) BeginTX Uses

func (db *Database) BeginTX(table string) (*Transaction, error)

create a transaction for a database table. a Transaction can only be used by a single Go routine. each transaction should be completed with either Commit, or Rollback

func (*Database) Close Uses

func (db *Database) Close() error

close the database. any memory segments are persisted to disk. The resulting segments are merged until the default maxSegments is reached

func (*Database) CloseWithMerge Uses

func (db *Database) CloseWithMerge(segmentCount int) error

close the database with control of the segment count. if segmentCount is 0, then the merge process is skipped

type LookupIterator Uses

type LookupIterator interface {
    // returns EndOfIterator when complete, if err is nil, then key and value are valid
    Next() (key []byte, value []byte, err error)
    // contains filtered or unexported methods
}

iterator interface for table scanning. all iterators should be read until completion

type Transaction Uses

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

func (*Transaction) Commit Uses

func (tx *Transaction) Commit() error

persist any changes to the table. after Commit the transaction can no longer be used

func (*Transaction) CommitSync Uses

func (tx *Transaction) CommitSync() error

persist any changes to the table. waiting for disk segment to be created. note that synchronous writes are not used, so that a hard OS failure could leave the database in a corrupted state. after Commit the transaction can no longer be used

func (*Transaction) Get Uses

func (tx *Transaction) Get(key []byte) (value []byte, err error)

retrieve a value from the table

func (*Transaction) GetID Uses

func (tx *Transaction) GetID() uint64

func (*Transaction) Lookup Uses

func (tx *Transaction) Lookup(lower []byte, upper []byte) (LookupIterator, error)

find matching record between lower and upper inclusive. lower or upper can be nil and then the range is unbounded on that side. Using the iterator after the transaction has been Commit/Rollback is not supported.

func (*Transaction) Put Uses

func (tx *Transaction) Put(key []byte, value []byte) error

put a value into the table. empty keys are not supported.

func (*Transaction) Remove Uses

func (tx *Transaction) Remove(key []byte) ([]byte, error)

remove a key and its value from the table. empty keys are not supported.

func (*Transaction) Rollback Uses

func (tx *Transaction) Rollback() error

discard any changes to the table. after Rollback the transaction can no longer be used

type Tree Uses

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

auto balancing binary Tree, based on code from 'applied go', but modified for []byte key and values, and range searching

func (*Tree) Find Uses

func (t *Tree) Find(key []byte) (value []byte, ok bool)

return the value for a key, ok is true if the key was found

func (*Tree) FindNodes Uses

func (t *Tree) FindNodes(lower []byte, upper []byte) []TreeEntry

func (*Tree) Insert Uses

func (t *Tree) Insert(key, data []byte)

func (*Tree) Remove Uses

func (t *Tree) Remove(key []byte) (value []byte, ok bool)

remove the value for a key, returning it. ok is true if the node existed and was found. If the key was not found a 'nil' value is inserted into the tree

type TreeEntry Uses

type TreeEntry struct {
    Key   []byte
    Value []byte
}

a node returned by FindNodes

Directories

PathSynopsis
_examples

Package keydb imports 16 packages (graph) and is imported by 1 packages. Updated 2018-09-21. Refresh now. Tools for package owners.