• Stars
    star
    279
  • Rank 145,439 (Top 3 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A toy project implementing RAFT on top of Akka Cluster (not prod ready)

akka-raft

This is an akka based implementation of the Raft consensus algorithm. It is generic enough that you can build your own replicated state machines on top of it (with raft keeping track of the consensus part of it).

This implementation is akka-cluster aware, so it can be easily deployed on multiple machines. Implementation wise, all parts of the raft whitepaper are covered:

  • Leader election
  • Dynamic membership changes (with transitioning periods implemented as Joint Consensus)
  • Deployment across multiple nodes
  • Log compaction, via snapshotting

Disclaimer

💥 💥

This project is a side-project of mine and is still work in progress (treat it as EARLY PREVIEW) and has a number of known protocol bugs (see Issues). It is NOT recommended to be used in production, however it's a great project to play around with implementing and discussing the Raft protocol.

💥 💥

In other words: Use at own risk, best not on any production-like environments (for now).

Basic info

Raft is a distributed consensus algorithm, much like Paxos (but simpler). This implementation is fully akka (and akka-cluster) based, and can be used to deploy a replicated state machine on top of akka clusters.

THIS API IS STILL SUBJECT TO CHANGE

class WordConcatRaftActor extends RaftActor {

  type Command = Cmnd

  var words = Vector[String]()

  /** 
   * Called when a command is determined by Raft to be safe to apply; 
   * Application results are sent back to the client issuing the command.
   */
  def apply = { 
    case AppendWord(word) =>
      words +: word
      log.info("Applied command [{}], full words is: {}", command, words)

      word // will be sent back to original actor, who sent the AppendWord command

    case GetWords =>
      val res = words.toList
      log.info("Replying with {}", res)
      res
  }
}

// ...

val members = (1 to 3) map { i => system.actorOf(Props[WordConcatRaftActor], name = s"raft-member-$i") }
val clusterConfiguration = ClusterConfiguration(raftConfiguration.members + additionalActor) // 0, 1

members foreach { _ ! ChangeConfiguration(clusterConfiguration)

// todo implement re-routing if you send to a non-leader
// then send messages to it; the state machine will only be applied when consensus has been reached about a value
leader ! ClientRequest(AppendWord("I"))
leader ! ClientRequest(AppendWord("like"))
leader ! ClientRequest(AppendWord("capybaras"))

// ... after some time
leader ! GetWords

expectMsg(List("I", "like", "capybaras"))

And if you want to enable snapshotting support it's as simple as implementing one method and matching for InstallSnapshot in your Actor:

class SnapshottingWordConcatRaftActor extends RaftActor {

  type Command = Cmnd

  var words = Vector[String]()

  def apply = {
    case AppendWord(word) =>
      words +: word
      word

    case GetWords =>
      val res = words.toList
      log.info("Replying with {}", res)
      res

    case InstallSnapshot(snapshot) =>
      words = snapshot.data.asInstanceOf[Vector[String]]
  }

  override def prepareSnapshot(meta: RaftSnapshotMetadata) =
    Future.successful(Some(RaftSnapshot(meta, words)))
}

RaftClientActor

In the above examples, the client implementation is very naive, and assumes you have some way of finding out who the current Leader is (as this is a requirement to interact with any Raft cluster). Thankfully, you can use the provided RaftClientActor, which works like a proxy that forwards all your messages to the current Leader, or stashes them if the cluster has no Leader at the moment (is undergoing an election) and sends the messages once the Leader becomes available.

License

Simply: Apache 2.0

Issues, Pull Requests as well as Tweets and Emails are more than welcome!

Links & kudos

We have discussed this paper both in Kraków and London, on these awesome reading clubs (drop by if you're into CS papers!):

Bitdeli Badge

More Repositories

1

scala-types-of-types

Scala's Types of Types
CSS
153
star
2

sbt-jol

Don't guess JVM object sizes. Get them on a silver platter.
Scala
88
star
3

scala-rainbow

Super simple terminal output colorizing for Scala
Scala
61
star
4

akka-persistence-hbase

An HBase backed Journal for Akka's experimental persistence / event-sourcing
Scala
47
star
5

akka-http-mini-workshop

Scala
33
star
6

lambda-spec

Adding λ to your Java Specs!
Java
26
star
7

go-home-raspberry

raspberrypi golang app, to manage home utensils such as light, fans...
Go
21
star
8

hadoop-scalding-nojartool

Hadoop Tool implementation which enables extreme productivity - running MR jobs on your cluster right from your sbt shell!
Scala
20
star
9

akka-streams-alpakka-talk-demos

Scala
18
star
10

scala-macro-method-alias

Scala 2.10 macros that help you delegate to other methods declaratively
Scala
16
star
11

scaladays-berlin-akka-streams

Scala
15
star
12

example-akka-http

Shell
14
star
13

oculus

Oculus is a hadoop based video fingerprinting system, using scala, scalding and ffmpeg
Shell
12
star
14

sbt-bash-completion

A simple sbt bash completion script (with caching)
12
star
15

intellij-theme-happy-hakking

11
star
16

intellij-colors-happy-hakking

My custom IntelliJ colour scheme, nicknamed "happy hakking"
10
star
17

g73-keyboard-backlight-sh

A super simple script to enable the G73 notebook series keyboard backlight on GNU/Linux systems
Shell
9
star
18

janbanery

The Fluent Kanbanery API Java connector :-)
Java
9
star
19

kaze-class

Like Case Class, but easier to bin-compat evolve
Scala
8
star
20

kanbanery-for-intellij

Kanbanery as Tasks resource for IntelliJ IDEA!
Java
8
star
21

GitHubDiff

An Gmail Contextual Gadget, that allows viewing diffs if an commit url is mentioned in the email.
8
star
22

akka-codepot-workshop

Scala
7
star
23

mk-javascript

Mortal Combat written in MVC "objective" JavaScript during an DevMeeting in Cracow
JavaScript
6
star
24

janbanery-shell

A Kanbanery.com command line client. With FULL API coverage!
Java
5
star
25

kanbanery-tv

Scala
4
star
26

scala-words

"A vocabulary of words to code by"
Scala
4
star
27

akkakucity-actors

A collection of useful Akka Actors
4
star
28

akka-streams-jdk9-strawman-mvn

Java
4
star
29

jo

Jo - The JVM based Go implementation
Java
4
star
30

scalaslide

Awesome landslide & scalatest driven presentation framework, built on sbt
Scala
4
star
31

rx-wiki

3
star
32

verfluchter-android

An time-keeping Android app that interacts with my company's "verfluchter" timetracker :-)
Java
3
star
33

cracow-mobi-android-di

My dependency injection in android talk @ Cracow.Mobi 2011
Shell
3
star
34

protodoc-scala

It's like JavaDoc, but for Google Protocol Buffers!
Scala
3
star
35

spray-servlet-example

Scala
3
star
36

sidewinder-x6-linux-macro-key-events

The reverse engineered protocol and event machine for the Sidewinder X6. The only way to make the macro keys work on a Linux system.
Shell
3
star
37

global-krakow-android-dev-camp

Homepage for Global (Kraków) Android Dev Camp
JavaScript
2
star
38

spring-akka-streams-support

Java
2
star
39

adb-bash_autocomplete

bash autocompletition for adb
Shell
2
star
40

AllFeedsOnePlace-Wicket

An simple rss/atom feeds crawler accregator written as Uni project and to check out if Wicket sux or rocks.
Java
2
star
41

scala-android-presentation

A presentation covering some tricks on using Scala within Android apps
JavaScript
2
star
42

git-presentation

My git presentation I have given during the Academic IT Festival 2011
2
star
43

softdevcon-2011

Przykładowy kod z podstawowymi rzeczami dot. programowania na androida
Java
2
star
44

devmeeting-2011-ssjs

ServerSideJavaScript
2
star
45

jgoogl

Java wrapper around the Goo.gl link shortening service, with full api coverage and typesafe, fluent API :-)
Java
2
star
46

dotfiles

Vim Script
1
star
47

protodoc-maven-plugin

Java
1
star
48

sidewinder-macros

My 90 Sidewinder macros
Shell
1
star
49

kanbanery-for-android

Java
1
star
50

bryce-jdbc-akka

Scala
1
star
51

swift-ring-benchmark

Swift
1
star
52

props2xls

An simple app to convert Java i18n property files (also used in GWT) to an online Spreadsheet - on Google Docs. :-)
Java
1
star
53

