Code Monkey home page Code Monkey logo

rafty's Introduction

Rafty

Please note rafty is experimental

Rafty is an implementation of the Raft concensus algorythm see here created using C# and .NET core. Rafty is the algorythm only and does not provide useful implementation of the transport between nodes, the state machine or log. Instead Rafty provides interfaces that you will need to implement. I reccomend at least 5 nodes in your cluster for Rafty to operate optimally and this is basically all I've tested....

Rafty was built to allow Ocelot (another project of mine) to run in a cluster without a database or relying on another piece of software to persist state. This will also allow me to turn Ocelot into a service discovery provider and key value store so its pretty nice....if it works!

Install

Bring the rafty package into your project using nuget.

Install-Package Rafty

This will make all the raft code available to you!

ILog

You must implement ILog which provides a description of each member in the summary comments of the interface. This log implementation should be persistant and not shared between nodes.

IFiniteStateMachine

You must implement IFiniteStateMachine which provides a description of each member in the summary comments of the interface. This just takes a command of T and you execute it! Pretty simple.

IPeer

You must implement IPeer which provides a description of each member in the summary comments of the interface. This encapsulates the transport logic to each node in the cluster.

IPeersProvider

You must implement IPeersProvider which provides a description of each member in the summary comments of the interface. This should return all available nodes in the cluster as peers.

ISettings

You must implement ISettings which provides a description of each member in the summary comments of the interface. Holds some basic settings information that you might want to tweak such as timeout.

Startup

Rafty provides some in memory implementations of its interfaces (you shouldn't use these for anything serious).

    var log = new InMemoryLog();
    var fsm = new InMemoryStateMachine();
    var settings = new InMemorySettings(1000, 3500, 50, 5000);
    var peersProvider = new InMemoryPeersProvider(_peers);
    var node = new Node(fsm, log, settings, peersProvider);
    node.Start();

The above code will get a Rafty node up and running. If the IPeersProvider does not return any IPeers then it will elect itself leader and just run along happily. If something joins the cluster later it will update that new node as the node will get a heartbeat before it can elect itself. Or an election will start!

So in order to get Rafty really running the IPeerProvider needs to return peers. The easiest way to do this is just provide a HTTP transport version of IPeer. The host and port of these peers is known to each node and you just push them into memory and return them. The request will then flow through the IPeer interfaces from the nodes!

Finally you need to expose the INode interface to some kind of HTTP. I would advise just a plain old .net core web api type thing. These are the methods you need to expose and the transport in your IPeer should hit these URLS (hope that makes some sense). You can look at NodePeer to see how I do this in memory.

Task<AppendEntriesResponse> Request(AppendEntries appendEntries);
Task<RequestVoteResponse> Request(RequestVote requestVote);
Task<Response<T>> Request<T>(T command);

Further help

The Acceptance and Integration tests will be helpful for anyone who wants to use Rafty.

Future

I will provide some half decent implementations of these interfaces so you don't have to.

rafty's People

Contributors

davidni avatar tompallister avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rafty's Issues

log of the raft state machine shoud be store

https://ramcloud.atlassian.net/wiki/download/attachments/6586375/raft.pdf
Replicated state machines are typically implemented using a replicated log, as shown in Figure 1. Each server stores a log containing a series of commands, which its state machine executes in order. Each log contains the same commands in the same order, so each state machine
processes the same sequence of commands. Since the state machines are deterministic, each computes the same state and the same sequence of outputs

Target netstandard2.0 (instead of netcoreapp2.0)

Expected Behavior / New Feature

This is needed in order to have Ocelot target netstandard2.0, thereby facilitating much wider adoption. This is a trivial change to make and I will submit a PR shortly.

How to handle BecomeXXXX?

This is great library ever : )

I need to handle the node state and send my state to server,
but I can't find class , that be adapt the node state (ex: handler) ?

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.