Help us shape the future of Go! Take the 2026 Go Developer Survey

world

package
v0.57.30 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

README

World

Key/value store combined with a Graph database.

Introduction

World objects can point to any Block structure, including: Key/value stores, MySQL DBs, Git repos, Hydra Volumes, Unix filesystems, and other Worlds.

The World has an attached changelog which can be used to efficiently wait for relevant changes to the watched objects. The ControlLoop utility implements a loop which waits for changes to an object before calling a callback function.

World is a series of interfaces with multiple available implementations, but is primarily implemented as a forkable Block graph with Protobuf objects. Other implementations might be read-only and/or watch real-world object states.

Documentation

Index

Constants

View Source
const ObjectBodiesBatchByteBudget = 8 << 20

ObjectBodiesBatchByteBudget is the encoded-size budget shared by body batch requests and responses. One page must fit in a single starpc frame, which is capped at 10,000,000 bytes, with room for the packet envelope. A body larger than the budget is reported as ObjectBodyTooLargeError.

View Source
const TypeObjectKeyPrefix = "types/"

TypeObjectKeyPrefix prefixes the key of every type object.

View Source
const TypePredicate = "type"

TypePredicate is the predicate linking an object to its type object, whose key is TypeObjectKeyPrefix followed by the type ID.

Variables

View Source
var (
	// ErrHistoryUnavailable is returned if the world storage implementation
	// does not implement looking up the world state at a given seqno.
	ErrHistoryUnavailable = errors.New("world history not available")
	// ErrWorldStorageUnavailable is returned if world storage access is unavailable.
	ErrWorldStorageUnavailable = errors.New("world storage not available")
	// ErrStateNotFound is returned if the state lookup returned not found.
	ErrStateNotFound = errors.New("world state not found")
	// ErrObjectExists returns if the object exists already.
	ErrObjectExists = errors.New("object already exists")
	// ErrObjectNotFound is returned if an object was not found.
	// Note: this is only returned in error conditions.
	// Most lookup functions return value, ok, error.
	ErrObjectNotFound = errors.New("object not found")
	// ErrQuadNotFound is returned if a graph quad was not found.
	// Note: this is only returned in error conditions.
	// Most lookup functions return value, ok, error.
	ErrQuadNotFound = graph.ErrQuadNotExist
	// ErrEmptyObjectKey returns if the object key was empty.
	ErrEmptyObjectKey = errors.New("object key cannot be empty")
	// ErrUnhandledOp is returned if the operation type was unhandled.
	ErrUnhandledOp = errors.New("operation type was not handled")
	// ErrEmptyOp is returned if the operation type ID or operation object are empty.
	ErrEmptyOp = errors.New("operation type id and body cannot be empty")
	// ErrEmptyChange is returned if the changelog entry was empty.
	ErrEmptyChange = errors.New("changelog entry cannot be empty")
	// ErrEmptyEngineID is returned if the engine id was empty.
	ErrEmptyEngineID = errors.New("engine id cannot be empty")
	// ErrUnexpectedChangeType is returned when a change with an unexpected
	// ChangeType is encountered. Typically wrapped with name of type.
	ErrUnexpectedChangeType = errors.New("change type was unexpected")
	// ErrUnexpectedRev is returned if the revision field was unexpected.
	ErrUnexpectedRev = errors.New("object rev unexpected")
	// ErrGraphPathResultLimit is returned if a graph path query has no result limit.
	ErrGraphPathResultLimit = errors.New("graph path result limit must be non-zero")
	// ErrGraphPathStepLimit is returned if a graph path step has no per-key limit.
	ErrGraphPathStepLimit = errors.New("graph path step limit must be non-zero")
	// ErrGraphPathPredicate is returned if a graph path step has no predicate.
	ErrGraphPathPredicate = errors.New("graph path step predicate cannot be empty")
	// ErrGraphPathDirection is returned if a graph path step has no valid direction.
	ErrGraphPathDirection = errors.New("graph path step direction is invalid")
	// ErrGraphEdgeBucketLimit is returned if a grouped edge query has no per-origin limit.
	ErrGraphEdgeBucketLimit = errors.New("graph edge bucket limit must be non-zero")
	// ErrGraphEdgeBucketDirection is returned if a grouped edge query direction is invalid.
	ErrGraphEdgeBucketDirection = errors.New("graph edge bucket direction is invalid")

	// ErrNilQuad is returned if the quad is nil and cannot be.
	ErrNilQuad = errors.New("quad cannot be nil")
	// ErrEmptyQuadSubject is returned if the subject field was empty.
	ErrEmptyQuadSubject = errors.New("quad subject cannot be empty")
	// ErrEmptyQuadPred is returned if the predicate field was empty.
	ErrEmptyQuadPred = errors.New("quad predicate cannot be empty")
	// ErrEmptyQuadObject is returned if the object field was empty.
	ErrEmptyQuadObject = errors.New("quad object cannot be empty")
	// ErrQuadSubjectNotIRI indicates a quad subject must be an IRI.
	ErrQuadSubjectNotIRI = errors.New("quad subject must be an iri")
	// ErrQuadObjectNotIRI indicates a quad object must be an IRI.
	ErrQuadObjectNotIRI = errors.New("quad object must be an iri")
	// ErrNotIRI is returned if the format <object-key> is not used for the graph key.
	ErrNotIRI = errors.New("quad value must be valid object IRIs")
)
View Source
var ErrPurgeUnsupported = errors.New("world state cannot purge objects")

ErrPurgeUnsupported is returned when the WorldState cannot purge objects.

View Source
var LookupOpControllerVersion = controller.MustParseVersion("0.0.1")

LookupOpControllerVersion is the version of the LookupOpController.

Functions

func AccessEngine

func AccessEngine(ctx context.Context, eng Engine, cb func(ctx context.Context, eng Engine) error) error

AccessEngine calls cb with the engine that serves eng. When eng resolves its engine on demand, as a BusEngine does, cb runs with the current engine under a context canceled when that engine is replaced, and runs again with its successor.

func AccessObject

func AccessObject(
	ctx context.Context,
	access AccessWorldStateFunc,
	ref *bucket.ObjectRef,
	cb AccessObjectCb,
) (*bucket.ObjectRef, error)

AccessObject is a utility for AccessWorldState to access or create an ObjectRef. Ref can be nil to indicate creating a new object. The block transaction is written upon completion and updated ObjectRef returned.

Returns the updated object ref and any error.

func AccessObjectState

func AccessObjectState(
	ctx context.Context,
	obj ObjectState,
	updateWorld bool,
	cb AccessObjectCb,
) (*bucket.ObjectRef, bool, error)

AccessObjectState applies cb to the object's current root and, when updateWorld is set and the root changed, publishes the result with SetRootRef. An object from an engine WorldState publishes only onto the root cb read: when another writer changed the object first, cb runs again against the new root, so cb must derive every effect from the cursor it is given. Returns the updated object ref, whether it changed, and any error.

func AccessWorldObject

func AccessWorldObject(
	ctx context.Context,
	ws WorldState,
	objKey string,
	updateWorld bool,
	cb AccessObjectCb,
) (*bucket.ObjectRef, bool, error)

AccessWorldObject attempts to look up an object in the world state. If the object did not exist, bcs will be empty; with updateWorld the object will be created, otherwise the build is discarded. If updateWorld=true, and the result is different, will SetRootRef with change. Note: if updateWorld=true but ws is read-only, sets updateWorld=false. Returns the modified object ref, if it was dirty, and any error.

func AddViewReads

func AddViewReads(ctx context.Context, set *ReadSet, rerunAt time.Time)

AddViewReads adds a finished read set to the running WatchView or SendViews evaluation, so the view reruns when a change touches set, and asks for a rerun at rerunAt like RerunAt. Use it for a value computed once on its own tracked transaction and shared by many views. The caller must not add reads to set afterward. It does nothing outside an evaluation. Call it before the evaluation returns.

func ApplyGraphDeltas

func ApplyGraphDeltas(ctx context.Context, ws WorldStateGraph, deltas []graph.Delta) error

ApplyGraphDeltas applies a set of graph deltas to a WorldStateGraph.

func ApplyWorldObjectOp

func ApplyWorldObjectOp(
	ctx context.Context,
	le *logrus.Entry,
	op Operation,
	objectHandle ObjectState,
	sender peer.ID,
) (sysErr bool, err error)

ApplyWorldObjectOp applies op to an object handle. It returns false, ErrUnhandledOp when op is not an ObjectOperation.

func AssertObjectRev

func AssertObjectRev(ctx context.Context, obj ObjectState, expected uint64) error

AssertObjectRev asserts that an object is at a given rev.

func CheckQuadExists

func CheckQuadExists(ctx context.Context, h CayleyHandle, gq quad.Quad) (bool, error)

CheckQuadExists checks if the quad exists on the graph handle.

func CollectFilteredFullQuadsBatch added in v0.51.7

func CollectFilteredFullQuadsBatch(ctx context.Context, h CayleyHandle, filters []quad.Quad, limitPerFilter uint32) ([][]quad.Quad, error)

CollectFilteredFullQuadsBatch collects full quads for a batch of concrete quad filters.

func CollectGraphPathStepWithKeys added in v0.51.6

func CollectGraphPathStepWithKeys(
	ctx context.Context,
	ws WorldStateGraph,
	entityKeys []string,
	direction GraphPathDirection,
	predicate string,
	limit uint32,
) ([]string, error)

CollectGraphPathStepWithKeys collects object keys after one bounded predicate step.

func CollectGraphPathWithKeys added in v0.51.6

func CollectGraphPathWithKeys(ctx context.Context, ws WorldStateGraph, query *GraphPathQuery) ([]string, error)

CollectGraphPathWithKeys collects object keys for a bounded graph traversal.

func CollectPathWithKeys

func CollectPathWithKeys(
	ctx context.Context,
	ws WorldStateGraph,
	entityKeys []string,
	pathCb func(p *cayley.Path) (*cayley.Path, error),
) ([]string, error)

CollectPathWithKeys collects the object keys for a given path starting at entityKeys.

If the entityKeys list is empty, returns nil, nil.

func ExecTransaction

func ExecTransaction(
	ctx context.Context,
	eng Engine,
	write bool,
	cb func(ctx context.Context, wtx WorldState) error,
) error

ExecTransaction runs cb in a transaction and commits it when write is set and cb succeeds. When another writer moves the World head or the storage snapshot becomes invalid, it replays cb in a fresh transaction, up to maxEngineWorldStateTries more times. cb must be safe to replay: it must create or reset its per-attempt state and perform no external effects.