cv

My Curriculum Vitae (in tex, and generated html, pdf, txt, html)
TeX
1
star
54

protoc-gen-scala

scala (case class) protobuf compiler plugin
Java
1
star
55

twitter-android-fun-app

Java
1
star
56

xmonad-conf

My xmonad configuration
Haskell
1
star
57

tdd-fun

Some TDD examples and trainings from an recent training in warszawa
Java
1
star
58

akka-io-spdy-playground

Playing around with SPDY
Scala
1
star
59

were-on-geecon

GeeCON "overlay" for your site ;-) Shows only while it's GeeCON time!
1
star
60

ktoso

1
star
61

ada2html

(university stuff) horrrrrrrible ada to html converter
Ada
1
star
62

akka-streaming-example

Scala
1
star
63

next-up-on-geecon

Backbone JavaScript app to display tweets and session information :-)
JavaScript
1
star
64

jcurry

The Java8 function currying library!
Java
1
star
65

SomeLib

Sample lib for showcasing package manager issue
Swift
1
star
66

prolog_lists_fun

just a few simple prolog tasks for an university course
Prolog
1
star
67

the-game-of-life

An "few minutes" implementation of the game of life. The UI code is not mine, I had to use it as it's an university task...
Java
1
star
68

tiny-term-pm

TinyPM for your terminal! Never again "click" to add a task!
Scala
1
star