Documentation
¶
Index ¶
- Constants
- Variables
- func Close()
- func DecodeWalKey(key []byte) *big.Int
- func EncodeWalKey(blockNum *big.Int) []byte
- func IsDbNotFoundErr(err error) bool
- func NonDbNotFoundErr(err error) bool
- func SetDBBlockChain(c Chain)
- func SetDBOptions(cache int, handles int)
- func SetDBPathWithNode(path string)
- type BaseDB
- type Chain
- type CurrentBase
- type CurrentHighest
- type DB
- type Database
- type Deleter
- type MemDatabase
- func (db *MemDatabase) DelBaseDB(key []byte) error
- func (db *MemDatabase) GetBaseDB(key []byte) ([]byte, error)
- func (db *MemDatabase) GetCurrent() *current
- func (db *MemDatabase) PutBaseDB(key, value []byte) error
- func (db *MemDatabase) SetCurrent(highestHash common.Hash, base, height big.Int) error
- func (db *MemDatabase) WriteBaseDB(kvs [][2][]byte) error
- type Putter
- type Writer
Constants ¶
View Source
const ( CurrentHighestBlock = "snapshotdbCurrentHighestBlock" CurrentBaseNum = "snapshotdbCurrentBaseNum" CurrentAll = "snapshotdbCurrentAll" CurrentSet = "snapshotdbCurrentSet" )
View Source
const ( //DBPath path of db DBPath = "snapshotdb" //DBBasePath path of basedb DBBasePath = "base" )
View Source
const ( JournalRemain = 200 UnBlockNeedClean = 200 MaxBlockCompaction = 10 MaxBlockNotCompactionSync = 10 MaxBlockTriggerCompaction = 200 )
View Source
const WalKeyPrefix = "journal-"
Variables ¶
View Source
var ( //ErrNotFound when db not found ErrNotFound = errors.New("snapshotDB: not found") ErrBlockTooLow = errors.New("the block is less than commit highest block") )
View Source
var DefaultComparer = bytesComparer{}
DefaultComparer are default implementation of the Comparer interface. It uses the natural ordering, consistent with bytes.Compare.
Functions ¶
func DecodeWalKey ¶
func EncodeWalKey ¶
func IsDbNotFoundErr ¶
func NonDbNotFoundErr ¶
func SetDBBlockChain ¶
func SetDBBlockChain(c Chain)
func SetDBOptions ¶
func SetDBPathWithNode ¶
func SetDBPathWithNode(path string)
Types ¶
type BaseDB ¶
type BaseDB interface {
PutBaseDB(key, value []byte) error
GetBaseDB(key []byte) ([]byte, error)
DelBaseDB(key []byte) error
// WriteBaseDB apply the given [][2][]byte to the baseDB.
WriteBaseDB(kvs [][2][]byte) error
//SetCurrent use for fast sync
SetCurrent(highestHash common.Hash, base, height big.Int) error
GetCurrent() *current
}
type Chain ¶
type Chain interface {
CurrentHeader() *types.Header
GetHeaderByHash(hash common.Hash) *types.Header
GetHeaderByNumber(number uint64) *types.Header
}
func GetDBBlockChain ¶
func GetDBBlockChain() Chain
type CurrentBase ¶
type DB ¶
type DB interface {
Put(hash common.Hash, key, value []byte) error
NewBlock(blockNumber *big.Int, parentHash common.Hash, hash common.Hash) error
Get(hash common.Hash, key []byte) ([]byte, error)
GetFromCommittedBlock(key []byte) ([]byte, error)
Del(hash common.Hash, key []byte) error
Has(hash common.Hash, key []byte) (bool, error)
Flush(hash common.Hash, blocknumber *big.Int) error
Ranking(hash common.Hash, key []byte, ranges int) iterator.Iterator
//notice , iter.key or iter.value is slice,if you want to save it to a slice,you can use copy
// container:=make([]byte,0)
// for iter.next{
// tosave:= make([]byte,len(iter.value))
// copy(tosave,iter.value)
// container = append(container,tosave)
// }
//
WalkBaseDB(slice *util.Range, f func(num *big.Int, iter iterator.Iterator) error) error
Commit(hash common.Hash) error
// Clear close db , remove all db file
Clear() error
BaseDB
GetLastKVHash(blockHash common.Hash) []byte
BaseNum() (*big.Int, error)
Close() error
Compaction() error
SetEmpty() error
//ues to Revert failed tx
RevertToSnapshot(hash common.Hash, revid int)
Snapshot(hash common.Hash) int
}
DB the main snapshotdb interface
example new a recognized blockData(sync from other peer) dbInstance.NewBlock(blockNumber, parentHash, hash) dbInstance.Put(hash, kv.key, kv.value) dbInstance.Commit(hash) new a unrecognized blockData(a block produce by self) dbInstance.NewBlock(blockNumber, parentHash, common.ZeroHash) dbInstance.Put(hash, kv.key, kv.value) dbInstance.Flush(hash common.Hash, blockNumber *big.Int) dbInstance.Commit(hash) get a blockData with hash dbInstance.Get(hash, key) get a blockData without hash dbInstance.Get(common.zerohash, key)
type Database ¶
type Database interface {
Putter
Deleter
Get(hash common.Hash, key []byte) ([]byte, error)
Has(hash common.Hash, key []byte) (bool, error)
}
Database wraps all database operations. All methods are safe for concurrent use.
type Deleter ¶
Deleter wraps the database delete operation supported by both batches and regular databases.
type MemDatabase ¶
type MemDatabase struct {
// contains filtered or unexported fields
}
func NewMemBaseDB ¶
func NewMemBaseDB() *MemDatabase
func (*MemDatabase) DelBaseDB ¶
func (db *MemDatabase) DelBaseDB(key []byte) error
func (*MemDatabase) GetCurrent ¶
func (db *MemDatabase) GetCurrent() *current
func (*MemDatabase) PutBaseDB ¶
func (db *MemDatabase) PutBaseDB(key, value []byte) error
func (*MemDatabase) SetCurrent ¶
SetCurrent use for fast sync
func (*MemDatabase) WriteBaseDB ¶
func (db *MemDatabase) WriteBaseDB(kvs [][2][]byte) error
WriteBaseDB apply the given [][2][]byte to the baseDB.
Click to show internal directories.
Click to hide internal directories.