snapshotdb

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: GPL-3.0 Imports: 31 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
	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 Close added in v1.1.3

func Close()

func DecodeWalKey added in v1.0.0

func DecodeWalKey(key []byte) *big.Int

func EncodeWalKey added in v1.0.0

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

func IsDbNotFoundErr added in v0.7.4

func IsDbNotFoundErr(err error) bool

func NonDbNotFoundErr added in v0.7.4

func NonDbNotFoundErr(err error) bool

func OpenWithStorage added in v1.4.1

func OpenWithStorage(st storage.Storage, cache int, handles int, baseOnly bool) (*snapshotDB, error)

func SetDBBlockChain

func SetDBBlockChain(c Chain)

func SetDBOptions added in v0.7.4

func SetDBOptions(cache int, handles int)

func SetDBPathWithNode

func SetDBPathWithNode(path string)

Types

type BaseDB added in v1.0.0

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 added in v0.7.5

func GetDBBlockChain() Chain

type CurrentBase added in v0.7.3

type CurrentBase struct {
	Num *big.Int `rlp:"nil"`
}

type CurrentHighest added in v0.7.3

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 added in v0.7.6

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 added in v0.7.6

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 added in v1.0.0

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

func NewMemBaseDB added in v1.0.0

func NewMemBaseDB() *MemDatabase

func (*MemDatabase) DelBaseDB added in v1.0.0

func (db *MemDatabase) DelBaseDB(key []byte) error

func (*MemDatabase) GetBaseDB added in v1.0.0

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

func (*MemDatabase) GetCurrent added in v1.0.0

func (db *MemDatabase) GetCurrent() *current

func (*MemDatabase) PutBaseDB added in v1.0.0

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

func (*MemDatabase) SetCurrent added in v1.0.0

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

SetCurrent use for fast sync

func (*MemDatabase) WriteBaseDB added in v1.0.0

func (db *MemDatabase) WriteBaseDB(kvs [][2][]byte) error

WriteBaseDB apply the given [][2][]byte to the baseDB.

type Putter added in v0.7.6

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 added in v0.7.6

type Writer interface {
	Putter
	Deleter
}

Jump to

Keyboard shortcuts

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