tm-db: github.com/tendermint/tm-db Index | Files | Directories

package db

import "github.com/tendermint/tm-db"

Index

Package Files

db.go fsdb.go go_level_db.go mem_batch.go mem_db.go prefix_db.go test_helpers.go types.go util.go

func FileExists Uses

func FileExists(filePath string) bool

func IsKeyInDomain Uses

func IsKeyInDomain(key, start, end []byte) bool

See DB interface documentation for more information.

type BackendType Uses

type BackendType string
const (
    // GoLevelDBBackend represents goleveldb (github.com/syndtr/goleveldb - most
    // popular implementation)
    //   - pure go
    //   - stable
    GoLevelDBBackend BackendType = "goleveldb"
    // CLevelDBBackend represents cleveldb (uses levigo wrapper)
    //   - fast
    //   - requires gcc
    //   - use cleveldb build tag (go build -tags cleveldb)
    CLevelDBBackend BackendType = "cleveldb"
    // MemDBBackend represents in-memoty key value store, which is mostly used
    // for testing.
    MemDBBackend BackendType = "memdb"
    // FSDBBackend represents filesystem database
    //	 - EXPERIMENTAL
    //   - slow
    FSDBBackend BackendType = "fsdb"
    // BoltDBBackend represents bolt (uses etcd's fork of bolt -
    // github.com/etcd-io/bbolt)
    //   - EXPERIMENTAL
    //   - may be faster is some use-cases (random reads - indexer)
    //   - use boltdb build tag (go build -tags boltdb)
    BoltDBBackend BackendType = "boltdb"
    // RocksDBBackend represents rocksdb (uses github.com/tecbot/gorocksdb)
    //   - EXPERIMENTAL
    //   - requires gcc
    //   - use rocksdb build tag (go build -tags rocksdb)
    RocksDBBackend BackendType = "rocksdb"
)

These are valid backend types.

type Batch Uses

type Batch interface {
    SetDeleter
    Write()
    WriteSync()
    Close()
}

Batch Close must be called when the program no longer needs the object.

type DB Uses

type DB interface {

    // Get returns nil iff key doesn't exist.
    // A nil key is interpreted as an empty byteslice.
    // CONTRACT: key, value readonly []byte
    Get([]byte) []byte

    // Has checks if a key exists.
    // A nil key is interpreted as an empty byteslice.
    // CONTRACT: key, value readonly []byte
    Has(key []byte) bool

    // Set sets the key.
    // A nil key is interpreted as an empty byteslice.
    // CONTRACT: key, value readonly []byte
    Set([]byte, []byte)
    SetSync([]byte, []byte)

    // Delete deletes the key.
    // A nil key is interpreted as an empty byteslice.
    // CONTRACT: key readonly []byte
    Delete([]byte)
    DeleteSync([]byte)

    // Iterate over a domain of keys in ascending order. End is exclusive.
    // Start must be less than end, or the Iterator is invalid.
    // A nil start is interpreted as an empty byteslice.
    // If end is nil, iterates up to the last item (inclusive).
    // CONTRACT: No writes may happen within a domain while an iterator exists over it.
    // CONTRACT: start, end readonly []byte
    Iterator(start, end []byte) Iterator

    // Iterate over a domain of keys in descending order. End is exclusive.
    // Start must be less than end, or the Iterator is invalid.
    // If start is nil, iterates up to the first/least item (inclusive).
    // If end is nil, iterates from the last/greatest item (inclusive).
    // CONTRACT: No writes may happen within a domain while an iterator exists over it.
    // CONTRACT: start, end readonly []byte
    ReverseIterator(start, end []byte) Iterator

    // Closes the connection.
    Close()

    // Creates a batch for atomic updates.
    NewBatch() Batch

    // For debugging
    Print()

    // Stats returns a map of property values for all keys and the size of the cache.
    Stats() map[string]string
}

DBs are goroutine safe.

func NewDB Uses

func NewDB(name string, backend BackendType, dir string) DB

NewDB creates a new database of type backend with the given name. NOTE: function panics if:

- backend is unknown (not registered)
- creator function, provided during registration, returns error

type FSDB Uses

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

It's slow.

func NewFSDB Uses

func NewFSDB(dir string) *FSDB

func (*FSDB) Close Uses

func (db *FSDB) Close()

func (*FSDB) Delete Uses

func (db *FSDB) Delete(key []byte)

func (*FSDB) DeleteNoLock Uses

func (db *FSDB) DeleteNoLock(key []byte)

NOTE: Implements atomicSetDeleter.

func (*FSDB) DeleteSync Uses

func (db *FSDB) DeleteSync(key []byte)

