Giter VIP home page Giter VIP logo

level-party's Introduction

level-party

open a leveldb handle multiple times, transparently upgrading to use multilevel when more than 1 process try to use the same leveldb data directory at once and re-electing a new master when the primary unix socket goes down

build status

level-party

example

Normally with level, when you try to open a database handle from more than one process you will get a locking error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
OpenError: IO error: lock /home/substack/projects/level-party/example/data/LOCK: Resource temporarily unavailable
    at /home/substack/projects/level-party/node_modules/level/node_modules/level-packager/node_modules/levelup/lib/levelup.js:114:34

With level-party, the database open will automatically drop down to using multilevel over a unix socket using metadata placed into the level data directory transparently.

This means that if you have 2 programs, 1 that gets:

var level = require('level-party');
var db = level(__dirname + '/data', { valueEncoding: 'json' });

setInterval(function () {
    db.get('a', function (err, value) {
        console.log('a=', value);
    });
}, 250);

and 1 that puts:

var level = require('level-party');
var db = level(__dirname + '/data', { valueEncoding: 'json' });

var n = Math.floor(Math.random() * 100000);

setInterval(function () {
    db.put('a', n + 1);
}, 1000);

and you start them up in any order, everything will just work! No more IO error: lock exceptions.

$ node put.js & sleep 0.2; node put.js & sleep 0.2; node put.js & sleep 0.2; node put.js & sleep 0.2
[1] 3498
[2] 3502
[3] 3509
[4] 3513
$ node get.js
a= 35340
a= 31575
a= 37639
a= 58874
a= 35341
a= 31576
$ node get.js
a= 35344
a= 31579
a= 37643
a= 58878
a= 35345
^C

Hooray!

seamless failover

level-party does seamless failover. This means that if you create a read-stream and the leader goes down while you are reading that stream level-party will resume your stream on the new leader.

This disables leveldb snapshotting so if your app relies on this you should disable this by setting opts.retry = false

var db = level('./data', {retry: false}) // will not retry streams / gets / puts if the leader goes down

windows support

level-party works on windows as well using named pipes.

methods

var level = require('level-party')

var db = level(...)

The arguments are exactly the same as level. You will sometimes get a real leveldb handle and sometimes get a multilevel handle back in the response.

install

With npm do:

npm install level-party

license

MIT

level-party's People

Contributors

mafintosh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.