- Source:
Classes
- CHash
- ClusterNode
- Connection
- DLMServer
- DSMServer
- DTable
- GenServer
- GossipRing
- Lock
- MTable
- NetKernel
- Node
- Semaphore
- VectorClock
Methods
(static) createCHash(rfactor, pfactor) → {Clusterluck.CHash}
Constructs a new instance of the consistent hash ring class.
Parameters:
Name | Type | Description |
---|---|---|
rfactor |
Number | Replication factor for every node inserted into the ring. Defaults to 3. |
pfactor |
Number | Persistence factor for every node inserted into the ring (used when calling .next on a consistent hash ring). Defaults to 2. |
Returns:
A consistent hash ring instance.
- Type
- Clusterluck.CHash
Example
let chash = clusterluck.createCHash(3, 2);
assert.equal(chash.rfactor(), 3);
assert.equal(chash.pfactor(), 2);
(static) createCluster(Identifier, host, port, optsopt) → {Clusterluck.ClusterNode}
Constructs an instance of a cluster node, the preferred and encompassing way to start/stop the underlying IPC node, as well as refer to underlying actors in the cluster (gossip ring, kernel, command server, forthcoming actors, etc.).
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Identifier |
String | for the node associated with this network kernel. Needs to be unique across the cluster, since nodes are addressed by id this way. |
|||||||||||||
host |
String | Hostname for this network kernel to bind to. Can be an IPV4 address, IPV6 address, or a hostname. Hostname resolution isn't done when checking the existence of a node inside a cluster, so this hostname is taken literally for the lifetime of the node (i.e. localhost vs. 127.0.0.1 vs |
|||||||||||||
port |
Number | Port for this network kernel to listen on. Defaults to 7022. |
|||||||||||||
opts |
Object |
<optional> |
Options object that controls configuration options for the constructed network kernel and gossip ring. Properties
|
Returns:
A new cluster node instance.
Example
let node = clusterluck.createCluster("foo", "localhost", 7022);
assert.equal(node.kernel().id(), "foo");
assert.equal(node.kernel().host(), "localhost");
assert.equal(node.kernel().port(), 7022);
assert.ok(node.kernel().self().equals(new Node("foo", "localhost", 7022)));
assert.equal(node.gossip().ring().rfactor(), 3);
assert.equal(node.gossip().ring().pfactor(), 2);
(static) createCommServer(gossip, kernel) → {Clusterluck.CommandServer}
Constructs an instance of a command server, which responds to CLI commands.
Parameters:
Name | Type | Description |
---|---|---|
gossip |
Clusterluck.Gossip | Gossip processor for this command server to report/manipulate the state of. |
kernel |
Clusterluck.Kernel | Network kernel this command server uses to reply over to a CLI process' IPC socket. |
Returns:
A new command server instance.
- Type
- Clusterluck.CommandServer
Example
let comms = clusterluck.createCommServer(gossip, kernel);
assert.deepEqual(comms.gossip(), gossip);
assert.deepEqual(comms.kernel(), kernel);
(static) createDLM(cluster, optsopt) → {Clusterluck.DLMServer}
Constructs a DLM server instance. Handles creating read locks, write locks, as well as removing such locks across a cluster of nodes. See documentation of the DLMServer class for how locks are routed and partitioned across the cluster.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cluster |
Clusterluck.ClusterNode | Cluster for this generic server to bind to. |
|||||||||||||||||||||||||||||||||||||||||||||||||
opts |
Object |
<optional> |
Options object for creating DLM server. Properties
|
Returns:
A new generic server instance.
Example
let server = clusterluck.createDLM(cluster, {disk: true, path: "/path/to/dir"});
server.load((err) => {
server.start("foo");
});
(static) createDSM(cluster, optsopt) → {Clusterluck.DSMServer}
Constructs a DSM server instance. Handles creating/reading/destroying semaphores, as well as posting and closing semaphores with requesters/actors. See documentation of the DSMServer class for how semaphores are routed and partitioned across the cluster.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cluster |
Clusterluck.ClusterNode | Cluster for this generic server to bind to. |
|||||||||||||||||||||||||||||||||||||||||
opts |
Object |
<optional> |
Options object for creating DSM server. Properties
|
Returns:
A new generic server instance.
Example
let server = clusterluck.createDSM(cluster, {disk: true, path: "/path/to/dir"});
server.load((err) => {
server.start("foo");
});
(static) createDTable(opts) → {Clusterluck.DTable}
Constructs a dtable instance, an in-memory key/value storage that persists to disk periodically.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Options object for creating dtable. Properties
|
Returns:
A new dtable instance.
- Type
- Clusterluck.DTable
Examples
let table = clusterluck.createDTable({
path: "/path/to/dir",
writeThreshold: 100,
autoSave: 180000,
fsyncInterval: 1000
});
table.start("foo");
let table = clusterluck.createDTable({
path: "/path/to/dir",
writeThreshold: 100,
autoSave: 180000,
fsyncInterval: 1000,
name: "TABLE_NAME"
});
table.load((err) => {
if (err) process.exit(1);
table.start();
});
(static) createGenServer(cluster, optsopt) → {Clusterluck.GenServer}
Constructs a generic server instance. Generic servers listen to the network kernel for events targetted at it's name/ID. For example, the gossip ring is a generic server that listens for events on the ID of the ring it belongs to.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
cluster |
Clusterluck.ClusterNode | Cluster for this generic server to bind to. |
|||||||||
opts |
Object |
<optional> |
Options object for creating generic server. Properties
|
Returns:
A new generic server instance.
Example
let server = clusterluck.createGenServer(cluster);
// based on how messages are parsed, will operate on event 'command_name' sent by another actor to this node
server.on("command_name", handlerForCommand);
// will listen on server.kernel() for messages emitted on event 'foo'.
server.start("foo");
(static) createGossip(kernel, optsopt) → {Clusterluck.GossipRing}
Constructs an instance of a gossip processor against network kernel kernel
.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kernel |
Clusterluck.NetKernel | Network kernel this new gossip processor instance will listen for jobs against. |
|||||||||||||||||||||||||||||||||
opts |
Object |
<optional> |
Gossip ring options to instantiate with. Affects vector clock trimming options, consistent hash ring instantiation, how often to gossip ring state against the cluster, and when/where to flush state to disk. Properties
|
Returns:
A new gossip ring instance.
Example
// initializes gossip ring with defaults found in `clusterluck.consts.gossipOpts`
let gossip = clusterluck.createGossip(kernel);
assert.equal(gossip.ring().rfactor(), 3);
assert.equal(gossip.ring().pfactor(), 2);
assert.deepEqual(gossip.kernel(), kernel);
(static) createKernel(id, host, port, optsopt) → {Clusterluck.NetKernel}
Constructs an instance of a network kernel with id
, listening on hostname host
and port port
.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
String | Identifier for the node associated with this network kernel. Needs to be unique across the cluster, since nodes are addressed by id this way. |
|||||||||||||||||||||||||||||
host |
String | Hostname for this network kernel to bind to. Can be an IPV4 address, IPV6 address, or a hostname. Hostname resolution isn't done when checking the existence of a node inside a cluster, so this hostname is taken literally for the lifetime of the node (i.e. localhost vs. 127.0.0.1 vs |
|||||||||||||||||||||||||||||
port |
Number | Port for this network kernel to listen on. Defaults to 7022. |
|||||||||||||||||||||||||||||
opts |
Object |
<optional> |
Network kernel options to instantiate with. Affects whether the server runs with TLS or just TCP, on what interval to attempt reconnect logic on a closed socket, and how many times to retry. Properties
|
Returns:
A new network kernel instance.
Example
let kernel = clusterluck.createKernel("foo", "localhost", 7022);
assert.equal(kernel.id(), "foo");
assert.equal(kernel.host(), "localhost");
assert.equal(kernel.port(), 7022);
assert.ok(kernel.self().equals(new Node("foo", "localhost", 7022)));
(static) createMTable() → {Clusterluck.MTable}
Constructs a mtable instance, an in-memory key/value storage.
Returns:
A new mtable instance.
- Type
- Clusterluck.MTable
Example
let table = clusterluck.createMTable();
table.start("foo");
(static) createVClock(id, count) → {Clusterluck.VectorClock}
Constructs a new instance of the vector clock class.
Parameters:
Name | Type | Description |
---|---|---|
id |
String | Identifier to insert this new vector clock on creation. |
count |
Number | Count to initialize |
Returns:
A vector clock instance.
Example
let vclock = clusterluck.createVClock();
assert.equal(vclock.size(), 0);
vclock = clutserluck.createVClock("id", 1);
assert.equal(vclock.size(), 1);
assert.ok(vclock.has("id"));