rwset

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash []byte

Hash represents bytes of a hash

type KVRead

type KVRead struct {
	Key     string
	Version *version.Height
}

KVRead - a tuple of key and its version at the time of transaction simulation

func NewKVRead

func NewKVRead(key string, version *version.Height) *KVRead

NewKVRead constructs a new `KVRead`

func (*KVRead) Marshal

func (r *KVRead) Marshal(buf *proto.Buffer) error

Marshal serializes a `KVRead`

func (*KVRead) String

func (r *KVRead) String() string

String prints a `KVRead`

func (*KVRead) Unmarshal

func (r *KVRead) Unmarshal(buf *proto.Buffer) error

Unmarshal deserializes a `KVRead`

type KVWrite

type KVWrite struct {
	Key      string
	IsDelete bool
	Value    []byte
}

KVWrite - a tuple of key and it's value that a transaction wants to set during simulation. In addition, IsDelete is set to true iff the operation performed on the key is a delete operation

func NewKVWrite

func NewKVWrite(key string, value []byte) *KVWrite

NewKVWrite constructs a new `KVWrite`

func (*KVWrite) Marshal

func (w *KVWrite) Marshal(buf *proto.Buffer) error

Marshal serializes a `KVWrite`

func (*KVWrite) SetValue

func (w *KVWrite) SetValue(value []byte)

SetValue sets the new value for the key

func (*KVWrite) String

func (w *KVWrite) String() string

String prints a `KVWrite`

func (*KVWrite) Unmarshal

func (w *KVWrite) Unmarshal(buf *proto.Buffer) error

Unmarshal deserializes a `KVWrite`

type MerkleSummary

type MerkleSummary struct {
	MaxDegree      int
	MaxLevel       MerkleTreeLevel
	MaxLevelHashes []Hash
}

MerkleSummary encloses the summary of the merkle tree that consists of the hashes of the results of a range query. This allows to reduce the size of RWSet in the presence of range query results by storing certain hashes instead of actual results.

func (*MerkleSummary) Equal

func (ms *MerkleSummary) Equal(anotherMS *MerkleSummary) bool

Equal verifies whether the give MerkleSummary is equals to this

func (*MerkleSummary) Marshal

func (ms *MerkleSummary) Marshal(buf *proto.Buffer) error

Marshal serializes a `QueryResultHash`

func (*MerkleSummary) Unmarshal

func (ms *MerkleSummary) Unmarshal(buf *proto.Buffer) error

Unmarshal deserializes a `QueryResultHash`

type MerkleTreeLevel

type MerkleTreeLevel int

MerkleTreeLevel used for representing a level of the merkle tree

type NsReadWriteSet

type NsReadWriteSet struct {
	NameSpace        string
	Reads            []*KVRead
	Writes           []*KVWrite
	RangeQueriesInfo []*RangeQueryInfo
}

NsReadWriteSet - a collection of all the reads and writes that belong to a common namespace

func (*NsReadWriteSet) Marshal

func (nsRW *NsReadWriteSet) Marshal(buf *proto.Buffer) error

Marshal serializes a `NsReadWriteSet`

func (*NsReadWriteSet) String

func (nsRW *NsReadWriteSet) String() string

String prints a `NsReadWriteSet`

func (*NsReadWriteSet) Unmarshal

func (nsRW *NsReadWriteSet) Unmarshal(buf *proto.Buffer) error

Unmarshal deserializes a `NsReadWriteSet`

type RWSet

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

RWSet maintains the read-write set

func NewRWSet

func NewRWSet() *RWSet

NewRWSet constructs a new instance of RWSet

func (*RWSet) AddToRangeQuerySet

func (rws *RWSet) AddToRangeQuerySet(ns string, rqi *RangeQueryInfo)

AddToRangeQuerySet adds a range query info for performing phantom read validation

func (*RWSet) AddToReadSet

func (rws *RWSet) AddToReadSet(ns string, key string, version *version.Height)

AddToReadSet adds a key and corresponding version to the read-set

func (*RWSet) AddToWriteSet

func (rws *RWSet) AddToWriteSet(ns string, key string, value []byte)

AddToWriteSet adds a key and value to the write-set

func (*RWSet) GetFromWriteSet

func (rws *RWSet) GetFromWriteSet(ns string, key string) ([]byte, bool)

GetFromWriteSet return the value of a key from the write-set

func (*RWSet) GetTxReadWriteSet

