Documentation
¶
Overview ¶
Package chasm is a generated GoMock package.
Package chasm is a generated GoMock package.
Package chasm is a generated GoMock package.
Package chasm is a generated GoMock package.
Index ¶
- func NewEntity[C Component, I any, O any](ctx context.Context, key EntityKey, ...) (O, []byte, error)
- func PollComponent[C Component, R []byte | ComponentRef, I any, O any, T any](ctx context.Context, r R, predicateFn func(C, Context, I) (T, bool, error), ...) (O, []byte, error)
- func ReadComponent[C Component, R []byte | ComponentRef, I any, O any](ctx context.Context, r R, readFn func(C, Context, I) (O, error), input I, ...) (O, error)
- func UpdateComponent[C Component, R []byte | ComponentRef, I any, O any](ctx context.Context, r R, updateFn func(C, MutableContext, I) (O, error), ...) (O, []byte, error)
- func UpdateWithNewEntity[C Component, I any, O1 any, O2 any](ctx context.Context, key EntityKey, ...) (O1, O2, []byte, error)
- type BusinessIDConflictPolicy
- type BusinessIDReusePolicy
- type Collection
- type Component
- type ComponentFieldOption
- type ComponentRef
- type Context
- type EntityKey
- type Field
- func NewComponentField[C Component](ctx MutableContext, c C, options ...ComponentFieldOption) *Field[C]
- func NewComponentPointerField[C Component](ctx MutableContext, c C) *Field[C]
- func NewDataField[D proto.Message](ctx MutableContext, d D) *Field[D]
- func NewDataPointerField[D proto.Message](ctx MutableContext, d D) *Field[D]
- type Library
- type LifecycleState
- type MockComponent
- type MockComponentMockRecorder
- type MockLibrary
- type MockLibraryMockRecorder
- type MockNodeBackend
- type MockNodeBackendMockRecorder
- type MockNodePathEncoder
- type MockNodePathEncoderMockRecorder
- type MockTaskHandler
- type MockTaskHandlerMockRecorder
- type MutableContext
- type Node
- func (n *Node) AddTask(component Component, taskAttributes TaskAttributes, task interface{}) error
- func (n *Node) ApplyMutation(mutation NodesMutation) error
- func (n *Node) ApplySnapshot(snapshot NodesSnapshot) error
- func (n *Node) CloseTransactionAsMutation() (*NodesMutation, error)
- func (n *Node) CloseTransactionAsSnapshot() (*NodesSnapshot, error)
- func (n *Node) Component(chasmContext Context, ref ComponentRef) (Component, error)
- func (n *Node) Now(_ Component) time.Time
- func (n *Node) Ref(component Component) (ComponentRef, bool)
- type NodeBackend
- type NodePathEncoder
- type NodesMutation
- type NodesSnapshot
- type OperationIntent
- type PollComponentRequest
- type RegistrableComponent
- type RegistrableComponentOption
- type RegistrableTask
- type RegistrableTaskOption
- type Registry
- type TaskAttributes
- type TaskHandler
- type TransitionOption
- type UnimplementedComponent
- type UnimplementedLibrary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PollComponent ¶
func ReadComponent ¶
func UpdateComponent ¶
func UpdateComponent[C Component, R []byte | ComponentRef, I any, O any]( ctx context.Context, r R, updateFn func(C, MutableContext, I) (O, error), input I, opts ...TransitionOption, ) (O, []byte, error)
TODO:
- consider merge with ReadComponent
- consider remove ComponentRef from the return value and allow components to get the ref in the transition function. There are some caveats there, check the comment of the NewRef method in MutableContext.
func UpdateWithNewEntity ¶
func UpdateWithNewEntity[C Component, I any, O1 any, O2 any]( ctx context.Context, key EntityKey, newFn func(MutableContext, I) (C, O1, error), updateFn func(C, MutableContext, I) (O2, error), input I, opts ...TransitionOption, ) (O1, O2, []byte, error)
Types ¶
type BusinessIDConflictPolicy ¶
type BusinessIDConflictPolicy int
const ( BusinessIDConflictPolicyFail BusinessIDConflictPolicy = iota BusinessIDConflictPolicyTermiateExisting BusinessIDConflictPolicyUseExisting )
type BusinessIDReusePolicy ¶
type BusinessIDReusePolicy int
const ( BusinessIDReusePolicyAllowDuplicate BusinessIDReusePolicy = iota BusinessIDReusePolicyRejectDuplicate )
type Collection ¶
type Component ¶
type Component interface { LifecycleState() LifecycleState // contains filtered or unexported methods }
type ComponentFieldOption ¶
type ComponentFieldOption func(*componentFieldOptions)
func ComponentFieldDetached ¶
func ComponentFieldDetached() ComponentFieldOption
type ComponentRef ¶
type ComponentRef struct { EntityKey // contains filtered or unexported fields }
func DeserializeComponentRef ¶
func DeserializeComponentRef(data []byte) (ComponentRef, error)
func NewComponentRef ¶
func NewComponentRef( entityKey EntityKey, rootComponentType string, ) ComponentRef
In V1, if you don't have a ref, then you can only interact with the top level entity.
func (*ComponentRef) Serialize ¶
func (r *ComponentRef) Serialize() []byte
type Field ¶
type Field[T any] struct { Internal fieldInternal }
This struct needs to be create via reflection but reflection can't set prviate fields...
func NewComponentField ¶
func NewComponentField[C Component]( ctx MutableContext, c C, options ...ComponentFieldOption, ) *Field[C]
func NewComponentPointerField ¶
func NewComponentPointerField[C Component]( ctx MutableContext, c C, ) *Field[C]
func NewDataField ¶
func NewDataField[D proto.Message]( ctx MutableContext, d D, ) *Field[D]
re. Data v.s. Component. Components have behavior and has a lifecycle. while Data doesn't and must be attached to a component.
You can define a component just for storing the data, that may contain other information like ref count etc. most importantly, the framework needs to know when it's safe to delete the data. i.e. the lifecycle of that data component reaches completed.
func NewDataPointerField ¶
func NewDataPointerField[D proto.Message]( ctx MutableContext, d D, ) *Field[D]
type Library ¶
type Library interface { Name() string Components() []*RegistrableComponent Tasks() []*RegistrableTask // contains filtered or unexported methods }
type LifecycleState ¶
type LifecycleState int
Shall it be named ComponentLifecycleState?
const ( LifecycleStateCreated LifecycleState = 1 << iota LifecycleStateRunning // LifecycleStatePaused // <- this can also be a method of the engine: PauseComponent LifecycleStateCompleted LifecycleStateFailed LifecycleStateUnspecified = LifecycleState(0) )
type MockComponent ¶
type MockComponent struct {
// contains filtered or unexported fields
}
MockComponent is a mock of Component interface.
func NewMockComponent ¶
func NewMockComponent(ctrl *gomock.Controller) *MockComponent
NewMockComponent creates a new mock instance.
func (*MockComponent) EXPECT ¶
func (m *MockComponent) EXPECT() *MockComponentMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockComponent) LifecycleState ¶
func (m *MockComponent) LifecycleState() LifecycleState
LifecycleState mocks base method.
type MockComponentMockRecorder ¶
type MockComponentMockRecorder struct {
// contains filtered or unexported fields
}
MockComponentMockRecorder is the mock recorder for MockComponent.
func (*MockComponentMockRecorder) LifecycleState ¶
func (mr *MockComponentMockRecorder) LifecycleState() *gomock.Call
LifecycleState indicates an expected call of LifecycleState.
type MockLibrary ¶
type MockLibrary struct {
// contains filtered or unexported fields
}
MockLibrary is a mock of Library interface.
func NewMockLibrary ¶
func NewMockLibrary(ctrl *gomock.Controller) *MockLibrary
NewMockLibrary creates a new mock instance.
func (*MockLibrary) Components ¶
func (m *MockLibrary) Components() []*RegistrableComponent
Components mocks base method.
func (*MockLibrary) EXPECT ¶
func (m *MockLibrary) EXPECT() *MockLibraryMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockLibrary) Tasks ¶
func (m *MockLibrary) Tasks() []*RegistrableTask
Tasks mocks base method.
type MockLibraryMockRecorder ¶
type MockLibraryMockRecorder struct {
// contains filtered or unexported fields
}
MockLibraryMockRecorder is the mock recorder for MockLibrary.
func (*MockLibraryMockRecorder) Components ¶
func (mr *MockLibraryMockRecorder) Components() *gomock.Call
Components indicates an expected call of Components.
func (*MockLibraryMockRecorder) Name ¶
func (mr *MockLibraryMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
func (*MockLibraryMockRecorder) Tasks ¶
func (mr *MockLibraryMockRecorder) Tasks() *gomock.Call
Tasks indicates an expected call of Tasks.
type MockNodeBackend ¶
type MockNodeBackend struct {
// contains filtered or unexported fields
}
MockNodeBackend is a mock of NodeBackend interface.
func NewMockNodeBackend ¶
func NewMockNodeBackend(ctrl *gomock.Controller) *MockNodeBackend
NewMockNodeBackend creates a new mock instance.
func (*MockNodeBackend) EXPECT ¶
func (m *MockNodeBackend) EXPECT() *MockNodeBackendMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockNodeBackendMockRecorder ¶
type MockNodeBackendMockRecorder struct {
// contains filtered or unexported fields
}
MockNodeBackendMockRecorder is the mock recorder for MockNodeBackend.
type MockNodePathEncoder ¶
type MockNodePathEncoder struct {
// contains filtered or unexported fields
}
MockNodePathEncoder is a mock of NodePathEncoder interface.
func NewMockNodePathEncoder ¶
func NewMockNodePathEncoder(ctrl *gomock.Controller) *MockNodePathEncoder
NewMockNodePathEncoder creates a new mock instance.
func (*MockNodePathEncoder) Decode ¶
func (m *MockNodePathEncoder) Decode(encodedPath string) ([]string, error)
Decode mocks base method.
func (*MockNodePathEncoder) EXPECT ¶
func (m *MockNodePathEncoder) EXPECT() *MockNodePathEncoderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockNodePathEncoderMockRecorder ¶
type MockNodePathEncoderMockRecorder struct {
// contains filtered or unexported fields
}
MockNodePathEncoderMockRecorder is the mock recorder for MockNodePathEncoder.
type MockTaskHandler ¶
MockTaskHandler is a mock of TaskHandler interface.
func NewMockTaskHandler ¶
func NewMockTaskHandler[C any, T any](ctrl *gomock.Controller) *MockTaskHandler[C, T]
NewMockTaskHandler creates a new mock instance.
func (*MockTaskHandler[C, T]) EXPECT ¶
func (m *MockTaskHandler[C, T]) EXPECT() *MockTaskHandlerMockRecorder[C, T]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockTaskHandler[C, T]) Execute ¶
func (m *MockTaskHandler[C, T]) Execute(arg0 context.Context, arg1 ComponentRef, arg2 T) error
Execute mocks base method.
func (*MockTaskHandler[C, T]) Validate ¶
func (m *MockTaskHandler[C, T]) Validate(arg0 Context, arg1 C, arg2 T) error
Validate mocks base method.
type MockTaskHandlerMockRecorder ¶
MockTaskHandlerMockRecorder is the mock recorder for MockTaskHandler.
type MutableContext ¶
type MutableContext interface { Context AddTask(Component, TaskAttributes, any) error }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the in-memory representation of a persisted CHASM node.
Node and all its methods are NOT meant to be used by CHASM component authors. They are exported for use by the CHASM engine and underlying MutableState implementation only.
func NewTree ¶
func NewTree( registry *Registry, persistenceNodes map[string]*persistencespb.ChasmNode, timeSource clock.TimeSource, backend NodeBackend, pathEncoder NodePathEncoder, ) (*Node, error)
NewTree creates a new in-memory CHASM tree from a collection of flattened persistence CHASM nodes.
func (*Node) AddTask ¶
func (n *Node) AddTask( component Component, taskAttributes TaskAttributes, task interface{}, ) error
AddTask implements the CHASM MutableContext interface
func (*Node) ApplyMutation ¶
func (n *Node) ApplyMutation( mutation NodesMutation, ) error
ApplyMutation is used by replication stack to apply node mutations from the source cluster.
func (*Node) ApplySnapshot ¶
func (n *Node) ApplySnapshot( snapshot NodesSnapshot, ) error
ApplySnapshot is used by replication stack to apply node snapshot from the source cluster.
If we simply substituting the entire CHASM tree, we will be forced to close the transaction as snapshot and potentially write extra data to persistence. This method will instead figure out the mutations needed to bring the current tree to the be the same as the snapshot, thus allowing us to close the transaction as mutation.
func (*Node) CloseTransactionAsMutation ¶
func (n *Node) CloseTransactionAsMutation() (*NodesMutation, error)
CloseTransactionAsMutation is used by MutableState to close the transaction and persist mutations into DB.
func (*Node) CloseTransactionAsSnapshot ¶
func (n *Node) CloseTransactionAsSnapshot() (*NodesSnapshot, error)
CloseTransactionAsSnapshot is used by MutableState to close the transaction and persist entire CHASM tree into DB.
func (*Node) Component ¶
func (n *Node) Component( chasmContext Context, ref ComponentRef, ) (Component, error)
Component retrieves a component from the tree rooted at node n using the provided component reference It also performs consistency, access rule, and task validation checks (for task processing requests) before returning the component.
type NodeBackend ¶
type NodeBackend interface { }
NodeBackend is a set of methods needed from MutableState
This is for breaking cycle dependency between this package and service/history/workflow package where MutableState is defined.
type NodePathEncoder ¶
type NodePathEncoder interface { Encode(node *Node, path []string) (string, error) Decode(encodedPath string) ([]string, error) }
NodePathEncoder is an interface for encoding and decoding node paths. Logic outside the chasm package should only work with encoded paths.
type NodesMutation ¶
type NodesMutation struct { UpdatedNodes map[string]*persistencespb.ChasmNode // flattened node path -> chasm node DeletedNodes map[string]struct{} }
NodesMutation is a set of mutations for all nodes rooted at a given node n, including the node n itself.
type NodesSnapshot ¶
type NodesSnapshot struct {
Nodes map[string]*persistencespb.ChasmNode // flattened node path -> chasm node
}
NodesSnapshot is a snapshot for all nodes rooted at a given node n, including the node n itself.
type OperationIntent ¶
type OperationIntent int
const ( OperationIntentProgress OperationIntent = 1 << iota OperationIntentObserve OperationIntentUnspecified = OperationIntent(0) )
type PollComponentRequest ¶
type PollComponentRequest[C Component, I any, O any] struct { Ref ComponentRef PredicateFn func(C, Context, I) bool OperationFn func(C, MutableContext, I) (O, error) Input I }
type RegistrableComponent ¶
type RegistrableComponent struct {
// contains filtered or unexported fields
}
func NewRegistrableComponent ¶
func NewRegistrableComponent[C Component]( componentType string, opts ...RegistrableComponentOption, ) *RegistrableComponent
func (RegistrableComponent) Type ¶
func (rc RegistrableComponent) Type() string
type RegistrableComponentOption ¶
type RegistrableComponentOption func(*RegistrableComponent)
func WithEphemeral ¶
func WithEphemeral() RegistrableComponentOption
func WithShardingFn ¶
func WithShardingFn( shardingFn func(EntityKey) string, ) RegistrableComponentOption
func WithSingleCluster ¶
func WithSingleCluster() RegistrableComponentOption
Is there any use case where we don't want to replicate certain instances of a archetype?
type RegistrableTask ¶
type RegistrableTask struct {
// contains filtered or unexported fields
}
func NewRegistrableTask ¶
func NewRegistrableTask[C any, T any]( taskType string, handler TaskHandler[C, T], opts ...RegistrableTaskOption, ) *RegistrableTask
NOTE: C is not Component but any.
func (RegistrableTask) Type ¶
func (rt RegistrableTask) Type() string
type RegistrableTaskOption ¶
type RegistrableTaskOption func(*RegistrableTask)
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
type TaskAttributes ¶
type TaskHandler ¶
type TransitionOption ¶
type TransitionOption func(*transitionOptions)
func WithBusinessIDPolicy ¶
func WithBusinessIDPolicy( reusePolicy BusinessIDReusePolicy, conflictPolicy BusinessIDConflictPolicy, ) TransitionOption
this only applies to NewEntity and UpdateWithNewEntity
func WithSpeculative ¶
func WithSpeculative() TransitionOption
(only) this transition will not be persisted The next non-speculative transition will persist this transition as well. Compared to the EntityEphemeral() operation on RegistrableComponent, the scope of this operation is limited to a certain transition, while the EntityEphemeral() applies to all transitions. TODO: we need to figure out a way to run the tasks generated in a speculative transition
type UnimplementedComponent ¶
type UnimplementedComponent struct{}
Embed UnimplementedComponent to get forward compatibility
func (UnimplementedComponent) LifecycleState ¶
func (UnimplementedComponent) LifecycleState() LifecycleState
type UnimplementedLibrary ¶
type UnimplementedLibrary struct{}
func (UnimplementedLibrary) Components ¶
func (UnimplementedLibrary) Components() []*RegistrableComponent
func (UnimplementedLibrary) Tasks ¶
func (UnimplementedLibrary) Tasks() []*RegistrableTask