storage

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

This file is for grabbing a leveldb instance without cleveldb support

Index

Constants

View Source
const (
	MEMORY StorageType = iota
	PERSISTENT

	CACHE      = "cache"
	CACHE_SAFE = "cache_safe"
	KEYVALUE   = "keyvalue"

	CHAINKEY_MAXLEN       = 20
	CHAINSTATE_CACHE_SIZE = 10000
)

Different types

View Source
const (
	OLDATA   = "OLDATA"
	NODEDATA = "nodedata"
)

Variables

View Source
var (
	ErrNotFound  = errors.New("key not found")
	ErrSetFailed = errors.New("failed to set data")
)
View Source
var ErrNilData = errors.New("data is nil")

Functions

func NewCache

func NewCache(name string) *cache

func NewCacheSafe

func NewCacheSafe(name string) *cacheSafe

Types

type ChainState

type ChainState struct {
	Name string
	Type StorageType

	Delivered *iavl.MutableTree // Build us a new set of transactions

	// Last committed values
	LastVersion int64
	Version     int64
	LastHash    []byte
	Hash        []byte
	TreeHeight  int8

	sync.RWMutex
	// contains filtered or unexported fields
}

Chainstate is a storage for balances on the chain, a snapshot of all accounts

func NewChainState

func NewChainState(name, dbDir, configDB string, newType StorageType) *ChainState

NewChainState generates a new ChainState object

func (*ChainState) Close

func (state *ChainState) Close()

func (*ChainState) Commit

func (state *ChainState) Commit() ([]byte, int64)

TODO: Not sure about this, it seems to be Cosmos-sdk's way of getting arround the immutable copy problem...

func (*ChainState) Dump

func (state *ChainState) Dump()

func (*ChainState) Exists

func (state *ChainState) Exists(key StoreKey) bool

TODO: Should be against the commit tree, not the delivered one!!!

func (*ChainState) FindAll

func (state *ChainState) FindAll() map[string][]byte

Expensive O(n) search through everything...

func (*ChainState) Get

func (state *ChainState) Get(key StoreKey, lastCommit bool) []byte

TODO: Should be against the commit tree, not the delivered one!!!

func (*ChainState) Iterate added in v0.10.4

func (state *ChainState) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

func (*ChainState) Remove added in v0.10.4

func (stake *ChainState) Remove(key []byte) ([]byte, bool)

Remove removes item from chainstate

func (*ChainState) Set

func (state *ChainState) Set(key StoreKey, val []byte) error

Do this only for the Delivery side

type IterItem

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

type Iterator

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

func (*Iterator) Key

func (i *Iterator) Key() []byte

func (*Iterator) Next

func (i *Iterator) Next() bool

func (*Iterator) Value

func (i *Iterator) Value() []byte

type KeyValue

type KeyValue struct {
	Type StorageType

	Name string
	File string

	sync.RWMutex
	// contains filtered or unexported fields
}
KeyValue begins here

KeyValue Wrap the underlying usage

func (KeyValue) BeginSession

func (store KeyValue) BeginSession() Session

BeginSession a new writable session

func (KeyValue) Close

func (store KeyValue) Close()

Close the database

func (KeyValue) Dump

func (store KeyValue) Dump()

Dump out debugging information from the KeyValue datastore

func (KeyValue) Errors

func (store KeyValue) Errors() string

Print out the error details

func (KeyValue) Exists

func (store KeyValue) Exists(key StoreKey) (bool, error)

Test to see if a key exists

func (KeyValue) FindAll

func (store KeyValue) FindAll() []StoreKey

FindAll of the keys in the database

func (KeyValue) Get

func (store KeyValue) Get(key StoreKey) ([]byte, error)

Get a key from the database

func (KeyValue) Iterate

func (store KeyValue) Iterate(fn func(key []byte, value []byte) bool) (stopped bool)

func (KeyValue) ReadAll

func (store KeyValue) ReadAll() []IterItem

func (KeyValue) Reopen

func (store KeyValue) Reopen()

Close and reopen the datastore

type KeyValueSession

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

KeyValueSession begins here

func (KeyValueSession) Commit

func (session KeyValueSession) Commit() bool

Commit the changes to persistence

func (KeyValueSession) Delete

func (session KeyValueSession) Delete(key StoreKey) (bool, error)

Delete a key from the datastore

func (KeyValueSession) Dump

func (session KeyValueSession) Dump()

Dump out the contents of the database

func (KeyValueSession) Errors

func (session KeyValueSession) Errors() string

List out the errors

func (KeyValueSession) Exists

func (session KeyValueSession) Exists(key StoreKey) bool

Test to see if a key exists

func (KeyValueSession) FindAll

func (session KeyValueSession) FindAll() []StoreKey

Find all of the keys in the datastore

func (KeyValueSession) Get

func (session KeyValueSession) Get(key StoreKey) ([]byte, error)

Load return the stored value

func (KeyValueSession) GetIterator

func (session KeyValueSession) GetIterator() *Iterator

GetIterator dummy iterator

func (KeyValueSession) Rollback

func (session KeyValueSession) Rollback() bool

Rollback any changes since the last commit

func (KeyValueSession) Set

func (session KeyValueSession) Set(key StoreKey, dat []byte) error

Store inserts or updates a value under a key

type Session

type Session interface {
	Store
	Commit() bool
	FindAll() []StoreKey
}

Session defines a session-ed storage object of your choice

func NewKeyValueSession

func NewKeyValueSession(store *KeyValue) Session

Create a new session

type SessionedStorage

type SessionedStorage interface {
	Get(StoreKey) ([]byte, error)
	Exists(StoreKey) (bool, error)

	BeginSession() Session
	Close()
	ReadAll() []IterItem
	Iterate(fn func(key []byte, value []byte) bool) (stopped bool)
}

SessionedStorage wraps objects with option to start a session(db transaction)

func NewStorageDB

func NewStorageDB(flavor, name string, DBDir, DBType string) SessionedStorage

NewStorageSession creates a new SessionStorage

type StorageType

type StorageType int

ENUM for datastore type

type Store

type Store interface {
	Get(StoreKey) ([]byte, error)
	Set(StoreKey, []byte) error
	Exists(StoreKey) bool
	Delete(StoreKey) (bool, error)
	GetIterator() *Iterator
}

store wraps object with option to use a cache type db

func NewStorage

func NewStorage(flavor, name string) Store

NewStorage initializes a non sessioned storage

type StoreKey

type StoreKey []byte

func (StoreKey) Bytes

func (sk StoreKey) Bytes() []byte

func (StoreKey) String

func (sk StoreKey) String() string

Jump to

Keyboard shortcuts

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