func (rws *RWSet) GetTxReadWriteSet() *TxReadWriteSet

GetTxReadWriteSet returns the read-write set in the form that can be serialized

type RangeQueryInfo

type RangeQueryInfo struct {
	StartKey     string
	EndKey       string
	ItrExhausted bool
	Results      []*KVRead
	ResultHash   *MerkleSummary
}

RangeQueryInfo captures a range query executed by a transaction and the tuples <key,version> that are read by the transaction This it to be used to perform a phantom-read validation during commit

func (*RangeQueryInfo) Marshal

func (rqi *RangeQueryInfo) Marshal(buf *proto.Buffer) error

Marshal serializes a `RangeQueryInfo`

func (*RangeQueryInfo) String

func (rqi *RangeQueryInfo) String() string

String prints a range query info

func (*RangeQueryInfo) Unmarshal

func (rqi *RangeQueryInfo) Unmarshal(buf *proto.Buffer) error

Unmarshal deserializes a `RangeQueryInfo`

type RangeQueryResultsHelper

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

RangeQueryResultsHelper helps preparing range query results for phantom items detection during validation. The results are expected to be fed as they are being iterated over. If the `hashingEnabled` is set to true, a merkle tree is built of the hashes over the results. The merkle tree helps reducing the size of the RWSet which otherwise would need to store all the raw KVReads

The mental model of the tree can be described as below: All the results are treated as leaf nodes (level 0) of the tree. Next up level of the tree is built by collecting 'maxDegree + 1' items from the previous level and hashing the entire collection. Further upper levels of the tree are built in similar manner however the only difference is that unlike level-0 (where collection consists of raw KVReads), collection at level 1 and above, consists of the hashes (of the collection of previous level). This is repeated until we reach at a level where we are left with the number of items less than or equals to `maxDegree`. In the last collection, the number of items can be less than 'maxDegree' (except if this is the only collection at the given level).

As a result, if the number of total input results are less than or equals to 'maxDegree', no hashing is performed at all. And the final output of the computation is either the collection of raw results (if less that or equals to 'maxDegree') or a collection of hashes (that or equals to 'maxDegree') at some level in the tree.

`AddResult` function should be invoke to supply the next result and at the end `Done` function should be invoked. The `Done` function does the final processing and returns the final output

func NewRangeQueryResultsHelper

func NewRangeQueryResultsHelper(enableHashing bool, maxDegree int) (*RangeQueryResultsHelper, error)

NewRangeQueryResultsHelper constructs a RangeQueryResultsHelper

func (*RangeQueryResultsHelper) AddResult

func (helper *RangeQueryResultsHelper) AddResult(kvRead *KVRead) error

AddResult adds a new query result for processing. Put the result into the list of pending results. If the number of pending results exceeds `maxDegree`, consume the results for incrementally update the merkle tree

func (*RangeQueryResultsHelper) Done

func (helper *RangeQueryResultsHelper) Done() ([]*KVRead, *MerkleSummary, error)

Done processes any pending results if needed This returns the final pending results (i.e., []*KVRead) and hashes of the results (i.e., *MerkleSummary) Only one of these two will be non-nil (except when no results are ever added). `MerkleSummary` will be nil if and only if either `enableHashing` is set to false or the number of total results are less than `maxDegree`

func (*RangeQueryResultsHelper) GetMerkleSummary

func (helper *RangeQueryResultsHelper) GetMerkleSummary() *MerkleSummary

GetMerkleSummary return the current state of the MerkleSummary This intermediate state of the merkle tree helps during validation to detect a mismatch early on. That helps by not requiring to build the complete merkle tree during validation if there is a mismatch in early portion of the result-set.

type TxReadWriteSet

type TxReadWriteSet struct {
	NsRWs []*NsReadWriteSet
}

TxReadWriteSet - a collection of all the reads and writes collected as a result of a transaction simulation

func (*TxReadWriteSet) Marshal

func (txRW *TxReadWriteSet) Marshal() ([]byte, error)

Marshal serializes a `TxReadWriteSet`

func (*TxReadWriteSet) String

func (txRW *TxReadWriteSet) String() string

String prints a `TxReadWriteSet`

func (*TxReadWriteSet) Unmarshal

func (txRW *TxReadWriteSet) Unmarshal(b []byte) error

Unmarshal deserializes a `TxReadWriteSet`

Jump to

Keyboard shortcuts

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