storage

package
v0.11.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2019 License: ISC Imports: 14 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: ISC

SPDX-License-Identifier: ISC

Package storage - maintain the on-disk data store

maintain separate pools of a number of elements in key->value form

This maintains a LevelDB database split into a series of tables. Each table is defined by a prefix byte that is obtained from the prefix tag in the struct defining the available tables.

Notes: 1. each separate pool has a single byte prefix (to spread the keys in LevelDB) 2. ⧺ = concatenation of byte data 3. BN = block number as 8 byte big endian (uint64) 4. txId = transaction digest as 32 byte SHA3-256(data) 5. asset id = fingerprint digest as 64 byte SHA3-512(data) 6. count = successive index value as 8 byte big endian (uint64) 7. owner = bitmark account (prefix ⧺ public key ≡ 33 bytes if Ed25519) 8. 00 = single byte values 00..ff 9. value = balance quantity value as 8 byte big endian (uint64) 10. *others* = byte values of various length

Blocks:

B ⧺ BN               - block store
                       data: header ⧺ (concat transactions)
2 ⧺ BN               - block Argon2 hashes
                       data: hash of block
H ⧺ BN               - current block currencies
                       data: map(currency → currency address)
I ⧺ txId             - current block owner transaction index
                       data: BN

Transactions:

T ⧺ txId             - confirmed transactions
                       data: BN ⧺ packed transaction data

Assets:

A ⧺ asset id         - confirmed asset identifier
                       data: BN ⧺ packed asset data

Ownership:

N ⧺ owner            - next count value to use for appending to owned items
                       data: count
L ⧺ owner ⧺ count    - list of owned items
                       data: txId
D ⧺ owner ⧺ txId     - position in list of owned items, for delete after transfer
                       data: count
P ⧺ txId             - owner data (00=asset, 01=block, 02=share) head of provenance chain
                       data: 00 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ asset id
                       data: 01 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ owned BN
                       data: 02 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ asset id

Bitmark Shares (txId ≡ share id)

F ⧺ txId             - share total value (constant)
                       data: value ⧺ txId
Q ⧺ owner ⧺ txId     - current balance quantity of shares (ShareId) for each owner (deleted if value becomes zero)
                       data: value

Testing:

Z ⧺ key              - testing data

Index

Constants

View Source
const (
	ReadOnly  = true
	ReadWrite = false
)

pool access modes

View Source
const (
	ErrEmptyTransaction = "Empty Transaction"
)

Variables

View Source
var Pool pools

Pool - the set of exported pools

Functions

func Finalise

func Finalise()

Finalise - close the database connection

func Initialise

func Initialise(database string, readOnly bool) (bool, bool, error)

Initialise - open up the database connection

this must be called before any pool is accessed

func ReindexDone added in v0.8.0

func ReindexDone() error

ReindexDone - called at the end of reindex

Types

type Cache added in v0.11.0

type Cache interface {
	Get(string) ([]byte, bool)
	Set(int, string, []byte)
	Clear()
}

type DataAccess added in v0.11.0

type DataAccess interface {
	Abort()
	Begin() error
	Commit() error
	Delete([]byte)
	DumpTx() []byte
	Get([]byte) ([]byte, error)
	Has([]byte) (bool, error)
	InUse() bool
	Iterator(*ldb_util.Range) iterator.Iterator
	Put([]byte, []byte)
}

for Database

type DataAccessImpl added in v0.11.0

type DataAccessImpl struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*DataAccessImpl) Abort added in v0.11.0

func (d *DataAccessImpl) Abort()

func (*DataAccessImpl) Begin added in v0.11.0

func (d *DataAccessImpl) Begin() error

func (*DataAccessImpl) Commit added in v0.11.0

func (d *DataAccessImpl) Commit() error

func (*DataAccessImpl) Delete added in v0.11.0

func (d *DataAccessImpl) Delete(key []byte)

func (*DataAccessImpl) DumpTx added in v0.11.0

func (d *DataAccessImpl) DumpTx() []byte

func (*DataAccessImpl) Get added in v0.11.0

func (d *DataAccessImpl) Get(key []byte) ([]byte, error)

func (*DataAccessImpl) Has added in v0.11.0

func (d *DataAccessImpl) Has(key []byte) (bool, error)

func (*DataAccessImpl) InUse added in v0.11.0

func (d *DataAccessImpl) InUse() bool

func (*DataAccessImpl) Iterator added in v0.11.0

func (d *DataAccessImpl) Iterator(searchRange *ldb_util.Range) iterator.Iterator

func (*DataAccessImpl) Put added in v0.11.0

func (d *DataAccessImpl) Put(key []byte, value []byte)

type Element

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

Element - a binary data item

type FetchCursor

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

FetchCursor - cursor structure

func (*FetchCursor) Fetch

func (cursor *FetchCursor) Fetch(count int) ([]Element, error)

Fetch - return some elements starting from key

func (*FetchCursor) Map added in v0.8.0

func (cursor *FetchCursor) Map(f func(key []byte, value []byte) error) error

Map - run a function on all elements in the range

func (*FetchCursor) Seek

func (cursor *FetchCursor) Seek(key []byte) *FetchCursor

