Documentation
¶
Index ¶
- Variables
- func AccessObject(ctx context.Context, access AccessWorldStateFunc, ref *bucket.ObjectRef, ...) (*bucket.ObjectRef, error)
- func AccessObjectState(ctx context.Context, obj ObjectState, updateWorld bool, cb AccessObjectCb) (*bucket.ObjectRef, bool, error)
- func AccessWorldObject(ctx context.Context, ws WorldState, objKey string, updateWorld bool, ...) (*bucket.ObjectRef, bool, error)
- func ApplyGraphDeltas(ctx context.Context, ws WorldStateGraph, deltas []graph.Delta) error
- func AssertObjectRev(ctx context.Context, obj ObjectState, expected uint64) error
- func CheckQuadExists(ctx context.Context, h CayleyHandle, gq quad.Quad) (bool, error)
- func CollectPathWithKeys(ctx context.Context, ws WorldStateGraph, entityKeys []string, ...) ([]string, error)
- func ExecTransaction(ctx context.Context, eng Engine, write bool, ...) error
- func FilterIterateQuads(ctx context.Context, h CayleyHandle, gq quad.Quad, cb func(q quad.Quad) error) error
- func GraphEnsureIsIRI(val string) (quad.IRI, error)
- func GraphQuadStringToCayleyValue(s string) quad.Value
- func GraphQuadToCayleyQuad(q GraphQuad, check bool) (quad.Quad, error)
- func GraphQuadToQuad(gq GraphQuad) *bquad.Quad
- func GraphValueToKey(gv string) (string, error)
- func GraphValueToString(gv quad.Value) string
- func IterateFilteredFullQuads(ctx context.Context, h CayleyHandle, filter quad.Quad, ...) error
- func IterateFullQuads(ctx context.Context, h CayleyHandle, sh shape.Shape, ...) error
- func IteratePathWithKeys(ctx context.Context, ws WorldStateGraph, entityKeys []string, ...) error
- func KeyToGraphValue(key string) quad.Value
- func LookupObjectRef[T block.Block](ctx context.Context, access AccessWorldStateFunc, ref *bucket.ObjectRef, ...) (out T, err error)
- func LookupRootRef(ctx context.Context, eng Engine, key string) (*bucket.ObjectRef, uint64, error)
- func NewEngineObjectIterator(ctx context.Context, e Engine, prefix string, reversed bool) *engineObjectIterator
- func NewLookupWorldOpResolver(lookupOp LookupOp) directive.Resolver
- func QuadEqual(q1, q2 quad.Quad) bool
- func QuadValueToKey(gv quad.Value) (string, error)
- func ValidateCayleyQuad(q quad.Quad) error
- func ValidateGraphQuad(q GraphQuad) error
- type AccessObjectCb
- type AccessWorldStateFunc
- type BuildCursorFn
- type BusEngine
- type CayleyHandle
- type Controller
- type Engine
- type EngineResolver
- type ForkableWorldState
- type GraphQuad
- type LookupOp
- type LookupOpController
- type LookupOpSlice
- type LookupWorldEngine
- type LookupWorldEngineValue
- type LookupWorldOp
- type LookupWorldOpValue
- type ObjectIterator
- type ObjectState
- func CollectObjectBodies[T block.Block](ctx context.Context, ws WorldState, objKeys []string, ctor func() block.Block) ([]T, []ObjectState, error)
- func CreateWorldObject(ctx context.Context, ws WorldState, objKey string, cb AccessObjectCb) (ObjectState, *bucket.ObjectRef, error)
- func LookupObject[T block.Block](ctx context.Context, ws WorldState, objKey string, ctor func() block.Block) (out T, objRef ObjectState, err error)
- func MustGetObject(ctx context.Context, w WorldStateObject, key string) (ObjectState, error)
- type Operation
- type RefCountEngine
- func (e *RefCountEngine) AccessWorldState(ctx context.Context, ref *bucket.ObjectRef, ...) error
- func (e *RefCountEngine) BuildStorageCursor(ctx context.Context) (*bucket_lookup.Cursor, error)
- func (e *RefCountEngine) ClearContext()
- func (e *RefCountEngine) GetSeqno(ctx context.Context) (uint64, error)
- func (e *RefCountEngine) NewTransaction(ctx context.Context, write bool) (Tx, error)
- func (e *RefCountEngine) SetContext(ctx context.Context)
- func (e *RefCountEngine) WaitSeqno(ctx context.Context, value uint64) (uint64, error)
- type RefCountTx
- type Tx
- type WorldEngineResolver
- type WorldState
- type WorldStateGraph
- type WorldStateObject
- type WorldStateOp
- type WorldStorage
- type WorldWaitSeqno
Constants ¶
This section is empty.
Variables ¶
var ( // does not implement looking up the world state at a given seqno. ErrHistoryUnavailable = errors.New("world history not available") 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") // 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") )
var LookupOpControllerVersion = semver.MustParse("0.0.1")
LookupOpControllerVersion is the version of the LookupOpController.
Functions ¶
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 accesses and updates a world object handle if updateWorld is set. 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 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, the object will be created. 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 ApplyGraphDeltas ¶
ApplyGraphDeltas applies a set of graph deltas to a WorldStateGraph
func AssertObjectRev ¶
func AssertObjectRev(ctx context.Context, obj ObjectState, expected uint64) error
AssertObjectRev asserts that an object is at a given rev.
func CheckQuadExists ¶
CheckQuadExists checks if the quad exists on the graph handle.
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 executes a transaction inside a function callback.
If a write transaction, calls Commit if the callback return nil. Otherwise, discards the transaction.
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 GraphEnsureIsIRI ¶
GraphEnsureIsIRI confirms that a string is an IRI.
func GraphQuadStringToCayleyValue ¶
GraphQuadStringToCayleyValue converts a graph quad string to a quad.Value
func GraphQuadToCayleyQuad ¶
GraphQuadToCayleyQuad converts a graph quad to a cayley quad.
func GraphQuadToQuad ¶
GraphQuadToQuad constructs a new Quad object.
func GraphValueToKey ¶
GraphValueToKey attempts to convert a graph value to a quad.IRI and then string. use with GraphQuadStringToCayleyValue
func GraphValueToString ¶
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 ¶
KeyToGraphValue is the string representation of the key for a graph IRI.
func LookupObjectRef ¶
func LookupObjectRef[T block.Block]( ctx context.Context, access AccessWorldStateFunc, ref *bucket.ObjectRef, ctor func() block.Block, ) (out T, err error)
LookupObjectRef looks up & unmarshals an object ref from the world.
func LookupRootRef ¶
LookupRootRef gets an object and returns its root reference and rev.
If not found, returns nil, 0, nil.
func NewEngineObjectIterator ¶
func NewEngineObjectIterator( ctx context.Context, e Engine, prefix string, reversed bool, ) *engineObjectIterator
NewEngineObjectIterator constructs a new engine object iterator.
func NewLookupWorldOpResolver ¶
NewLookupWorldOpResolver constructs a new resolver with a static lookup func list.
func QuadValueToKey ¶
QuadValueToKey attempts to convert a graph value to a quad.IRI and then string. use with GraphQuadStringToCayleyValue
func ValidateCayleyQuad ¶
ValidateCayleyQuad checks a cayley quad for validity.
func ValidateGraphQuad ¶
ValidateGraphQuad checks a graph quad for validity.
Types ¶
type AccessObjectCb ¶
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 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.
type CayleyHandle ¶
CayleyHandle is a cayley graph handle. Note: QuadWriter is not included, writes must be done with WorldStateGraph.
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 {
// 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.
NewTransaction(ctx context.Context, write bool) (Tx, error)
// WorldStorage provides access to the world storage via bucket cursors.
WorldStorage
// WorldWaitSeqno allows waiting for the world seqno to change.
WorldWaitSeqno
}
Engine implements a transactional world state container.
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 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.
// (empty in most cases)
GetLabel() string
}
GraphQuad is the common graph entry interface.
func CayleyQuadToGraphQuad ¶
CayleyQuadToGraphQuad converts a cayley quad into a graph quad.
func NewGraphQuad ¶
NewGraphQuad constructs a new in-memory GraphQuad.
func NewGraphQuadWithKeys ¶
NewGraphQuadWithKeys creates a new graph quad from object keys.
func QuadToGraphQuad ¶
QuadToGraphQuad converts quad into a graph quad.
type LookupOp ¶
LookupOp looks up an operation type for a op type id.
returns nil, nil if not found.
func BuildLookupWorldOpFunc ¶
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.
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.
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 nil 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 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 block.Block]( ctx context.Context, ws WorldState, objKeys []string, ctor func() block.Block, ) ([]T, []ObjectState, error)
CollectObjectBodies looks up and unmarshals the objects with the given keys.
ctor must return an object of type T returns two slices of length objKeys if any objects are not found, returns nil for that object state / value and objs, objsStates, ErrNotFound 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 block.Block]( ctx context.Context, ws WorldState, objKey string, ctor func() block.Block, ) (out T, 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
// Validate performs cursory validation of the operation.
// Should not block.
Validate() error
// GetOperationTypeId returns the operation type identifier.
GetOperationTypeId() string
// ApplyWorldOp applies the operation as a world operation.
// 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)
// ApplyWorldObjectOp applies the operation to a world object handle.
// returns false, ErrUnhandledOp if the operation cannot handle a object op
ApplyWorldObjectOp(
ctx context.Context,
le *logrus.Entry,
objectHandle ObjectState,
sender peer.ID,
) (sysErr bool, err error)
}
Operation is a batch operation against World or Object.
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 ¶
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.
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.
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.
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 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 ¶
func (r *WorldEngineResolver) Resolve(ctx context.Context, handler directive.ResolverHandler) error
Resolve resolves the values, emitting them to the handler.
type WorldState ¶
type WorldState interface {
// GetReadOnly returns if the state is read-only.
GetReadOnly() bool
// WorldStorage accesses the world storage.
WorldStorage
// 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.
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)
// 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)
}
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.
Source Files
¶
- bus-engine.go
- controller.go
- dir-lookup-world-engine.go
- dir-lookup-world-op.go
- engine-iterator.go
- engine-state-object.go
- engine-state.go
- engine.go
- errors.go
- ex-lookup-world-engine.go
- ex-lookup-world-op.go
- graph-quad.go
- graph-util.go
- lookup-op-controller.go
- object-state.go
- operation.go
- refcount-engine.go
- refcount-tx.go
- res-lookup-world-engine.go
- res-lookup-world-op.go
- tx.go
- util.go
- world-state.go
- world-storage.go