store

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: Apache-2.0 Imports: 17 Imported by: 9

README

存储结构

qbase引用了cosmos-sdk的存储实现,在此对cosmos团队表示诚挚的感谢 此文档意在对cosmos-sdk存储模块进行分析,并说明qbase对其的修改,以供开发者参考

继承关系

为了理解存储设计思路,突出两大类存储接口:

commiter

为配合abci接口调用的进程,实现对version的控制和提交到底层存储

cachewraper

为配合abci接口调用的数据生命周期,实现双层缓存/提交的控制逻辑

查询过程解释及接口定义

通过abci的Query(req RequestQuery)查询时:

req.Data:查询的key
req.Path:查询的路由信息,组成:"store/$storeName/$subpath"
"store" 为固定字段,表示查询的对象时存储
$storeName 为某一iavlStore(或其他)指定的名字
$subpath:
  • 为"store"/"key"时,表示当前查询目标为key为req.Data的value
  • 为"subspace"时,比哦是当前查询目标为前缀为req.Data的子树(可展开) 需要注意存取的对象是否需要解码

存储过程解释及接口定义

直接存储数值

调用可调用实例提供的mapper mapper直接访问BaseApp.cms实现存储

abci提交

两层缓存结构,在BaseApp.cms上,分别包装成两个缓存:checkState、deliverState

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheKVStore

func NewCacheKVStore(parent KVStore) *cacheKVStore

nolint

func NewCommitMultiStore

func NewCommitMultiStore(db dbm.DB) *baseMultiStore

nolint

func PrefixEndBytes

func PrefixEndBytes(prefix []byte) []byte

PrefixEndBytes returns the []byte that would end a range query for all []byte with a certain prefix Deals with last byte of prefix being FF without overflowing

func RequireProof

func RequireProof(subpath string) bool

RequireProof return whether proof is require for the subpath

func VerifyMultiStoreCommitInfo

func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHash []byte) ([]byte, error)

VerifyMultiStoreCommitInfo verify multiStoreCommitInfo against appHash

func VerifyRangeProof

func VerifyRangeProof(key, value []byte, substoreCommitHash []byte, rangeProof *iavl.RangeProof) error

VerifyRangeProof verify iavl RangeProof

Types

type CacheKVStore

type CacheKVStore interface {
	KVStore

	// Writes operations to underlying KVStore
	Write()
}

CacheKVStore cache-wraps a KVStore. After calling .Write() on the CacheKVStore, all previously created CacheKVStores on the object expire.

type CacheMultiStore

type CacheMultiStore interface {
	MultiStore
	Write() // Writes operations to underlying KVStore
}

From MultiStore.CacheMultiStore()....

type CacheWrap

type CacheWrap interface {
	// Write syncs with the underlying store.
	Write()

	// CacheWrap recursively wraps again.
	CacheWrap() CacheWrap

	// CacheWrapWithTrace recursively wraps again with tracing enabled.
	CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
}

CacheWrap makes the most appropriate cache-wrap. For example, IAVLStore.CacheWrap() returns a CacheKVStore. CacheWrap should not return a Committer, since Commit cache-wraps make no sense. It can return KVStore, HeapStore, SpaceStore, etc.

type CacheWrapper

type CacheWrapper interface {
	// CacheWrap cache wraps.
	CacheWrap() CacheWrap

	// CacheWrapWithTrace cache wraps with tracing enabled.
	CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
}

type CommitID

type CommitID struct {
	Version int64
	Hash    []byte
}

CommitID contains the tree version number and its merkle root.

func (CommitID) IsZero

func (cid CommitID) IsZero() bool

func (CommitID) String

func (cid CommitID) String() string

type CommitKVStore

type CommitKVStore interface {
	Committer
	KVStore
}

Stores of MultiStore must implement CommitStore.

type CommitMultiStore