func (*FSDB) Get Uses

func (db *FSDB) Get(key []byte) []byte

func (*FSDB) Has Uses

func (db *FSDB) Has(key []byte) bool

func (*FSDB) Iterator Uses

func (db *FSDB) Iterator(start, end []byte) Iterator

func (*FSDB) MakeIterator Uses

func (db *FSDB) MakeIterator(start, end []byte, isReversed bool) Iterator

func (*FSDB) Mutex Uses

func (db *FSDB) Mutex() *sync.Mutex

func (*FSDB) NewBatch Uses

func (db *FSDB) NewBatch() Batch

func (*FSDB) Print Uses

func (db *FSDB) Print()

func (*FSDB) ReverseIterator Uses

func (db *FSDB) ReverseIterator(start, end []byte) Iterator

func (*FSDB) Set Uses

func (db *FSDB) Set(key []byte, value []byte)

func (*FSDB) SetNoLock Uses

func (db *FSDB) SetNoLock(key []byte, value []byte)

NOTE: Implements atomicSetDeleter.

func (*FSDB) SetSync Uses

func (db *FSDB) SetSync(key []byte, value []byte)

func (*FSDB) Stats Uses

func (db *FSDB) Stats() map[string]string

type GoLevelDB Uses

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

func NewGoLevelDB Uses

func NewGoLevelDB(name string, dir string) (*GoLevelDB, error)

func NewGoLevelDBWithOpts Uses

func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error)

func (*GoLevelDB) Close Uses

func (db *GoLevelDB) Close()

Implements DB.

func (*GoLevelDB) DB Uses

func (db *GoLevelDB) DB() *leveldb.DB

func (*GoLevelDB) Delete Uses

func (db *GoLevelDB) Delete(key []byte)

Implements DB.

func (*GoLevelDB) DeleteSync Uses

func (db *GoLevelDB) DeleteSync(key []byte)

Implements DB.

func (*GoLevelDB) Get Uses

func (db *GoLevelDB) Get(key []byte) []byte

Implements DB.

func (*GoLevelDB) Has Uses

func (db *GoLevelDB) Has(key []byte) bool

Implements DB.

func (*GoLevelDB) Iterator Uses

func (db *GoLevelDB) Iterator(start, end []byte) Iterator

Implements DB.

func (*GoLevelDB) NewBatch Uses

func (db *GoLevelDB) NewBatch() Batch

Implements DB.

func (*GoLevelDB) Print Uses

func (db *GoLevelDB) Print()

Implements DB.

func (*GoLevelDB) ReverseIterator Uses

func (db *GoLevelDB) ReverseIterator(start, end []byte) Iterator

Implements DB.

func (*GoLevelDB) Set Uses

func (db *GoLevelDB) Set(key []byte, value []byte)

Implements DB.

func (*GoLevelDB) SetSync Uses

func (db *GoLevelDB) SetSync(key []byte, value []byte)

Implements DB.

func (*GoLevelDB) Stats Uses

func (db *GoLevelDB) Stats() map[string]string

Implements DB.

type Iterator Uses

type Iterator interface {

    // The start & end (exclusive) limits to iterate over.
    // If end < start, then the Iterator goes in reverse order.
    //
    // A domain of ([]byte{12, 13}, []byte{12, 14}) will iterate
    // over anything with the prefix []byte{12, 13}.
    //
    // The smallest key is the empty byte array []byte{} - see BeginningKey().
    // The largest key is the nil byte array []byte(nil) - see EndingKey().
    // CONTRACT: start, end readonly []byte
    Domain() (start []byte, end []byte)

    // Valid returns whether the current position is valid.
    // Once invalid, an Iterator is forever invalid.
    Valid() bool

    // Next moves the iterator to the next sequential key in the database, as
    // defined by order of iteration.
    //
    // If Valid returns false, this method will panic.
    Next()

    // Key returns the key of the cursor.
    // If Valid returns false, this method will panic.
    // CONTRACT: key readonly []byte
    Key() (key []byte)

    // Value returns the value of the cursor.
    // If Valid returns false, this method will panic.
    // CONTRACT: value readonly []byte
    Value() (value []byte)

    // Close releases the Iterator.
    Close()
}

Usage:

var itr Iterator = ... defer itr.Close()

for ; itr.Valid(); itr.Next() {

k, v := itr.Key(); itr.Value()
// ...

}

func IteratePrefix Uses

func IteratePrefix(db DB, prefix []byte) Iterator

IteratePrefix is a convenience function for iterating over a key domain restricted by prefix.

type MemDB Uses

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

func NewMemDB Uses

func NewMemDB() *MemDB

