Documentation
¶
Overview ¶
Package grpcproc gives goroutines Erlang-style network transparency on top of the gRPC server a service already runs. A process is addressed by a PID or a name; Send, Call, Monitor, Link and Exit work the same whether the target lives in this binary or on another node.
Index ¶
- Constants
- Variables
- func WithMetadata(ctx context.Context, md Metadata) context.Context
- type Addr
- type Config
- type Done
- type Down
- type Event
- type EventKind
- type ExitError
- type Exited
- type Hooks
- type LinkError
- type LinkInfo
- type LinkState
- type MailboxInfo
- type Member
- type MemberEvent
- type Membership
- type Metadata
- type Msg
- type Name
- type Node
- func (n *Node) Call[R, N proto.Message](ctx context.Context, to Addr[N], req N) (R, error)
- func (n *Node) CallTo[R proto.Message](ctx context.Context, to Target, req proto.Message) (R, error)
- func (n *Node) Disconnect(peer string) bool
- func (n *Node) Exit(ctx context.Context, to Target, reason string) error
- func (n *Node) ID() NodeID
- func (n *Node) Info() NodeInfo
- func (n *Node) Inspect(ctx context.Context, pid PID) (map[string]string, error)
- func (n *Node) Name() string
- func (n *Node) PID() PID
- func (n *Node) Peers() []string
- func (n *Node) Process(pid PID) (ProcessInfo, bool)
- func (n *Node) Processes() []ProcessInfo
- func (n *Node) Register(s grpc.ServiceRegistrar)
- func (n *Node) Send[N proto.Message](ctx context.Context, to Addr[N], m N) error
- func (n *Node) SendTo(ctx context.Context, to Target, m proto.Message) error
- func (n *Node) SetLogLevel(pid PID, level slog.Level) error
- func (n *Node) Spawn[M proto.Message](fn func(*Process[M]) error, opts ...SpawnOption) (Addr[M], error)
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Stop(ctx context.Context) error
- func (n *Node) Subscribe(ctx context.Context, buffer int) <-chan Event
- func (n *Node) Whereis(name string) (PID, bool)
- type NodeID
- type NodeInfo
- type NopHooks
- func (NopHooks) OnDeadLetter(PID, PID, proto.Message, string)
- func (NopHooks) OnExit(ProcessInfo, string)
- func (NopHooks) OnLinkDown(NodeID, error)
- func (NopHooks) OnLinkUp(NodeID)
- func (NopHooks) OnReceive(_ ReceiveInfo, md Metadata) (Metadata, Done)
- func (NopHooks) OnSend(_ SendInfo, md Metadata) (Metadata, Done)
- func (NopHooks) OnSpawn(ProcessInfo)
- type PID
- type Process
- func (p *Process[M]) Addr() Addr[M]
- func (p *Process[M]) Call[R, N proto.Message](ctx context.Context, to Addr[N], req N) (R, error)
- func (p *Process[M]) CallTo[R proto.Message](ctx context.Context, to Target, req proto.Message) (R, error)
- func (p Process) Context() context.Context
- func (p Process) Demonitor(ref Ref)
- func (p Process) Exit(to Target, reason string) error
- func (p Process) Link(target Target)
- func (p Process) Log() *slog.Logger
- func (p Process) Monitor(target Target) Ref
- func (p Process) Node() *Node
- func (p Process) PID() PID
- func (p Process) Parent() PID
- func (p *Process[M]) Receive() (Msg[M], error)
- func (p *Process[M]) ReceiveTimeout(d time.Duration) (Msg[M], error)
- func (*Process[M]) Reply(m Msg[M], resp proto.Message, err error) error
- func (p *Process[M]) Send[N proto.Message](to Addr[N], m N) error
- func (p *Process[M]) SendAfter[N proto.Message](d time.Duration, to Addr[N], m N) *Timer
- func (p Process) SendTo(to Target, msg proto.Message) error
- func (p Process) SetTrapExit(trap bool)
- func (p *Process[M]) Spawn[N proto.Message](fn func(*Process[N]) error, opts ...SpawnOption) (Addr[N], error)
- func (p *Process[M]) SpawnMonitor[N proto.Message](fn func(*Process[N]) error, opts ...SpawnOption) (Addr[N], Ref, error)
- func (p Process) TrapExit() bool
- func (p Process) Unlink(target Target)
- type ProcessInfo
- type ProcessState
- type ReceiveInfo
- type Ref
- type Registrar
- type RemoteError
- type Resolver
- type ResolverFunc
- type SendInfo
- type SpawnOption
- type StaticResolver
- type Target
- type Timer
Constants ¶
const ( ReasonNormal = "normal" ReasonNoProc = "noproc" ReasonNoConnection = "noconnection" ReasonShutdown = "shutdown" ReasonKilled = "killed" ReasonType = "type" )
Exit reasons used by grpcproc itself. Applications use any string.
Variables ¶
var ( ErrNoProc = errors.New("grpcproc: no such process") ErrNoConnection = errors.New("grpcproc: no connection to node") ErrNameTaken = errors.New("grpcproc: name already registered") ErrNotLocal = errors.New("grpcproc: pid does not belong to this node") ErrNodeStopped = errors.New("grpcproc: node stopped") ErrNotCall = errors.New("grpcproc: message is not a call") ErrType = errors.New("grpcproc: process does not accept this message type") )
Functions ¶
Types ¶
type Addr ¶
Addr is a typed address: a PID or a Name plus the message type M the process behind it accepts. The type is checked at compile time for local and remote sends alike; it is verified again on delivery, because types do not cross the wire.
func AddrOf ¶
AddrOf types an untyped target. Nothing checks that the process behind it really accepts M until a message is delivered.
type Config ¶
type Config struct {
// Name is the node's logical name; peers address it by this.
Name string
// Advertise is the address peers dial to reach this node's gRPC server.
// It is only informational to the core (NodeInfo, Hello); a Registrar
// publishes it.
Advertise string
// Incarnation distinguishes this start of the node from earlier ones,
// and must grow with each start: a peer that has seen an incarnation of
// the node refuses links from older ones, so that an instance that was
// replaced, and still runs, cannot take the links of its replacement.
// The peer refuses them until Membership reports the newer one gone, or
// it calls Disconnect: a random or hashed Incarnation would be refused
// whenever it came out lower than the last one. Zero picks the current
// Unix time in nanoseconds, which grows as long as the clocks of the
// hosts the node starts on agree to within the time between two starts.
Incarnation uint64
// Resolver maps peer names to addresses.
Resolver Resolver
// Registrar, if set, publishes the node on Start and withdraws it on Stop.
Registrar Registrar
// Membership, if set, is watched from Start: a peer that leaves the
// cluster, or comes back as a newer incarnation, has its links dropped,
// which fires Down{noconnection} for monitors across them and fails
// pending calls. An older incarnation reported up is ignored.
Membership Membership
// DialOptions are used for every outbound connection: credentials,
// keepalive, interceptors. Keepalive is what turns a silent partition
// into a link error; set it.
DialOptions []grpc.DialOption
// Authorize, if set, runs for every inbound link with the peer's
// transport credentials in ctx (grpc/peer) and the identity it claims.
Authorize func(ctx context.Context, peer NodeID) error
// Logger defaults to slog.Default().
Logger *slog.Logger
// Hooks is the observability tap; nil means none.
Hooks Hooks
// CopyLocal clones every locally delivered message, so a sender can keep
// mutating what it sent. Off by default: the pointer is shared.
CopyLocal bool
// DialTimeout bounds a dial: resolving the peer, connecting, and the
// handshake. A send that waits for a dial waits at most this long, as
// long as the Resolver and any interceptors in DialOptions honour their
// ctx. Default 5s.
DialTimeout time.Duration
// DialBackoff is the longest a node waits before dialing a peer again
// once dials to it have failed. Meanwhile everything routed to the peer
// fails at once with ErrNoConnection rather than wait for a dial that
// would likely fail too: sends, calls, exits, replies, Downs; a Monitor
// gets Down{noconnection} at once. The first send after the wait dials
// again, and the others keep failing while it does. The first wait is a
// 32nd of DialBackoff, up to a fifth less for jitter. Each further failure
// doubles it, unless the peer was left alone for longer than DialBackoff,
// and a dial that succeeds starts over. A link the peer opens lets the
// next send dial at once, without starting over, since it shows the peer
// is up but not that this node can reach it. Membership reporting the peer
// up (not as an older incarnation than this node has seen), or
// Disconnect, ends the wait. Default 5s; negative dials again at once.
DialBackoff time.Duration
}
Config configures a Node. Name and Resolver are required.
type Done ¶
type Done func(err error)
Done ends what a hook started. For a send it runs once the message is handed to delivery, with the error Send returns; for a call, once the call returns, with its error; for a received message, when the process next calls Receive (nil) or exits (nil if normally, else its reason).
type Down ¶
type Down struct {
Ref Ref
// PID is the process that exited. For a monitor placed by name, when no
// process held the name or its node became unreachable, which process
// it would have been is not known: PID has only its Node, and Name says
// what was monitored.
PID PID
Name string // the registered name, when the monitor was placed by name
Reason string
}
Down is delivered to a watcher when the process it monitors exits, or when that process's node becomes unreachable.
type Event ¶
type Event struct {
Kind EventKind
Time time.Time
Process ProcessInfo
Reason string
Peer NodeID
Err string
From PID
To PID
Type string
// Missed is how many events this subscriber lost, because its buffer
// was full, since the event before this one.
Missed uint64
}
Event is something that happened on a node. Which fields are set depends on Kind:
EventSpawn Process EventExit Process, Reason EventLinkUp Peer EventLinkDown Peer, Err EventDeadLetter From, To, Type (proto full name), Reason
type ExitError ¶
type ExitError struct{ Reason string }
ExitError is the cause of a process's context when it was asked to exit, or a process it is linked to exited.
type Exited ¶ added in v0.0.4
type Exited struct {
// PID is the process that exited. For a link placed by name, when no
// process held the name or its node became unreachable, which process
// it would have been is not known: PID has only its Node, and Name says
// what was linked to.
PID PID
Name string // the registered name, when the link was placed by name
Reason string
}
Exited is what a process that traps exits (see Process.SetTrapExit) receives when a process it is linked to exits, or that process's node becomes unreachable; a process that does not trap exits ends instead. See Process.Link.
type Hooks ¶
type Hooks interface {
OnSpawn(ProcessInfo)
OnExit(info ProcessInfo, reason string)
OnSend(s SendInfo, md Metadata) (Metadata, Done)
OnReceive(r ReceiveInfo, md Metadata) (Metadata, Done)
// OnDeadLetter runs when a message could not be delivered: no such
// process (ReasonNoProc), wrong type (ReasonType), or queued on a link
// that broke before or while writing it (ReasonNoConnection). A message
// that could not be sent at all is not one: its sender gets the error.
// body is nil for a message that could not be decoded.
OnDeadLetter(from, to PID, body proto.Message, reason string)
OnLinkUp(peer NodeID)
OnLinkDown(peer NodeID, err error)
}
Hooks is the single tap for observability. Every method is called synchronously on the goroutine doing the work, so implementations must be cheap and must not call back into the node. Embed NopHooks and override what you need; combine several with JoinHooks.
OnSend and OnReceive return the metadata to use from then on, which is how trace context is propagated: OnSend may add to what leaves, and what OnReceive returns is what the process's own sends inherit while it handles the message. They must not modify md, which may be shared; return a copy to change it.
type LinkError ¶
type LinkError struct {
Peer string
Err error
// Unsent reports that the message never left this node, so sending it
// again cannot deliver it twice: the peer could not be reached, or dials
// to it are backed off. Otherwise it may have been handled: a Call whose
// link broke while it waited for the reply.
Unsent bool
}
LinkError reports that a link to a peer closed or could not open; Err says why.
type LinkInfo ¶
type LinkInfo struct {
Peer NodeID
Outbound bool // this node opened the stream
State LinkState
EstablishedAt time.Time
Reconnects uint64
Messages uint64 // envelopes: messages, calls, replies, monitors, downs
Bytes uint64 // message bodies carried, not counting framing
Queued int // outbound: envelopes waiting to be written
LastError string // why dials to the peer failed; set with RetryAt
// RetryAt is set on an outbound link that is down because dials to the
// peer failed: sends to the peer fail at once until then, and the first
// send after it dials again (Config.DialBackoff). It may be in the past:
// nothing has been sent since, or that dial is under way. Such a link's
// Peer has no Incarnation, which only a dial that succeeds learns.
RetryAt time.Time
}
LinkInfo describes one direction of traffic with a peer.
type MailboxInfo ¶
type MailboxInfo struct {
Depth int
Peak int
// OldestAge is how long the oldest queued message has waited, 0 when
// empty. It is read from when its batch started queueing: exact for the
// first message of a burst, an upper bound for later ones.
OldestAge time.Duration
}
MailboxInfo is a snapshot of a mailbox.
type Member ¶
type Member struct {
Name string
Incarnation uint64
Addr string // where peers dial it: its Config.Advertise
}
Member is one incarnation of a node, as the cluster knows it.
type MemberEvent ¶
MemberEvent is a member joining (Up) or leaving the cluster. A leaving member with Incarnation 0 means whichever incarnation it was; a joining one, an incarnation not known.
type Membership ¶
type Membership interface {
// Watch reports members joining and leaving until ctx is done, then
// closes the channel.
Watch(ctx context.Context) (<-chan MemberEvent, error)
}
Membership is the cluster's authoritative view of which nodes are alive. Links notice a dead peer by themselves, but only as fast as keepalive allows and not at all behind a half-open connection; Membership (an etcd lease expiring, say) settles it.
type Metadata ¶
Metadata is propagated with every message, unchanged by grpcproc: trace context, tenant, anything the application's interceptors would carry.
func MetadataFrom ¶
MetadataFrom returns the metadata carried by ctx, or nil.
type Msg ¶
type Msg[M proto.Message] struct { From PID Body M Down *Down Exited *Exited Metadata Metadata // contains filtered or unexported fields }
Msg is what Receive returns: a message (Body), a Down or an Exited, one of them only.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node hosts processes and links to peers. It is a plain value the application constructs, registers on its gRPC server, starts and stops.
func (*Node) Call ¶
Call sends req to a typed address and waits for the reply, typed as R:
resp, err := node.Call[*orderspb.Reserved](ctx, addr, &orderspb.Order{…})
A reply of another type is ErrType; a handler error is a *RemoteError; a callee that is gone, or exits before answering, is ErrNoProc; a peer that cannot be reached is a *LinkError, whose Unsent says that req never left. If ctx ends first, Call returns its error, and req may have been handled; a ctx already done sends nothing.
func (*Node) CallTo ¶
func (n *Node) CallTo[R proto.Message](ctx context.Context, to Target, req proto.Message) (R, error)
CallTo is Call to an untyped target.
func (*Node) Disconnect ¶
Disconnect drops every link with peer, as if the network had, and forgets that dials to it failed (Config.DialBackoff) and which incarnation of it this node has seen, so that none is refused (see Config.Incarnation). Monitors across it fire Down{noconnection} and pending calls fail; the next send dials again. It reports whether there was a link to drop.
func (*Node) Exit ¶
Exit asks a process anywhere to terminate with reason. As for Send, ctx bounds only the wait for a connection to a peer this node has no link to yet.
func (*Node) Inspect ¶
Inspect asks a local process what it currently believes: the map its WithInspect function returns, produced on the process's own goroutine between two messages. A process busy in a handler answers when it next calls Receive; ctx bounds the wait, and the error then wraps ctx.Err(). A process that is gone, or exits before answering (its inspect function panicked), is ErrNoProc.
func (*Node) PID ¶
PID is the node's own pseudo-process (ID 0): the sender of messages sent from outside any process.
func (*Node) Process ¶
func (n *Node) Process(pid PID) (ProcessInfo, bool)
Process snapshots one local process.
func (*Node) Processes ¶
func (n *Node) Processes() []ProcessInfo
Processes snapshots every local process, ordered by PID.
func (*Node) Register ¶
func (n *Node) Register(s grpc.ServiceRegistrar)
Register mounts the grpcproc.v1.Node service on s. Call it before the server starts serving.
func (*Node) Send ¶
Send delivers m to a typed address, local or remote, with the node as sender and the metadata carried by ctx. It returns once m is queued; ctx bounds only the wait for a connection to a peer this node has no link to yet, and while dials to the peer are failing it does not wait at all (see Config.DialBackoff). Sending to a process that does not exist is not an error (it is a dead letter); an error means m could not be encoded, the node could not be reached, or ctx ended first.
func (*Node) SendTo ¶
SendTo delivers m to an untyped target: a PID, a Name, or an Addr of another type. The target's type is checked on delivery only.
func (*Node) SetLogLevel ¶
SetLogLevel sets the threshold of a local process's Log() at runtime.
func (*Node) Spawn ¶
func (n *Node) Spawn[M proto.Message](fn func(*Process[M]) error, opts ...SpawnOption) (Addr[M], error)
Spawn starts fn as a process that accepts messages of type M. The process ends when fn returns; nil means exit reason "normal", otherwise the error text is the reason. A panic is recovered, logged with its stack, and becomes reason "panic: …".
M may be a concrete type (one contract per process), an interface the accepted types implement, or proto.Message for an untyped process.
func (*Node) Start ¶
Start watches Membership and publishes the node with its Registrar, when configured. Processes may be spawned before Start and run immediately; Start only makes the node known. ctx bounds it. A call after one that succeeded does nothing; after one that failed, Start tries again; concurrent calls wait for the one in progress; after Stop began, Start fails with ErrNodeStopped.
func (*Node) Stop ¶
Stop asks every process to exit (Receive returns ReasonShutdown), waits for them until ctx is done, then closes every link. Watchers of this node's processes receive Down{shutdown} while the links are still up: every outbound link flushes, and is waited on until its peer ends it, or ctx is done. A dial in flight completes within Config.DialTimeout and its link is discarded; Stop waits for it too, until ctx is done. If ctx cuts any of these waits short, Stop returns its error. The Registrar's withdraw comes last, and gets a second of its own if ctx is done by then.
type NodeInfo ¶
type NodeInfo struct {
ID NodeID
Advertise string
StartedAt time.Time
Processes int
Spawned uint64
Exited uint64
DeadLetters uint64
Links []LinkInfo // ordered by peer name, outbound before inbound
}
NodeInfo is a snapshot of the node.
type NopHooks ¶
type NopHooks struct{}
NopHooks implements Hooks with no-ops, for embedding.
func (NopHooks) OnExit ¶
func (NopHooks) OnExit(ProcessInfo, string)
func (NopHooks) OnLinkDown ¶
func (NopHooks) OnSpawn ¶
func (NopHooks) OnSpawn(ProcessInfo)
type PID ¶
PID identifies a process anywhere in the cluster. It is a plain comparable value that can travel inside messages.
type Process ¶
Process is a goroutine with a mailbox of M and a cluster-wide PID.
func (*Process[M]) Call ¶
Call sends req and waits for the Reply, typed as R:
resp, err := p.Call[*orderspb.Reserved](ctx, addr, &orderspb.Order{…})
Replies do not pass through the mailbox, so calling from inside a process never reorders its messages. Errors are as for Node.Call.
func (*Process[M]) CallTo ¶
func (p *Process[M]) CallTo[R proto.Message](ctx context.Context, to Target, req proto.Message) (R, error)
CallTo is Call to an untyped target, such as a Msg's From.
func (Process) Context ¶
Context is cancelled when the process is asked to exit, a process it is linked to exits, or its node stops. context.Cause is then an *ExitError, or context.Canceled.
func (Process) Demonitor ¶
func (p Process) Demonitor(ref Ref)
Demonitor stops a monitor. A Down already in the mailbox stays there.
func (Process) Exit ¶
Exit asks another process, anywhere, to terminate with reason. A first exit to a node with no link yet waits for the dial as Send does. It is not trapped: a process that traps exits ends all the same.
func (Process) Link ¶ added in v0.0.4
func (p Process) Link(target Target)
Link links p to target, one way: when target exits, p exits too, with target's reason, whatever it is, normal included. If p traps exits (see SetTrapExit), it receives a Msg with Exited set instead. A target that does not exist ends p with noproc, and one whose node cannot be reached, now or later, with noconnection. p's own exit does not affect target, which can link to p for that.
A second link to the same target is the same link. Linking to itself, or from a process that has exited, does nothing.
func (Process) Log ¶
Log returns a logger with the process's pid and label attached. Its threshold can be changed at runtime with Node.SetLogLevel.
func (Process) Monitor ¶
Monitor watches target. When it exits, or its node becomes unreachable, this process receives a Msg with Down set and the returned Ref. Monitoring a process that does not exist yields Down{Reason: "noproc"}.
func (Process) Parent ¶ added in v0.0.4
func (p Process) Parent() PID
Parent returns the process that spawned p with Process.Spawn or SpawnMonitor, or the zero PID.
func (*Process[M]) Receive ¶
Receive blocks until a message, a Down or an Exited arrives, or the process is told to exit. The error is then context.Canceled (node stop) or an *ExitError: after Exit, or the exit of a process it is linked to.
func (*Process[M]) ReceiveTimeout ¶
ReceiveTimeout is Receive with a deadline; context.DeadlineExceeded on timeout.
func (*Process[M]) Reply ¶
Reply answers a message for which IsCall is true. It may be called later, from any goroutine (a deferred reply), and on another process than the one that received m. A call is answered once: a second Reply is dropped, and so is one after the receiving process exited (which answers ErrNoProc) or its node's Stop gave up on it (ErrNodeStopped).
func (*Process[M]) Send ¶
Send delivers m to a typed address, local or remote. It carries the metadata of the message the process is handling. A first send to a node with no link yet waits for the dial, up to Config.DialTimeout, unless dials to it are failing (Config.DialBackoff). See Node.Send.
func (*Process[M]) SendAfter ¶
SendAfter sends m to a typed address after d, as this process. The timer belongs to the process: it is cancelled if the process exits first. The message carries the metadata the process holds now, when it is scheduled, not whatever it is handling when the timer fires.
func (Process) SendTo ¶
SendTo delivers msg to an untyped target such as a Msg's From. The target's type is checked on delivery only.
func (Process) SetTrapExit ¶ added in v0.0.4
func (p Process) SetTrapExit(trap bool)
SetTrapExit sets whether p traps exits: whether the exit of a process it is linked to reaches it as a Msg with Exited set, rather than ending it. It takes effect for exits that arrive from then on. A request to exit, Process.Exit or Node.Exit, is never trapped.
func (*Process[M]) Spawn ¶
func (p *Process[M]) Spawn[N proto.Message](fn func(*Process[N]) error, opts ...SpawnOption) (Addr[N], error)
Spawn starts fn as a process on p's node, like Node.Spawn, with p recorded as its parent. By itself that is for inspection: p does not monitor the child, and neither exits when the other does, unless LinkParent or LinkChild links them. A process that has exited spawns nothing: the error is ErrNoProc.
func (*Process[M]) SpawnMonitor ¶
func (p *Process[M]) SpawnMonitor[N proto.Message](fn func(*Process[N]) error, opts ...SpawnOption) (Addr[N], Ref, error)
SpawnMonitor is Spawn, with the child monitored from p before it runs: however soon the child exits, p receives its Down with the real reason, never noproc. It is Erlang's spawn_monitor, and what a supervisor needs. A process that has exited spawns nothing: the error is ErrNoProc.
type ProcessInfo ¶
type ProcessInfo struct {
PID PID
Name string // WithName; "" for an unnamed process
Label string // WithLabel; the low-cardinality key for metrics
Type string // the Go type of M, for display
Parent PID // the spawning process, for Process.Spawn and SpawnMonitor; zero for Node.Spawn
State ProcessState
StartedAt time.Time
Mailbox MailboxInfo
Received uint64
Sent uint64
CallsInFlight uint32
LastMessage string // proto full name of the last body taken from the mailbox
Monitors int // held by this process
Links int // process links held by this one: whose exits end it, or reach it as an Exited
Watchers int // processes monitoring or linked to this one
Wakeups uint64 // Receive returns
LogLevel slog.Level
TrapExit bool // see Process.SetTrapExit
}
ProcessInfo is a snapshot of one process, the same for local inspection, the Inspector service and any tool built on either.
type ProcessState ¶
type ProcessState uint8
ProcessState is where a process is in its loop.
const ( StateIdle ProcessState = iota // blocked in Receive StateRunning // between Receive calls StateWaitingReply // blocked in Call StateExiting )
func (ProcessState) String ¶
func (s ProcessState) String() string
type ReceiveInfo ¶
type ReceiveInfo struct {
PID PID
Label string
From PID
Body proto.Message // nil for a Down or an Exited
Down *Down
Exited *Exited
Call bool // the sender waits for a Reply
Waited time.Duration
}
ReceiveInfo describes a message a process has just taken from its mailbox.
type Registrar ¶
type Registrar interface {
// Register returns once self is published, and keeps it published
// until withdraw is called. Start calls Register; Stop calls withdraw
// last, after the node's processes have exited and their Down notices
// have reached its peers. An error must leave self unpublished: Start
// may call Register again.
Register(ctx context.Context, self Member) (withdraw func(context.Context) error, err error)
}
Registrar publishes a node to the cluster, so that peers resolve it and Membership reports it.
type RemoteError ¶
type RemoteError struct{ Msg string }
RemoteError is the error a Call handler returned, carried back to the caller.
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string
type Resolver ¶
Resolver turns a node name into an address grpc can dial. Resolve must return once ctx is done: that is what bounds a dial by Config.DialTimeout.
type ResolverFunc ¶
ResolverFunc adapts a function to Resolver.
type SendInfo ¶
type SendInfo struct {
From PID
FromLabel string // "" when sent from outside any process
To PID // To.ID is 0 when the target is a name
ToName string
Body proto.Message
Call bool // a Call, which ends when answered
Remote bool // the target is on another node
}
SendInfo describes a message or call about to leave its sender.
type SpawnOption ¶
type SpawnOption func(*spawnOpts)
SpawnOption configures Node.Spawn, Process.Spawn and Process.SpawnMonitor.
func LinkChild ¶ added in v0.0.4
func LinkChild() SpawnOption
LinkChild links the spawning process to the child, before the child runs: when the child exits, the parent does too, with the child's reason, or receives an Exited if it traps exits. With LinkParent as well, the two are linked both ways, as Erlang's spawn_link does. Node.Spawn refuses it.
func LinkParent ¶ added in v0.0.4
func LinkParent() SpawnOption
LinkParent links the child to the process that spawns it, before the child runs: when the parent exits, the child does too, with the parent's reason, or receives an Exited if it traps exits. See Process.Link. It is for Process.Spawn and SpawnMonitor: Node.Spawn, which has no parent, refuses it.
func WithInspect ¶
func WithInspect(fn func() map[string]string) SpawnOption
WithInspect lets the process publish what it currently believes. fn runs on the process's own goroutine, inside Receive, so it may read the process's state without locking. A panic in fn is the process's own: it exits with reason "panic: …", and Inspect returns ErrNoProc. See Node.Inspect.
func WithLabel ¶
func WithLabel(label string) SpawnOption
WithLabel tags the process with a low-cardinality label, the key metrics aggregate by. Defaults to the type of M.
func WithName ¶
func WithName(name string) SpawnOption
WithName registers the process under name on its node before it runs. The name is held until the process exits; while another process holds it, spawning fails with ErrNameTaken.
type StaticResolver ¶
StaticResolver is a fixed node -> address map.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package actor is optional structure on top of grpcproc processes: a handler loop in the style of gen_server, and supervisors that restart what fails.
|
Package actor is optional structure on top of grpcproc processes: a handler loop in the style of gen_server, and supervisors that restart what fails. |
|
cron
module
|
|
|
etcd
module
|
|
|
Package grpcproctest runs a grpcproc cluster inside one test binary.
|
Package grpcproctest runs a grpcproc cluster inside one test binary. |
|
Package inspect serves grpcproc.inspect.v1.Inspector: a node's processes, links and events over gRPC, for tools and for people.
|
Package inspect serves grpcproc.inspect.v1.Inspector: a node's processes, links and events over gRPC, for tools and for people. |
|
internal
|
|
|
leader
module
|
|
|
otel
module
|
|
|
proto
|
|
|
saga
|
|
|
postgres
module
|
|
|
tools
module
|