type CommitMultiStore interface {
	Committer
	MultiStore

	// Mount a store of type using the given db.
	// If db == nil, the new store will use the CommitMultiStore db.
	MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB)

	// Panics on a nil key.
	GetCommitStore(key StoreKey) CommitStore

	// Panics on a nil key.
	GetCommitKVStore(key StoreKey) CommitKVStore

	// Load the latest persisted version.  Called once after all
	// calls to Mount*Store() are complete.
	LoadLatestVersion() error

	// Load a specific persisted version.  When you load an old
	// version, or when the last commit attempt didn't complete,
	// the next commit after loading must be idempotent (return the
	// same commit id).  Otherwise the behavior is undefined.
	LoadVersion(ver int64) error
}

A non-cache MultiStore.

type CommitStore

type CommitStore interface {
	Committer
	Store
}

Stores of MultiStore must implement CommitStore.

func LoadIAVLStore

func LoadIAVLStore(db dbm.DB, id CommitID, pruning PruningStrategy) (CommitStore, error)

load the iavl store

type Committer

type Committer interface {
	Commit() CommitID
	LastCommitID() CommitID
	SetPruning(PruningStrategy)
}

something that can persist to disk

type Iterator

type Iterator = dbm.Iterator

Alias iterator to db's Iterator for convenience.

func KVStorePrefixIterator

func KVStorePrefixIterator(kvs KVStore, prefix []byte) Iterator

Iterator over all the keys with a certain prefix in ascending order

func KVStoreReversePrefixIterator

func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator

Iterator over all the keys with a certain prefix in descending order.

type KVPair

type KVPair cmn.KVPair

---------------------------------------- key-value result for iterator queries

type KVStore

type KVStore interface {
	Store

	// Get returns nil iff key doesn't exist. Panics on nil key.
	Get(key []byte) []byte

	// Has checks if a key exists. Panics on nil key.
	Has(key []byte) bool

	// Set sets the key. Panics on nil key.
	Set(key, value []byte)

	// Delete deletes the key. Panics on nil key.
	Delete(key []byte)

	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	Iterator(start, end []byte) Iterator

	// Iterator over a domain of keys in descending order. End is exclusive.
	// Start must be greater than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	ReverseIterator(start, end []byte) Iterator

	// Prefix applied keys with the argument
	// CONTRACT: when Prefix is called on a KVStore more than once,
	// the concatanation of the prefixes is applied
	Prefix(prefix []byte) KVStore
}

KVStore is a simple interface to get/set data

type KVStoreKey

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

KVStoreKey is used for accessing substores. Only the pointer value should ever be used - it functions as a capabilities key.

func NewKVStoreKey

func NewKVStoreKey(name string) *KVStoreKey

NewKVStoreKey returns a new pointer to a KVStoreKey. Use a pointer so keys don't collide.

func (*KVStoreKey) Name

func (key *KVStoreKey) Name() string

func (*KVStoreKey) String

func (key *KVStoreKey) String() string

type MultiStore

type MultiStore interface {
	Store

	// Cache wrap MultiStore.
	// NOTE: Caller should probably not call .Write() on each, but
	// call CacheMultiStore.Write().
	CacheMultiStore() CacheMultiStore

	// Convenience for fetching substores.
	GetStore(StoreKey) Store
	GetKVStore(StoreKey) KVStore

	// TracingEnabled returns if tracing is enabled for the MultiStore.
	TracingEnabled() bool

	// WithTracer sets the tracer for the MultiStore that the underlying
	// stores will utilize to trace operations. A MultiStore is returned.
	WithTracer(w io.Writer) MultiStore

	// WithTracingContext sets the tracing context for a MultiStore. It is
	// implied that the caller should update the context when necessary between
	// tracing operations. A MultiStore is returned.
	WithTracingContext(TraceContext) MultiStore

	// ResetTraceContext resets the current tracing context.
	ResetTraceContext() MultiStore
}

type MultiStoreProof

type MultiStoreProof struct {
	StoreInfos []storeInfo
	StoreName  string
	RangeProof iavl.RangeProof
}

MultiStoreProof defines a collection of store proofs in a multi-store

type PruningStrategy

type PruningStrategy uint8

PruningStrategy specfies how old states will be deleted over time

