snapshotdb

package
v0.11.1-0...-daaff9c Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

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
	MaxBlockCompactionSync    = 100
	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 DecodeWalKey(key []byte) *big.Int

func EncodeWalKey

func EncodeWalKey(blockNum *big.Int) []byte

func IsDbNotFoundErr

func IsDbNotFoundErr(err error) bool

func NonDbNotFoundErr

func NonDbNotFoundErr(err error) bool

func SetDBBlockChain

func SetDBBlockChain(c Chain)

func SetDBOptions

func SetDBOptions(cache int, handles int)

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 CurrentBase struct {
	Num *big.Int `rlp:"nil"`
}

type CurrentHighest

type CurrentHighest struct {
	Num  *big.Int `rlp:"nil"`
	Hash common.Hash
}

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)

func Instance

func Instance() DB

Instance return the Instance of the db

func Open

func Open(path string, cache int, handles int, baseOnly bool) (DB, error)

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

type Deleter interface {
	Delete(hash common.Hash, key []byte) error
}

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) GetBaseDB

func (db *MemDatabase) GetBaseDB(key []byte) ([]byte, error)

func (*MemDatabase) GetCurrent

func (db *MemDatabase) GetCurrent() *current

func (*MemDatabase) PutBaseDB

func (db *MemDatabase) PutBaseDB(key, value []byte) error

func (*MemDatabase) SetCurrent

func (db *MemDatabase) SetCurrent(highestHash common.Hash, base, height big.Int) error

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.

type Putter

type Putter interface {
	Put(hash common.Hash, key []byte, value []byte) error
}

Putter wraps the database write operation supported by both batches and regular databases.

type Writer

type Writer interface {
	Putter
	Deleter
}

Jump to

Keyboard shortcuts

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