Git Product home page Git Product logo

level-2pc's Introduction

SYNOPSIS

A two-phase-commit protocol for leveldb.

DESCRIPTION

Provides strong-consistency for local-cluster replication. Injectable transport (so it should work in the browser).

SPECIFICATION

The algorithm for how this works is here.

CONSIDERATIONS

There are trade-offs to every type of replication. I will try to create some specific numbers for you soon.

USAGE

EXAMPLE

SERVER A

var level = require('level');
var replicate = require('level-2pc');
var net = require('net');

var db1 = level('./db', { valueEncoding: 'json' });

var a = replicate.createServer(db1);

a.peers = [
  { host: 'localhost', port: 3001 }, 
  { host: 'localhost', port: 3002 }
];

net.createServer(function(con) {
  a.pipe(con).pipe(a);
}).listen(3000);

SERVER B

var b = rs.createServer(db2);

b.peers = [
  { host: 'localhost', port: 3000 }, 
  { host: 'localhost', port: 3002 }
];

net.createServer(function(con) {
  b.pipe(con).pipe(b);
}).listen(3001);

SERVER C

var c = rs.createServer(db3);

c.peers = [
  { host: 'localhost', port: 3000 }, 
  { host: 'localhost', port: 3001 }
];

net.createServer(function(con) {
  c.pipe(con).pipe(c);
}).listen(3002);

WRITE SOME DATA

Now go ahead and write some data to one of the servers and watch the data magically appear in the other servers!

setTimeout(function() {
  
  db1.put('x', 100, function(err) {
    console.log(err || 'ok');
  });

  setTimeout(function() {
    db2.get('x', function() {
      console.log(arguments);
      db3.get('x', function() {
        console.log(arguments);
      });
    });
  }, 100);

}, 100);

TRANSPORT

When the server wants to connect to the peers that have been specified, it defaults to using tcp from the net module. You can inject any transportation layer you want like this...

var net = require('net');
var opts = {};

opts.transport = function() {
  return net.connect.apply(null, arguments);
};

var a = replicate.createServer(db1, opts);

level-2pc's People

Contributors

heapwolf avatar

Stargazers

Toaster avatar

Watchers

Erik Kristensen avatar James Cloos 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.