ptndb

package
v1.0.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const IdealBatchSize = 100 * 1024

Code using batches should try to add this much data to the batch. The value was determined empirically.

Variables

View Source
var (
	ErrReleased    = errors.New("leveldb: resource already relesed")
	ErrHasReleaser = errors.New("leveldb: releaser already defined")
)
View Source
var OpenFileLimit = 64

Functions

func EncodeBlockNumber

func EncodeBlockNumber(number uint64) []byte

encodeBlockNumber encodes a block number as big endian uint64

Types

type Batch

type Batch interface {
	Putter
	Deleter
	ValueSize() int // amount of data in the batch
	Write() error
	// Reset resets the batch for reuse
	Reset()
}

Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.

func NewTableBatch

func NewTableBatch(db Database, prefix string) Batch

NewTableBatch returns a Batch object which prefixes all keys with a given string.

type Database

type Database interface {
	Putter
	Deleter
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Close()
	NewBatch() Batch

	NewIterator() iterator.Iterator
	NewIteratorWithPrefix(prefix []byte) iterator.Iterator
}

Database wraps all database operations. All methods are safe for concurrent use.

func NewTable

func NewTable(db Database, prefix string) Database

NewTable returns a Database object that prefixes all keys with a given string.

type Deleter

type Deleter interface {
	Delete(key []byte) error
}

Deleter wraps the database delete operation supported by both batches and regular databases.

type Iterator

type Iterator interface {
	iterator.Iterator
}

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

type LDBDatabase

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

func NewLDBDatabase

func NewLDBDatabase(file string, cache int, handles int) (*LDBDatabase, error)

NewLDBDatabase returns a LevelDB wrapped object.

func (*LDBDatabase) Close

func (db *LDBDatabase) Close()

func (*LDBDatabase) Delete

func (db *LDBDatabase) Delete(key []byte) error

Delete deletes the key from the queue and database

func (*LDBDatabase) Get

func (db *LDBDatabase) Get(key []byte) ([]byte, error)

Get returns the given key if it's present.

func (*LDBDatabase) Has

func (db *LDBDatabase) Has(key []byte) (bool, error)

func (*LDBDatabase) LDB

func (db *LDBDatabase) LDB() *leveldb.DB

func (*LDBDatabase) Meter

func (db *LDBDatabase) Meter(prefix string)

Meter configures the database metrics collectors and

func (*LDBDatabase) NewBatch

func (db *LDBDatabase) NewBatch() Batch

func (*LDBDatabase) NewIterator

func (db *LDBDatabase) NewIterator() iterator.Iterator

func (*LDBDatabase) NewIteratorWithPrefix

func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator

NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.

func (*LDBDatabase) Path

func (db *LDBDatabase) Path() string

Path returns the path to the database directory.

func (*LDBDatabase) Put

func (db *LDBDatabase) Put(key []byte, value []byte) error

Put puts the given key / value to the queue

type MemDatabase

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

* This is a test memory database. Do not use for any production it does not get persisted

func NewMemDatabase

func NewMemDatabase() (*MemDatabase, error)

func NewMemDatabaseWithCap

func NewMemDatabaseWithCap(size int) (*MemDatabase, error)

func (*MemDatabase) Close

func (db *MemDatabase) Close()

func (*MemDatabase) Delete

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

func (*MemDatabase) Get

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

func (*MemDatabase) Has

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

func (*MemDatabase) Keys

func (db *MemDatabase) Keys() [][]byte

func (*MemDatabase) Len

func (db *MemDatabase) Len() int

func (*MemDatabase) NewBatch

func (db *MemDatabase) NewBatch() Batch

func (*MemDatabase) NewIterator

func (db *MemDatabase) NewIterator() iterator.Iterator

func (*MemDatabase) NewIteratorWithPrefix

func (db *MemDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator

NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.

func (*MemDatabase) Put

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

type MemIterator

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

func (*MemIterator) Error

func (i *MemIterator) Error() error

func (*MemIterator) First

func (i *MemIterator) First() bool

implement iterator interface

func (*MemIterator) Key

func (i *MemIterator) Key() []byte

func (*MemIterator) Last

func (i *MemIterator) Last() bool

func (*MemIterator) Next

func (i *MemIterator) Next() bool

func (*MemIterator) Prev

func (i *MemIterator) Prev() bool

func (*MemIterator) Release

func (i *MemIterator) Release()

func (*MemIterator) Seek

func (i *MemIterator) Seek(key []byte) bool

func (*MemIterator) SetReleaser

func (i *MemIterator) SetReleaser(releaser util.Releaser)

func (*MemIterator) Valid

func (i *MemIterator) Valid() bool

func (*MemIterator) Value

func (i *MemIterator) Value() []byte

type Putter

type Putter interface {
	Put(key []byte, value []byte) error
}

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

type Tempdb added in v1.0.6

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

func NewTempdb added in v1.0.6

func NewTempdb(db Database) (*Tempdb, error)

func (*Tempdb) Clear added in v1.0.6

func (db *Tempdb) Clear()

func (*Tempdb) Close added in v1.0.6

func (db *Tempdb) Close()

func (*Tempdb) Delete added in v1.0.6

func (db *Tempdb) Delete(key []byte) error

func (*Tempdb) Get added in v1.0.6

func (db *Tempdb) Get(key []byte) ([]byte, error)

func (*Tempdb) Has added in v1.0.6

func (db *Tempdb) Has(key []byte) (bool, error)

func (*Tempdb) Len added in v1.0.6

func (db *Tempdb) Len() int

func (*Tempdb) NewBatch added in v1.0.6

func (db *Tempdb) NewBatch() Batch

func (*Tempdb) NewIterator added in v1.0.6

func (db *Tempdb) NewIterator() iterator.Iterator

func (*Tempdb) NewIteratorWithPrefix added in v1.0.6

func (db *Tempdb) NewIteratorWithPrefix(prefix []byte) iterator.Iterator

NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix. 这个最复杂,需要先去db数据库查询出map,然后把temp的列举出来,同样key的会被替换成新值,如果出现在del里面就删除,然后map转KeyValue数组

func (*Tempdb) Put added in v1.0.6

func (db *Tempdb) Put(key []byte, value []byte) error

type TempdbIterator added in v1.0.6

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

func (*TempdbIterator) Error added in v1.0.6

func (i *TempdbIterator) Error() error

func (*TempdbIterator) First added in v1.0.6

func (i *TempdbIterator) First() bool

implement iterator interface

func (*TempdbIterator) Key added in v1.0.6

func (i *TempdbIterator) Key() []byte

func (*TempdbIterator) Last added in v1.0.6

func (i *TempdbIterator) Last() bool

func (*TempdbIterator) Next added in v1.0.6

func (i *TempdbIterator) Next() bool

func (*TempdbIterator) Prev added in v1.0.6

func (i *TempdbIterator) Prev() bool

func (*TempdbIterator) Release added in v1.0.6

func (i *TempdbIterator) Release()

func (*TempdbIterator) Seek added in v1.0.6

func (i *TempdbIterator) Seek(key []byte) bool

func (*TempdbIterator) SetReleaser added in v1.0.6

func (i *TempdbIterator) SetReleaser(releaser util.Releaser)

func (*TempdbIterator) Valid added in v1.0.6

func (i *TempdbIterator) Valid() bool

func (*TempdbIterator) Value added in v1.0.6

func (i *TempdbIterator) Value() []byte

Jump to

Keyboard shortcuts

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