func FilterIterateQuads

func FilterIterateQuads(ctx context.Context, h CayleyHandle, gq quad.Quad, cb func(q quad.Quad) error) error

FilterIterateQuads iterates over quads matching the input quad. Empty fields are ignored.

func GetObjectModSeqno

func GetObjectModSeqno(ctx context.Context, obj ObjectState) (uint64, error)

GetObjectModSeqno returns the ModSeqno obj reports, or zero when obj does not implement ObjectModSeqnoReader.

func GetObjectRev

func GetObjectRev(ctx context.Context, ws WorldState, key string) (uint64, bool, error)

GetObjectRev returns the revision of the object at key and whether it exists.

func GraphEnsureIsIRI

func GraphEnsureIsIRI(val string) (quad.IRI, error)

GraphEnsureIsIRI confirms that a string is an IRI.

func GraphQuadStringToCayleyValue

func GraphQuadStringToCayleyValue(s string) quad.Value

GraphQuadStringToCayleyValue converts a graph quad string to a quad.Value.

func GraphQuadToCayleyQuad

func GraphQuadToCayleyQuad(q GraphQuad, check bool) (quad.Quad, error)

GraphQuadToCayleyQuad converts a graph quad to a cayley quad.

func GraphQuadToQuad

func GraphQuadToQuad(gq GraphQuad) *bquad.Quad

GraphQuadToQuad constructs a new Quad object.

func GraphValueToKey

func GraphValueToKey(gv string) (string, error)

GraphValueToKey converts a graph value string to an object key. Use with GraphQuadStringToCayleyValue.

func GraphValueToString

func GraphValueToString(gv quad.Value) string

GraphValueToString calls String() on the GraphValue if it's not nil.

func IterateFilteredFullQuads

func IterateFilteredFullQuads(ctx context.Context, h CayleyHandle, filter quad.Quad, cb func(q quad.Quad) error) error

IterateFilteredFullQuads iterates over full quads matching a concrete quad filter.

func IterateFullQuads

func IterateFullQuads(ctx context.Context, h CayleyHandle, sh shape.Shape, cb func(q quad.Quad) error) error

IterateFullQuads iterates over the full quads matched by a shape.

func IteratePathWithKeys

func IteratePathWithKeys(
	ctx context.Context,
	ws WorldStateGraph,
	entityKeys []string,
	pathCb func(p *cayley.Path) (*cayley.Path, error),
	valueCb func(objKey string) (ctnu bool, err error),
) error

IteratePathWithKeys starts & iterates a path from the given object keys.

func KeyToGraphValue

func KeyToGraphValue(key string) quad.Value

KeyToGraphValue is the string representation of the key for a graph IRI.

func LookupGraphObjectKey

func LookupGraphObjectKey(ctx context.Context, ws WorldStateGraph, subject, pred string) (string, bool, error)

LookupGraphObjectKey returns the object key targeted by the first graph quad matching (subject, pred, *). It reports false when no such edge is set.

func LookupObjectBody added in v0.52.0

func LookupObjectBody[T any, PT block.Ptr[T]](
	ctx context.Context,
	ws WorldState,
	objKey string,
) (out PT, err error)

LookupObjectBody looks up and unmarshals an object without returning the object-state handle.

func LookupObjectBodyBytes added in v0.57.0

func LookupObjectBodyBytes(
	ctx context.Context,
	ws WorldState,
	objKey string,
) ([]byte, bool, error)

LookupObjectBodyBytes looks up the transformed root body for an object. It returns nil, false, nil when the object does not exist.

func LookupObjectRef

func LookupObjectRef[T any, PT block.Ptr[T]](
	ctx context.Context,
	access AccessWorldStateFunc,
	ref *bucket.ObjectRef,
) (out PT, err error)

LookupObjectRef looks up & unmarshals an object ref from the world.

func LookupRootRef

func LookupRootRef(ctx context.Context, eng Engine, key string) (*bucket.ObjectRef, uint64, error)

LookupRootRef gets an object and returns its root reference and rev.

If not found, returns nil, 0, nil.

func MatchGraphQuad

func MatchGraphQuad(filter, q GraphQuad) bool

MatchGraphQuad checks whether q, spelled as the graph stores it, matches every non-empty field of filter. The filter is spelled as for LookupGraphQuads, so it may name a predicate as a bare string.

func NewEngineObjectIterator

func NewEngineObjectIterator(
	ctx context.Context,
	e Engine,
	prefix string,
	reversed bool,
) *engineObjectIterator

NewEngineObjectIterator constructs a new engine object iterator.

func NewLookupWorldOpResolver

func NewLookupWorldOpResolver(lookupOp LookupOp) directive.Resolver

NewLookupWorldOpResolver constructs a new resolver with a static lookup func list.

func OperationOwnerFromContext

func OperationOwnerFromContext(ctx context.Context) bool

OperationOwnerFromContext reports whether the replay authority found the operation's signer to be an owner. It is false when none was recorded.

func OperationPersonFromContext

func OperationPersonFromContext(ctx context.Context) string

OperationPersonFromContext returns the person bound by the replay authority.

func OrderedCommit

func OrderedCommit(ctx context.Context) bool

OrderedCommit reports whether ctx carries WithOrderedCommit.

func PurgeObject

func PurgeObject(ctx context.Context, ws WorldState, key string) (bool, error)

PurgeObject purges the object at key through ws when it is an ObjectPurger.

func QuadEqual

func QuadEqual(q1, q2 quad.Quad) bool

QuadEqual checks if two quads are equal.

func QuadValueToKey

func QuadValueToKey(gv quad.Value) (string, error)

QuadValueToKey converts a graph value to an object key. Use with GraphQuadStringToCayleyValue.

func ReleaseObjectState added in v0.52.0

func ReleaseObjectState(obj ObjectState)

ReleaseObjectState calls Release on obj when the ObjectState implementation has a Release method.

func RerunAt

func RerunAt(ctx context.Context, deadline time.Time)

RerunAt asks the running WatchView or SendViews evaluation to run again at deadline even without a World change. The earliest nonzero deadline wins. It does nothing outside an evaluation. Call it before the evaluation returns.

func SendViews

func SendViews[T View[T]](
	ctx context.Context,
	source WorldWaitSeqno,
	read func(context.Context, WorldState) (T, error),
	send func(T) error,
) error

SendViews sends the first projection and each later unequal projection. It is SendViewsWith with zero options.

func SendViewsWith

func SendViewsWith[T View[T]](
	ctx context.Context,
	source WorldWaitSeqno,
	opts WatchViewOptions,
	read func(context.Context, WorldState) (T, error),
	send func(T) error,
) error

SendViewsWith sends the first projection and each later unequal projection, evaluating like WatchViewWith with opts. source and read follow WatchViewWith's contract, including context-carried transactions and RerunAt. read must return an immutable message; send must not mutate it. Returns when ctx ends or read or send fails.

func ValidateCayleyQuad

func ValidateCayleyQuad(q quad.Quad) error

ValidateCayleyQuad checks a cayley quad for validity.

func ValidateGraphQuad

func ValidateGraphQuad(q GraphQuad) error

ValidateGraphQuad checks a graph quad for validity.

func ValidateOp

func ValidateOp(op Operation) error

ValidateOp validates op when it implements ValidatedOperation.

func WaitObjectChange

func WaitObjectChange(ctx context.Context, ws WorldState, seen ...*ObjectRootRef) error

WaitObjectChange waits until an object differs from the root a reader saw in seen: a later revision, its deletion, or, for an object seen missing, its creation. A view reads seen with GetObjectRootRefsBatch before it reads the objects, so a change after the read ends the wait. An object deleted and created again at its seen revision before the wait begins is not a change to the wait; a caller that waits long after its read compares the roots first. With no objects it waits until ctx ends.

func WaitObjectRev

func WaitObjectRev(ctx context.Context, ws WorldState, key string, rev uint64, ignoreNotFound bool) (uint64, error)

WaitObjectRev waits until the object at key reaches rev on ws and returns its revision. It returns ErrObjectNotFound if the object does not exist, unless ignoreNotFound is set, in which case it waits for the object to appear. An ObjectRevWaiter waits through its watch. Any other WorldState waits on the object's own WaitRev, and rereads a missing object after each World commit.

func WaitObjectRevBySeqno

func WaitObjectRevBySeqno(
	ctx context.Context,
	e Engine,
	key string,
	rev uint64,
	ignoreNotFound bool,
) (uint64, error)

WaitObjectRevBySeqno waits for an object revision by rereading the object after every World revision. Engines without a key-scoped change watch use it; each World commit costs every waiter one read transaction.

func WatchChanges

func WatchChanges(
	ctx context.Context,
	w WorldWaitSeqno,
	afterSeqno uint64,
	cb func(seqno uint64, changes *ChangeSet) error,
) error

WatchChanges calls cb with each seqno of w after afterSeqno and the changes since the previous call. w is an Engine or a WorldState; one that is not a ChangeWatcher reports every advance as an unknown ChangeSet. Returns when ctx is canceled or cb returns an error.

func WatchInterestedChanges

func WatchInterestedChanges(
	ctx context.Context,
	w WorldWaitSeqno,
	afterSeqno uint64,
	interest *ChangeInterest,
	cb func(seqno uint64, changes *ChangeSet) error,
) error

WatchInterestedChanges is WatchTouchingChanges for the changes interest accepts. A World whose change feed indexes its watchers tests interest only on the changes it names; any other World tests it as a ChangeFilter.

func WatchTouchingChanges

func WatchTouchingChanges(
	ctx context.Context,
	w WorldWaitSeqno,
	afterSeqno uint64,
	touches ChangeFilter,
	cb func(seqno uint64, changes *ChangeSet) error,
) error

WatchTouchingChanges is WatchChanges for the changes touches accepts. A World with a change feed tests each change once on the feed and wakes only the watchers it concerns.

func WatchView

func WatchView(ctx context.Context, source WorldWaitSeqno, view func(ctx context.Context, ws WorldState) error) error

WatchView runs view immediately and again when a change touches its reads or its earliest RerunAt deadline arrives. It is WatchViewWith with zero options.

func WatchViewWith

func WatchViewWith(
	ctx context.Context,
	source WorldWaitSeqno,
	opts WatchViewOptions,
	view func(ctx context.Context, ws WorldState) error,
) error

