Sagas: distributed transactions without locks · Sagas: distributed transactions without locks in...

Post on 17-Aug-2020

8 views 0 download

transcript

Sagas:distributedtransactionswithoutlocksinErlangMARKALLEN- ALERTLOGIC

MARK.ALLEN@ALERTLOGIC.COM

@BYTEMEORG

Sagas

TypesofSagas§BackwardRecovery§ForwardRecovery§“RecoveryBlocks”§ParallelSagas

SagasinErlang

TheBig IdeaFoldoveralistofclosures…

TheBig IdeaFoldoveralistofclosures…...unlessthere’sanerror.

TheBig IdeaFoldoveralistofclosures…...unlessthere’sanerror;Then,foldoveralistofclosures.

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

Flows

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

BOOM

Flows

Forward1 Forward2 Forward3

Rollback1 Rollback2 Rollback3

BOOM

Flows

Forward1 Forward2 Forward3

Rollback1 Rollback2 Rollback3

BOOM

Flows

Forward1 Forward2 Forward3

Rollback1 Rollback2 Rollback3

BOOM

Flows

Forward1 Forward2 Forward3

Rollback1 Rollback2 Rollback3

BOOM

Terminology

§Operation§Step§Transaction

Terminology

Forward1 Forward2 Forward3 Forward4 Forward5

Rollback1 Rollback2 Rollback3 Rollback4 Rollback5

ImplicitAssumptionsandRequirements

CompensatingClosures

CannotAbort

IdempotentRequests

Whatif??

Forward1 Forward2 Forward3

Rollback1 Rollback2 Rollback3

BOOM

Whatif??

Forward1 Forward2 Forward3 Forward4

Rollback1 Rollback2 Rollback3

FuturesinErlang

WhydoesErlangneedfutures?!

Itdoesn’t!Except…

AsynchronousSagaOperations

Implementation

Semantics?

PropertyBasedTests

Whatisit?§Writeoneormoreinvariants§Testvaluesareautomaticallygeneratedandtheinvarianttested§Failuresareshrunktothesmallestpossiblefailurecase§Modifycode(ortestcase)andrestarttest§Testsareusuallytimeboxed§Extremelyusefultobuildconfidenceincomplexscenarios

AcademichistoryQuickCheck:ALightweightToolforRandomTestingofHaskellPrograms

Implementationsfor§Go§C/C++§Clojure§Scala§Haskell(ofcourse)§… lotsofothers…§Erlang/Elixir(watchThomasArtstalkatElixirConf EU2015)

Erlang implementations§Quviq CommercialQuickCheck (http://www.quviq.com)§Free(butnotopensource)“QuickCheck mini”– doesn’tdostatem§PropEr (https://github.com/manopapad/proper)§Triq (https://github.com/triqng/triq)

Generators§Allstandardbasictypes:§ integers,§ floats,§atoms,§binaries,§strings,§ lists

§Listsofbasictypes§Userdefinedgeneratorsusing?LETand?SUCHTHAT

Propositions§?FORALL(Variable,generator_function(),test_function(Variable))

Resources§https://github.com/mrallen1/gisla

§https://github.com/mrallen1/criswell

§Sagaspaper:http://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf

§Caitie McCaffrey,PapersWeLoveonSagas:https://youtu.be/7dc4Tl5ZHRg?t=27m16s

§Caitie McCaffrey,DistributedSagas:https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for-coordinating-microservices

§Theseslides: https://speakerdeck.com/mrallen1/sagas-distributed-transactions-without-locks