Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 12, 2024. It is now read-only.
/akka-raftPublic archive

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

License

NotificationsYou must be signed in to change notification settings

ktoso/akka-raft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an akka based implementation of theRaft 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 isakka-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 (seeIssues). 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

classWordConcatRaftActorextendsRaftActor {typeCommand=Cmndvarwords=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.*/defapply= {caseAppendWord(word)=>      words+: word      log.info("Applied command [{}], full words is: {}", command, words)      word// will be sent back to original actor, who sent the AppendWord commandcaseGetWords=>valres= words.toList      log.info("Replying with {}", res)      res  }}// ...valmembers= (1 to3) map { i=> system.actorOf(Props[WordConcatRaftActor], name=s"raft-member-$i") }valclusterConfiguration=ClusterConfiguration(raftConfiguration.members+ additionalActor)// 0, 1members 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 valueleader!ClientRequest(AppendWord("I"))leader!ClientRequest(AppendWord("like"))leader!ClientRequest(AppendWord("capybaras"))// ... after some timeleader!GetWordsexpectMsg(List("I","like","capybaras"))

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

classSnapshottingWordConcatRaftActorextendsRaftActor {typeCommand=Cmndvarwords=Vector[String]()defapply= {caseAppendWord(word)=>      words+: word      wordcaseGetWords=>valres= words.toList      log.info("Replying with {}", res)      rescaseInstallSnapshot(snapshot)=>      words= snapshot.data.asInstanceOf[Vector[String]]  }overridedefprepareSnapshot(meta:RaftSnapshotMetadata)=Future.successful(Some(RaftSnapshot(meta, words)))}

RaftClientActor

In the above examples, theclient implementation is very naive, and assumes you have some wayof finding out who the current Leader is (as this is a requirement to interact with any Raft cluster).Thankfully, you can use the providedRaftClientActor, which works like a proxy that forwards all your messagesto the currentLeader, or stashes them if the cluster has noLeader at the moment (is undergoing an election) andsends 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 theseawesome reading clubs (drop by if you're into CS papers!):

Bitdeli Badge

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors7

Languages


[8]ページ先頭

©2009-2025 Movatter.jp