WatchViewWith runs view like WatchView, tuned by opts. source must be an Engine or WorldState; an Engine supplies a live, read-only WorldState. Every evaluation has a fresh read set carried by its context. Transactions opened through a ReadTrackingEngine with that context join the same set, including transactions opened by clients captured by view, and AddViewReads joins a finished set. All transactions must read source's World, and all evaluation work must finish before view returns. Unknown changes can rerun an unchanged projection; use SendViews to suppress equal results. Returns when ctx ends or view or the watch fails.

func WithOperationOwner

func WithOperationOwner(ctx context.Context, owner bool) context.Context

WithOperationOwner records whether the accepted config makes the operation's signer an owner of the shared object, who may moderate content others wrote.

func WithOperationPerson

func WithOperationPerson(ctx context.Context, person string) context.Context

WithOperationPerson binds the accepted config's person to authenticated replay.

func WithOrderedCommit

func WithOrderedCommit(ctx context.Context) context.Context

WithOrderedCommit marks write transactions committed with ctx as allowed to commit ordered: Commit returns once the change is applied and safe against a process crash, and the change becomes durable at the engine's next Sync or its storage's own durability point. Engines without ordered commits ignore the mark and commit in full.

func WithViewReads

func WithViewReads(ctx context.Context, set *ReadSet) (child context.Context, finish func() time.Time)

WithViewReads starts a child evaluation that records into set, for a value computed once and shared by many views. Transactions opened through a ReadTrackingEngine with the returned context, and AddViewReads and RerunAt calls made with it, record into set and the child's deadline instead of the running evaluation; nothing reaches the parent until the caller passes the finished set to AddViewReads. finish joins the sets the child added to set by reference and returns its earliest rerun time, or zero; call it once, after every read made with the context. It works outside a view too.

Types

type AccessObjectCb

type AccessObjectCb func(bcs *block.Cursor) error

AccessObjectCb is a callback to access a block cursor.

type AccessWorldStateFunc

type AccessWorldStateFunc = func(
	ctx context.Context,
	ref *bucket.ObjectRef,
	cb func(*bucket_lookup.Cursor) error,
) error

AccessWorldStateFunc is a function to access world state. Ref can be nil to indicate accessing context-specific default.

func NewAccessWorldStateFunc

func NewAccessWorldStateFunc(cursor *bucket_lookup.Cursor) AccessWorldStateFunc

NewAccessWorldStateFunc constructs an AccessWorldStateFunc from a existing cursor

type AuthenticatedOperation

type AuthenticatedOperation interface {
	Operation
	AuthenticatedOperation()
}

AuthenticatedOperation uses the transaction's authenticated signer as sender. Serialized delegated sender fields are ignored for these operations.

type BatchEngine

type BatchEngine struct {
	// Engine supplies storage and transactions outside an active batch.
	Engine
}

BatchEngine composes sequential transaction clients into one atomic write. Only calls carrying Run's context join the batch. Other callers continue to use the underlying Engine. A batch and its transaction handles must not escape Run or be used concurrently. Publish external effects after Run succeeds.

func NewBatchEngine

func NewBatchEngine(engine Engine) *BatchEngine

NewBatchEngine wraps an engine without opening a transaction.

func (*BatchEngine) NewTransaction

func (e *BatchEngine) NewTransaction(ctx context.Context, write bool) (Tx, error)

NewTransaction borrows the active batch, or opens an independent transaction. Borrowed Commit accepts changes into the batch; only Run makes them durable.

func (*BatchEngine) Run

func (e *BatchEngine) Run(ctx context.Context, fn func(context.Context) error) error

Run executes sequential clients against one lazily opened write transaction. Any discarded write aborts the entire batch, even if its caller ignores the error. An empty batch performs no storage operation. Run never retries fn.

func (*BatchEngine) Sync

func (e *BatchEngine) Sync(ctx context.Context) (bool, error)

Sync cannot establish durability inside an uncommitted batch.

func (*BatchEngine) SyncThrough

func (e *BatchEngine) SyncThrough(ctx context.Context, seqno uint64) (uint64, error)

SyncThrough cannot establish durability inside an uncommitted batch.

type BuildCursorFn

type BuildCursorFn func(ctx context.Context) (*bucket_lookup.Cursor, error)

BuildCursorFn builds a object cursor.

type BusEngine

type BusEngine = RefCountEngine

BusEngine uses a directive lookup to access the Engine.

func NewBusEngine

func NewBusEngine(ctx context.Context, b bus.Bus, engineID string) *BusEngine

NewBusEngine constructs a new BusEngine instance.

ctx can be nil to prevent the lookup from occurring until SetContext is called.

func StartEngine

func StartEngine(
	ctx context.Context,
	b bus.Bus,
	conf EngineConfig,
	factory controller.Factory,
) (*BusEngine, directive.Reference, error)

StartEngine loads the controller conf configures and returns an Engine that resolves conf's engine ID on the bus. The Engine follows each engine the controller serves, across the loader's restarts of a failed run and replacements within one run, so a caller never holds a retired engine.

StartEngine waits for the first engine and returns the startup error the controller reports for it. factory constructs the controller when set; otherwise the bus resolves the factory by config ID. ctx bounds the Engine's lookups. Release the reference to stop the controller.

The returned Engine implements only Engine. Assert an optional interface of the served engine, such as RootRetainingEngine, inside AccessEngine.

type CayleyHandle

type CayleyHandle interface {
	graph.QuadStore
}

CayleyHandle is a cayley graph handle. Note: QuadWriter is not included, writes must be done with WorldStateGraph.

func NewReadOperationCayleyHandle added in v0.51.7

func NewReadOperationCayleyHandle(h CayleyHandle) CayleyHandle

NewReadOperationCayleyHandle wraps a Cayley handle for a batched read operation.

The returned handle caches ValueOf, NameOf, QuadIteratorSize, and QuadDirection results for one read operation. It does not cache resolved quad refs; batch reads resolve each quad ref at most once, so caching them only costs memory.

type ChangeFilter

type ChangeFilter func(changes *ChangeSet) bool

ChangeFilter reports whether a ChangeSet concerns a watcher. A nil filter accepts every change, and an unknown ChangeSet passes every filter.

func (ChangeFilter) Accepts

func (f ChangeFilter) Accepts(changes *ChangeSet) bool

Accepts reports whether the filter lets changes through.

type ChangeIndex

type ChangeIndex[T comparable] struct {
	// contains filtered or unexported fields
}

ChangeIndex holds a change feed's watchers by the names in their ChangeInterests, so a ChangeSet finds the watchers it may concern with one lookup per changed key and quad field, independent of the watcher count. Watchers whose interest names nothing are candidates for every change.

A shared read set is indexed once by its own reads while a watcher or a held set that joined it holds it, and links to the held sets it joined. A change a set's reads name reaches the set's watchers and those of every held set that joined it, directly or through others. A watcher holding a set built from large ones thus subscribes and leaves at the cost of its own reads and the sets it joins, never of every key below them. The caller synchronizes access.

func NewChangeIndex

func NewChangeIndex[T comparable]() *ChangeIndex[T]

NewChangeIndex constructs an empty ChangeIndex.

func (*ChangeIndex[T]) Add

func (x *ChangeIndex[T]) Add(w T, interest *ChangeInterest)

Add indexes watcher w by the names in interest, replacing an earlier entry. A nil interest is tested on every change.

func (*ChangeIndex[T]) All

func (x *ChangeIndex[T]) All() iter.Seq[T]

All iterates over the watchers.

func (*ChangeIndex[T]) Candidates

func (x *ChangeIndex[T]) Candidates(changes *ChangeSet) (accepted, tested []T)

Candidates returns the watchers whose interest may accept changes, each once, in two lists. accepted holds those a changed object key names, directly or through a held set: a ChangeInterest's filter accepts any change to a key it names, so these need no test. tested holds the rest that must be tested: those named only by a changed quad field, whose pattern may still miss, and those tested on every change, or every watcher for an unknown ChangeSet. A watcher in neither rejects changes.

func (*ChangeIndex[T]) Len

func (x *ChangeIndex[T]) Len() int

Len returns the number of watchers.

func (*ChangeIndex[T]) Remove

func (x *ChangeIndex[T]) Remove(w T)

Remove drops watcher w from the index.

type ChangeInterest

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

ChangeInterest is a ChangeFilter that also names the changes it may accept, so a change feed can index its watcher by those names and test it only on a change that names one of them. An interest without names, or one marked as needing every change, is tested on every change. A change feed reads the names once, when the watch starts, so a filter that may later accept other changes must start a new watch.

func NewChangeInterest

func NewChangeInterest(filter ChangeFilter) *ChangeInterest

NewChangeInterest returns an interest that filters changes with filter and names none of them, so a change feed tests it on every change.

func NewReadSetsInterest

func NewReadSetsInterest(sets ...*ReadSet) *ChangeInterest

NewReadSetsInterest returns an interest in the changes that touch any of sets, finished read sets. A ChangeIndex holds each set once for all the watchers naming it, so watchers built from shared sets cost one entry per set.

func (*ChangeInterest) Accepts

func (c *ChangeInterest) Accepts(changes *ChangeSet) bool

Accepts reports whether the interest's filter lets changes through. A nil interest accepts every change.

type ChangeSet

type ChangeSet struct {
	// Unknown means the changes could not be determined.
	// Every ReadSet is touched by an unknown ChangeSet.
	Unknown bool
	// Keys are the object keys that were set, deleted, renamed, or revised.
	// A rename lists both the old and the new key. A revision that only
	// follows a set or deleted quad naming the object is reported through
	// Quads alone.
	Keys []string
	// Quads are the graph quads that were set or deleted, each field spelled
	// as the graph stores it.
	Quads []GraphQuad
}

ChangeSet describes the World changes between two sequence numbers.

func MergeChangeSets

func MergeChangeSets(a, b *ChangeSet, maxEntries int) *ChangeSet

MergeChangeSets returns the union of two ChangeSets without modifying either, sharing b when a is nil. The union is unknown when either is, or when it lists more than maxEntries keys and quads.

func NewUnknownChangeSet

func NewUnknownChangeSet() *ChangeSet

NewUnknownChangeSet returns a ChangeSet whose changes are unknown.

type ChangeWatcher