const (
	// PruneSyncable means only those states not needed for state syncing will be deleted (keeps last 100 + every 10000th)
	PruneSyncable PruningStrategy = iota

	// PruneEverything means all saved states will be deleted, storing only the current state
	PruneEverything PruningStrategy = iota

	// PruneNothing means all historic states will be saved, nothing will be deleted
	PruneNothing PruningStrategy = iota
)

type Queryable

type Queryable interface {
	Query(abci.RequestQuery) abci.ResponseQuery
}

Queryable allows a Store to expose internal state to the abci.Query interface. Multistore can route requests to the proper Store.

This is an optional, but useful extension to any CommitStore

type Store

type Store interface {
	GetStoreType() StoreType
	CacheWrapper
}

type StoreKey

type StoreKey interface {
	Name() string
	String() string
}

StoreKey is a key used to index stores in a MultiStore.

type StoreType

type StoreType int

kind of store

const (
	//nolint
	StoreTypeMulti StoreType = iota
	StoreTypeDB
	StoreTypeIAVL
	StoreTypeTransient
)

type TraceContext

type TraceContext map[string]interface{}

TraceContext contains TraceKVStore context data. It will be written with every trace operation.

type TraceKVStore

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

TraceKVStore implements the KVStore interface with tracing enabled. Operations are traced on each core KVStore call and written to the underlying io.writer.

TODO: Should we use a buffered writer and implement Commit on TraceKVStore?

func NewTraceKVStore

func NewTraceKVStore(parent KVStore, writer io.Writer, tc TraceContext) *TraceKVStore

NewTraceKVStore returns a reference to a new traceKVStore given a parent KVStore implementation and a buffered writer.

func (*TraceKVStore) CacheWrap

func (tkv *TraceKVStore) CacheWrap() CacheWrap

CacheWrap implements the KVStore interface. It panics as a TraceKVStore cannot be cache wrapped.

func (*TraceKVStore) CacheWrapWithTrace

func (tkv *TraceKVStore) CacheWrapWithTrace(_ io.Writer, _ TraceContext) CacheWrap

CacheWrapWithTrace implements the KVStore interface. It panics as a TraceKVStore cannot be cache wrapped.

func (*TraceKVStore) Delete

func (tkv *TraceKVStore) Delete(key []byte)

Delete implements the KVStore interface. It traces a write operation and delegates the Delete call to the parent KVStore.

func (*TraceKVStore) Get

func (tkv *TraceKVStore) Get(key []byte) []byte

Get implements the KVStore interface. It traces a read operation and delegates a Get call to the parent KVStore.

func (*TraceKVStore) GetStoreType

func (tkv *TraceKVStore) GetStoreType() StoreType

GetStoreType implements the KVStore interface. It returns the underlying KVStore type.

func (*TraceKVStore) Has

func (tkv *TraceKVStore) Has(key []byte) bool

Has implements the KVStore interface. It delegates the Has call to the parent KVStore.

func (*TraceKVStore) Iterator

func (tkv *TraceKVStore) Iterator(start, end []byte) dbm.Iterator

Iterator implements the KVStore interface. It delegates the Iterator call the to the parent KVStore.

func (*TraceKVStore) Prefix

func (tkv *TraceKVStore) Prefix(prefix []byte) KVStore

Prefix implements the KVStore interface.

func (*TraceKVStore) ReverseIterator

func (tkv *TraceKVStore) ReverseIterator(start, end []byte) dbm.Iterator

ReverseIterator implements the KVStore interface. It delegates the ReverseIterator call the to the parent KVStore.

func (*TraceKVStore) Set

func (tkv *TraceKVStore) Set(key []byte, value []byte)

Set implements the KVStore interface. It traces a write operation and delegates the Set call to the parent KVStore.

type TransientStoreKey

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

TransientStoreKey is used for indexing transient stores in a MultiStore

func NewTransientStoreKey

func NewTransientStoreKey(name string) *TransientStoreKey

Constructs new TransientStoreKey Must return a pointer according to the ocap principle

func (*TransientStoreKey) Name

func (key *TransientStoreKey) Name() string

Implements StoreKey

func (*TransientStoreKey) String

func (key *TransientStoreKey) String() string

Implements StoreKey

Jump to

Keyboard shortcuts

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