Seek - move cursor to specific key position

type Handle added in v0.11.0

type Handle interface {
	Begin()
	Commit() error
	Get([]byte) []byte
	GetN([]byte) (uint64, bool)
	GetNB([]byte) (uint64, []byte)
	Has([]byte) bool
	// contains filtered or unexported methods
}

type PoolHandle

type PoolHandle struct {
	Handle
	// contains filtered or unexported fields
}

PoolHandle - the structure of a pool handle

func (*PoolHandle) Begin added in v0.11.0

func (p *PoolHandle) Begin()

func (*PoolHandle) Commit added in v0.11.0

func (p *PoolHandle) Commit() error

func (*PoolHandle) Get

func (p *PoolHandle) Get(key []byte) []byte

Get - read a value for a given key

this returns the actual element - copy the result if it must be preserved

func (*PoolHandle) GetN added in v0.8.0

func (p *PoolHandle) GetN(key []byte) (uint64, bool)

GetN - read a record and decode first 8 bytes as big endian uint64

second parameter is false if record was not found panics if not 8 (or more) bytes in the record

func (*PoolHandle) GetNB added in v0.8.0

func (p *PoolHandle) GetNB(key []byte) (uint64, []byte)

GetNB - read a record and decode first 8 bytes as big endian uint64 and return the rest of the record as byte slice

second parameter is nil if record was not found panics if not 9 (or more) bytes in the record this returns the actual element in the second parameter - copy the result if it must be preserved

func (*PoolHandle) Has

func (p *PoolHandle) Has(key []byte) bool

Has - Check if a key exists

func (*PoolHandle) LastElement

func (p *PoolHandle) LastElement() (Element, bool)

LastElement - get the last element in a pool

func (*PoolHandle) NewFetchCursor

func (p *PoolHandle) NewFetchCursor() *FetchCursor

NewFetchCursor - initialise a cursor to the start of a key range

type PoolNB added in v0.8.0

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

PoolNB - handle for a storage pool

func (*PoolNB) Begin added in v0.11.0

func (p *PoolNB) Begin()

func (*PoolNB) Commit added in v0.11.0

func (p *PoolNB) Commit() error

func (*PoolNB) Get added in v0.11.0

func (p *PoolNB) Get(key []byte) []byte

for interface

func (*PoolNB) GetN added in v0.11.0

func (p *PoolNB) GetN(key []byte) (uint64, bool)

for interface only

func (*PoolNB) GetNB added in v0.8.0

func (p *PoolNB) GetNB(key []byte) (uint64, []byte)

GetNB - read a record and decode first 8 bytes as big endian uint64 and return the rest of the record as byte slice

second parameter is nil if record was not found panics if not 9 (or more) bytes in the record this returns the actual element in the second parameter - copy the result if it must be preserved

func (*PoolNB) Has added in v0.8.0

func (p *PoolNB) Has(key []byte) bool

Has - Check if a key exists

func (*PoolNB) NewFetchCursor added in v0.8.0

func (p *PoolNB) NewFetchCursor() *FetchCursor

NewFetchCursor - initialise a cursor to the start of a key range

type Transaction added in v0.11.0

type Transaction interface {
	Abort()
	Begin() error
	Commit() error
	Delete(Handle, []byte)
	Get(Handle, []byte) []byte
	GetN(Handle, []byte) (uint64, bool)
	GetNB(Handle, []byte) (uint64, []byte)
	Has(Handle, []byte) bool
	InUse() bool
	Put(Handle, []byte, []byte, []byte)
	PutN(Handle, []byte, uint64)
}

Transaction RDBS transaction

func NewDBTransaction added in v0.11.0

func NewDBTransaction() (Transaction, error)

type TransactionImpl added in v0.11.0

type TransactionImpl struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TransactionImpl) Abort added in v0.11.0

func (t *TransactionImpl) Abort()

func (*TransactionImpl) Begin added in v0.11.0

func (t *TransactionImpl) Begin() error

func (*TransactionImpl) Commit added in v0.11.0

func (t *TransactionImpl) Commit() error

func (*TransactionImpl) Delete added in v0.11.0

func (t *TransactionImpl) Delete(h Handle, key []byte)

func (*TransactionImpl) Get added in v0.11.0

func (t *TransactionImpl) Get(h Handle, key []byte) []byte

func (*TransactionImpl) GetN added in v0.11.0

func (t *TransactionImpl) GetN(h Handle, key []byte) (uint64, bool)

func (*TransactionImpl) GetNB added in v0.11.0

func (t *TransactionImpl) GetNB(h Handle, key []byte) (uint64, []byte)

func (*TransactionImpl) Has added in v0.11.0

func (t *TransactionImpl) Has(h Handle, key []byte) bool

func (*TransactionImpl) InUse added in v0.11.0

func (t *TransactionImpl) InUse() bool

func (*TransactionImpl) Put added in v0.11.0

func (t *TransactionImpl) Put(
	h Handle,
	key []byte,
	value []byte,
	additional []byte,
)

func (*TransactionImpl) PutN added in v0.11.0

func (t *TransactionImpl) PutN(h Handle, key []byte, value uint64)

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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