type ChangeWatcher interface {
	// WatchChanges calls cb with each later seqno whose changes touches
	// accepts, starting after afterSeqno, and the accepted changes since the
	// previous call. Changes touches rejects never wake the watcher. Calls
	// coalesce while cb runs. Returns when ctx is canceled or cb returns an
	// error.
	WatchChanges(ctx context.Context, afterSeqno uint64, touches ChangeFilter, cb func(seqno uint64, changes *ChangeSet) error) error
}

ChangeWatcher is an Engine that reports what changed between seqnos.

type CommitReceipt

type CommitReceipt interface {
	Done() <-chan struct{}
	Wait(context.Context) error
}

CommitReceipt separates accepted preparation from completed durable publication. Wait cancellation only stops waiting; it never implies that publication rolled back. The receipt can be waited again. A nil result means the normal Commit durability and publication contract has completed, not merely queue admission.

type Controller

type Controller interface {
	// Controller indicates this is a controller-bus controller.
	controller.Controller
	// GetWorldEngine waits for the engine to be built.
	GetWorldEngine(context.Context) (Engine, error)
}

Controller is a Hydra World controller managing an Engine.

type Engine

type Engine interface {
	// OperationAuthor returns this engine's signing device and its accepted person.
	// Unsigned engines return an empty device; callers requiring authorship reject it.
	OperationAuthor(ctx context.Context) (peer.ID, string, error)
	// NewTransaction returns a new transaction against the store.
	// A read transaction retains one immutable revision until Discard. Use
	// NewEngineWorldState for live reads and object revision watches.
	// Indicate write if the transaction will not be read-only.
	// Always call Discard() after you are done with the transaction.
	// Check GetReadOnly, might not return a write tx if write=true.
	NewTransaction(ctx context.Context, write bool) (Tx, error)

	// Sync fences durable storage and advances the durable world head.
	// Runs the block barrier so every block written so far is durable, then
	// commits the current in-memory root to the durable head ordered after the
	// barrier. Returns true if a durability fence was applied, false if the
	// store is always-durable and no fence was required.
	Sync(ctx context.Context) (bool, error)

	// SyncThrough returns once every commit with seqno <= seqno is durable and
	// covered by the durable head. It returns without a fence when the durable
	// head already covers seqno, and it waits for commits up to seqno to be
	// published but not for commits admitted after seqno. It returns the
	// durable seqno, >= seqno. An engine whose commits are durable on write
	// returns at once.
	SyncThrough(ctx context.Context, seqno uint64) (durable uint64, err error)

	// WorldStorage provides access to the world storage via bucket cursors.
	WorldStorage

	// StageWorldState opens a staging scope for writes outside a transaction.
	// Build through the stage, adopt the result in a transaction, then
	// release the stage after that transaction returns.
	StageWorldState(ctx context.Context) (WorldStage, error)

	// WorldWaitSeqno allows waiting for the world seqno to change.
	WorldWaitSeqno

	// WaitObjectRev waits until the object at key reaches rev and returns its
	// revision. Returns ErrObjectNotFound if the object does not exist, unless
	// ignoreNotFound is set, in which case it waits for the object to appear.
	// Use WaitObjectRevBySeqno when the engine cannot watch individual keys.
	WaitObjectRev(ctx context.Context, key string, rev uint64, ignoreNotFound bool) (uint64, error)
}

Engine implements a transactional world state container.

type EngineConfig

type EngineConfig interface {
	config.Config
	// GetEngineId returns the ID the controller serves its engine under.
	GetEngineId() string
}

EngineConfig configures a controller that serves a World engine on the bus under its engine ID.

type EngineController

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

EngineController lends an existing Engine to a bus under one exact identifier. The caller owns the Engine and must retain it until the controller is removed.

func NewEngineController

func NewEngineController(id string, engine Engine) *EngineController

NewEngineController exposes an already-authorized Engine without reopening storage.

func (*EngineController) Close

func (c *EngineController) Close() error

Close releases no storage; the caller retains ownership of the Engine.

func (*EngineController) Execute

func (c *EngineController) Execute(context.Context) error

Execute leaves the borrowed capability available for the controller lifetime.

func (*EngineController) GetControllerInfo

func (c *EngineController) GetControllerInfo() *controller.Info

GetControllerInfo identifies this borrowed Engine mount.

func (*EngineController) GetWorldEngine

func (c *EngineController) GetWorldEngine(context.Context) (Engine, error)

GetWorldEngine returns the capability supplied by the owner.

func (*EngineController) HandleDirective

func (c *EngineController) HandleDirective(_ context.Context, di directive.Instance) ([]directive.Resolver, error)

HandleDirective resolves only the mounted identifier, avoiding ambient World selection.

type EngineResolver

type EngineResolver = refcount.RefCountResolver[*Engine]

EngineResolver is a function which resolves an engine for a ref count.

func NewBusEngineResolver

func NewBusEngineResolver(b bus.Bus, engineID string) EngineResolver

NewBusEngineResolver constructs a resolver function for a bus engine.

type ForkableWorldState

type ForkableWorldState interface {
	WorldState

	// Fork forks the current state into a new state.
	Fork(ctx context.Context) (WorldState, error)
}

ForkableWorldState adds a Fork function to the WorldState, which returns an independent WorldState with a new underlying tx.

type GraphEdgeBucket added in v0.51.7

type GraphEdgeBucket struct {
	// OriginObjectKey is the requested origin object key.
	OriginObjectKey string
	// Outgoing contains quads where the origin is the subject.
	Outgoing []GraphQuad
	// Incoming contains quads where the origin is the object.
	Incoming []GraphQuad
	// OutgoingTruncated indicates more outgoing edges matched than were returned.
	OutgoingTruncated bool
	// IncomingTruncated indicates more incoming edges matched than were returned.
	IncomingTruncated bool
}

GraphEdgeBucket contains grouped graph edges for one origin object key.

func ListGraphEdgeBuckets added in v0.51.7

func ListGraphEdgeBuckets(ctx context.Context, ws WorldStateGraph, query *GraphEdgeBucketQuery) ([]*GraphEdgeBucket, error)

ListGraphEdgeBuckets lists grouped inbound/outbound graph edges for object keys.

type GraphEdgeBucketDirection added in v0.51.7

type GraphEdgeBucketDirection int

GraphEdgeBucketDirection indicates which edge directions to list.

const (
	// GraphEdgeBucketDirectionBoth lists incoming and outgoing edges.
	GraphEdgeBucketDirectionBoth GraphEdgeBucketDirection = iota
	// GraphEdgeBucketDirectionOut lists only outgoing edges.
	GraphEdgeBucketDirectionOut
	// GraphEdgeBucketDirectionIn lists only incoming edges.
	GraphEdgeBucketDirectionIn
)

type GraphEdgeBucketQuery added in v0.51.7

type GraphEdgeBucketQuery struct {
	// OriginObjectKeys are object keys whose graph edges should be grouped.
	OriginObjectKeys []string
	// Predicate optionally restricts grouped edges.
	Predicate string
	// LimitPerOrigin is the maximum edge count returned per origin direction.
	LimitPerOrigin uint32
	// Direction selects which edge directions are included.
	Direction GraphEdgeBucketDirection
}

GraphEdgeBucketQuery describes grouped graph edge bucket lookup.

type GraphPathDirection added in v0.51.6

type GraphPathDirection int

GraphPathDirection indicates which side of the current object key to follow.

const (
	// GraphPathDirectionOut follows quads where the current key is the subject.
	GraphPathDirectionOut GraphPathDirection = iota + 1
	// GraphPathDirectionIn follows quads where the current key is the object.
	GraphPathDirectionIn
	// GraphPathDirectionBoth follows incoming and outgoing quads.
	GraphPathDirectionBoth
)

type GraphPathQuery added in v0.51.6

type GraphPathQuery struct {
	// StartKeys is the list of object keys where traversal starts.
	StartKeys []string
	// Steps is the ordered traversal to execute.
	Steps []GraphPathStep
	// ResultLimit is the maximum number of final object keys returned.
	ResultLimit uint32
	// IncludeQuads includes traversed quads in the result.
	IncludeQuads bool
}

GraphPathQuery describes a bounded server-executed graph traversal.

type GraphPathQueryResult added in v0.51.6

type GraphPathQueryResult struct {
	// ObjectKeys is the set of reached object keys.
	ObjectKeys []string
	// Quads is the set of traversed quads when requested.
	Quads []GraphQuad
}

GraphPathQueryResult contains graph path traversal results.

func QueryGraphPathWithLookups added in v0.51.6

func QueryGraphPathWithLookups(ctx context.Context, ws WorldStateGraph, query *GraphPathQuery) (*GraphPathQueryResult, error)

QueryGraphPathWithLookups executes a graph path query with bounded quad lookups.

type GraphPathStep added in v0.51.6

type GraphPathStep struct {
	// Direction is the edge direction to follow.
	Direction GraphPathDirection
	// Predicate is the graph predicate to match.
	Predicate string
	// Limit is the maximum number of quads inspected per current key.
	Limit uint32
}

GraphPathStep is one bounded predicate traversal step.

type GraphQuad

type GraphQuad interface {
	// GetSubject returns the subject field.
	GetSubject() string
	// GetPredicate returns the predicate field.
	GetPredicate() string
	// GetObj returns the object field.
	GetObj() string
	// GetLabel returns the label field, which is usually empty.
	GetLabel() string
}

GraphQuad is the common graph entry interface.

func CayleyQuadToGraphQuad

func CayleyQuadToGraphQuad(q quad.Quad) GraphQuad

CayleyQuadToGraphQuad converts a cayley quad into a graph quad.

func NewGraphQuad

func NewGraphQuad(subj, pred, obj, value string) GraphQuad

NewGraphQuad constructs a new in-memory GraphQuad.

func NewGraphQuadWithKeys

func NewGraphQuadWithKeys(subjKey, pred, objKey, value string) GraphQuad

NewGraphQuadWithKeys creates a new graph quad from object keys.

func NewTypeQuadFilter

func NewTypeQuadFilter(typeID string) GraphQuad

NewTypeQuadFilter returns the lookup filter of the type edges into typeID, which ListObjectsWithType lists.

func QuadToGraphQuad

func QuadToGraphQuad(q *bquad.Quad) GraphQuad

QuadToGraphQuad converts quad into a graph quad.

type IndexedChangeWatcher

type IndexedChangeWatcher interface {
	ChangeWatcher
	// WatchIndexedChanges is WatchChanges for the changes interest accepts. A
	// change that names none of the interest's keys or quad fields never tests
	// or wakes the watcher.
	WatchIndexedChanges(ctx context.Context, afterSeqno uint64, interest *ChangeInterest, cb func(seqno uint64, changes *ChangeSet) error) error
}

