Slimmer profile, low-calorie distributed locking library based on node-zookeeper-client
- Mildly different, much smaller interface
- Fewer features (no master election)
- Incompatible locking strategy
Like node-zookeeper-client
, node-zk-ultralight's locking is based on the ZooKeeper lock recipe.
The key difference: the ZK lock recipe recommends negotiating for the lock under the requested lock node with child nodes like _locknode_/guid-lock-<sequence number>
. However, ephemeral nodes may not have children, so applications with a large number of unique locks, especially a monotonically increasing number of locks (such as locking on a unique timestamp), pose a management problem. Locks created with node-zk-ultralight are ephemeral, and when no longer needed, they'll evaporate like the morning dew with the sunrise.
function someAsyncActionWithLocking(callback) {
var cxn = zkultra.getCxn(settings.ZOOKEEPER_URLS);
async.series([
cxn.lock.bind(cxn, '/some/lock/i/need', process.title +'-'+ process.pid),
someAsyncAction,
cxn.unlock.bind(cxn, '/some/lock/i/need')
], callback);
};
$ git clone https://github.com/rackerlabs/node-zk-ultralight
$ cd node-zk-ultralight
$ npm install .
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ make
npm test
npm run-script lint
npm run-script coverage
Library is distributed under the Apache license.