gizlang:mesh
which servers of one service are alive, and which of them owns a key. A node listens on a TCP port and, every interval, exchanges its view with each node it knows (and each seed) in one short connection: it sends its own line and reads the live members of the other node. A member not heard of for holdMs is dead. Ownership is rendezvous hashing: each key goes to the live member with the highest hash of (member, key), so a join or a leave moves only the keys of that member. A mesh belongs to the thread that made it; threads of one process share one node, not one mesh each.
import * as Mesh from "gizlang:mesh";Types
Member
type Member = { id: string; host: string; port: i64; meta: string; seen: i64; }One node: its name, the address that other nodes connect to, and meta, a word without spaces that the node tells the others (for example the port of its service). seen is the time (Task.now) it was last heard of.
id:stringhost:stringport:i64meta:stringseen:i64
Mesh
type MeshThe live view of one node.
self:gizlang_mesh.MemberholdMs:i64
Functions
join
function join(sys: System, id: string, host: string, port: i64, meta: string, seeds: Vec<string>, intervalMs: i64, holdMs: i64): Mesh throws IoErrorJoin the mesh as id, listening on host:port (0 picks a port; the Mesh says which). seeds are "host:port" of nodes to find
the others through. The view refreshes every intervalMs; a node silent for holdMs is dead (holdMs should be a few intervals).
Effects: fail, read, write, io.
Methods
Mesh.alive
function Mesh.alive(self: Mesh): Vec<Member>The live members, this node first.
Effects: fail, read, io.
Mesh.owner
function Mesh.owner(self: Mesh, key: string): MemberThe member that owns key (rendezvous hashing over the live members).
Effects: fail, read, io.
Mesh.leave
function Mesh.leave(self: Mesh, sys: System): voidLeave: stop answering and probing, and tell each member at once, so the others drop this node now and not after their holdMs. Stop taking new requests first (close the listener of the service); this does not touch the requests it is answering.
Effects: fail, read, io.