swarm v1.1.3 Swarm.Tracker

This module implements the distributed tracker for process registrations and groups. It is implemented as an OTP special process, so it behaves like a GenServer, but it is actually implemented directly with :proc_lib and :sys.

Each node Swarm runs on will have a single instance of this process, and the trackers will replicate data between each other, and/or forward requests to remote trackers as necessary.

The tracker itself is a finite state machine, where each top-level state kicks off a smaller, more restricted state machine, which both handles it’s sub-states, and enables us to respond to certain critical calls from other trackers without blocking, or in the case of events where the two trackers are blocking on calls to each other, without deadlocking.

Summary

Functions

Adds some metadata to the given process (pid). This is primarily used for tracking group membership

Removes metadata from the given process (pid)

Tracks a process (pid) with the given name. Tracking processes with this function will not restart the process when it’s parent node goes down, or shift the process to other nodes if the cluster topology changes. It is strictly for global name registration

Tracks a process created via the provided module/function/args with the given name. The process will be distributed on the cluster based on the hash of it’s name on the hash ring. If the process’s parent node goes down, it will be restarted on the new node which own’s it’s keyspace. If the cluster topology changes, and the owner of it’s keyspace changes, it will be shifted to the new owner, after initiating the handoff process as described in the documentation

Stops tracking the given process (pid)

Functions

add_meta(key, value, pid)

Adds some metadata to the given process (pid). This is primarily used for tracking group membership.

init(parent)
remove_meta(key, pid)

Removes metadata from the given process (pid).

start_link()
system_code_change(misc, module, old, extra)
system_continue(parent, debug, arg)
system_get_state(arg)
system_replace_state(state_fun, arg)
system_terminate(reason, arg2, debug, state)
track(name, pid)

Tracks a process (pid) with the given name. Tracking processes with this function will not restart the process when it’s parent node goes down, or shift the process to other nodes if the cluster topology changes. It is strictly for global name registration.

track(name, m, f, a)

Tracks a process created via the provided module/function/args with the given name. The process will be distributed on the cluster based on the hash of it’s name on the hash ring. If the process’s parent node goes down, it will be restarted on the new node which own’s it’s keyspace. If the cluster topology changes, and the owner of it’s keyspace changes, it will be shifted to the new owner, after initiating the handoff process as described in the documentation.

untrack(pid)

Stops tracking the given process (pid)