IndexedChangeWatcher is a ChangeWatcher that indexes its watchers by the names in their ChangeInterests, so a change tests and wakes only the watchers it names. An Engine wrapper that forwards WatchChanges forwards WatchIndexedChanges too, or its watchers fall back to WatchChanges.

type LookupOp

type LookupOp = func(ctx context.Context, operationTypeID string) (Operation, error)

LookupOp looks up an operation type for a op type id.

returns nil, nil if not found.

func BuildLookupWorldOpFunc

func BuildLookupWorldOpFunc(b bus.Bus, le *logrus.Entry, engineID string) LookupOp

BuildLookupWorldOpFunc implements a apply world op handler backed by a directive lookup against a bus.

func NewLookupOpFromSlice

func NewLookupOpFromSlice(sl LookupOpSlice) LookupOp

NewLookupOpFromSlice builds LookupOp from a LookupOpSlice.

type LookupOpController

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

LookupOpController implements LookupWorldOp on a bus.

func NewLookupOpController

func NewLookupOpController(
	controllerID string,
	engineID string,
	lookupOp LookupOp,
) *LookupOpController

NewLookupOpController builds a new operation controller with the handlers. controllerID is the id of the operation controller on the bus. if engineID is empty, does not filter that field

func (*LookupOpController) Close

func (c *LookupOpController) Close() error

Close releases any resources used by the controller. Error indicates any issue encountered releasing.

func (*LookupOpController) Execute

func (c *LookupOpController) Execute(ctx context.Context) error

Execute executes the controller goroutine. Returning nil ends execution. Returning an error triggers a retry with backoff.

func (*LookupOpController) GetControllerInfo

func (c *LookupOpController) GetControllerInfo() *controller.Info

GetControllerInfo returns information about the controller.

func (*LookupOpController) HandleDirective

func (c *LookupOpController) HandleDirective(
	ctx context.Context,
	di directive.Instance,
) ([]directive.Resolver, error)

HandleDirective asks if the handler can resolve the directive.

type LookupOpSlice

type LookupOpSlice []LookupOp

LookupOpSlice is a set of LookupOp calls called in sequence.

func (LookupOpSlice) LookupOp

func (s LookupOpSlice) LookupOp(ctx context.Context, opTypeID string) (Operation, error)

LookupOp performs the LookupOp call against a list of funcs.

type LookupWorldEngine

type LookupWorldEngine interface {
	// Directive indicates LookupWorldEngine is a directive.
	directive.Directive

	// LookupWorldEngineID returns a specific world engine we are looking for.
	// Can be empty.
	LookupWorldEngineID() string
}

LookupWorldEngine is a directive to lookup a running World Graph engine. Value type: world.Engine.

func NewLookupWorldEngine

func NewLookupWorldEngine(id string) LookupWorldEngine

NewLookupWorldEngine constructs a new LookupWorldEngine directive.

type LookupWorldEngineValue

type LookupWorldEngineValue = Engine

LookupWorldEngineValue is the value type for LookupWorldEngine.

func ExLookupWorldEngine

func ExLookupWorldEngine(
	ctx context.Context,
	b bus.Bus,
	returnIfIdle bool,
	id string,
	disposeCb func(),
) (LookupWorldEngineValue, directive.Instance, directive.Reference, error)

ExLookupWorldEngine executes a single-value engine lookup against a bus by ID. If ID is empty, selects any.

type LookupWorldOp

type LookupWorldOp interface {
	// Directive indicates LookupWorldOp is a directive.
	directive.Directive

	// LookupWorldOpOperationTypeID returns the operation type ID.
	// Cannot be empty.
	LookupWorldOpOperationTypeID() string
	// LookupWorldOpEngineID returns the world engine ID.
	// Can be empty.
	LookupWorldOpEngineID() string
}

LookupWorldOp is a directive to lookup a world operation handler.

func NewLookupWorldOp

func NewLookupWorldOp(operationTypeID, engineID string) LookupWorldOp

NewLookupWorldOp constructs an LookupWorldOp. objectKey can be empty to indicate a world operation.

type LookupWorldOpValue

type LookupWorldOpValue = LookupOp

LookupWorldOpValue is the result type for LookupWorldOp.

func ExLookupWorldOp

func ExLookupWorldOp(
	ctx context.Context,
	b bus.Bus,
	le *logrus.Entry,
	operationTypeID string,
	engineID string,
) ([]LookupWorldOpValue, directive.Instance, directive.Reference, error)

ExLookupWorldOp executes a lookup against a bus for a operation handler.

type ObjectBody added in v0.57.0

type ObjectBody struct {
	// ObjectKey is the requested object key.
	ObjectKey string
	// Body is the transformed root block data when the object exists.
	Body []byte
	// Rev is the object revision observed with Body.
	Rev uint64
	// ModSeqno is the World seqno after the last commit that changed the
	// object. Zero when the object state does not report it.
	ModSeqno uint64
	// Exists reports whether the object key exists.
	Exists bool
}

ObjectBody contains the serialized root body for one object key.

func GetObjectBodiesBatch added in v0.57.0

func GetObjectBodiesBatch(ctx context.Context, ws WorldState, keys []string) ([]*ObjectBody, error)

GetObjectBodiesBatch returns serialized object bodies for object keys. Results preserve the requested key order and include one missing marker per key that does not exist.

func GetObjectBodiesBatchPage added in v0.57.0

func GetObjectBodiesBatchPage(
	ctx context.Context,
	ws WorldState,
	keys []string,
	byteBudget int,
) ([]*ObjectBody, uint32, error)

GetObjectBodiesBatchPage returns one encoded-size-bounded page of bodies.

func GetObjectBodiesBatchPageWithSeqno added in v0.57.0

func GetObjectBodiesBatchPageWithSeqno(
	ctx context.Context,
	ws WorldState,
	keys []string,
	byteBudget int,
) ([]*ObjectBody, uint32, uint64, error)

GetObjectBodiesBatchPageWithSeqno returns one page and its World sequence number.

func LookupObjectBodyEntry

func LookupObjectBodyEntry(ctx context.Context, ws WorldState, objKey string) (*ObjectBody, error)

LookupObjectBodyEntry looks up the transformed root body of an object with its revision and, when the object state reports it, its ModSeqno. A missing object returns a body with Exists unset.

type ObjectBodyBatcher added in v0.57.0

type ObjectBodyBatcher interface {
	// GetObjectBodiesBatch returns object bodies for object keys.
	GetObjectBodiesBatch(ctx context.Context, keys []string) ([]*ObjectBody, error)
}

ObjectBodyBatcher returns serialized object bodies for object keys.

type ObjectBodyPageBatcher added in v0.57.0

type ObjectBodyPageBatcher interface {
	// GetObjectBodiesBatchPage returns bodies and the number of keys consumed.
	GetObjectBodiesBatchPage(ctx context.Context, keys []string, byteBudget int) ([]*ObjectBody, uint32, error)
}

ObjectBodyPageBatcher returns one budgeted page of serialized object bodies.

type ObjectBodyPageSeqnoBatcher added in v0.57.0

type ObjectBodyPageSeqnoBatcher interface {
	// GetObjectBodiesBatchPageWithSeqno returns bodies, consumed keys, and the
	// World sequence number observed by the read transaction.
	GetObjectBodiesBatchPageWithSeqno(ctx context.Context, keys []string, byteBudget int) ([]*ObjectBody, uint32, uint64, error)
}

ObjectBodyPageSeqnoBatcher returns one budgeted page and its World sequence number.

type ObjectBodyResult added in v0.57.0

type ObjectBodyResult[T block.Block] struct {
	// ObjectKey is the requested object key.
	ObjectKey string
	// Body is the decoded object body when the object exists.
	Body T
	// Exists reports whether the object key exists.
	Exists bool
}

ObjectBodyResult contains a typed body or a missing marker for one object key.

func LookupObjectBodies added in v0.57.0

func LookupObjectBodies[T any, PT block.Ptr[T]](
	ctx context.Context,
	ws WorldState,
	objKeys []string,
) ([]*ObjectBodyResult[PT], error)

LookupObjectBodies looks up and unmarshals object bodies for the given keys. Results preserve the requested key order and include a zero Body with Exists=false for missing objects.

type ObjectBodyTooLargeError added in v0.57.0

type ObjectBodyTooLargeError struct {
	// ObjectKey is the key whose encoded entry exceeds the page budget.
	ObjectKey string
	// EncodedSize is the serialized size of the object body response entry.
	EncodedSize int
	// ByteBudget is the maximum encoded size allowed for one page.
	ByteBudget int
}

ObjectBodyTooLargeError reports a body that cannot fit in one response page.

func (*ObjectBodyTooLargeError) Error added in v0.57.0

func (e *ObjectBodyTooLargeError) Error() string

Error returns the oversized object body details.

type ObjectIterator

type ObjectIterator interface {
	// Err returns any error that has closed the iterator.
	// May return context.Canceled if closed.
	Err() error

	// Valid returns if the iterator points to a valid entry.
	//
	// If err is set, returns false.
	Valid() bool

	// Key returns the current entry key, or nil if not valid.
	Key() string

	// Next advances to the next entry and returns Valid.
	Next() bool

	// Seek moves the iterator to the first key >= the provided key (or <= in reverse mode).
	// Pass an empty string to seek to the beginning (or end if reversed).
	// Seek has two failure modes:
	//  - return an error without modifying the iterator.
	//  - set the iterator Err to the error and return nil.
	Seek(k string) error

	// Close releases the iterator.
	Close()
}

ObjectIterator iterates over objects in a WorldState. Always call Close when done with the iterator. ObjectIterator functions are NOT thread safe, use it from one goroutine at a time.

type ObjectModSeqnoReader

type ObjectModSeqnoReader interface {
	// GetModSeqno returns the World seqno after the last commit that changed
	// the object.
	GetModSeqno(ctx context.Context) (uint64, error)
}

ObjectModSeqnoReader is an ObjectState that reports the World seqno after the last commit that changed its object. Rev counts the object's own changes; ModSeqno orders them with every other change in the World, so a reader can watch for changes after it. Wrappers forward it when the state they wrap implements it.

type ObjectOperation

type ObjectOperation interface {
	Operation

	// ApplyWorldObjectOp applies the operation to a world object handle. It
	// returns false, ErrUnhandledOp if the operation cannot handle an object op.
	ApplyWorldObjectOp(
		ctx context.Context,
		le *logrus.Entry,
		objectHandle ObjectState,
		sender peer.ID,
	) (sysErr bool, err error)
}

