Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from azuqua/kevin/develop
Browse files Browse the repository at this point in the history
Kevin/develop
  • Loading branch information
kevinwilson541 committed May 26, 2017
2 parents 67f93da + f14b727 commit 0b81f96
Show file tree
Hide file tree
Showing 4 changed files with 725 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/gen_server/dlm/README.md
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);
});
});
});
});
```

0 comments on commit 0b81f96

Please sign in to comment.