Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

level-party

Level21.7kMITdeprecated5.1.1

Superseded by rave-level (https://github.com/Level/community#faq)

Open a leveldb handle multiple times

level, leveldb, database, handle, multi-handle, multilevel, unix, socket

readme

level-party

Open a leveldb handle multiple times, transparently upgrading to use multileveldown 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.

level badge npm Node version Test Coverage Standard Common Changelog Donate

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:

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

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

And 1 that puts:

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

const 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:

const 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.

API

db = level(...)

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

Install

With npm do:

npm install level-party

Contributing

Level/party is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

Support us with a monthly donation on Open Collective and help us continue our work.

License

MIT

changelog

Changelog

5.1.1 - 2021-10-02

Fixed

  • Bump dependencies to prevent dedupe (ac6e8c9) (Vincent Weevers).

5.1.0 - 2021-10-01

Effectively adds db.getMany(keys), db.supports, db.clear() and for await...of db.iterator().

Changed

  • Bump multileveldown from 3.x to 5.x (bcd7c70, a33b0a8) (Vincent Weevers)
  • Bump level from 6.x to 7.x (#32) (3db143d) (Vincent Weevers).

5.0.0 - 2021-03-07

Changed

  • Breaking: modernize syntax (drops node 8) (#26) (9615cac, b0aa870) (Robert Nagy)
  • Bump subleveldown from 4.1.4 to 5.0.1 (#24) (0732684) (Vincent Weevers).

4.0.0 - 2019-12-08

Changed

Added

Removed

3.0.4 - 2016-01-10

Fixed

3.0.3 - 2016-01-10

Fixed

3.0.2 - 2016-01-09

Fixed

3.0.1 - 2016-01-09

Fixed

3.0.0 - 2016-01-09

Changed

2.1.2 - 2015-06-29

Fixed

2.1.1 - 2015-05-04

Added

Fixed

2.1.0 - 2015-04-25

Changed

Added

2.0.0 - 2015-04-25

Changed

  • Breaking: use multileveldown instead of multilevel to get seamless failover (64bd1dd) (@mafintosh)

Added

1.0.1 - 2014-09-25

No changes.

1.0.0 - 2014-09-25

Changed

Added

Fixed

0.0.4 - 2014-04-02

Changed

0.0.3 - 2014-02-27

Changed

0.0.2 - 2014-02-18

Added

Fixed

0.0.1 - 2014-02-17

Changed

0.0.0 - 2014-02-17

Initial release :seedling:.