ObjectOperation is an Operation that can also apply to one object handle.

type ObjectPurger

type ObjectPurger interface {
	// PurgeObject removes the object entry at key and every graph quad naming
	// it, without reading the object's record or root. The deletion change
	// keeps no reference to the record, so nothing still reaches its blocks.
	// Returns false, nil if not found.
	PurgeObject(ctx context.Context, key string) (bool, error)
}

ObjectPurger is a WorldState that can remove an object whose record or blocks the store lacks.

type ObjectRevWaiter

type ObjectRevWaiter interface {
	// WaitObjectRev waits until the object at key reaches rev and returns its
	// revision, with the contract of Engine.WaitObjectRev.
	WaitObjectRev(ctx context.Context, key string, rev uint64, ignoreNotFound bool) (uint64, error)
}

ObjectRevWaiter is a WorldState that waits for object revisions through a key-scoped watch instead of rereading the object after every World commit.

type ObjectRootRef added in v0.51.7

type ObjectRootRef struct {
	// ObjectKey is the object key.
	ObjectKey string
	// RootRef is the current object root ref.
	RootRef *bucket.ObjectRef
	// Rev is the object revision.
	Rev uint64
	// Exists is true when the object exists.
	Exists bool
}

ObjectRootRef holds the current root reference metadata for one object key.

func GetObjectRootRefsBatch added in v0.51.7

func GetObjectRootRefsBatch(ctx context.Context, ws WorldState, keys []string) ([]*ObjectRootRef, error)

GetObjectRootRefsBatch returns object root refs for object keys.

type ObjectRootRefBatcher added in v0.51.7

type ObjectRootRefBatcher interface {
	// GetObjectRootRefsBatch returns object root refs for object keys.
	GetObjectRootRefsBatch(ctx context.Context, keys []string) ([]*ObjectRootRef, error)
}

ObjectRootRefBatcher returns object root refs for object keys.

type ObjectState

type ObjectState interface {
	// GetKey returns the key this state object is for.
	GetKey() string

	// GetRootRef returns the root reference.
	// Returns the revision number.
	GetRootRef(ctx context.Context) (*bucket.ObjectRef, uint64, error)

	// AccessWorldState builds a bucket lookup cursor with an optional ref.
	// If the ref is empty, will default to the object RootRef.
	// If the ref Bucket ID is empty, uses the same bucket + volume as the world.
	// The lookup cursor will be released after cb returns.
	AccessWorldState(
		ctx context.Context,
		ref *bucket.ObjectRef,
		cb func(*bucket_lookup.Cursor) error,
	) error

	// SetRootRef changes the root reference of the object.
	// Increments the revision of the object if changed.
	// Returns revision just after the change was applied.
	SetRootRef(ctx context.Context, nref *bucket.ObjectRef) (uint64, error)

	// ApplyObjectOp applies a batch operation at the object level.
	// The handling of the operation is operation-type specific.
	// Returns the revision following the operation execution.
	// If nil is returned for the error, implies success.
	// If sysErr is set, the error is treated as a transient system error.
	// Returns rev, sysErr, err
	ApplyObjectOp(
		ctx context.Context,
		op Operation,
		opSender peer.ID,
	) (rev uint64, sysErr bool, err error)

	// IncrementRev increments the revision of the object.
	// Returns revision just after the change was applied.
	IncrementRev(ctx context.Context) (uint64, error)

	// WaitRev waits until the object rev is >= the specified.
	// Returns ErrObjectNotFound if the object is deleted.
	// If ignoreNotFound is set, waits for the object to exist.
	// Returns the new rev.
	WaitRev(ctx context.Context, rev uint64, ignoreNotFound bool) (uint64, error)
}

ObjectState contains the object state interface. Represents a handle a object in the store.

func CollectObjectBodies

func CollectObjectBodies[T any, PT block.Ptr[T]](
	ctx context.Context,
	ws WorldState,
	objKeys []string,
) ([]PT, []ObjectState, error)

CollectObjectBodies looks up and unmarshals the objects with the given keys.

Returns two slices of length len(objKeys). If any objects are not found, their entries are nil and ErrObjectNotFound is returned with the rest. Returns nil, nil, err for any other error.

func CreateWorldObject

func CreateWorldObject(
	ctx context.Context,
	ws WorldState,
	objKey string,
	cb AccessObjectCb,
) (ObjectState, *bucket.ObjectRef, error)

CreateWorldObject is a utility for WorldState to create a Object.

Returns the updated object ref and any error.

func LookupObject

func LookupObject[T any, PT block.Ptr[T]](
	ctx context.Context,
	ws WorldState,
	objKey string,
) (out PT, objRef ObjectState, err error)

LookupObject looks up & unmarshals an object from the world.

func MustGetObject

func MustGetObject(ctx context.Context, w WorldStateObject, key string) (ObjectState, error)

MustGetObject looks up an object in a world state or returns ErrObjectNotFound.

type Operation

type Operation interface {
	// Block indicates this operation is serializable to a block.
	block.Block

	// TypeID returns the operation type identifier.
	TypeID() string

	// ApplyWorldOp applies the operation as a world operation. It returns
	// false, ErrUnhandledOp if the operation cannot handle a world op.
	ApplyWorldOp(
		ctx context.Context,
		le *logrus.Entry,
		worldHandle WorldState,
		sender peer.ID,
	) (sysErr bool, err error)
}

Operation is a batch operation against World or Object.

A generated message becomes an Operation by declaring its (typeid.id) option, which generates TypeID, and implementing ApplyWorldOp.

type OperationRejection

type OperationRejection struct {
	Code    string
	Message string
}

OperationRejection reports a deterministic application rejection. The World transaction owner discards all changes; callers may present Message directly.

func (*OperationRejection) Error

func (e *OperationRejection) Error() string

Error returns the safe application explanation.

type PayloadOperation

type PayloadOperation interface {
	Operation

	// GetPayloadRefs returns the roots of the operation's payload.
	GetPayloadRefs() []*block.BlockRef
}

PayloadOperation is an Operation whose payload was written outside the World tree before the operation was applied. The World after the operation need not reference the payload, but replay reads it again through its roots, so the replay keeps the payload owned while the operation is above the checkpoint.

type ReadSet

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

ReadSet records what a view read from the World, so a ChangeSet can be checked against it. Reads it cannot describe precisely mark it conservative, and any change touches it. A ReadSet can track several WorldStates at once, and join finished sets by reference, whose reads become its own.

func NewReadSet

func NewReadSet() *ReadSet

NewReadSet constructs an empty ReadSet.

func (*ReadSet) Touched

func (r *ReadSet) Touched(changes *ChangeSet) bool

Touched checks whether a ChangeSet may change what was read, by this set or a set it joined.

func (*ReadSet) Track

func (r *ReadSet) Track(ws WorldState) WorldState

Track returns a WorldState that records the reads made through it. The seqno of ws identifies the state the reads observed.

func (*ReadSet) WaitChange

func (r *ReadSet) WaitChange(ctx context.Context, w WorldWaitSeqno, afterSeqno uint64) (uint64, error)

WaitChange waits for the first change of w after afterSeqno that touches the reads, and returns its seqno. Record afterSeqno before the reads. Reads may continue while WaitChange runs: each one restarts the wait from afterSeqno, so a change that lands before the read of what it changed still ends it.

type ReadTrackingEngine

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

ReadTrackingEngine records transactions opened with a view's context into that evaluation's reads. Wrap the engine before passing it to clients that open their own transactions inside WatchView or SendViews.

func NewReadTrackingEngine

func NewReadTrackingEngine(engine Engine) *ReadTrackingEngine

NewReadTrackingEngine constructs a tracking engine without opening a transaction.

func (*ReadTrackingEngine) AccessWorldState

func (e *ReadTrackingEngine) AccessWorldState(ctx context.Context, ref *bucket.ObjectRef, cb func(*bucket_lookup.Cursor) error) error

AccessWorldState records a root read whose dependencies are otherwise opaque.

func (*ReadTrackingEngine) BuildStorageCursor

func (e *ReadTrackingEngine) BuildStorageCursor(ctx context.Context) (*bucket_lookup.Cursor, error)

BuildStorageCursor builds an empty cursor through the underlying engine.

func (*ReadTrackingEngine) GetSeqno

func (e *ReadTrackingEngine) GetSeqno(ctx context.Context) (uint64, error)

GetSeqno returns the current World seqno.

func (*ReadTrackingEngine) NewTransaction

func (e *ReadTrackingEngine) NewTransaction(ctx context.Context, write bool) (Tx, error)

NewTransaction records reads in the context's evaluation, when one is active. Commit and Discard retain the underlying transaction's contract.

func (*ReadTrackingEngine) OperationAuthor

func (e *ReadTrackingEngine) OperationAuthor(ctx context.Context) (peer.ID, string, error)

OperationAuthor returns the underlying engine's signing device and person.

func (*ReadTrackingEngine) StageWorldState

func (e *ReadTrackingEngine) StageWorldState(ctx context.Context) (WorldStage, error)

StageWorldState records an opaque storage access and opens its staging scope.

func (*ReadTrackingEngine) Sync

func (e *ReadTrackingEngine) Sync(ctx context.Context) (bool, error)

Sync fences writes through the underlying engine.

func (*ReadTrackingEngine) SyncThrough

func (e *ReadTrackingEngine) SyncThrough(ctx context.Context, seqno uint64) (uint64, error)

SyncThrough fences writes through seqno via the underlying engine.

func (*ReadTrackingEngine) WaitObjectRev

func (e *ReadTrackingEngine) WaitObjectRev(ctx context.Context, key string, rev uint64, ignoreNotFound bool) (uint64, error)

WaitObjectRev waits through the underlying engine's object watch.

func (*ReadTrackingEngine) WaitSeqno

func (e *ReadTrackingEngine) WaitSeqno(ctx context.Context, seqno uint64) (uint64, error)

WaitSeqno waits through the underlying engine.

func (*ReadTrackingEngine) WatchChanges

func (e *ReadTrackingEngine) WatchChanges(ctx context.Context, afterSeqno uint64, touches ChangeFilter, cb func(uint64, *ChangeSet) error) error

WatchChanges forwards the underlying change feed without replacing it.

func (*ReadTrackingEngine) WatchIndexedChanges

