Documentation
¶
Index ¶
- Constants
- Variables
- func CloseGroup(process gen.Process, domain gen.Atom, key string) error
- func CreateApp(options Options) gen.ApplicationBehavior
- func DemonitorAll(process gen.Process, domain gen.Atom) error
- func DemonitorKey(process gen.Process, domain gen.Atom, key string) error
- func DemonitorPrefix(process gen.Process, domain gen.Atom, prefix string) error
- func Dispatch(process gen.Process, domain gen.Atom, key string, message any) error
- func Join(process gen.Process, domain gen.Atom, key string) (gen.Event, error)
- func Leave(process gen.Process, event gen.Event) error
- func LocalRegistryCount(process gen.Process, domain gen.Atom) int
- func Lookup(process gen.Process, domain gen.Atom, key string) (gen.PID, any, bool)
- func MemberCount(process gen.Process, domain gen.Atom, key string) (int, error)
- func MonitorAll(process gen.Process, domain gen.Atom) error
- func MonitorKey(process gen.Process, domain gen.Atom, key string) error
- func MonitorPrefix(process gen.Process, domain gen.Atom, prefix string) error
- func OpenGroup(process gen.Process, domain gen.Atom, key string) error
- func Peers(process gen.Process, domain gen.Atom) ([]gen.Atom, error)
- func Register(process gen.Process, domain gen.Atom, key string, meta any) error
- func RegistryCount(process gen.Process, domain gen.Atom) int
- func Unregister(process gen.Process, domain gen.Atom, key string) error
- type Entry
- type MessageRegistered
- type MessageUnregistered
- type MessageUpdated
- type Options
- type UnregisterReason
Constants ¶
const ( DefaultDomain gen.Atom = "default" DefaultShards int = 8 DefaultSeparator string = "/" )
Variables ¶
var ErrRegistryConflict = errors.New("grid: registry conflict")
ErrRegistryConflict is the exit reason sent to a local owner that lost a registry conflict.
var Version = gen.Version{ Name: "Grid Application", Release: strings.TrimPrefix(strings.TrimSpace(version), "v"), License: gen.LicenseMIT, }
Functions ¶
func CloseGroup ¶
CloseGroup removes the group opened by OpenGroup.
func CreateApp ¶
func CreateApp(options Options) gen.ApplicationBehavior
CreateApp creates the grid application: an AP eventually-consistent distributed in-memory store and registry.
func DemonitorAll ¶
DemonitorAll cancels a MonitorAll subscription.
func DemonitorKey ¶
DemonitorKey cancels a MonitorKey subscription for key.
func DemonitorPrefix ¶
DemonitorPrefix cancels a MonitorPrefix subscription for prefix.
func Dispatch ¶
Dispatch broadcasts message to all members of key's group. It must be called on the owner node, where the group is open.
func Join ¶
Join subscribes the calling process to key's group, which must already be open on the owner. Dispatched messages arrive in HandleEvent as gen.MessageEvent. It returns the joined event; pass it to Leave to unsubscribe. When the owner terminates, the subscription ends with a MessageDownEvent.
func LocalRegistryCount ¶
LocalRegistryCount returns the number of keys owned by the caller's node.
func MemberCount ¶
MemberCount returns the number of members of key's group. It must be called on the owner node.
func MonitorAll ¶
MonitorAll subscribes to every key in the domain.
func MonitorKey ¶
MonitorKey subscribes the calling process to lifecycle events for the exact key. Events arrive as MessageRegistered/MessageUnregistered/MessageUpdated in HandleMessage. On subscribe it first receives MessageRegistered for the key if it is already present. A subscription is identified by its scope: cancel with DemonitorKey. Re-monitoring the same scope is a no-op.
func MonitorPrefix ¶
MonitorPrefix subscribes to every key at or below prefix, split on the domain Separator (default "/"): "a/b" matches "a/b" and "a/b/c" but not "a/bc".
func OpenGroup ¶
OpenGroup opens a group for key on the calling process, which should own key in the registry. Members can then Join and receive Dispatch. The group is removed by CloseGroup or automatically when the owner terminates.
func Peers ¶
Peers returns the peer node names known to the local grid instance of the given domain. Empty domain resolves to DefaultDomain.
func Register ¶
Register registers key under the calling process, owned by its PID. The meta value crosses the wire on replication, so a non-primitive meta type must be EDF-registered by the consumer. Returns gen.ErrTaken if a live owner holds it.
func RegistryCount ¶
RegistryCount returns the number of keys in the caller's local registry view, which converges to the cluster-wide count.
Types ¶
type MessageRegistered ¶
MessageRegistered is delivered to a subscriber when a monitored key is registered.
type MessageUnregistered ¶
type MessageUnregistered struct {
Domain gen.Atom
Key string
Owner gen.PID
Reason UnregisterReason
}
MessageUnregistered is delivered when a monitored key is unregistered. Reason says why (manual unregister, owner down, lost conflict, or peer loss).
type MessageUpdated ¶
MessageUpdated is delivered when a monitored key's meta changes under the same owner.
type Options ¶
type Options struct {
// Domain is the peering domain; a node peers only with grids of the same
// Domain. The Ergo application name is "grid_<Domain>". Default: "default".
Domain gen.Atom
// Shards is the keyspace shard count; all nodes in a domain must agree.
// Default: 8.
Shards int
// Separator is the key hierarchy separator used by MonitorPrefix: a prefix
// matches the key itself and everything below it at a separator boundary, so
// MonitorPrefix("a/b") matches "a/b" and "a/b/c" but not "a/bc". Default: "/".
Separator string
// Peers are optional static seed nodes for discovery without a registrar.
Peers []gen.Atom
}
Options configures a grid application instance.
type UnregisterReason ¶
type UnregisterReason uint8
UnregisterReason says why a key left the registry.
const ( ReasonUnregister UnregisterReason = iota // the owner called Unregister ReasonDown // the owner process terminated ReasonConflict // the owner lost a registry conflict ReasonNodeDown // the owner's node/peer was lost )
func (UnregisterReason) String ¶
func (r UnregisterReason) String() string