Lockstep.RPC (Lockstep v0.1.0)

Copy Markdown View Source

Mirror of Erlang's :rpc module under Lockstep's controlled scheduling. Cross-node apply/4-style calls are modeled by spawning a process on the target node, having it execute the function, and shipping the result back to the caller via a Lockstep-controlled message.

Partition-aware: if the caller's node and the target are in opposing partition groups, the spawn message itself is dropped or deferred (per partition mode). Calls in :drop partitions error with {:badrpc, :nodedown}-equivalent semantics; in :defer partitions they hang until heal (and then complete).

Supported

  • call/4,5 -- synchronous remote call
  • multicall/4,5 -- call same function on a list of nodes, gather successes and failures
  • cast/4 -- fire-and-forget remote call
  • abcast/2,3 -- async broadcast a message to a registered atom name on every node

Summary

Functions

Single-arity abcast: broadcasts to all known nodes.

Async-broadcast msg to a registered atom name on every node in nodes. Mirrors :rpc.abcast/3.

Synchronous call: invoke apply(module, fun, args) on node, return its result.

Fire-and-forget call: apply(module, fun, args) on node with no reply. Returns true (matching :rpc.cast/4's contract).

Call apply(module, fun, args) on each node in nodes. Returns {successes, bad_nodes} where successes is the list of return values (in node order) and bad_nodes is a list of nodes that errored or timed out.

Functions

abcast(name, msg)

@spec abcast(atom(), any()) :: :abcast

Single-arity abcast: broadcasts to all known nodes.

abcast(nodes, name, msg)

@spec abcast([atom()], atom(), any()) :: :abcast

Async-broadcast msg to a registered atom name on every node in nodes. Mirrors :rpc.abcast/3.

call(node, module, fun, args, timeout \\ 5000)

@spec call(atom(), module(), atom(), [any()], timeout()) :: any()

Synchronous call: invoke apply(module, fun, args) on node, return its result.

Returns the function's value, or {:badrpc, reason} on failure (timeout, unreachable node, etc.) -- mirroring :rpc.call/4-5.

cast(node, module, fun, args)

@spec cast(atom(), module(), atom(), [any()]) :: true

Fire-and-forget call: apply(module, fun, args) on node with no reply. Returns true (matching :rpc.cast/4's contract).

multicall(nodes, module, fun, args, timeout \\ 5000)

@spec multicall([atom()], module(), atom(), [any()], timeout()) :: {[any()], [atom()]}

Call apply(module, fun, args) on each node in nodes. Returns {successes, bad_nodes} where successes is the list of return values (in node order) and bad_nodes is a list of nodes that errored or timed out.