Skip to content

ynachiket/node-zk-ultralight

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ultralight ZK locking utility

Slimmer profile, low-calorie distributed locking library based on node-zookeeper-client

Dependency Status

Why a new library?

  • Mildly different, much smaller interface
  • Fewer features (no master election)
  • Incompatible locking strategy

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.

Usage

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);
};

Development

Building

$ git clone https://github.com/rackerlabs/node-zk-ultralight
$ cd node-zk-ultralight
$ npm install .
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ make

Tests

npm test

Lint

npm run-script lint

Coverage

npm run-script coverage

License

Library is distributed under the Apache license.

About

An ultralight locking library for ZooKeeper in nodejs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.1%
  • Puppet 3.9%