func (e *ReadTrackingEngine) WatchIndexedChanges(ctx context.Context, afterSeqno uint64, interest *ChangeInterest, cb func(uint64, *ChangeSet) error) error

WatchIndexedChanges forwards the underlying indexed change feed.

type RefCountEngine

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

RefCountEngine is an engine backed by a reference counter.

func NewRefCountEngine

func NewRefCountEngine(ctx context.Context, keepUnref bool, resolver EngineResolver) *RefCountEngine

NewRefCountEngine constructs a new refcount engine.

keepUnref sets if the engine should be kept if there are zero references. ctx is used to resolve the value when a reference is added. ctx can be nil and updated with SetContext or ClearContext.

func NewRefCountEngineWithCtr

func NewRefCountEngineWithCtr(
	ctx context.Context,
	keepUnref bool,
	resolver EngineResolver,
	target *ccontainer.CContainer[*Engine],
	targetErr *ccontainer.CContainer[*error],
) *RefCountEngine

NewRefCountEngineWithCtr builds a new refcount engine that stores the engine in the target ccontainers. Either of the ccontainers can be nil.

keepUnref sets if the engine should be kept if there are zero references.

func (*RefCountEngine) AccessWorldState

func (e *RefCountEngine) AccessWorldState(
	ctx context.Context,
	ref *bucket.ObjectRef,
	cb func(*bucket_lookup.Cursor) error,
) error

AccessWorldState builds a bucket lookup cursor with an optional ref. If the ref Bucket ID is empty, uses the same bucket + volume as the world. The lookup cursor will be released after cb returns.

func (*RefCountEngine) BuildStorageCursor

func (e *RefCountEngine) BuildStorageCursor(ctx context.Context) (*bucket_lookup.Cursor, error)

BuildStorageCursor builds a cursor to the world storage with an empty ref. The cursor should be released independently of the WorldState. Be sure to call Release on the cursor when done.

func (*RefCountEngine) ClearContext

func (e *RefCountEngine) ClearContext()

ClearContext clears the context used for fetching the bus engine.

func (*RefCountEngine) GetSeqno

func (e *RefCountEngine) GetSeqno(ctx context.Context) (uint64, error)

GetSeqno returns the current seqno of the world state. This is also the sequence number of the most recent change. Initializes at 0 for initial world state.

func (*RefCountEngine) NewTransaction

func (e *RefCountEngine) NewTransaction(ctx context.Context, write bool) (Tx, error)

NewTransaction returns a new transaction against the store. Indicate write if the transaction will not be read-only. Always call Discard() after you are done with the transaction. Check GetReadOnly, might not return a write tx if write=true. The returned transaction retains the resolved engine until Discard.

func (*RefCountEngine) OperationAuthor

func (e *RefCountEngine) OperationAuthor(ctx context.Context) (peer.ID, string, error)

OperationAuthor resolves the current engine's signing device and person.

func (*RefCountEngine) SetContext

func (e *RefCountEngine) SetContext(ctx context.Context)

SetContext updates the context used for fetching the bus engine.

Can be nil to prevent / cancel looking up the engine.

func (*RefCountEngine) StageWorldState

func (e *RefCountEngine) StageWorldState(ctx context.Context) (WorldStage, error)

StageWorldState opens a stage on the current engine and holds the engine until the stage is released.

func (*RefCountEngine) Sync added in v0.52.0

func (e *RefCountEngine) Sync(ctx context.Context) (bool, error)

Sync fences durable storage and advances the durable head via the engine.

func (*RefCountEngine) SyncThrough

func (e *RefCountEngine) SyncThrough(ctx context.Context, seqno uint64) (uint64, error)

SyncThrough fences durable storage through seqno via the engine.

func (*RefCountEngine) WaitObjectRev

func (e *RefCountEngine) WaitObjectRev(ctx context.Context, key string, rev uint64, ignoreNotFound bool) (uint64, error)

WaitObjectRev waits until the object at key reaches rev.

func (*RefCountEngine) WaitSeqno

func (e *RefCountEngine) WaitSeqno(ctx context.Context, value uint64) (uint64, error)

WaitSeqno waits for the seqno of the world state to be >= value. Returns nil when the condition is reached. If value == 0, this might return immediately unconditionally.

func (*RefCountEngine) WatchChanges

func (e *RefCountEngine) WatchChanges(
	ctx context.Context,
	afterSeqno uint64,
	touches ChangeFilter,
	cb func(seqno uint64, changes *ChangeSet) error,
) error

WatchChanges forwards the change feed of the current engine. A restart on a newly resolved engine continues after the last reported seqno.

func (*RefCountEngine) WatchIndexedChanges

func (e *RefCountEngine) WatchIndexedChanges(
	ctx context.Context,
	afterSeqno uint64,
	interest *ChangeInterest,
	cb func(seqno uint64, changes *ChangeSet) error,
) error

WatchIndexedChanges forwards the indexed change feed of the current engine. A restart on a newly resolved engine continues after the last reported seqno.

type RefCountTx

type RefCountTx struct {
	WorldState
	// contains filtered or unexported fields
}

RefCountTx wraps an engine transaction with a refcount reference.

func NewRefCountTx

func NewRefCountTx(tx Tx, ref refcount.RefLike) *RefCountTx

NewRefCountTx constructs a new refcount engine tx.

func (*RefCountTx) Commit

func (r *RefCountTx) Commit(ctx context.Context) error

Commit commits the transaction to storage. Can return an error to indicate tx failure.

func (*RefCountTx) Discard

func (r *RefCountTx) Discard()

Discard cancels the transaction. If called after Commit, does nothing. Cannot return an error. Can be called unlimited times.

func (*RefCountTx) GetObjectBodiesBatch

func (r *RefCountTx) GetObjectBodiesBatch(ctx context.Context, keys []string) ([]*ObjectBody, error)

GetObjectBodiesBatch returns object bodies through the wrapped transaction.

func (*RefCountTx) GetObjectBodiesBatchPage

func (r *RefCountTx) GetObjectBodiesBatchPage(ctx context.Context, keys []string, byteBudget int) ([]*ObjectBody, uint32, error)

GetObjectBodiesBatchPage returns one budgeted page through the wrapped transaction.

func (*RefCountTx) GetObjectBodiesBatchPageWithSeqno

func (r *RefCountTx) GetObjectBodiesBatchPageWithSeqno(ctx context.Context, keys []string, byteBudget int) ([]*ObjectBody, uint32, uint64, error)

GetObjectBodiesBatchPageWithSeqno returns one budgeted page and its World sequence number through the wrapped transaction.

func (*RefCountTx) GetObjectRootRefsBatch

func (r *RefCountTx) GetObjectRootRefsBatch(ctx context.Context, keys []string) ([]*ObjectRootRef, error)

GetObjectRootRefsBatch returns object root refs through the wrapped transaction.

type ReplacingController

type ReplacingController interface {
	Controller
	// AcquireWorldEngine waits for the served engine and holds it open until
	// release is called.
	AcquireWorldEngine(ctx context.Context) (eng Engine, release func(), err error)
	// WaitWorldEngineReplaced waits until eng is no longer the engine the
	// controller serves.
	WaitWorldEngineReplaced(ctx context.Context, eng Engine) error
}

ReplacingController is a Controller that can replace its engine while it runs, such as after losing and regaining read access. It closes a replaced engine only after every holder released it, so a lookup that withdraws the engine before releasing it never publishes a closed engine.

type RootRetainingEngine

type RootRetainingEngine interface {
	// SetRetainedRoot retains the World root ref under name, replacing the
	// root the name held. ref must be the accepted head, with its blocks in
	// the World's storage. An empty ref releases the name.
	SetRetainedRoot(ctx context.Context, name string, ref *block.BlockRef) error
}

RootRetainingEngine is an Engine that retains named World roots in its shared state, so storage reclaim keeps their blocks for recovery.

type Schema

type Schema map[string]func() any

Schema resolves World operations and block types by their generated type IDs.

A Schema is built from the []typeid.Type lists that protoc-gen-go-typeid generates for each .proto file declaring (typeid.id) options.

func NewSchema

func NewSchema(lists ...[]typeid.Type) Schema

NewSchema builds a Schema from generated type lists.

NewSchema panics if two entries declare the same type ID: the lists are fixed at build time, so a collision is a programming error.

func (Schema) LookupBlockType

func (s Schema) LookupBlockType(_ context.Context, typeID string) (blocktype.BlockType, error)

LookupBlockType returns the block type with the type ID.

Returns nil, nil if the schema does not declare the type ID.

func (Schema) LookupOp

func (s Schema) LookupOp(_ context.Context, opTypeID string) (Operation, error)

LookupOp constructs the operation with the type ID.

Returns nil, nil if the schema does not declare the type ID.

type SubmittableTx

type SubmittableTx interface {
	Tx
	Submit(context.Context) (CommitReceipt, error)
}

SubmittableTx optionally releases the producer's mutable transaction after sealing and admission, while returning an explicit durable completion fence. A successor may prepare against that producer's private ordered revision. Canonical readers and other writers still observe only durable state.

Ordinary Commit remains synchronous. Resource callers can use concurrent Commit requests without changing the existing wire contract. Implementations without run-ahead may return a receipt already completed by synchronous Commit.

type Tx

type Tx interface {
	// WorldState contains the world read/write ops.
	WorldState
	// Tx contains the transaction Commit/Discard ops.
	tx.Tx
}

Tx implements the world state transaction interfaces.

Concurrent calls to WorldState functions should be supported.

type ValidatedOperation

type ValidatedOperation interface {
	Operation

	// Validate performs cursory validation of the operation.
	// Should not block.
	Validate() error
}

ValidatedOperation is an Operation with cursory validation.

type View

type View[T any] interface {
	// EqualVT reports whether two messages carry the same content.
	EqualVT(T) bool
}

View is a generated message whose content SendViews can compare.

type WatchViewOptions

type WatchViewOptions struct {
	// AfterSeqno is a seqno the caller already holds the view at. When it is
	// above zero, the first evaluation waits for the World to pass it.
	AfterSeqno uint64
	// MinInterval is the least time between the starts of two evaluations. A
	// burst of touching commits reruns the view once per interval, and the rerun
	// reads the newest head. Zero reruns as soon as a change or deadline arrives.
	MinInterval time.Duration
}

WatchViewOptions tunes WatchViewWith. The zero value is WatchView's behavior.

type WorldEngineResolver

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

WorldEngineResolver resolves LookupWorldEngine with the controller engine.

