Distributed Consensus A.K.A. "What do we eat for lunch?"
-
Upload
konrad-malawski -
Category
Technology
-
view
2.738 -
download
1
description
Transcript of Distributed Consensus A.K.A. "What do we eat for lunch?"
![Page 1: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/1.jpg)
Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL
Konrad `@ktosopl` Malawski
Distributed Consensus A.K.A.
“What do we eat for lunch?”
![Page 2: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/2.jpg)
Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL
Distributed Consensus A.K.A.
“What do we eat for lunch?”
Konrad `@ktosopl` Malawski
real world edition
![Page 3: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/3.jpg)
Konrad `@ktosopl` Malawski
hAkker @
![Page 4: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/4.jpg)
Konrad `@ktosopl` Malawski
typesafe.com geecon.org
Java.pl / KrakowScala.pl sckrk.com / meetup.com/Paper-Cup @ London
GDGKrakow.pl meetup.com/Lambda-Lounge-Krakow
hAkker @
![Page 5: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/5.jpg)
You?
Distributed systems?
![Page 6: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/6.jpg)
You?
Distributed systems?
?
![Page 7: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/7.jpg)
You?
Distributed systems?
?
?
![Page 8: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/8.jpg)
What is this talk about?
The network. !
How to think about distributed systems. !
Some healthy madness.
Code in slides covers only “simplest possible case”.
![Page 9: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/9.jpg)
Ordering[T]
Slightly chronological. !
By no means is it “worst to best”.
![Page 10: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/10.jpg)
Consensus
![Page 11: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/11.jpg)
Consensus - informal
“we all agree on something”
![Page 12: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/12.jpg)
Consensus - formalTermination
Every correct process decides some value.
!
Validity If all correct processes propose the same value v,
then all correct processes decide v.
!
Integrity If a correct process decides v,
then v must have been proposed by some correct process.
!
Agreement Every correct process must agree on the same value.
![Page 13: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/13.jpg)
Consensus
![Page 14: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/14.jpg)
Consensus
![Page 15: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/15.jpg)
Distributed Consensus
![Page 16: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/16.jpg)
Distributed Consensus
What is a distributed system anyway?
![Page 17: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/17.jpg)
Distributed system definition
A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable.
— Leslie Lamport
http://research.microsoft.com/en-us/um/people/lamport/pubs/distributed-system.txt
![Page 18: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/18.jpg)
Distributed system definition
A system in which participants communicate asynchronously using messages.
http://research.microsoft.com/en-us/um/people/lamport/pubs/distributed-system.txt
![Page 19: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/19.jpg)
Distributed Systems - failure detection
![Page 20: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/20.jpg)
Distributed Systems - failure detection
![Page 21: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/21.jpg)
Distributed Systems - failure detection
Jim had quit CorpSoft a while ago, but no-one ever told Bob…
![Page 22: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/22.jpg)
Distributed Systems - failure detection
![Page 23: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/23.jpg)
Distributed Systems - failure detection
Failure detection:• can only rely on external knowledge • but what if there’s no-one to tell you?
• thus: must be in-some-way time based
![Page 24: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/24.jpg)
Two Generals Problem
![Page 25: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/25.jpg)
Two Generals ProblemYellow and Blue armies must attack Pink City.
They must attack together, otherwise they’ll die in vain. Now they must agree on the exact time of the attack.
!They can only send messengers, which Pink may intercept and kill.
![Page 26: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/26.jpg)
Two Generals Problem
![Page 27: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/27.jpg)
Two Generals Problem - happy case
I need to inform blue about my attack plan.
I don’t know when yellow will attack…
![Page 28: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/28.jpg)
Two Generals Problem - happy case
![Page 29: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/29.jpg)
1) Initial message not lost
![Page 30: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/30.jpg)
Two Generals Problem - happy case
I don’t know if Blue will also attack at 13:37… I’ll wait until I hear back from him.
![Page 31: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/31.jpg)
Two Generals Problem - happy case
I don’t know if Blue will also attack at 13:37… I’ll wait until I hear back from him.
Why?
![Page 32: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/32.jpg)
2) Message might have not reached blue
![Page 33: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/33.jpg)
Blue must confirm the reception of the command
![Page 34: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/34.jpg)
1) Yellow is now sure, but Blue isn’t!
![Page 35: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/35.jpg)
1) Yellow is now sure, but Blue isn’t!
Why?
![Page 36: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/36.jpg)
2) Blue’s confirmation might have been lost!
![Page 37: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/37.jpg)
This is exactly mirrors the initial situation!
![Page 38: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/38.jpg)
2 Generals Problem Translated to Akka
![Page 39: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/39.jpg)
2 Generals translated to Akka:
Akka Actors implement the Actor Model: !
Actors: • communicate via messages • create other actors • change their behaviour on receiving a msg
!
![Page 40: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/40.jpg)
2 Generals translated to Akka:
Akka Actors implement the Actor Model: !
Actors: • communicate via messages • create other actors • change their behaviour on receiving a msg
!
Gains? Distribution / separation / modelling abstraction
![Page 41: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/41.jpg)
2 Generals translated to Akka:
case class AttackAt(when: Date)
Presentation–sized–snippet = does not cover all cases
![Page 42: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/42.jpg)
2 Generals translated to Akka:! !class General(general: Option[ActorRef]) extends Actor {!!! val WhenIWantToAttack: Date = ???! ! general foreach { _ ! AttackAt(WhenIWantToAttack) }! ! def receive = {! case AttackAt(when) =>! println(s”General ${otherGeneralName} attacks at $when”)!! ! ! println(s”I must confirm this!")! ! sender() ! AttackAt(when)! }!! def otherGeneralName = !! ! ! if(self.path.name == “blue")!“yellow" else "blue"! }!
Presentation–sized–snippet = does not cover all cases
![Page 43: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/43.jpg)
2 Generals translated to Akka:! !class General(general: Option[ActorRef]) extends Actor {!!! val WhenIWantToAttack: Date = ???! ! general foreach { _ ! AttackAt(WhenIWantToAttack) }! ! def receive = {! case AttackAt(when) =>! println(s”General ${otherGeneralName} attacks at $when”)!! ! ! println(s”I must confirm this!")! ! sender() ! AttackAt(when)! }!! def otherGeneralName = !! ! ! if(self.path.name == “blue")!“yellow" else "blue"! }!
Presentation–sized–snippet = does not cover all cases
![Page 44: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/44.jpg)
2 Generals translated to Akka:! !class General(general: Option[ActorRef]) extends Actor {!!! val WhenIWantToAttack: Date = ???! ! general foreach { _ ! AttackAt(WhenIWantToAttack) }! ! def receive = {! case AttackAt(when) =>! println(s”General ${otherGeneralName} attacks at $when”)!! ! ! println(s”I must confirm this!")! ! sender() ! AttackAt(when)! }!! def otherGeneralName = !! ! ! if(self.path.name == “blue")!“yellow" else "blue"! }!
Presentation–sized–snippet = does not cover all cases
![Page 45: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/45.jpg)
2 Generals translated to Akka:! !class General(general: Option[ActorRef]) extends Actor {!!! val WhenIWantToAttack: Date = ???! ! general foreach { _ ! AttackAt(WhenIWantToAttack) }! ! def receive = {! case AttackAt(when) =>! println(s”General ${otherGeneralName} attacks at $when”)!! ! ! println(s”I must confirm this!")! ! sender() ! AttackAt(when)! }!! def otherGeneralName = !! ! ! if (self.path.name == “blue")!"yellow" else "blue"! }!
Presentation–sized–snippet = does not cover all cases
![Page 46: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/46.jpg)
2 Generals translated to Akka:
val system = ActorSystem("two-generals")!!val blue = ! system.actorOf(Props(new General(general = None)), name = "blue")!!val yellow = ! system.actorOf(Props(new General(Some(blue))), name = "yellow")!
The blue general attacks at 13:37, I must confirm this!!The yellow general attacks at 13:37, I must confirm this!!The blue general attacks at 13:37, I must confirm this!!...
Presentation–sized–snippet = does not cover all cases
![Page 47: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/47.jpg)
8 Fallacies of Distributed Computing
![Page 48: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/48.jpg)
8 Fallacies of Distributed Computing
1. The network is reliable. 2. Latency is zero. 3. Bandwidth is infinite. 4. The network is secure. 5. Topology doesn’t change. 6. There is one administrator. 7. Transport cost is zero. 8. The network is homogeneous.
Peter Deutsch “The Eight Fallacies of Distributed Computing” https://blogs.oracle.com/jag/resource/Fallacies.html
![Page 49: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/49.jpg)
Failure Models
![Page 50: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/50.jpg)
Failure models:
Fail – Stop
Fail – Recover
Byzantine
![Page 51: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/51.jpg)
Failure models:
Fail – Stop
Fail – Recover
Byzantine
![Page 52: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/52.jpg)
Failure models:
Fail – Stop
Fail – Recover
Byzantine
![Page 53: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/53.jpg)
Failure models:
Fail – Stop
Fail – Recover
Byzantine
![Page 54: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/54.jpg)
2-phase commit
![Page 55: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/55.jpg)
2PC - step 1: Propose value
![Page 56: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/56.jpg)
2PC - step 1: Propose value
![Page 57: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/57.jpg)
2PC - step 1: Promise to agree on write
![Page 58: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/58.jpg)
2PC - step 2: Commit the write
![Page 59: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/59.jpg)
2PC - step 1: Propose value, and die
![Page 60: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/60.jpg)
2PC - step 1: Propose value to 1 node, and die
![Page 61: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/61.jpg)
2PC: Prepare needs timeouts
![Page 62: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/62.jpg)
2PC: Timeouts + recovery committer
![Page 63: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/63.jpg)
2PC: Timeouts + recovery committer
![Page 64: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/64.jpg)
2PC: Timeouts + recovery committer
![Page 65: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/65.jpg)
2PC: Timeouts + recovery committer
![Page 66: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/66.jpg)
2PC: Timeouts + recovery committer
![Page 67: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/67.jpg)
Still can’t tolerate if the “accepted value” Actor dies
![Page 68: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/68.jpg)
2PC: Timeouts + recovery committer
![Page 69: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/69.jpg)
2PC: Timeouts + recovery committer
![Page 70: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/70.jpg)
2 Phase Commit translated to Akka
![Page 71: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/71.jpg)
2PC translated to Akka
case class Prepare(value: Any)!case object Commit!!sealed class AcceptorStatus!case object Prepared extends AcceptorStatus!case object Conflict extends AcceptorStatus!!
Presentation–sized–snippet = does not cover all cases
![Page 72: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/72.jpg)
2PC translated to Akka
case class Prepare(value: Any)!case object Commit!!sealed class AcceptorStatus!case object Prepared extends AcceptorStatus!case object Conflict extends AcceptorStatus!!
Presentation–sized–snippet = does not cover all cases
![Page 73: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/73.jpg)
2PC translated to Akka class Proposer(acceptors: List[ActorRef]) extends Actor {! var transactionId = 0! var preparedAcceptors = 0!! def receive = {! case value: String =>! transactionId += 1! acceptors foreach { _ ! Prepare(transactionId, value) }!! case Prepared =>! preparedAcceptors += 1! ! if (preparedAcceptors == acceptors.size)! acceptors foreach { _ ! Commit }!! case Conflict =>!! ! ! ! ! context stop self! }! }!
Presentation–sized–snippet = does not cover all cases
![Page 74: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/74.jpg)
2PC translated to Akka class Proposer(acceptors: List[ActorRef]) extends Actor {! var transactionId = 0! var preparedAcceptors = 0!! def receive = {! case value: String =>! transactionId += 1! acceptors foreach { _ ! Prepare(transactionId, value) }!! case Prepared =>! preparedAcceptors += 1! ! if (preparedAcceptors == acceptors.size)! acceptors foreach { _ ! Commit }!! case Conflict =>!! ! ! ! ! context stop self! }! }!
Presentation–sized–snippet = does not cover all cases
![Page 75: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/75.jpg)
2PC translated to Akka class Proposer(acceptors: List[ActorRef]) extends Actor {! var transactionId = 0! var preparedAcceptors = 0!! def receive = {! case value: String =>! transactionId += 1! acceptors foreach { _ ! Prepare(transactionId, value) }!! case Prepared =>! preparedAcceptors += 1! ! if (preparedAcceptors == acceptors.size)! acceptors foreach { _ ! Commit }!! case Conflict =>!! ! ! ! ! context stop self! }! }!
Presentation–sized–snippet = does not cover all cases
![Page 76: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/76.jpg)
2PC with ResumeProposer in Akka
case class Prepare(value: Any)!case object Commit!!sealed class AcceptorStatus!case object Prepared extends AcceptorStatus!case object Conflict extends AcceptorStatus!case class Committed(value: Any) extends AcceptorStatus!
Presentation–sized–snippet = does not cover all cases
![Page 77: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/77.jpg)
2PC with ResumeProposer in Akka!class ResumeProposer(! proposer: ActorRef, ! acceptors: List[ActorRef]) extends Actor {!! context watch proposer!! var anyAcceptorCommitted = false!! def receive = {! case Terminated(`proposer`) =>! println("Proposer died! Try to finish the transaction...")! acceptors map { _ ! StatusPlz }!! case _: AcceptorStatus =>! // impl of recovery here! }!}
Presentation–sized–snippet = does not cover all cases
![Page 78: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/78.jpg)
2PC with ResumeProposer in Akka
Presentation–sized–snippet = does not cover all cases
![Page 79: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/79.jpg)
Quorum
![Page 80: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/80.jpg)
Quorum voting
From the perspective of the Omnipotent Observer *
![Page 81: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/81.jpg)
Quorum voting
* does not exist in a running system
From the perspective of the Omnipotent Observer *
![Page 82: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/82.jpg)
Quorum voting
![Page 83: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/83.jpg)
Quorum voting
![Page 84: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/84.jpg)
Quorum voting
![Page 85: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/85.jpg)
Quorum voting
![Page 86: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/86.jpg)
Quorum voting
![Page 87: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/87.jpg)
Quorum voting
![Page 88: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/88.jpg)
Quorum voting – split votes
![Page 89: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/89.jpg)
Quorum voting – split votes
![Page 90: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/90.jpg)
Quorum voting – split votes
![Page 91: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/91.jpg)
Quorum voting – split votes
![Page 92: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/92.jpg)
Quorum voting – split votes
![Page 93: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/93.jpg)
James Mickens “The Saddest Moment” http://research.microsoft.com/en-us/people/mickens/thesaddestmoment.pdf
![Page 94: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/94.jpg)
Paxos
![Page 95: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/95.jpg)
Basic Paxos =
“choose exactly one value”
![Page 97: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/97.jpg)
Paxos: a high-level overview
It’s the distributed systems algorithm
![Page 98: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/98.jpg)
Paxos: a high-level overview
JavaZone had a full session on Paxos already today…
![Page 99: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/99.jpg)
A few Paxos whitepapers
"Reaching Agreement in the Presence of Faults” – Lamport, 1980 …
“FLP Impossibility Result” – Fisher et al, 1985 “The Part Time Parliament” – Lamport, 1998
… “Paxos made Simple” – Lamport, 2001
“Fast Paxos” – Lamport, 2005 …
“Paxos made Live” – Chandra et al, 2007 …
“Paxos made Moderately Complex” – Rennesse, 2011 ;-)
![Page 100: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/100.jpg)
Lamport’s “Replicated State Machine”
![Page 101: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/101.jpg)
Paxos: The cast
![Page 102: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/102.jpg)
Paxos: The cast
![Page 103: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/103.jpg)
Paxos: The cast
![Page 104: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/104.jpg)
Paxos: The cast
![Page 105: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/105.jpg)
Paxos: The cast
![Page 106: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/106.jpg)
Paxos: The cast
![Page 107: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/107.jpg)
!
Consensus time! Chose a value (raise your hand)
![Page 108: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/108.jpg)
Consensus time! Chose a value (raise your hand):
v1 = Basic Paxos + Raft v2 = Just Raft
![Page 109: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/109.jpg)
Consensus time! Chose a value (raise your hand):
v1 = Basic Paxos + Raft v2 = Just Raft
![Page 110: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/110.jpg)
Consensus time! Chose a value (raise your hand):
v2 = Just Raftv1 = Basic Paxos + Raft
![Page 111: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/111.jpg)
Consensus time! Chose a value (raise your hand):
v1 = Basic Paxos + Raft v2 = Just Raft (if enough time, Paxos)
![Page 112: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/112.jpg)
Basic Paxos simple example
![Page 113: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/113.jpg)
Paxos: Proposals
ProposalNr must: • be greaterThan any prev proposalNr
used by this Proposer • example: [roundNr|serverId]
![Page 114: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/114.jpg)
Paxos: 2 phases
Phase 1: Prepare Phase 2: Accept
![Page 115: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/115.jpg)
Paxos, Prepare Phase
n = nextSeqNr()
![Page 116: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/116.jpg)
Paxos, Prepare Phase
acceptors ! Prepare(n, value)
![Page 117: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/117.jpg)
Paxos, Prepare Phase
case Prepare(n, value) =>! if (n > minProposal) {! minProposal = n! accVal = value! }!! sender() ! Accepted(minProposal, accVal)
![Page 118: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/118.jpg)
Paxos, Prepare Phase
case Prepare(n, value) =>! if (n > minProposal) {! minProposal = n! accVal = value! }!! sender() ! Accepted(minProposal, accVal)
![Page 119: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/119.jpg)
Paxos, Prepare Phase
value = highestN(responses).accVal ! // replace my value, with accepted value!
![Page 120: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/120.jpg)
Paxos, Accept Phase
acceptors ! Accept(n, value)
![Page 121: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/121.jpg)
Paxos, Accept Phase
case Accept(n, value) =>! if (n >= minProposal) {! acceptedProposal = minProposal = n! acceptedValue = value! }!!learners ! Learn(value)!sender() ! minProposal
![Page 122: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/122.jpg)
Paxos, Accept Phase
![Page 123: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/123.jpg)
Paxos, Accept Phase
![Page 124: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/124.jpg)
Paxos, Accept Phase
if (acceptedN > n) restartPaxos()!else println(n + “ was chosen!”)
![Page 125: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/125.jpg)
Basic Paxos
Basic Paxos, needs extensions for the “real world”.
Additions: • “stable leader” • performance (basic = 2 * broadcast roundtrip) • ensure full replication • configuration changes
![Page 126: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/126.jpg)
Multi Paxos
![Page 127: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/127.jpg)
Multi Paxos
“Basically everyone does it, but everyone does it differently.”
![Page 128: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/128.jpg)
Multi Paxos
• Keeps the Leader • Clients find and talk to the Leader
• Skips Phase 1, in stable state • 2 delays instead of 4, until learning a value
![Page 129: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/129.jpg)
Raft
![Page 130: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/130.jpg)
Raft – inspired by Paxos
Paxos is great. Multi-Paxos is great, but no “common understanding”. !
!
Raft wants to be understandable and just as solid."In search of an understandable consensus protocol" (2013)
![Page 131: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/131.jpg)
Raft – inspired by Paxos!
!
• Leader based • Less processes than Paxos • It’s goal is simplicity • “Basic” includes snapshotting / membership
![Page 132: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/132.jpg)
Raft - summarised on one page
Diego Ongaro & John Ouserhout – In search of an understandable consensus protocol
![Page 133: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/133.jpg)
Raft
![Page 134: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/134.jpg)
Raft
![Page 135: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/135.jpg)
Raft - starting the cluster
![Page 136: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/136.jpg)
Raft - Election timeout
![Page 137: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/137.jpg)
Raft - 1st election
![Page 138: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/138.jpg)
Raft - 1st election
![Page 139: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/139.jpg)
Raft - Election Timeout
![Page 140: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/140.jpg)
Raft - Election Phase
![Page 141: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/141.jpg)
Raft
![Page 142: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/142.jpg)
Raft
![Page 143: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/143.jpg)
Raft
![Page 144: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/144.jpg)
Raft
![Page 145: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/145.jpg)
Raft
![Page 146: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/146.jpg)
Raft
![Page 147: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/147.jpg)
Raft
![Page 148: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/148.jpg)
Raft
![Page 149: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/149.jpg)
Raft
![Page 150: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/150.jpg)
Raft
![Page 151: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/151.jpg)
Raft – heartbeat = empty entries
![Page 152: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/152.jpg)
Raft – heartbeat = empty entries
![Page 153: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/153.jpg)
Akka–Raft !
(community project) (work in progress)
![Page 154: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/154.jpg)
Raft, reminder:
![Page 155: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/155.jpg)
Raft translated to Akka
abstract class RaftActor !! extends Actor ! ! with FSM[RaftState, Metadata]
![Page 156: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/156.jpg)
Raft translated to Akka
abstract class RaftActor !! extends Actor ! ! with FSM[RaftState, Metadata]
![Page 157: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/157.jpg)
Raft translated to Akka
onTransition {!! case Follower -> Candidate =>! self ! BeginElection! resetElectionDeadline()!! // ...!}
![Page 158: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/158.jpg)
Raft translated to Akka
onTransition {!! case Follower -> Candidate =>! self ! BeginElection! resetElectionDeadline()!! // ...!}
![Page 159: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/159.jpg)
Raft translated to Akka
! case Event(BeginElection, m: ElectionMeta) =>! log.info("Init election (among {} nodes) for {}”,! m.config.members.size, m.currentTerm)!! val request = RequestVote(m.currentTerm, m.clusterSelf, replicatedLog.lastTerm, replicatedLog.lastIndex)!! m.membersExceptSelf foreach { _ ! request }!! val includingThisVote = m.incVote! stay() using includingThisVote.withVoteFor(m.currentTerm, m.clusterSelf)! }!
![Page 160: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/160.jpg)
Raft translated to Akka
![Page 161: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/161.jpg)
Raft Heartbeat using Akka
akka-raft is a work in progress community project – it may change a lot
sendHeartbeat(m)!log.info("Starting hearbeat, with interval: {}", heartbeatInterval)!setTimer(HeartbeatName, SendHeartbeat, heartInterval, repeat = true)!
![Page 162: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/162.jpg)
Raft Heartbeat using Akka
akka-raft is a work in progress community project – it may change a lot
sendHeartbeat(m)!log.info("Starting hearbeat, with interval: {}", heartbeatInterval)!setTimer(HeartbeatName, SendHeartbeat, heartInterval, repeat = true)!
![Page 163: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/163.jpg)
Raft Heartbeat using Akka
akka-raft is a work in progress community project – it may change a lot
sendHeartbeat(m)!log.info("Starting hearbeat, with interval: {}", heartbeatInterval)!setTimer(HeartbeatName, SendHeartbeat, heartInterval, repeat = true)!
val leaderBehaviour = {! // ...! case Event(SendHeartbeat, m: LeaderMeta) =>! sendHeartbeat(m)! stay()!}
![Page 164: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/164.jpg)
Akka-Raft in User-Land //alpha!!!
class WordConcatRaftActor extends RaftActor {!! type Command = Cmnd!! var words = Vector[String]()!! /** Applied when command committed by Raft consensus */! def apply = {! case AppendWord(word) =>! words = words :+ word! word!! case GetWords =>! log.info("Replying with {}", words.toList)! words.toList! }!}!
akka-raft is a work in progress community project – it may change a lot
![Page 165: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/165.jpg)
FLP Impossibility
![Page 166: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/166.jpg)
FLP Impossibility Proof (19
Impossibility of Distributed Consensus with One Faulty Process 1985 by Fisher, Lynch, Paterson
![Page 167: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/167.jpg)
FLP Impossibility Result
Impossibility of Distributed Consensus with One Faulty Process 1985 by Fisher, Lynch, Paterson
![Page 168: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/168.jpg)
FLP Impossibility Result
Impossibility of Distributed Consensus with One Faulty Process 1985 by Fisher, Lynch, Paterson
![Page 169: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/169.jpg)
ktoso @ typesafe.com twitter: ktosopl github: ktoso blog: project13.pl team blog: letitcrash.com
JavaZone @ Oslo 2014
!
!
Takk! Dzięki! Thanks! ありがとう!
akka.io
![Page 170: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/170.jpg)
Konrad 'ktoso' Malawski GeeCON 2014 @ Kraków, PL
Happy Byzantine Lunch-time!
![Page 171: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/171.jpg)
©Typesafe 2014 – All Rights Reserved
![Page 172: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/172.jpg)
Links1. http://cs-www.cs.yale.edu/homes/arvind/cs425/doc/fischer.pdf 2. http://hydra.infosys.tuwien.ac.at/teaching/courses/AdvancedDistributedSystems/download/
1975_Akkoyunlu,%20Ekanadham,%20Huber_Some%20constraints%20and%20tradeoffs%20in%20the%20design%20of%20network%20communications.pdf
3. http://research.microsoft.com/en-us/people/mickens/thesaddestmoment.pdf 4. http://research.microsoft.com/en-us/um/people/lamport/pubs/lamport-paxos.pdf 5. http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf 6. http://the-paper-trail.org/blog/consensus-protocols-paxos/ 7. http://static.googleusercontent.com/media/research.google.com/en//archive/
paxos_made_live.pdf 8. http://static.googleusercontent.com/media/research.google.com/en//archive/chubby-
osdi06.pdf 9. https://ramcloud.stanford.edu/wiki/download/attachments/11370504/raft.pdf 10. Recent Leslie Lamport interview: http://www.se-radio.net/2014/04/episode-203-leslie-
lamport-on-distributed-systems/ 11. http://book.mixu.net/distsys/ 12. http://codahale.com/you-cant-sacrifice-partition-tolerance/
Peter Deutsch “The Eight Fallacies of Distributed Computing” https://blogs.oracle.com/jag/resource/Fallacies.html
![Page 173: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/173.jpg)
Links1. Excellent Paxos lecture by Diego Ongaro
https://www.youtube.com/watch?v=JEpsBg0AO6o 2. Fallacies, actual paper: http://www.rgoarchitects.com/Files/fallacies.pdf 3. Diego Ongaro & John Ouserhout – In search of an understandable consensus protocol 4. http://macs.citadel.edu/rudolphg/csci604/ImpossibilityofConsensus.pdf
Peter Deutsch “The Eight Fallacies of Distributed Computing” https://blogs.oracle.com/jag/resource/Fallacies.html
![Page 174: Distributed Consensus A.K.A. "What do we eat for lunch?"](https://reader034.fdocuments.us/reader034/viewer/2022051609/547895deb4af9faa158b458e/html5/thumbnails/174.jpg)
Images / drawings1. Paxos Island Photo – Luigi Piazzi (CC license) https://www.flickr.com/photos/photolupi/
3686769346/in/photolist-6BME5J-orKHL2-58qmez-58uz7s-7bRwTj-7bRvHY-6DdRC2-fBqFFU-35KTg7-8vbe23-bsBGL7-58qq6z-58uAjG-8vbeCd-d1Sqqw-d1Smsj-d1Sqi5-d1SoMA-d1SmBE-d1SpVo-d1Sk2U-d1SoBQ-d1SoXu-d1SoqN-d1Spqu-d1Sq4w-d1SpLU-d1SKDG-d1Skcu-d1Sp8f-d1Sqaq-d1SpCw-75YaVN-d1SLs1-d1SK15-d1SJiC-d1Suiu-d1SKtS-d1SjQS-d1StyU-d1SKi1-d1SxGS-d1Sm6j-d1Sxdh-d1SKMN-d1SxAq-d1SwgC-d1Smgj-d1SvhJ-d1SjC7
2. Drawings – myself (use-them-at-will-unless-mocking-my-horrible-drawing-skills-license)
Peter Deutsch “The Eight Fallacies of Distributed Computing” https://blogs.oracle.com/jag/resource/Fallacies.html