types

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 0 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIndexChanID added in v0.2.0

func GetIndexChanID(b byte) int

func GetShardID added in v0.2.0

func GetShardID(bz []byte) int

func LimitRange added in v0.2.0

func LimitRange(b byte) byte

Types

type Batch

type Batch interface {
	SetDeleter
	Write()
	WriteSync()
	Close()
}

Batch Close must be called when the program no longer needs the object.

type DB

type DB interface {

	// Get returns nil iff key doesn't exist.
	// A nil key is interpreted as an empty byteslice.
	// CONTRACT: key, value readonly []byte
	Get([]byte) []byte

	// Has checks if a key exists.
	// A nil key is interpreted as an empty byteslice.
	// CONTRACT: key, value readonly []byte
	Has(key []byte) bool

	// Set sets the key.
	// A nil key is interpreted as an empty byteslice.
	// CONTRACT: key, value readonly []byte
	Set([]byte, []byte)
	SetSync([]byte, []byte)

	// Delete deletes the key.
	// A nil key is interpreted as an empty byteslice.
	// CONTRACT: key readonly []byte
	Delete([]byte)
	DeleteSync([]byte)

	// Iterate over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// A nil start is interpreted as an empty byteslice.
	// If end is nil, iterates up to the last item (inclusive).
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// CONTRACT: start, end readonly []byte
	Iterator(start, end []byte) Iterator

	// Iterate over a domain of keys in descending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// If start is nil, iterates up to the first/least item (inclusive).
	// If end is nil, iterates from the last/greatest item (inclusive).
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// CONTRACT: start, end readonly []byte
	ReverseIterator(start, end []byte) Iterator

	// Closes the connection.
	Close()

	// Creates a batch for atomic updates.
	NewBatch() Batch

	// For debugging
	Print()

	// Stats returns a map of property values for all keys and the size of the cache.
	Stats() map[string]string
}

DBs are goroutine safe.

type DataTree

type DataTree interface {
	DeactiviateEntry(sn int64) int
	AppendEntry(entry *Entry) int64
	AppendEntryRawBytes(entryBz []byte, sn int64) int64
	ReadEntry(pos int64) *Entry
	ReadEntryBytesForProof(pos int64) []byte
	GetActiveBit(sn int64) bool
	EvictTwig(twigID int64)
	GetActiveEntriesInTwig(twigID int64) chan []byte
	ScanEntries(oldestActiveTwigID int64, outChan chan EntryX)
	ScanEntriesLite(oldestActiveTwigID int64, outChan chan KeyAndPos)
	TwigCanBePruned(twigID int64) bool
	PruneTwigs(startID, endID int64) []byte
	GetFileSizes() (int64, int64)
	EndBlock() [32]byte
	WaitForFlushing()
	DeactivedSNListSize() int
	PrintTree()
	GetProofBytesAndCheck(sn int64, entryBz []byte) ([]byte, error)
	SaveMemToDisk()
	Close()
}

type Entry

type Entry struct {
	Key        []byte
	Value      []byte
	NextKey    []byte
	Height     int64
	LastHeight int64
	SerialNum  int64
}

type EntryHandler

type EntryHandler func(pos int64, entry *Entry, deactivedSNList []int64)

type EntryX

type EntryX struct {
	Entry           *Entry
	Pos             int64
	DeactivedSNList []int64
}

type HotEntry

type HotEntry struct {
	EntryPtr        *Entry
	Operation       OperationOnEntry
	IsModified      bool
	IsTouchedByNext bool
}

type IndexTree

type IndexTree interface {
	Init(repFn func([]byte)) error
	SetDuringInit(b bool)
	ActiveCount() int
	BeginWrite(height int64)
	EndWrite()
	Iterator(start, end []byte) IteratorUI64
	ReverseIterator(start, end []byte) IteratorUI64
	Get(k []byte) (int64, bool)
	GetAtHeight(k []byte, height uint64) (int64, bool)
	Set(k []byte, v int64)
	Delete(k []byte)
	Close()
}

type Iterator

type Iterator interface {

	// The start & end (exclusive) limits to iterate over.
	// If end < start, then the Iterator goes in reverse order.
	//
	// A domain of ([]byte{12, 13}, []byte{12, 14}) will iterate
	// over anything with the prefix []byte{12, 13}.
	//
	// The smallest key is the empty byte array []byte{} - see BeginningKey().
	// The largest key is the nil byte array []byte(nil) - see EndingKey().
	// CONTRACT: start, end readonly []byte
	Domain() (start []byte, end []byte)

	// Valid returns whether the current position is valid.
	// Once invalid, an Iterator is forever invalid.
	Valid() bool

	// Next moves the iterator to the next sequential key in the database, as
	// defined by order of iteration.
	//
	// If Valid returns false, this method will panic.
	Next()

	// Key returns the key of the cursor.
	// If Valid returns false, this method will panic.
	// CONTRACT: key readonly []byte
	Key() (key []byte)

	// Value returns the value of the cursor.
	// If Valid returns false, this method will panic.
	// CONTRACT: value readonly []byte
	Value() (value []byte)

	// Close releases the Iterator.
	Close()
}

Usage:

var itr Iterator = ... defer itr.Close()

for ; itr.Valid(); itr.Next() {
	k, v := itr.Key(); itr.Value()
	// ...
}

type IteratorUI64

type IteratorUI64 interface {
	Domain() (start []byte, end []byte)
	Valid() bool
	Next()
	Key() []byte
	Value() int64
	Close()
}

type KeyAndPos

type KeyAndPos struct {
	Key       []byte
	Pos       int64
	SerialNum int64
}

type MetaDB

type MetaDB interface {
	Commit()
	ReloadFromKVDB()
	PrintInfo()

	SetCurrHeight(h int64)
	GetCurrHeight() int64

	SetTwigMtFileSize(shardID int, size int64)
	GetTwigMtFileSize(shardID int) int64

	SetEntryFileSize(shardID int, size int64)
	GetEntryFileSize(shardID int) int64

	GetTwigHeight(shardID int, twigID int64) int64
	DeleteTwigHeight(shardID int, twigID int64)

	SetLastPrunedTwig(shardID int, twigID int64)
	GetLastPrunedTwig(shardID int) int64

	SetEdgeNodes(shardID int, bz []byte)
	GetEdgeNodes(shardID int) []byte

	// MaxSerialNum is the maximum serial num among all the entries
	GetMaxSerialNum(shardID int) int64
	IncrMaxSerialNum(shardID int) // It should call setTwigHeight(twigID int64, height int64)
	GetYoungestTwigID(shardID int) int64

	SetRootHash(shardID int, h [32]byte)
	GetRootHash(shardID int) [32]byte

	// the ID of the oldest active twig, increased by ReapOldestActiveTwig
	GetOldestActiveTwigID(shardID int) int64
	IncrOldestActiveTwigID(shardID int)

	Init()
	Close()
}

type OperationOnEntry

type OperationOnEntry int32
const (
	OpNone OperationOnEntry = iota
	OpDelete
	OpInsertOrChange

	ShardCount     = 8
	IndexChanCount = 10
)

type SetDeleter

type SetDeleter interface {
	Set(key, value []byte) // CONTRACT: key, value readonly []byte
	Delete(key []byte)     // CONTRACT: key readonly []byte
}

Jump to

Keyboard shortcuts

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