Lockstep.Global (Lockstep v0.1.0)

Copy Markdown View Source

Cluster-wide name registry, mirror of Erlang's :global.

Phase C semantics (simplified)

  • Single shared name table maintained at the controller level
  • register_name(name, pid) succeeds globally if name is free, returns :no otherwise
  • whereis_name(name) returns the pid (or :undefined)
  • No two-phase commit, no name conflict resolution after partition heal -- if two partitioned sides could each register the same name independently, that case isn't modeled here
  • Cross-node whereis_name works during partition (same shared table)

Real :global does much more (sync protocol, conflict callbacks, atomic register-or-fail across nodes). The simplified version covers the most common usage: one process registers a name, others look it up. If you need split-brain semantics, build them on top of Lockstep.Cluster.partition.

Implementation

Backed directly by a cluster-wide table inside the Lockstep.Controller (no per-node namespacing, no auxiliary gen_server). Names are auto-cleared when the registered pid dies.

Rewriter integration

Lockstep.Rewriter rewrites :global.{register_name, unregister_name, whereis_name, sync, send, registered_names} to the corresponding Lockstep.Global.* calls.

Summary

Functions

Register pid under cluster-wide name. Returns :yes on success, :no if the name is already taken or pid already owns another name.

Names currently registered globally.

Send msg to the pid registered as name. Raises if no such name. Mirrors :global.send/2.

Synchronize the global name table -- a no-op in this simplified model since the single controller-side table is always consistent. Provided for source compatibility with real :global.

Unregister name. Returns the freed name.

Return the pid registered under name, or :undefined.

Functions

register_name(name, pid)

@spec register_name(any(), pid()) :: :yes | :no

Register pid under cluster-wide name. Returns :yes on success, :no if the name is already taken or pid already owns another name.

registered_names()

@spec registered_names() :: [any()]

Names currently registered globally.

send(name, msg)

@spec send(any(), any()) :: pid()

Send msg to the pid registered as name. Raises if no such name. Mirrors :global.send/2.

sync()

@spec sync() :: :ok

Synchronize the global name table -- a no-op in this simplified model since the single controller-side table is always consistent. Provided for source compatibility with real :global.

unregister_name(name)

@spec unregister_name(any()) :: any()

Unregister name. Returns the freed name.

whereis_name(name)

@spec whereis_name(any()) :: pid() | :undefined

Return the pid registered under name, or :undefined.