GithubHelp home page GithubHelp logo

raft.net's Introduction

Raft.NET

Build status

A .Net implementation of the RAFT consensus algorithm. This is still WORK IN PROGRESS.

High Level Design

This framework makes heavy use of ring buffers to facilitate message passing between threads. When a command is executed against the cluster leader, it is placed in the leader ring buffer. This buffer has 4 consumer threads that perform the following for each entry in the ring buffer (in order):

  • Encode the log entry (done using ProtBuf).
  • Writing the log entry to disk (using the journaler).
  • Replicating the log entry to peer nodes.
  • Updating the internal state of the node.

Replication

For each node in the cluster, there is an Actor that is responsible for replicating new entries as well as ensuring the log for that node remains consistent with the leader. The Replication buffer handler(for the leader ring buffer) is responsible for: cloning the entry for each node, posting the new entry to the corresponding Actors, and waiting until at least half of the actors have successfully replicated the log entry.

Followers that receive the AppendEntries request ensure the entry is valid (based on rules outlined in the whitepaper) and publish the new entry (along with other information received in the request) to the follower ring buffer. This buffer has 3 consumer threads that perform the following for each entry in the buffer (in order):

  • Truncate log if log matching (followers log is inconsistent).
  • Write entries to disk (using the journaler).
  • Apply entries that have been successfully commited by the leader.

Persistance

All encoded entries are written to journal files. The journal files are append-only and their size is pre-allocated to ensure reading and writing to the file can be done sequentially. The journaller by default uses Unbuffered IO and ensures the blocks written to the journal files are padded to align to hard drive sector boundaries. Additionally, the journaller will allow you to pass metadata for the block which will be encoded and written next to the journal entry.

Things left to do (there is quite a bit):
  • Compress entries in memory. Entries are kept in memory for log matching when replicating. In the solution there is a ZipList structure that will encode entries in a contiguous block of memory. This structure should be used to hold entries for each term (currently an array is used). Once the term ends, use a compression lib (such as Snappy) to compress the block in memory.
  • Implement rules around elections and voting!!!!
  • Implement auto-discovery/joining of nodes to the cluster. This will be done by utilising multicast IP so the nodes can gossip about which other nodes are in the cluster. This will also be used for heartbeats from the leader to the followers.
  • Make fluent configuration builders for the framework to make installing into the applciation easy.
  • Create test application and test, test, test!!!

#####Technologies used:

  • Disruptor-net
  • TPL Dataflow
  • Protocol Buffers
  • Stateless
  • WCF
  • LightInject

raft.net's People

Contributors

yburke94 avatar

Stargazers

 avatar 问道老王 avatar  avatar Robert Luong avatar Tiago Margalho avatar Reuben Bond avatar  avatar Chris Greeno avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

cgreeno lobut codeyu

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.