GithubHelp home page GithubHelp logo

tempbottle / raft.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kanaka/raft.js

0.0 2.0 0.0 16.71 MB

Raft.js is an implementation of the Raft consensus algorithm in JavaScript.

License: Mozilla Public License 2.0

JavaScript 5.52% HTML 0.24% Makefile 0.01% Clojure 0.01% TeX 89.92% MATLAB 0.27% Shell 0.30% Python 0.11% Lua 3.57% CSS 0.05%

raft.js's Introduction

Raft.js: Raft Consensus Algorithm in JavaScript

Raft.js is an implementation of The Raft Consensus Algorithm in JavaScript. The Raft algorithm was developed by Diego Ongaro and John Ousterhout at Stanford University. Please refer to their excellent paper on Raft: "In Search of an Understandable Consensus Algorithm".

Example

Start a node REPL and require one of the test modules.

> t = require('./test_local');
# OR
> t = require('./test_http');

The local test module starts servers in the same process that communicate directly with function calls. The http test creates servers in the same process but they communicate with each other by sending messages over HTTP.

Start 3 servers (an optional second argument specifies the number of servers to start):

> t.startServers({debug:true});

Get the leader ID and show its entry log:

> lid = t.getLeaderId();
> t.getAll('log')[lid];

Set a key/value in the state machine, show the log and stateMachine for all the servers, then read back the value:

> t.serverPool[lid].clientRequest({op:"set",key:'a',value:1}, function(results) { console.log("results: ", results); });
> t.getAll('log');
> t.getAll('stateMachine');
> t.serverPool[lid].clientRequest({op:"get",key:'a',ro:1}, function(results) { console.log("results: ", results); });

Add a new server (ID 3), set a different value and show that it has propagated to all the server state machines:

> t.addServer(3,{debug:true});
> t.serverPool[lid].clientRequest({op:"set",key:'b',value:2}, function(results) { console.log("results: ", results); });
> t.getAll('stateMachine');

Status

The following features have been implemented (the section number of the Raft paper is listed in brackets):

  • [5.2] Leader election
  • [5.3] Log replication and persistence
  • [5.4, 5.5, 5.6, 5.7] Safety features
  • [7.1] Client interaction (except filtering duplicates)
  • [5.1] RPCs:
  • In-process (direct function calls) for quick testing
  • Over HTTP
  • [6] Membership change / joint consensus

TODO

  • [7.1] filter duplicate client requests
  • [7.2] log compaction
  • faster resend of appendEntries when follower responds with fail (nextIndex update)
  • faster re-issue of requestVote to non-responders
  • more exception handling
  • in depth testing

License

Licensed under MPL-2.0. See LICENSE.txt.

raft.js's People

Contributors

kanaka avatar

Watchers

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