snapshotdb

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

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.

Variables

View Source
var (

	//ErrorSnaphotLock when db is Lock
	ErrorSnaphotLock = errors.New("can't create snapshot,snapshot is lock now")

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

	//ErrDBNotInit when db  not init
	ErrDBNotInit   = errors.New("snapshotDB: not init")
	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 SetDBBlockChain

func SetDBBlockChain(n Chain)

func SetDBPathWithNode

func SetDBPathWithNode(n *node.Node)

Types

type Chain

type Chain interface {
	CurrentHeader() *types.Header
	GetHeaderByHash(hash common.Hash) *types.Header
}

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)

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

	DelBaseDB(key []byte) error
	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 New

func New() (DB, error)

New create a new snapshotDB,will clear old snapshotDB data

func Open

func Open(path string) (DB, error)

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.

Jump to

Keyboard shortcuts

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