func (*MemDB) Close Uses

func (db *MemDB) Close()

Implements DB.

func (*MemDB) Delete Uses

func (db *MemDB) Delete(key []byte)

Implements DB.

func (*MemDB) DeleteNoLock Uses

func (db *MemDB) DeleteNoLock(key []byte)

Implements atomicSetDeleter.

func (*MemDB) DeleteNoLockSync Uses

func (db *MemDB) DeleteNoLockSync(key []byte)

Implements atomicSetDeleter.

func (*MemDB) DeleteSync Uses

func (db *MemDB) DeleteSync(key []byte)

Implements DB.

func (*MemDB) Get Uses

func (db *MemDB) Get(key []byte) []byte

Implements DB.

func (*MemDB) Has Uses

func (db *MemDB) Has(key []byte) bool

Implements DB.

func (*MemDB) Iterator Uses

func (db *MemDB) Iterator(start, end []byte) Iterator

Implements DB.

func (*MemDB) Mutex Uses

func (db *MemDB) Mutex() *sync.Mutex

Implements atomicSetDeleter.

func (*MemDB) NewBatch Uses

func (db *MemDB) NewBatch() Batch

Implements DB.

func (*MemDB) Print Uses

func (db *MemDB) Print()

Implements DB.

func (*MemDB) ReverseIterator Uses

func (db *MemDB) ReverseIterator(start, end []byte) Iterator

Implements DB.

func (*MemDB) Set Uses

func (db *MemDB) Set(key []byte, value []byte)

Implements DB.

func (*MemDB) SetNoLock Uses

func (db *MemDB) SetNoLock(key []byte, value []byte)

Implements atomicSetDeleter.

func (*MemDB) SetNoLockSync Uses

func (db *MemDB) SetNoLockSync(key []byte, value []byte)

Implements atomicSetDeleter.

func (*MemDB) SetSync Uses

func (db *MemDB) SetSync(key []byte, value []byte)

Implements DB.

func (*MemDB) Stats Uses

func (db *MemDB) Stats() map[string]string

Implements DB.

type PrefixDB Uses

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

func NewPrefixDB Uses

func NewPrefixDB(db DB, prefix []byte) *PrefixDB

NewPrefixDB lets you namespace multiple DBs within a single DB.

func (*PrefixDB) Close Uses

func (pdb *PrefixDB) Close()

Implements DB.

func (*PrefixDB) Delete Uses

func (pdb *PrefixDB) Delete(key []byte)

Implements DB.

func (*PrefixDB) DeleteSync Uses

func (pdb *PrefixDB) DeleteSync(key []byte)

Implements DB.

func (*PrefixDB) Get Uses

func (pdb *PrefixDB) Get(key []byte) []byte

Implements DB.

func (*PrefixDB) Has Uses

func (pdb *PrefixDB) Has(key []byte) bool

Implements DB.

func (*PrefixDB) Iterator Uses

func (pdb *PrefixDB) Iterator(start, end []byte) Iterator

Implements DB.

func (*PrefixDB) Mutex Uses

func (pdb *PrefixDB) Mutex() *sync.Mutex

Implements atomicSetDeleter.

func (*PrefixDB) NewBatch Uses

func (pdb *PrefixDB) NewBatch() Batch

Implements DB. Panics if the underlying DB is not an atomicSetDeleter.

func (*PrefixDB) Print Uses

func (pdb *PrefixDB) Print()

Implements DB.

func (*PrefixDB) ReverseIterator Uses

func (pdb *PrefixDB) ReverseIterator(start, end []byte) Iterator

Implements DB.

func (*PrefixDB) Set Uses

func (pdb *PrefixDB) Set(key []byte, value []byte)

Implements DB.

func (*PrefixDB) SetSync Uses

func (pdb *PrefixDB) SetSync(key []byte, value []byte)

Implements DB.

func (*PrefixDB) Stats Uses

func (pdb *PrefixDB) Stats() map[string]string

Implements DB.

type SetDeleter Uses

type SetDeleter interface {
    Set(key, value []byte) // CONTRACT: key, value readonly []byte
    Delete(key []byte)     // CONTRACT: key readonly []byte
}

Directories

PathSynopsis
remotedbremotedb is a package for connecting to distributed Tendermint db.DB instances.
remotedb/grpcdbgrpcdb is the distribution of Tendermint's db.DB instances using the gRPC transport to decouple local db.DB usages from applications, to using them over a network in a highly performant manner.
remotedb/protoPackage protodb is a generated protocol buffer package.

Package db imports 15 packages (graph) and is imported by 155 packages. Updated 2019-11-19. Refresh now. Tools for package owners.