tstate

package
v0.0.0-...-3f8a4bd Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotSpecified = errors.New("key not specified")

Functions

This section is empty.

Types

type Database

type Database interface {
	GetValue(ctx context.Context, key []byte) (value []byte, err error)
	Insert(ctx context.Context, key []byte, value []byte) error
	Remove(ctx context.Context, key []byte) error
}

type TState

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

TState defines a struct for storing temporary state.

func New

func New(storageSize int, changedSize int) *TState

New returns a new instance of TState. Initializes the storage and changedKeys maps to have an initial size of [storageSize] and [changedSize] respectively.

func (*TState) FetchAndSetScope

func (ts *TState) FetchAndSetScope(ctx context.Context, db Database, keys [][]byte) error

FetchAndSetScope updates ts to include the [db] values associated with [keys]. FetchAndSetScope then sets the scope of ts to [keys]. If a key exists in ts.fetchCache set the key's value to the value from cache.

func (*TState) GetValue

func (ts *TState) GetValue(ctx context.Context, key []byte) ([]byte, error)

GetValue returns the value associated from tempStorage with the associated [key]. If [key] does not exist in readScope or if it is not found in storage an error is returned.

func (*TState) Insert

func (ts *TState) Insert(ctx context.Context, key []byte, value []byte) error

Insert sets or updates ts.storage[key] to equal {value, false}.

func (*TState) OpIndex

func (ts *TState) OpIndex() int

OpIndex returns the number of operations done on ts.

func (*TState) Remove

func (ts *TState) Remove(ctx context.Context, key []byte) error

Renove deletes a key-value pair from ts.storage.

func (*TState) Rollback

func (ts *TState) Rollback(_ context.Context, restorePoint int)

Rollback restores the TState to before the ts.op[restorePoint] operation.

func (*TState) SetScope

func (ts *TState) SetScope(_ context.Context, keys [][]byte)

SetReadScope sets the readscope of ts to [keys].

func (*TState) SetStorage

func (ts *TState) SetStorage(_ context.Context, key []byte, value []byte)

SetStorage sets ts.storage[key] = {value, true}. Does not add to storage if ts already stores a mapping with key, or that key was previously modified.

func (*TState) WriteChanges

func (ts *TState) WriteChanges(
	ctx context.Context,
	db Database,
	t trace.Tracer,
) error

WriteChanges updates [db] to reflect changes in ts. Insert to [db] if key was added, or remove key if otherwise.

Jump to

Keyboard shortcuts

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