snapshotdb

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: GPL-3.0 Imports: 35 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 (
	TypeCurrent fileType = 1 << iota
	TypeJournal
	TypeAll = TypeCurrent | TypeJournal
)

File types.

View Source
const (
	JournalRemain             = 200
	UnBlockNeedClean          = 200
	MaxBlockCompaction        = 10
	MaxBlockCompactionSync    = 100
	MaxBlockTriggerCompaction = 200
)

Variables

View Source
var (

	//ErrNotFound when db not found
	ErrNotFound = errors.New("snapshotDB: not found")

	ErrBlockRepeat = errors.New("the block is exist in snapshotdb uncommit")
	ErrBlockTooLow = errors.New("the block is less than commit highest block")
)
View Source
var (
	ErrInvalidFile = errors.New("snapshotdb/storage: invalid file for argument")
	ErrLocked      = errors.New("snapshotdb/storage: already locked")
	ErrClosed      = errors.New("snapshotdb/storage: closed")
)

Common error.

View Source
var DefaultComparer = bytesComparer{}

DefaultComparer are default implementation of the Comparer interface. It uses the natural ordering, consistent with bytes.Compare.

Functions

func FileDescOk

func FileDescOk(fd fileDesc) bool

FileDescOk returns true if fd is a valid 'file descriptor'.

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

	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

	GetLastKVHash(blockHash common.Hash) []byte
	BaseNum() (*big.Int, error)
	Close() error
	Compaction() error
	SetEmpty() error
}

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) (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 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 Reader

type Reader interface {
	io.ReadSeeker
	io.ReaderAt
	io.Closer
}

Reader is the interface that groups the basic Read, Seek, ReadAt and Close methods.

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