func NewWorldEngineResolver

func NewWorldEngineResolver(c Controller) (*WorldEngineResolver, error)

NewWorldEngineResolver constructs a new dial resolver.

func (*WorldEngineResolver) Resolve

Resolve publishes the engine the controller serves. When the controller replaces its engine within a run, Resolve removes the retired engine before the controller closes it and publishes its successor, so a lookup never holds a closed engine.

type WorldStage

type WorldStage interface {
	// WorldStorage builds cursors whose writes the stage owns.
	WorldStorage

	// ReleaseRoots drops the stage's ownership of roots built through it. Call
	// it once the transaction that references them has returned. Each root
	// then survives only through a committed parent. The stage stays open.
	ReleaseRoots(ctx context.Context, roots []*block.BlockRef) error

	// Release ends the stage. Writes through its cursors fail afterward.
	Release()
}

WorldStage is World storage whose writes a staging scope owns.

Blocks written through the stage stay alive until Release, so a caller can build object data outside a World transaction and adopt it in a later one. Hold the stage until the transaction that references the built roots has returned, then call Release. Blocks no committed parent references are reclaimed after Release, including when the adopting transaction failed.

A stage that outlives many builds, such as one held by a long-lived store, calls ReleaseRoots after each adopting transaction returns, so it holds only the builds still in flight.

func NewStorageStage

func NewStorageStage(storage WorldStorage) WorldStage

NewStorageStage stages the writes made through cursors from storage.

Each cursor's block store opens its own volume stage, so a cursor following a reference into another bucket stages there too. A store without root retention writes directly, as it does outside a stage.

func NewTransactionStage

func NewTransactionStage(storage WorldStorage) WorldStage

NewTransactionStage returns a stage over a write transaction's storage. The transaction adopts the build when it commits, after the caller would release a stage, so writes go through the transaction's own storage and Release does nothing.

func OpenStagedCursor

func OpenStagedCursor(ctx context.Context, ws WorldState, ref *bucket.ObjectRef) (*bucket_lookup.Cursor, WorldStage, error)

OpenStagedCursor opens storage for building through ws with OpenWorldStorage and returns a cursor at ref with the stage that owns its writes. Releasing the stage releases the cursor first; release it after the build is adopted or abandoned.

func OpenWorldStorage

func OpenWorldStorage(ctx context.Context, ws WorldState) (WorldStage, error)

OpenWorldStorage opens storage for building through ws. A writable ws opens a stage that owns the build; a read-only ws returns its own storage, so reads work and writes fail. Release the result after the build is adopted or abandoned.

type WorldState

type WorldState interface {
	// GetReadOnly returns if the state is read-only.
	GetReadOnly() bool

	// Sync fences the block writes made through this state durable.
	// Returns true if a durability fence was applied, false if the underlying
	// store is always-durable. Advancing the durable head is the Engine's
	// responsibility (see Engine.Sync); a bare WorldState only fences blocks.
	Sync(ctx context.Context) (bool, error)

	// ListObjectsWithType returns distinct typed keys in graph-index order,
	// strictly after startAfter. Limit must be non-zero; more marks another page.
	// The World must remain unchanged for exactly-once traversal across pages.
	ListObjectsWithType(ctx context.Context, typeID, startAfter string, limit uint32) ([]string, bool, error)

	// WorldStorage accesses the world storage.
	WorldStorage

	// StageWorldState opens a staging scope for writes outside a transaction.
	// Build through the stage, adopt the result through this state, then
	// release the stage after the adopting call returns. An engine-level state
	// opens an engine stage. A write transaction adopts the build only when it
	// commits, after the adopting call returns, so its stage writes through the
	// transaction's own storage and Release does nothing. A read-only state
	// returns tx.ErrNotWrite.
	StageWorldState(ctx context.Context) (WorldStage, error)

	// WorldStateObject contains the object APIs.
	WorldStateObject
	// WorldStateGraph contains the graph APIs.
	WorldStateGraph
	// WorldStateOp contains the operation APIs.
	WorldStateOp

	// WorldWaitSeqno waits for the world state to change.
	WorldWaitSeqno
}

WorldState is the state read/write operations interface.

func NewEngineWorldState

func NewEngineWorldState(e Engine, write bool) WorldState

NewEngineWorldState constructs a WorldState with an Engine.

type WorldStateGraph

type WorldStateGraph interface {
	// AccessCayleyGraph calls a callback with a temporary Cayley graph handle.
	// All accesses of the handle should complete before returning cb.
	// Try to make access (queries) as short as possible.
	// Write operations will fail if the store is read-only.
	// Remote WorldState implementations may reject this local-only Cayley handle
	// access; use QueryGraphPath or exact graph lookup for remote traversal.
	AccessCayleyGraph(ctx context.Context, write bool, cb func(ctx context.Context, h CayleyHandle) error) error

	// LookupGraphQuads searches for graph quads in the store.
	// If the filter fields are empty, matches any for that field.
	// If not found, returns nil, nil
	// If limit is set, stops after finding that number of matching quads.
	LookupGraphQuads(ctx context.Context, filter GraphQuad, limit uint32) ([]GraphQuad, error)

	// LookupGraphQuadsBatch searches for graph quads for each filter in one
	// World graph read operation. Each result set preserves the corresponding
	// filter index and applies the limit independently.
	LookupGraphQuadsBatch(ctx context.Context, filters []GraphQuad, limitPerFilter uint32) ([][]GraphQuad, error)

	// QueryGraphPath executes a bounded graph traversal without exposing a Cayley handle.
	QueryGraphPath(ctx context.Context, query *GraphPathQuery) (*GraphPathQueryResult, error)

	// SetGraphQuad sets a quad in the graph store.
	// Subject: must be an existing object IRI: <object-key>
	// Predicate: a predicate string, e.x. IRI: <ref>
	// Object: an existing object IRI: <object-key>
	// If already exists, returns nil.
	SetGraphQuad(ctx context.Context, q GraphQuad) error

	// DeleteGraphQuad deletes a quad from the graph store.
	// Note: if quad did not exist, returns nil.
	DeleteGraphQuad(ctx context.Context, q GraphQuad) error

	// DeleteGraphObject deletes all quads with Subject or Object set to value.
	// Note: value should be the object key, NOT the object key <iri> format.
	DeleteGraphObject(ctx context.Context, value string) error
}

WorldStateGraph contains the graph APIs on WorldState.

type WorldStateObject

type WorldStateObject interface {
	// GetObject looks up an object by key.
	// Returns nil, false if not found.
	GetObject(ctx context.Context, key string) (ObjectState, bool, error)

	// IterateObjects returns an iterator with the given object key prefix.
	// The prefix is NOT clipped from the output keys.
	// Keys are returned in sorted order.
	// Must call Next() or Seek() before valid.
	// Call Close when done with the iterator.
	// Any init errors will be available via the iterator's Err() method.
	IterateObjects(ctx context.Context, prefix string, reversed bool) ObjectIterator

	// CreateObject creates a object with a key and initial root ref.
	// Returns ErrObjectExists if the object already exists.
	// Appends a OBJECT_SET change to the changelog.
	CreateObject(ctx context.Context, key string, rootRef *bucket.ObjectRef) (ObjectState, error)

	// RenameObject renames an object key and updates associated graph quads.
	// If descendants is true, all objects under oldKey + "/" are renamed
	// to the matching newKey + "/" prefix in the same operation.
	// Returns ErrObjectNotFound if the old object key does not exist.
	// Returns ErrObjectExists if the new object key already exists.
	RenameObject(ctx context.Context, oldKey, newKey string, descendants bool) (ObjectState, error)

	// DeleteObject deletes an object and associated graph quads by ID.
	// Calls DeleteGraphObject internally.
	// Returns false, nil if not found.
	DeleteObject(ctx context.Context, key string) (bool, error)

	// HasObject reports whether an object exists at key. Implementations may
	// answer from transaction-local knowledge without a storage read; on a miss
	// they fall back to the underlying object lookup.
	HasObject(ctx context.Context, key string) (bool, error)
}

WorldStateObject contains the object APIs on WorldState.

type WorldStateOp

type WorldStateOp interface {
	// ApplyWorldOp applies a batch operation at the world level.
	// The handling of the operation is operation-type specific.
	// Returns the seqno following the operation execution.
	// If nil is returned for the error, implies success.
	// If sysErr is set, the error is treated as a transient system error.
	// Must support recursive calls to ApplyWorldOp / ApplyObjectOp.
	// Returns seqno, sysErr, err.
	ApplyWorldOp(
		ctx context.Context,
		op Operation,
		opSender peer.ID,
	) (seqno uint64, sysErr bool, err error)
}

WorldStateOp contains the operation APIs on WorldState.

type WorldStorage

type WorldStorage interface {
	// BuildStorageCursor builds a cursor to the world storage with an empty ref.
	// The cursor should be released independently of the WorldState.
	// Be sure to call Release on the cursor when done.
	BuildStorageCursor(ctx context.Context) (*bucket_lookup.Cursor, error)

	// AccessWorldState builds a bucket lookup cursor with an optional ref.
	// If the ref is empty, returns a cursor pointing to the root world state.
	// The lookup cursor will be released after cb returns.
	AccessWorldState(
		ctx context.Context,
		ref *bucket.ObjectRef,
		cb func(*bucket_lookup.Cursor) error,
	) error
}

WorldStorage allows accessing the world storage via bucket lookup.

func NewCursorWorldStorage

func NewCursorWorldStorage(buildCursor BuildCursorFn) WorldStorage

NewCursorWorldStorage constructs a WorldStorage from a object cursor.

func NewWorldStorageFromCursor

func NewWorldStorageFromCursor(cursor *bucket_lookup.Cursor) WorldStorage

NewWorldStorageFromCursor builds a WorldStorage from an existing cursor.

type WorldWaitSeqno

type WorldWaitSeqno interface {
	// GetSeqno returns the current seqno of the world state.
	// This is also the sequence number of the most recent change.
	// Initializes at 0 for initial world state.
	GetSeqno(ctx context.Context) (uint64, error)

	// WaitSeqno waits for the seqno of the world state to be >= value.
	// Returns the seqno when the condition is reached.
	// If value == 0, this might return immediately unconditionally.
	WaitSeqno(ctx context.Context, value uint64) (uint64, error)
}

WorldWaitSeqno allows readers to wait for a minimum state sequence number.

Directories

Path Synopsis
tx

Jump to

Keyboard shortcuts

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