This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from azuqua/develop
Added examples for gen_servers, dtable module for persistent in-memory key/value storage
- Loading branch information
Showing
12 changed files
with
2,142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
DLM example | ||
=========== | ||
|
||
A distributed lock manager `gen_server` implementation for reference, using the [Redlock algorithm](https://redis.io/topics/distlock). May be added into clusterluck as an optional feature if there's community interest. | ||
|
||
Example Usage | ||
------------- | ||
|
||
A simple example usage of this `gen_server` follows. For a more detailed integration test on a single node, refer to `test.js`. For a multi-node integration test, refer to `multi_test.js`. In this test, we try to lock the same resource with two different requesters. | ||
|
||
``` javascript | ||
const cl = require("../../index"), | ||
os = require("os"), | ||
assert = require("chai").assert; | ||
|
||
const nodeID = "name", | ||
port = 7022, | ||
host = os.hostname(); | ||
|
||
const node = cl.createCluster(nodeID, host, port), | ||
gossip = node.gossip(), | ||
kernel = node.kernel(); | ||
|
||
const DLMServer = require("./dlm"); | ||
const dlm = new DLMServer(gossip, kernel, { | ||
rquorum: 0.51, | ||
wquorum: 0.51 | ||
}); | ||
|
||
// load node state | ||
node.load(() => { | ||
// first start dlm, then start network kernel | ||
dlm.start("locker"); | ||
node.start("cookie", "ring", () => { | ||
console.log("Node %s listening on hostname %s, port %s", nodeID, host, port); | ||
dlm.wlock("id", "holder", 30000, (err, nodes) => { | ||
assert.notOk(err); | ||
assert.isArray(nodes); | ||
dlm.wlock("id", "holder", 30000, (err, wNodes) => { | ||
assert.ok(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
``` |
Oops, something went wrong.