Created
January 23, 2012 16:20
-
-
Save jamii/1664066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in_journal() -> | |
receive | |
{Seq, Event} -> | |
transaction_manager ! {Seq, Event}, | |
write({Seq, Event}), | |
sync(), | |
out_journal ! {journaled, Seq} | |
end. | |
% in cpp or ocaml | |
transaction_manager() -> | |
receive | |
{Seq, Event} -> | |
{Result, OutEvents} = handle(Event), | |
out_jornal ! {handled, Seq, Result, OutEvents} | |
end. | |
out_journal() -> | |
receive | |
{handled, Seq, Result, OutEvents} -> | |
receive | |
{journaled, Seq} -> | |
write({Seq, started}), | |
sync(), | |
send(OutEvents), | |
write({Seq, finished}), | |
sync() | |
end | |
end. | |
% on recovery, have to manually check any unfinished output | |
% worth batching writes so we don't have to sync as often eg | |
receive_batch(Acc, 0) -> | |
Acc; | |
receive_batch(Acc, Max) -> | |
receive | |
Event -> | |
receive_batch([Event|Acc], Max-1) | |
after 0 -> | |
Acc | |
end. | |
in_journal() -> | |
Events = receive_batch([], 16), | |
transaction_manager ! Events | |
write(Events), | |
sync(), | |
out_journal ! {journaled_up_to, max_seq(Events)} | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment