diff --git a/doc/README.md b/doc/README.md index 74849f7..c4d1c8c 100644 --- a/doc/README.md +++ b/doc/README.md @@ -6,7 +6,27 @@ Erlang documentation, please use this link: ## Documents in this directory -* __chain-self-management-sketch.org__ is an introduction to the +### chain-self-management-sketch.org + +__chain-self-management-sketch.org__ is an introduction to the self-management algorithm proposed for Machi. This algorithm is (hoped to be) sufficient for managing the Chain Replication state of a Machi cluster. + +### high-level-machi.pdf + +__high-level-machi.pdf__ is an overview of the high level design for +Machi. Its abstract: + +> Our goal is a robust & reliable, distributed, highly available large +> file store based upon write-once registers, append-only files, Chain +> Replication, and client-server style architecture. All members of +> the cluster store all of the files. Distributed load +> balancing/sharding of files is outside of the scope of this system. +> However, it is a high priority that this system be able to integrate +> easily into systems that do provide distributed load balancing, +> e.g., Riak Core. Although strong consistency is a major feature of +> Chain Replication, this document will focus mainly on eventual +> consistency features --- strong consistency design will be discussed +> in a separate document. + diff --git a/doc/chain-self-management-sketch.org b/doc/chain-self-management-sketch.org index fcd8f8b..dd11a35 100644 --- a/doc/chain-self-management-sketch.org +++ b/doc/chain-self-management-sketch.org @@ -5,20 +5,10 @@ #+SEQ_TODO: TODO WORKING WAITING DONE * 1. Abstract -Yo, this is the first draft of a document that attempts to describe a -proposed self-management algorithm for Machi's chain replication. -Welcome! Sit back and enjoy the disjointed prose. +The high level design of the Machi "chain manager" has moved to the +[[high-level-chain-manager.pdf][Machi chain manager high level design]] document. -We attempt to describe first the self-management and self-reliance -goals of the algorithm. Then we make a side trip to talk about -write-once registers and how they're used by Machi, but we don't -really fully explain exactly why write-once is so critical (why not -general purpose registers?) ... but they are indeed critical. Then we -sketch the algorithm by providing detailed annotation of a flowchart, -then let the flowchart speak for itself, because writing good prose is -prose is damn hard, but flowcharts are very specific and concise. - -Finally, we try to discuss the network partition simulator that the +We try to discuss the network partition simulator that the algorithm runs in and how the algorithm behaves in both symmetric and asymmetric network partition scenarios. The symmetric partition cases are all working well (surprising in a good way), and the asymmetric @@ -46,325 +36,13 @@ the simulator. %% under the License. #+END_SRC -* 3. Naming: possible ideas (TODO) -** Humming consensus? -See [[https://tools.ietf.org/html/rfc7282][On Consensus and Humming in the IETF]], RFC 7282. +* 3. Document restructuring -See also: [[http://www.snookles.com/slf-blog/2015/03/01/on-humming-consensus-an-allegory/][On “Humming Consensus”, an allegory]]. +Much of the text previously appearing in this document has moved to the +[[high-level-chain-manager.pdf][Machi chain manager high level design]] document. -** Foggy consensus? - -CORFU-like consensus between mist-shrouded islands of network -partitions - -** Rough consensus - -This is my favorite, but it might be too close to handwavy/vagueness -of English language, even with a precise definition and proof -sketching? - -** Let the bikeshed continue! - -I agree with Chris: there may already be a definition that's close -enough to "rough consensus" to continue using that existing tag than -to invent a new one. TODO: more research required - -* 4. What does "self-management" mean in this context? - -For the purposes of this document, chain replication self-management -is the ability for the N nodes in an N-length chain replication chain -to manage the state of the chain without requiring an external party -to participate. Chain state includes: - -1. Preserve data integrity of all data stored within the chain. Data - loss is not an option. -2. Stably preserve knowledge of chain membership (i.e. all nodes in - the chain, regardless of operational status). A systems - administrators is expected to make "permanent" decisions about - chain membership. -3. Use passive and/or active techniques to track operational - state/status, e.g., up, down, restarting, full data sync, partial - data sync, etc. -4. Choose the run-time replica ordering/state of the chain, based on - current member status and past operational history. All chain - state transitions must be done safely and without data loss or - corruption. -5. As a new node is added to the chain administratively or old node is - restarted, add the node to the chain safely and perform any data - synchronization/"repair" required to bring the node's data into - full synchronization with the other nodes. - -* 5. Goals -** Better than state-of-the-art: Chain Replication self-management - -We hope/believe that this new self-management algorithem can improve -the current state-of-the-art by eliminating all external management -entities. Current state-of-the-art for management of chain -replication chains is discussed below, to provide historical context. - -*** "Leveraging Sharding in the Design of Scalable Replication Protocols" by Abu-Libdeh, van Renesse, and Vigfusson. - -Multiple chains are arranged in a ring (called a "band" in the paper). -The responsibility for managing the chain at position N is delegated -to chain N-1. As long as at least one chain is running, that is -sufficient to start/bootstrap the next chain, and so on until all -chains are running. (The paper then estimates mean-time-to-failure -(MTTF) and suggests a "band of bands" topology to handle very large -clusters while maintaining an MTTF that is as good or better than -other management techniques.) - -If the chain self-management method proposed for Machi does not -succeed, this paper's technique is our best fallback recommendation. - -*** An external management oracle, implemented by ZooKeeper - -This is not a recommendation for Machi: we wish to avoid using ZooKeeper. -However, many other open and closed source software products use -ZooKeeper for exactly this kind of data replica management problem. - -*** An external management oracle, implemented by Riak Ensemble - -This is a much more palatable choice than option #2 above. We also -wish to avoid an external dependency on something as big as Riak -Ensemble. However, if it comes between choosing Riak Ensemble or -choosing ZooKeeper, the choice feels quite clear: Riak Ensemble will -win, unless there is some critical feature missing from Riak -Ensemble. If such an unforseen missing feature is discovered, it -would probably be preferable to add the feature to Riak Ensemble -rather than to use ZooKeeper (and document it and provide product -support for it and so on...). - -** Support both eventually consistent & strongly consistent modes of operation - -Machi's first use case is for Riak CS, as an eventually consistent -store for CS's "block" storage. Today, Riak KV is used for "block" -storage. Riak KV is an AP-style key-value store; using Machi in an -AP-style mode would match CS's current behavior from points of view of -both code/execution and human administrator exectations. - -Later, we wish the option of using CP support to replace other data -store services that Riak KV provides today. (Scope and timing of such -replacement TBD.) - -We believe this algorithm allows a Machi cluster to fragment into -arbitrary islands of network partition, all the way down to 100% of -members running in complete network isolation from each other. -Furthermore, it provides enough agreement to allow -formerly-partitioned members to coordinate the reintegration & -reconciliation of their data when partitions are healed. - -** Preserve data integrity of Chain Replicated data - -While listed last in this section, preservation of data integrity is -paramount to any chain state management technique for Machi. - -** Anti-goal: minimize churn - -This algorithm's focus is data safety and not availability. If -participants have differing notions of time, e.g., running on -extremely fast or extremely slow hardware, then this algorithm will -"churn" in different states where the chain's data would be -effectively unavailable. - -In practice, however, any series of network partition changes that -case this algorithm to churn will cause other management techniques -(such as an external "oracle") similar problems. [Proof by handwaving -assertion.] See also: "time model" assumptions (below). - -* 6. Assumptions -** Introduction to assumptions, why they differ from other consensus algorithms - -Given a long history of consensus algorithms (viewstamped replication, -Paxos, Raft, et al.), why bother with a slightly different set of -assumptions and a slightly different protocol? - -The answer lies in one of our explicit goals: to have an option of -running in an "eventually consistent" manner. We wish to be able to -make progress, i.e., remain available in the CAP sense, even if we are -partitioned down to a single isolated node. VR, Paxos, and Raft -alone are not sufficient to coordinate service availability at such -small scale. - -** The CORFU protocol is correct - -This work relies tremendously on the correctness of the CORFU -protocol, a cousin of the Paxos protocol. If the implementation of -this self-management protocol breaks an assumption or prerequisite of -CORFU, then we expect that the implementation will be flawed. - -** Communication model: Asyncronous message passing -*** Unreliable network: messages may be arbitrarily dropped and/or reordered -**** Network partitions may occur at any time -**** Network partitions may be asymmetric: msg A->B is ok but B->A fails -*** Messages may be corrupted in-transit -**** Assume that message MAC/checksums are sufficient to detect corruption -**** Receiver informs sender of message corruption -**** Sender may resend, if/when desired -*** System particpants may be buggy but not actively malicious/Byzantine -** Time model: per-node clocks, loosely synchronized (e.g. NTP) - -The protocol & algorithm presented here do not specify or require any -timestamps, physical or logical. Any mention of time inside of data -structures are for human/historic/diagnostic purposes only. - -Having said that, some notion of physical time is suggested for -purposes of efficiency. It's recommended that there be some "sleep -time" between iterations of the algorithm: there is no need to "busy -wait" by executing the algorithm as quickly as possible. See below, -"sleep intervals between executions". - -** Failure detector model: weak, fallible, boolean - -We assume that the failure detector that the algorithm uses is weak, -it's fallible, and it informs the algorithm in boolean status -updates/toggles as a node becomes available or not. - -If the failure detector is fallible and tells us a mistaken status -change, then the algorithm will "churn" the operational state of the -chain, e.g. by removing the failed node from the chain or adding a -(re)started node (that may not be alive) to the end of the chain. -Such extra churn is regrettable and will cause periods of delay as the -"rough consensus" (decribed below) decision is made. However, the -churn cannot (we assert/believe) cause data loss. - -** The "wedge state", as described by the Machi RFC & CORFU - -A chain member enters "wedge state" when it receives information that -a newer projection (i.e., run-time chain state reconfiguration) is -available. The new projection may be created by a system -administrator or calculated by the self-management algorithm. -Notification may arrive via the projection store API or via the file -I/O API. - -When in wedge state, the server/FLU will refuse all file write I/O API -requests until the self-management algorithm has determined that -"rough consensus" has been decided (see next bullet item). The server -may also refuse file read I/O API requests, depending on its CP/AP -operation mode. - -See the Machi RFC for more detail of the wedge state and also the -CORFU papers. - -** "Rough consensus": consensus built upon data that is *visible now* - -CS literature uses the word "consensus" in the context of the problem -description at -[[http://en.wikipedia.org/wiki/Consensus_(computer_science)#Problem_description]]. -This traditional definition differs from what is described in this -document. - -The phrase "rough consensus" will be used to describe -consensus derived only from data that is visible/known at the current -time. This implies that a network partition may be in effect and that -not all chain members are reachable. The algorithm will calculate -"rough consensus" despite not having input from all/majority/minority -of chain members. "Rough consensus" may proceed to make a -decision based on data from only a single participant, i.e., the local -node alone. - -When operating in AP mode, i.e., in eventual consistency mode, "rough -consensus" could mean that an chain of length N could split into N -independent chains of length 1. When a network partition heals, the -rough consensus is sufficient to manage the chain so that each -replica's data can be repaired/merged/reconciled safely. -(Other features of the Machi system are designed to assist such -repair safely.) - -When operating in CP mode, i.e., in strong consistency mode, "rough -consensus" would require additional supplements. For example, any -chain that didn't have a minimum length of the quorum majority size of -all members would be invalid and therefore would not move itself out -of wedged state. In very general terms, this requirement for a quorum -majority of surviving participants is also a requirement for Paxos, -Raft, and ZAB. - -(Aside: The Machi RFC also proposes using "witness" chain members to -make service more available, e.g. quorum majority of "real" plus -"witness" nodes *and* at least one member must be a "real" node. See -the Machi RFC for more details.) - -** Heavy reliance on a key-value store that maps write-once registers - -The projection store is implemented using "write-once registers" -inside a key-value store: for every key in the store, the value must -be either of: - -- The special 'unwritten' value -- An application-specific binary blob that is immutable thereafter - -* 7. The projection store, built with write-once registers - -- NOTE to the reader: The notion of "public" vs. "private" projection - stores does not appear in the Machi RFC. - -Each participating chain node has its own "projection store", which is -a specialized key-value store. As a whole, a node's projection store -is implemented using two different key-value stores: - -- A publicly-writable KV store of write-once registers -- A privately-writable KV store of write-once registers - -Both stores may be read by any cluster member. - -The store's key is a positive integer; the integer represents the -epoch number of the projection. The store's value is an opaque -binary blob whose meaning is meaningful only to the store's clients. - -See the Machi RFC for more detail on projections and epoch numbers. - -** The publicly-writable half of the projection store - -The publicly-writable projection store is used to share information -during the first half of the self-management algorithm. Any chain -member may write a projection to this store. - -** The privately-writable half of the projection store - -The privately-writable projection store is used to store the "rough -consensus" result that has been calculated by the local node. Only -the local server/FLU may write values into this store. - -The private projection store serves multiple purposes, including: - -- remove/clear the local server from "wedge state" -- act as the store of record for chain state transitions -- communicate to remote nodes the past states and current operational - state of the local node - -* 8. Modification of CORFU-style epoch numbering and "wedge state" triggers - -According to the CORFU research papers, if a server node N or client -node C believes that epoch E is the latest epoch, then any information -that N or C receives from any source that an epoch E+delta (where -delta > 0) exists will push N into the "wedge" state and C into a mode -of searching for the projection definition for the newest epoch. - -In the algorithm sketch below, it should become clear that it's -possible to have a race where two nodes may attempt to make proposals -for a single epoch number. In the simplest case, assume a chain of -nodes A & B. Assume that a symmetric network partition between A & B -happens, and assume we're operating in AP/eventually consistent mode. - -On A's network partitioned island, A can choose a UPI list of `[A]'. -Similarly B can choose a UPI list of `[B]'. Both might choose the -epoch for their proposal to be #42. Because each are separated by -network partition, neither can realize the conflict. However, when -the network partition heals, it can become obvious that there are -conflicting values for epoch #42 ... but if we use CORFU's protocol -design, which identifies the epoch identifier as an integer only, then -the integer 42 alone is not sufficient to discern the differences -between the two projections. - -The proposal modifies all use of CORFU's projection identifier -to use the identifier below instead. (A later section of this -document presents a detailed example.) - -#+BEGIN_SRC -{epoch #, hash of the entire projection (minus hash field itself)} -#+END_SRC - -* 9. Diagram of the self-management algorithm +* 4. Diagram of the self-management algorithm ** Introduction Refer to the diagram [[https://github.com/basho/machi/blob/master/doc/chain-self-management-sketch.Diagram1.pdf][chain-self-management-sketch.Diagram1.pdf]], @@ -579,7 +257,7 @@ use of quorum majority for UPI members is out of scope of this document. Also out of scope is the use of "witness servers" to augment the quorum majority UPI scheme.) -* 10. The Network Partition Simulator +* 5. The Network Partition Simulator ** Overview The function machi_chain_manager1_test:convergence_demo_test() executes the following in a simulated network environment within a diff --git a/doc/high-level-machi.pdf b/doc/high-level-machi.pdf new file mode 100644 index 0000000..c357c2d Binary files /dev/null and b/doc/high-level-machi.pdf differ diff --git a/doc/src.high-level/.gitignore b/doc/src.high-level/.gitignore new file mode 100644 index 0000000..2a517a6 --- /dev/null +++ b/doc/src.high-level/.gitignore @@ -0,0 +1,4 @@ +*.aux +*.dvi +*.log +*.pdf diff --git a/doc/src.high-level/Makefile b/doc/src.high-level/Makefile new file mode 100644 index 0000000..3c99a71 --- /dev/null +++ b/doc/src.high-level/Makefile @@ -0,0 +1,8 @@ +all: + latex high-level-machi.tex + dvipdfm high-level-machi.dvi + latex high-level-chain-mgr.tex + dvipdfm high-level-chain-mgr.dvi + +clean: + rm -f *.aux *.dvi *.log diff --git a/doc/src.high-level/append-flow.eps b/doc/src.high-level/append-flow.eps new file mode 100644 index 0000000..9df810e --- /dev/null +++ b/doc/src.high-level/append-flow.eps @@ -0,0 +1,268 @@ +%!PS-Adobe-3.0 EPSF-2.0 +%%BoundingBox: 0 0 416.500000 280.000000 +%%Creator: mscgen 0.18 +%%EndComments +0.700000 0.700000 scale +0 0 moveto +0 400 lineto +595 400 lineto +595 0 lineto +closepath +clip +%PageTrailer +%Page: 1 1 +/Helvetica findfont +10 scalefont +setfont +/Helvetica findfont +12 scalefont +setfont +0 400 translate +/mtrx matrix def +/ellipse + { /endangle exch def + /startangle exch def + /ydia exch def + /xdia exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y translate + xdia 2 div ydia 2 div scale + 1 -1 scale + 0 0 1 startangle endangle arc + savematrix setmatrix +} def +(client) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 42 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +42 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(Projection) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 127 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +127 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(ProjStore_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 212 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +212 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(Sequencer_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 297 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +297 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 382 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +382 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_B) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 467 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +467 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_C) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 552 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +552 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +newpath 42 -22 moveto 42 -49 lineto stroke +newpath 127 -22 moveto 127 -49 lineto stroke +newpath 212 -22 moveto 212 -49 lineto stroke +newpath 297 -22 moveto 297 -49 lineto stroke +newpath 382 -22 moveto 382 -49 lineto stroke +newpath 467 -22 moveto 467 -49 lineto stroke +newpath 552 -22 moveto 552 -49 lineto stroke +newpath 42 -35 moveto 127 -35 lineto stroke +newpath 127 -35 moveto 117 -41 lineto stroke +(get current) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 57 -33 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +57 -33 moveto show +newpath 42 -49 moveto 42 -76 lineto stroke +newpath 127 -49 moveto 127 -76 lineto stroke +newpath 212 -49 moveto 212 -76 lineto stroke +newpath 297 -49 moveto 297 -76 lineto stroke +newpath 382 -49 moveto 382 -76 lineto stroke +newpath 467 -49 moveto 467 -76 lineto stroke +newpath 552 -49 moveto 552 -76 lineto stroke +newpath 127 -62 moveto 42 -62 lineto stroke +newpath 42 -62 moveto 52 -68 lineto stroke +(ok, #12...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 61 -60 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +61 -60 moveto show +newpath 42 -76 moveto 42 -103 lineto stroke +newpath 127 -76 moveto 127 -103 lineto stroke +newpath 212 -76 moveto 212 -103 lineto stroke +newpath 297 -76 moveto 297 -103 lineto stroke +newpath 382 -76 moveto 382 -103 lineto stroke +newpath 467 -76 moveto 467 -103 lineto stroke +newpath 552 -76 moveto 552 -103 lineto stroke +newpath 42 -89 moveto 297 -89 lineto stroke +newpath 297 -89 moveto 287 -95 lineto stroke +(Req. 123 bytes, prefix="foo", epoch=12) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 66 -87 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +66 -87 moveto show +newpath 42 -103 moveto 42 -130 lineto stroke +newpath 127 -103 moveto 127 -130 lineto stroke +newpath 212 -103 moveto 212 -130 lineto stroke +newpath 297 -103 moveto 297 -130 lineto stroke +newpath 382 -103 moveto 382 -130 lineto stroke +newpath 467 -103 moveto 467 -130 lineto stroke +newpath 552 -103 moveto 552 -130 lineto stroke +newpath 297 -116 moveto 42 -116 lineto stroke +newpath 42 -116 moveto 52 -122 lineto stroke +1.000000 0.000000 0.000000 setrgbcolor +(bad_epoch, 13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 131 -114 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +1.000000 0.000000 0.000000 setrgbcolor +131 -114 moveto show +0.000000 0.000000 0.000000 setrgbcolor +newpath 42 -130 moveto 42 -157 lineto stroke +newpath 127 -130 moveto 127 -157 lineto stroke +newpath 212 -130 moveto 212 -157 lineto stroke +newpath 297 -130 moveto 297 -157 lineto stroke +newpath 382 -130 moveto 382 -157 lineto stroke +newpath 467 -130 moveto 467 -157 lineto stroke +newpath 552 -130 moveto 552 -157 lineto stroke +newpath 42 -143 moveto 212 -143 lineto stroke +newpath 212 -143 moveto 202 -149 lineto stroke +(get epoch #13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 89 -141 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +89 -141 moveto show +newpath 42 -157 moveto 42 -184 lineto stroke +newpath 127 -157 moveto 127 -184 lineto stroke +newpath 212 -157 moveto 212 -184 lineto stroke +newpath 297 -157 moveto 297 -184 lineto stroke +newpath 382 -157 moveto 382 -184 lineto stroke +newpath 467 -157 moveto 467 -184 lineto stroke +newpath 552 -157 moveto 552 -184 lineto stroke +newpath 212 -170 moveto 42 -170 lineto stroke +newpath 42 -170 moveto 52 -176 lineto stroke +(ok, #13...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 103 -168 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +103 -168 moveto show +newpath 42 -184 moveto 42 -211 lineto stroke +newpath 127 -184 moveto 127 -211 lineto stroke +newpath 212 -184 moveto 212 -211 lineto stroke +newpath 297 -184 moveto 297 -211 lineto stroke +newpath 382 -184 moveto 382 -211 lineto stroke +newpath 467 -184 moveto 467 -211 lineto stroke +newpath 552 -184 moveto 552 -211 lineto stroke +newpath 42 -197 moveto 297 -197 lineto stroke +newpath 297 -197 moveto 287 -203 lineto stroke +(Req. 123 bytes, prefix="foo", epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 66 -195 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +66 -195 moveto show +newpath 42 -211 moveto 42 -238 lineto stroke +newpath 127 -211 moveto 127 -238 lineto stroke +newpath 212 -211 moveto 212 -238 lineto stroke +newpath 297 -211 moveto 297 -238 lineto stroke +newpath 382 -211 moveto 382 -238 lineto stroke +newpath 467 -211 moveto 467 -238 lineto stroke +newpath 552 -211 moveto 552 -238 lineto stroke +newpath 297 -224 moveto 42 -224 lineto stroke +newpath 42 -224 moveto 52 -230 lineto stroke +(ok, "foo.seq_a.009" offset=447) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 89 -222 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +89 -222 moveto show +newpath 42 -238 moveto 42 -265 lineto stroke +newpath 127 -238 moveto 127 -265 lineto stroke +newpath 212 -238 moveto 212 -265 lineto stroke +newpath 297 -238 moveto 297 -265 lineto stroke +newpath 382 -238 moveto 382 -265 lineto stroke +newpath 467 -238 moveto 467 -265 lineto stroke +newpath 552 -238 moveto 552 -265 lineto stroke +newpath 42 -251 moveto 382 -251 lineto stroke +newpath 382 -251 moveto 372 -257 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 51 -249 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +51 -249 moveto show +newpath 42 -265 moveto 42 -292 lineto stroke +newpath 127 -265 moveto 127 -292 lineto stroke +newpath 212 -265 moveto 212 -292 lineto stroke +newpath 297 -265 moveto 297 -292 lineto stroke +newpath 382 -265 moveto 382 -292 lineto stroke +newpath 467 -265 moveto 467 -292 lineto stroke +newpath 552 -265 moveto 552 -292 lineto stroke +newpath 382 -278 moveto 42 -278 lineto stroke +newpath 42 -278 moveto 52 -284 lineto stroke +(ok) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 206 -276 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +206 -276 moveto show +newpath 42 -292 moveto 42 -319 lineto stroke +newpath 127 -292 moveto 127 -319 lineto stroke +newpath 212 -292 moveto 212 -319 lineto stroke +newpath 297 -292 moveto 297 -319 lineto stroke +newpath 382 -292 moveto 382 -319 lineto stroke +newpath 467 -292 moveto 467 -319 lineto stroke +newpath 552 -292 moveto 552 -319 lineto stroke +newpath 42 -305 moveto 467 -305 lineto stroke +newpath 467 -305 moveto 457 -311 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 94 -303 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +94 -303 moveto show +newpath 42 -319 moveto 42 -346 lineto stroke +newpath 127 -319 moveto 127 -346 lineto stroke +newpath 212 -319 moveto 212 -346 lineto stroke +newpath 297 -319 moveto 297 -346 lineto stroke +newpath 382 -319 moveto 382 -346 lineto stroke +newpath 467 -319 moveto 467 -346 lineto stroke +newpath 552 -319 moveto 552 -346 lineto stroke +newpath 467 -332 moveto 42 -332 lineto stroke +newpath 42 -332 moveto 52 -338 lineto stroke +(ok) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 249 -330 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +249 -330 moveto show +newpath 42 -346 moveto 42 -373 lineto stroke +newpath 127 -346 moveto 127 -373 lineto stroke +newpath 212 -346 moveto 212 -373 lineto stroke +newpath 297 -346 moveto 297 -373 lineto stroke +newpath 382 -346 moveto 382 -373 lineto stroke +newpath 467 -346 moveto 467 -373 lineto stroke +newpath 552 -346 moveto 552 -373 lineto stroke +newpath 42 -359 moveto 552 -359 lineto stroke +newpath 552 -359 moveto 542 -365 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 136 -357 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +136 -357 moveto show +newpath 42 -373 moveto 42 -400 lineto stroke +newpath 127 -373 moveto 127 -400 lineto stroke +newpath 212 -373 moveto 212 -400 lineto stroke +newpath 297 -373 moveto 297 -400 lineto stroke +newpath 382 -373 moveto 382 -400 lineto stroke +newpath 467 -373 moveto 467 -400 lineto stroke +newpath 552 -373 moveto 552 -400 lineto stroke +newpath 552 -386 moveto 42 -386 lineto stroke +newpath 42 -386 moveto 52 -392 lineto stroke +(ok) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 291 -384 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +291 -384 moveto show diff --git a/doc/src.high-level/append-flow2.eps b/doc/src.high-level/append-flow2.eps new file mode 100644 index 0000000..0acff62 --- /dev/null +++ b/doc/src.high-level/append-flow2.eps @@ -0,0 +1,345 @@ +%!PS-Adobe-3.0 EPSF-2.0 +%%BoundingBox: 0 0 416.500000 355.600006 +%%Creator: mscgen 0.18 +%%EndComments +0.700000 0.700000 scale +0 0 moveto +0 508 lineto +595 508 lineto +595 0 lineto +closepath +clip +%PageTrailer +%Page: 1 1 +/Helvetica findfont +10 scalefont +setfont +/Helvetica findfont +12 scalefont +setfont +0 508 translate +/mtrx matrix def +/ellipse + { /endangle exch def + /startangle exch def + /ydia exch def + /xdia exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y translate + xdia 2 div ydia 2 div scale + 1 -1 scale + 0 0 1 startangle endangle arc + savematrix setmatrix +} def +(client) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 42 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +42 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(Projection) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 127 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +127 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(ProjStore_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 212 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +212 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(Sequencer_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 297 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +297 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_A) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 382 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +382 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_B) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 467 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +467 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_C) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 552 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +552 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +newpath 42 -22 moveto 42 -49 lineto stroke +newpath 127 -22 moveto 127 -49 lineto stroke +newpath 212 -22 moveto 212 -49 lineto stroke +newpath 297 -22 moveto 297 -49 lineto stroke +newpath 382 -22 moveto 382 -49 lineto stroke +newpath 467 -22 moveto 467 -49 lineto stroke +newpath 552 -22 moveto 552 -49 lineto stroke +newpath 42 -35 moveto 127 -35 lineto stroke +newpath 127 -35 moveto 117 -41 lineto stroke +(get current) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 57 -33 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +57 -33 moveto show +newpath 42 -49 moveto 42 -76 lineto stroke +newpath 127 -49 moveto 127 -76 lineto stroke +newpath 212 -49 moveto 212 -76 lineto stroke +newpath 297 -49 moveto 297 -76 lineto stroke +newpath 382 -49 moveto 382 -76 lineto stroke +newpath 467 -49 moveto 467 -76 lineto stroke +newpath 552 -49 moveto 552 -76 lineto stroke +newpath 127 -62 moveto 42 -62 lineto stroke +newpath 42 -62 moveto 52 -68 lineto stroke +(ok, #12...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 61 -60 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +61 -60 moveto show +newpath 42 -76 moveto 42 -103 lineto stroke +newpath 127 -76 moveto 127 -103 lineto stroke +newpath 212 -76 moveto 212 -103 lineto stroke +newpath 297 -76 moveto 297 -103 lineto stroke +newpath 382 -76 moveto 382 -103 lineto stroke +newpath 467 -76 moveto 467 -103 lineto stroke +newpath 552 -76 moveto 552 -103 lineto stroke +newpath 42 -89 moveto 382 -89 lineto stroke +newpath 382 -89 moveto 372 -95 lineto stroke +(append prefix="foo" <<123 bytes...>> epoch=12) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 85 -87 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +85 -87 moveto show +newpath 42 -103 moveto 42 -130 lineto stroke +newpath 127 -103 moveto 127 -130 lineto stroke +newpath 212 -103 moveto 212 -130 lineto stroke +newpath 297 -103 moveto 297 -130 lineto stroke +newpath 382 -103 moveto 382 -130 lineto stroke +newpath 467 -103 moveto 467 -130 lineto stroke +newpath 552 -103 moveto 552 -130 lineto stroke +newpath 382 -116 moveto 42 -116 lineto stroke +newpath 42 -116 moveto 52 -122 lineto stroke +1.000000 0.000000 0.000000 setrgbcolor +(bad_epoch, 13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 173 -114 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +1.000000 0.000000 0.000000 setrgbcolor +173 -114 moveto show +0.000000 0.000000 0.000000 setrgbcolor +newpath 42 -130 moveto 42 -157 lineto stroke +newpath 127 -130 moveto 127 -157 lineto stroke +newpath 212 -130 moveto 212 -157 lineto stroke +newpath 297 -130 moveto 297 -157 lineto stroke +newpath 382 -130 moveto 382 -157 lineto stroke +newpath 467 -130 moveto 467 -157 lineto stroke +newpath 552 -130 moveto 552 -157 lineto stroke +newpath 42 -143 moveto 212 -143 lineto stroke +newpath 212 -143 moveto 202 -149 lineto stroke +(get epoch #13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 89 -141 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +89 -141 moveto show +newpath 42 -157 moveto 42 -184 lineto stroke +newpath 127 -157 moveto 127 -184 lineto stroke +newpath 212 -157 moveto 212 -184 lineto stroke +newpath 297 -157 moveto 297 -184 lineto stroke +newpath 382 -157 moveto 382 -184 lineto stroke +newpath 467 -157 moveto 467 -184 lineto stroke +newpath 552 -157 moveto 552 -184 lineto stroke +newpath 212 -170 moveto 42 -170 lineto stroke +newpath 42 -170 moveto 52 -176 lineto stroke +(ok, #13...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 103 -168 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +103 -168 moveto show +newpath 42 -184 moveto 42 -211 lineto stroke +newpath 127 -184 moveto 127 -211 lineto stroke +newpath 212 -184 moveto 212 -211 lineto stroke +newpath 297 -184 moveto 297 -211 lineto stroke +newpath 382 -184 moveto 382 -211 lineto stroke +newpath 467 -184 moveto 467 -211 lineto stroke +newpath 552 -184 moveto 552 -211 lineto stroke +newpath 42 -197 moveto 382 -197 lineto stroke +newpath 382 -197 moveto 372 -203 lineto stroke +(append prefix="foo" <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 85 -195 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +85 -195 moveto show +newpath 42 -211 moveto 42 -238 lineto stroke +newpath 127 -211 moveto 127 -238 lineto stroke +newpath 212 -211 moveto 212 -238 lineto stroke +newpath 297 -211 moveto 297 -238 lineto stroke +newpath 382 -211 moveto 382 -238 lineto stroke +newpath 467 -211 moveto 467 -238 lineto stroke +newpath 552 -211 moveto 552 -238 lineto stroke +1.000000 1.000000 1.000000 setrgbcolor +newpath 263 -211 moveto 417 -211 lineto 417 -236 lineto 263 -236 lineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +newpath 269 -211 moveto 411 -211 lineto stroke +newpath 269 -236 moveto 411 -236 lineto stroke +newpath 269 -211 moveto 263 -223 lineto stroke +newpath 263 -223 moveto 269 -236 lineto stroke +newpath 411 -211 moveto 417 -223 lineto stroke +newpath 417 -223 moveto 411 -236 lineto stroke +(Co-located on same box) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 275 -227 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +275 -227 moveto show +newpath 42 -238 moveto 42 -265 lineto stroke +newpath 127 -238 moveto 127 -265 lineto stroke +newpath 212 -238 moveto 212 -265 lineto stroke +newpath 297 -238 moveto 297 -265 lineto stroke +newpath 382 -238 moveto 382 -265 lineto stroke +newpath 467 -238 moveto 467 -265 lineto stroke +newpath 552 -238 moveto 552 -265 lineto stroke +newpath 382 -251 moveto 297 -251 lineto stroke +newpath 297 -251 moveto 307 -257 lineto stroke +(Req. 123 bytes, prefix="foo", epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 236 -249 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +236 -249 moveto show +newpath 42 -265 moveto 42 -292 lineto stroke +newpath 127 -265 moveto 127 -292 lineto stroke +newpath 212 -265 moveto 212 -292 lineto stroke +newpath 297 -265 moveto 297 -292 lineto stroke +newpath 382 -265 moveto 382 -292 lineto stroke +newpath 467 -265 moveto 467 -292 lineto stroke +newpath 552 -265 moveto 552 -292 lineto stroke +newpath 297 -278 moveto 382 -278 lineto stroke +newpath 382 -278 moveto 372 -284 lineto stroke +(ok, "foo.seq_a.009" offset=447) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 259 -276 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +259 -276 moveto show +newpath 42 -292 moveto 42 -319 lineto stroke +newpath 127 -292 moveto 127 -319 lineto stroke +newpath 212 -292 moveto 212 -319 lineto stroke +newpath 297 -292 moveto 297 -319 lineto stroke +newpath 382 -292 moveto 382 -319 lineto stroke +newpath 467 -292 moveto 467 -319 lineto stroke +newpath 552 -292 moveto 552 -319 lineto stroke +newpath 382 -305 85 13 270 90 ellipse stroke +newpath 382 -311 moveto 392 -317 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 58 -303 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +58 -303 moveto show +newpath 42 -319 moveto 42 -346 lineto stroke +newpath 127 -319 moveto 127 -346 lineto stroke +newpath 212 -319 moveto 212 -346 lineto stroke +newpath 297 -319 moveto 297 -346 lineto stroke +newpath 382 -319 moveto 382 -346 lineto stroke +newpath 467 -319 moveto 467 -346 lineto stroke +newpath 552 -319 moveto 552 -346 lineto stroke +newpath 382 -332 moveto 467 -332 lineto stroke +newpath 467 -332 moveto 457 -338 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 264 -330 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +264 -330 moveto show +newpath 42 -346 moveto 42 -373 lineto stroke +newpath 127 -346 moveto 127 -373 lineto stroke +newpath 212 -346 moveto 212 -373 lineto stroke +newpath 297 -346 moveto 297 -373 lineto stroke +newpath 382 -346 moveto 382 -373 lineto stroke +newpath 467 -346 moveto 467 -373 lineto stroke +newpath 552 -346 moveto 552 -373 lineto stroke +newpath 467 -359 moveto 552 -359 lineto stroke +newpath 552 -359 moveto 542 -365 lineto stroke +(write "foo.seq_a.009" offset=447 <<123 bytes...>> epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 273 -357 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +273 -357 moveto show +newpath 42 -373 moveto 42 -400 lineto stroke +newpath 127 -373 moveto 127 -400 lineto stroke +newpath 212 -373 moveto 212 -400 lineto stroke +newpath 297 -373 moveto 297 -400 lineto stroke +newpath 382 -373 moveto 382 -400 lineto stroke +newpath 467 -373 moveto 467 -400 lineto stroke +newpath 552 -373 moveto 552 -400 lineto stroke +newpath 552 -386 moveto 42 -386 lineto stroke +newpath 42 -386 moveto 52 -392 lineto stroke +(ok, "foo.seq_a.009" offset=447) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 216 -384 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +216 -384 moveto show +newpath 42 -400 moveto 42 -427 lineto stroke +newpath 127 -400 moveto 127 -427 lineto stroke +newpath 212 -400 moveto 212 -427 lineto stroke +newpath 297 -400 moveto 297 -427 lineto stroke +newpath 382 -400 moveto 382 -427 lineto stroke +newpath 467 -400 moveto 467 -427 lineto stroke +newpath 552 -400 moveto 552 -427 lineto stroke +(The above is "fast path" for FLU->FLU forwarding.) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 164 -416 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +164 -416 moveto show +[2] 0 setdash +newpath 21 -413 moveto 162 -413 lineto stroke +[] 0 setdash +[2] 0 setdash +newpath 432 -413 moveto 574 -413 lineto stroke +[] 0 setdash +newpath 42 -427 moveto 42 -454 lineto stroke +newpath 127 -427 moveto 127 -454 lineto stroke +newpath 212 -427 moveto 212 -454 lineto stroke +newpath 297 -427 moveto 297 -454 lineto stroke +newpath 382 -427 moveto 382 -454 lineto stroke +newpath 467 -427 moveto 467 -454 lineto stroke +newpath 552 -427 moveto 552 -454 lineto stroke +(If, in an alternate scenario, FLU_C has an error...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 167 -443 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +167 -443 moveto show +[2] 0 setdash +newpath 21 -440 moveto 165 -440 lineto stroke +[] 0 setdash +[2] 0 setdash +newpath 429 -440 moveto 574 -440 lineto stroke +[] 0 setdash +newpath 42 -454 moveto 42 -481 lineto stroke +newpath 127 -454 moveto 127 -481 lineto stroke +newpath 212 -454 moveto 212 -481 lineto stroke +newpath 297 -454 moveto 297 -481 lineto stroke +newpath 382 -454 moveto 382 -481 lineto stroke +newpath 467 -454 moveto 467 -481 lineto stroke +newpath 552 -454 moveto 552 -481 lineto stroke +newpath 552 -467 moveto 42 -467 lineto stroke +newpath 42 -467 moveto 52 -473 lineto stroke +1.000000 0.000000 0.000000 setrgbcolor +(bad_epoch, 15) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 258 -465 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +1.000000 0.000000 0.000000 setrgbcolor +258 -465 moveto show +0.000000 0.000000 0.000000 setrgbcolor +newpath 42 -481 moveto 42 -508 lineto stroke +newpath 127 -481 moveto 127 -508 lineto stroke +newpath 212 -481 moveto 212 -508 lineto stroke +newpath 297 -481 moveto 297 -508 lineto stroke +newpath 382 -481 moveto 382 -508 lineto stroke +newpath 467 -481 moveto 467 -508 lineto stroke +newpath 552 -481 moveto 552 -508 lineto stroke +(... then repair becomes the client's responsibility \("slow path"\).) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 133 -497 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +133 -497 moveto show +[2] 0 setdash +newpath 21 -494 moveto 131 -494 lineto stroke +[] 0 setdash +[2] 0 setdash +newpath 464 -494 moveto 574 -494 lineto stroke +[] 0 setdash diff --git a/doc/src.high-level/figure6.eps b/doc/src.high-level/figure6.eps new file mode 100644 index 0000000..f445c26 --- /dev/null +++ b/doc/src.high-level/figure6.eps @@ -0,0 +1,557 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Title: figure6.fig +%%Creator: fig2dev Version 3.2 Patchlevel 5d +%%CreationDate: Mon Oct 20 21:56:33 2014 +%%For: fritchie@sbb3.local (Scott Lystig Fritchie) +%%BoundingBox: 0 0 633 332 +%Magnification: 1.0000 +%%EndComments +%%BeginProlog +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def +/reencdict 12 dict def /ReEncode { reencdict begin +/newcodesandnames exch def /newfontname exch def /basefontname exch def +/basefontdict basefontname findfont def /newfont basefontdict maxlength dict def +basefontdict { exch dup /FID ne { dup /Encoding eq +{ exch dup length array copy newfont 3 1 roll put } +{ exch newfont 3 1 roll put } ifelse } { pop pop } ifelse } forall +newfont /FontName newfontname put newcodesandnames aload pop +128 1 255 { newfont /Encoding get exch /.notdef put } for +newcodesandnames length 2 idiv { newfont /Encoding get 3 1 roll put } repeat +newfontname newfont definefont pop end } def +/isovec [ +8#055 /minus 8#200 /grave 8#201 /acute 8#202 /circumflex 8#203 /tilde +8#204 /macron 8#205 /breve 8#206 /dotaccent 8#207 /dieresis +8#210 /ring 8#211 /cedilla 8#212 /hungarumlaut 8#213 /ogonek 8#214 /caron +8#220 /dotlessi 8#230 /oe 8#231 /OE +8#240 /space 8#241 /exclamdown 8#242 /cent 8#243 /sterling +8#244 /currency 8#245 /yen 8#246 /brokenbar 8#247 /section 8#250 /dieresis +8#251 /copyright 8#252 /ordfeminine 8#253 /guillemotleft 8#254 /logicalnot +8#255 /hyphen 8#256 /registered 8#257 /macron 8#260 /degree 8#261 /plusminus +8#262 /twosuperior 8#263 /threesuperior 8#264 /acute 8#265 /mu 8#266 /paragraph +8#267 /periodcentered 8#270 /cedilla 8#271 /onesuperior 8#272 /ordmasculine +8#273 /guillemotright 8#274 /onequarter 8#275 /onehalf +8#276 /threequarters 8#277 /questiondown 8#300 /Agrave 8#301 /Aacute +8#302 /Acircumflex 8#303 /Atilde 8#304 /Adieresis 8#305 /Aring +8#306 /AE 8#307 /Ccedilla 8#310 /Egrave 8#311 /Eacute +8#312 /Ecircumflex 8#313 /Edieresis 8#314 /Igrave 8#315 /Iacute +8#316 /Icircumflex 8#317 /Idieresis 8#320 /Eth 8#321 /Ntilde 8#322 /Ograve +8#323 /Oacute 8#324 /Ocircumflex 8#325 /Otilde 8#326 /Odieresis 8#327 /multiply +8#330 /Oslash 8#331 /Ugrave 8#332 /Uacute 8#333 /Ucircumflex +8#334 /Udieresis 8#335 /Yacute 8#336 /Thorn 8#337 /germandbls 8#340 /agrave +8#341 /aacute 8#342 /acircumflex 8#343 /atilde 8#344 /adieresis 8#345 /aring +8#346 /ae 8#347 /ccedilla 8#350 /egrave 8#351 /eacute +8#352 /ecircumflex 8#353 /edieresis 8#354 /igrave 8#355 /iacute +8#356 /icircumflex 8#357 /idieresis 8#360 /eth 8#361 /ntilde 8#362 /ograve +8#363 /oacute 8#364 /ocircumflex 8#365 /otilde 8#366 /odieresis 8#367 /divide +8#370 /oslash 8#371 /ugrave 8#372 /uacute 8#373 /ucircumflex +8#374 /udieresis 8#375 /yacute 8#376 /thorn 8#377 /ydieresis] def +/Times-Bold /Times-Bold-iso isovec ReEncode +/Times-Roman /Times-Roman-iso isovec ReEncode +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +/pageheader { +save +newpath 0 332 moveto 0 0 lineto 633 0 lineto 633 332 lineto closepath clip newpath +-331.7 473.8 translate +1 -1 scale +$F2psBegin +10 setmiterlimit +0 slj 0 slc + 0.06000 0.06000 sc +} bind def +/pagefooter { +$F2psEnd +restore +} bind def +%%EndProlog +pageheader +% +% Fig objects follow +% +% +% here starts figure with depth 50 +/Times-Roman-iso ff 166.67 scf sf +5925 7275 m +gs 1 -1 sc (Step 6: Client now knows that projection 12 is invalid. Fetch projection 13, then retry at step #8.) col16 sh gr +/Times-Bold-iso ff 200.00 scf sf +8550 3225 m +gs 1 -1 sc (Get epoch 13) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 6900 m +gs 1 -1 sc (Active=[a,b,c]) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 6675 m +gs 1 -1 sc (Members=[a,b,c]) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 6450 m +gs 1 -1 sc (Epoch=13) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 5580 m +gs 1 -1 sc (Epoch=12) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 5835 m +gs 1 -1 sc (Members=[a,b,c]) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 6090 m +gs 1 -1 sc (Active=[a,b]) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5925 5175 m +gs 1 -1 sc (Projection \(data structure\)) col0 sh gr +% Polyline +0 slj +0 slc +15.000 slw +n 8400 4950 m 5625 4950 l 5625 7050 l 8400 7050 l + cp gs col0 s gr +/Times-Bold-iso ff 200.00 scf sf +12825 6405 m +gs 1 -1 sc (- write once) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 6660 m +gs 1 -1 sc (- key=integer) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 6915 m +gs 1 -1 sc (- value=projection data structure) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 7170 m +gs 1 -1 sc (k=11, v=...) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 7425 m +gs 1 -1 sc (k=12, v=...) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 7680 m +gs 1 -1 sc (k=13, v=...) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 6150 m +gs 1 -1 sc (FLU projection store \(proc\)) col0 sh gr +% Polyline +n 12750 5925 m 15900 5925 l 15900 7725 l 12750 7725 l + cp gs col0 s gr +% Polyline +gs clippath +14788 5055 m 14940 5055 l 14940 4995 l 14788 4995 l 14788 4995 l 14908 5025 l 14788 5055 l cp +14612 4995 m 14460 4995 l 14460 5055 l 14612 5055 l 14612 5055 l 14492 5025 l 14612 4995 l cp +eoclip +n 14475 5025 m + 14925 5025 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 14612 4995 m 14492 5025 l 14612 5055 l col0 s +% arrowhead +n 14788 5055 m 14908 5025 l 14788 4995 l col0 s +% Polyline +15.000 slw +gs clippath +15688 5055 m 15840 5055 l 15840 4995 l 15688 4995 l 15688 4995 l 15808 5025 l 15688 5055 l cp +15137 4995 m 14985 4995 l 14985 5055 l 15137 5055 l 15137 5055 l 15017 5025 l 15137 4995 l cp +eoclip +n 15000 5025 m + 15825 5025 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 15137 4995 m 15017 5025 l 15137 5055 l col0 s +% arrowhead +n 15688 5055 m 15808 5025 l 15688 4995 l col0 s +% Polyline +15.000 slw +gs clippath +14638 5355 m 14790 5355 l 14790 5295 l 14638 5295 l 14638 5295 l 14758 5325 l 14638 5355 l cp +14612 5295 m 14460 5295 l 14460 5355 l 14612 5355 l 14612 5355 l 14492 5325 l 14612 5295 l cp +eoclip +n 14475 5325 m 14550 5325 l 14625 5325 l 14700 5325 l 14775 5325 l 14700 5325 l + + 14775 5325 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 14612 5295 m 14492 5325 l 14612 5355 l col0 s +% arrowhead +n 14638 5355 m 14758 5325 l 14638 5295 l col0 s +% Polyline +15.000 slw +gs clippath +15163 5355 m 15315 5355 l 15315 5295 l 15163 5295 l 15163 5295 l 15283 5325 l 15163 5355 l cp +15137 5295 m 14985 5295 l 14985 5355 l 15137 5355 l 15137 5355 l 15017 5325 l 15137 5295 l cp +eoclip +n 15000 5325 m 15075 5325 l 15150 5325 l 15225 5325 l + 15300 5325 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 15137 5295 m 15017 5325 l 15137 5355 l col0 s +% arrowhead +n 15163 5355 m 15283 5325 l 15163 5295 l col0 s +% Polyline +15.000 slw +gs clippath +15688 5355 m 15840 5355 l 15840 5295 l 15688 5295 l 15688 5295 l 15808 5325 l 15688 5355 l cp +15587 5295 m 15435 5295 l 15435 5355 l 15587 5355 l 15587 5355 l 15467 5325 l 15587 5295 l cp +eoclip +n 15450 5325 m 15525 5325 l 15600 5325 l 15675 5325 l 15750 5325 l + 15825 5325 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 15587 5295 m 15467 5325 l 15587 5355 l col0 s +% arrowhead +n 15688 5355 m 15808 5325 l 15688 5295 l col0 s +% Polyline + [60] 0 sd +n 14475 5025 m + 15825 5025 l gs col0 s gr [] 0 sd +% Polyline + [60] 0 sd +n 14475 5325 m + 15825 5325 l gs col0 s gr [] 0 sd +% Polyline + [60] 0 sd +n 14475 5550 m + 15825 5550 l gs col0 s gr [] 0 sd +/Times-Bold-iso ff 200.00 scf sf +12825 4575 m +gs 1 -1 sc (epoch=13) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 4830 m +gs 1 -1 sc (files:) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 5085 m +gs 1 -1 sc ( "foo.seq_a.006") col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 5340 m +gs 1 -1 sc ( "foo.seq_b.007") col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 5595 m +gs 1 -1 sc ( "foo.seq_b.008") col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 4275 m +gs 1 -1 sc (FLU \(proc\)) col0 sh gr +% Polyline +15.000 slw +n 12750 4050 m 15975 4050 l 15975 5775 l 12750 5775 l + cp gs col0 s gr +% Polyline +n 12750 2775 m 15150 2775 l 15150 3900 l 12750 3900 l + cp gs col0 s gr +/Times-Bold-iso ff 200.00 scf sf +12825 3000 m +gs 1 -1 sc (Sequencer \(proc\)) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 3300 m +gs 1 -1 sc (epoch=13) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +12825 3555 m +gs 1 -1 sc (map=[{"foo", next_file=8,) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +13500 3750 m +gs 1 -1 sc (next_offset=0}...]) col0 sh gr +% Polyline +n 5700 3975 m 5700 4275 l 8250 4275 l 8250 3075 l 7950 3075 l 7950 3975 l + + 5700 3975 l cp gs col0 s gr +/Times-Bold-iso ff 200.00 scf sf +5775 4200 m +gs 1 -1 sc (server logic) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5775 3060 m +gs 1 -1 sc (Append <<123 bytes>>) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5775 3315 m +gs 1 -1 sc (to a file with prefix) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5775 3570 m +gs 1 -1 sc ("foo".) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +5775 2700 m +gs 1 -1 sc (CLIENT \(proc\)) col0 sh gr +% Polyline +gs clippath +5970 3763 m 5970 3915 l 6030 3915 l 6030 3763 l 6030 3763 l 6000 3883 l 5970 3763 l cp +eoclip +n 6000 3600 m + 6000 3900 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 5970 3763 m 6000 3883 l 6030 3763 l col0 s +% Polyline +15.000 slw +gs clippath +6630 3737 m 6630 3585 l 6570 3585 l 6570 3737 l 6570 3737 l 6600 3617 l 6630 3737 l cp +eoclip +n 6600 3900 m 6600 3825 l 6600 3750 l 6600 3675 l + 6600 3600 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 6630 3737 m 6600 3617 l 6570 3737 l col0 s +/Times-Bold-iso ff 200.00 scf sf +6675 3900 m +gs 1 -1 sc (ok) col0 sh gr +% Polyline +15.000 slw +n 5550 4350 m 8325 4350 l 8325 2475 l 5550 2475 l + cp gs col0 s gr +% Polyline +gs clippath +8143 4500 m 8035 4393 l 7993 4435 l 8100 4543 l 8100 4543 l 8037 4437 l 8143 4500 l cp +eoclip +n 12525 5175 m 8775 5175 l + 8025 4425 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 8143 4500 m 8037 4437 l 8100 4543 l col0 s +/Times-Bold-iso ff 200.00 scf sf +11625 5100 m +gs 1 -1 sc (ok) col0 sh gr +% Polyline +15.000 slw +gs clippath +5970 4663 m 5970 4815 l 6030 4815 l 6030 4663 l 6030 4663 l 6000 4783 l 5970 4663 l cp +eoclip +n 6000 4425 m + 6000 4800 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 5970 4663 m 6000 4783 l 6030 4663 l col0 s +% Polyline +15.000 slw +gs clippath +6630 4562 m 6630 4410 l 6570 4410 l 6570 4562 l 6570 4562 l 6600 4442 l 6630 4562 l cp +eoclip +n 6600 4800 m 6600 4650 l 6600 4575 l 6600 4500 l + 6600 4425 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 6630 4562 m 6600 4442 l 6570 4562 l col0 s +% Polyline +15.000 slw +gs clippath +12388 2730 m 12540 2730 l 12540 2670 l 12388 2670 l 12388 2670 l 12508 2700 l 12388 2730 l cp +eoclip +n 8475 2700 m + 12525 2700 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 12388 2730 m 12508 2700 l 12388 2670 l col0 s +% Polyline +15.000 slw +gs clippath +8612 2970 m 8460 2970 l 8460 3030 l 8612 3030 l 8612 3030 l 8492 3000 l 8612 2970 l cp +eoclip +n 12525 3000 m + 8475 3000 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 8612 2970 m 8492 3000 l 8612 3030 l col0 s +% Polyline +15.000 slw +gs clippath +8612 3645 m 8460 3645 l 8460 3705 l 8612 3705 l 8612 3705 l 8492 3675 l 8612 3645 l cp +eoclip +n 12525 6900 m 12000 6900 l 12000 3675 l + 8475 3675 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 8612 3645 m 8492 3675 l 8612 3705 l col0 s +% Polyline +15.000 slw +gs clippath +12388 3330 m 12540 3330 l 12540 3270 l 12388 3270 l 12388 3270 l 12508 3300 l 12388 3330 l cp +eoclip +n 8475 3975 m 12300 3975 l 12300 3300 l + 12525 3300 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 12388 3330 m 12508 3300 l 12388 3270 l col0 s +% Polyline +15.000 slw +gs clippath +12388 4905 m 12540 4905 l 12540 4845 l 12388 4845 l 12388 4845 l 12508 4875 l 12388 4905 l cp +eoclip +n 8250 4425 m 8700 4875 l + 12525 4875 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 12388 4905 m 12508 4875 l 12388 4845 l col0 s +% Polyline +15.000 slw +n 12675 2400 m 16050 2400 l 16050 7875 l 12675 7875 l + cp gs col0 s gr +% Polyline +gs clippath +8612 4245 m 8460 4245 l 8460 4305 l 8612 4305 l 8612 4305 l 8492 4275 l 8612 4245 l cp +eoclip +n 12525 3600 m 12375 3600 l 12375 4275 l + 8475 4275 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 8612 4245 m 8492 4275 l 8612 4305 l col0 s +/Times-Bold-iso ff 200.00 scf sf +8850 5625 m +gs 1 -1 sc (Write to FLU B -> ok) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +8850 6135 m +gs 1 -1 sc (Write to FLU C -> ok) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +8550 2625 m +gs 1 -1 sc (Request 123 bytes, prefix="foo", epoch=12) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +11100 2925 m +gs 1 -1 sc ({bad_epoch,13}) col4 sh gr +/Times-Bold-iso ff 200.00 scf sf +10875 3600 m +gs 1 -1 sc ({ok, proj=...}) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +8550 4500 m +gs 1 -1 sc (Write <<123 bytes>> to) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +8550 4755 m +gs 1 -1 sc (file="foo.seq_a.008", offset=0) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +13575 2625 m +gs 1 -1 sc (Server A) col0 sh gr +/Times-Bold-iso ff 200.00 scf sf +8550 3900 m +gs 1 -1 sc (Req. 123 bytes, prefix="foo", epoch=13) col0 sh gr +/Times-Roman-iso ff 166.67 scf sf +6075 3825 m +gs 1 -1 sc (1) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +6075 4650 m +gs 1 -1 sc (2) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +6675 4650 m +gs 1 -1 sc (3) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +10950 2850 m +gs 1 -1 sc (5) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +10725 3525 m +gs 1 -1 sc (7) col16 sh gr +/Times-Bold-iso ff 200.00 scf sf +9375 4200 m +gs 1 -1 sc (file="foo.seq_a.008", offset=0) col0 sh gr +/Times-Roman-iso ff 166.67 scf sf +8400 3225 m +gs 1 -1 sc (6) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +8400 2625 m +gs 1 -1 sc (4) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +6675 3750 m +gs 1 -1 sc (16) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +8400 3900 m +gs 1 -1 sc (8) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +9225 4200 m +gs 1 -1 sc (9) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +8400 4500 m +gs 1 -1 sc (10) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +8475 5625 m +gs 1 -1 sc (12,13) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +8475 6075 m +gs 1 -1 sc (14,15) col16 sh gr +/Times-Roman-iso ff 166.67 scf sf +11400 5100 m +gs 1 -1 sc (11) col16 sh gr +% Polyline +15.000 slw +gs clippath +12388 6630 m 12540 6630 l 12540 6570 l 12388 6570 l 12388 6570 l 12508 6600 l 12388 6630 l cp +eoclip +n 8475 3300 m 12150 3300 l 12150 6600 l + 12525 6600 l gs col0 s gr gr + +% arrowhead +7.500 slw +n 12388 6630 m 12508 6600 l 12388 6570 l col0 s +% here ends figure; +pagefooter +showpage +%%Trailer +%EOF diff --git a/doc/src.high-level/high-level-chain-mgr.tex b/doc/src.high-level/high-level-chain-mgr.tex new file mode 100644 index 0000000..6a06c22 --- /dev/null +++ b/doc/src.high-level/high-level-chain-mgr.tex @@ -0,0 +1,1568 @@ + +%% \documentclass[]{report} +\documentclass[preprint,10pt]{sigplanconf} +% The following \documentclass options may be useful: + +% preprint Remove this option only once the paper is in final form. +% 10pt To set in 10-point type instead of 9-point. +% 11pt To set in 11-point type instead of 9-point. +% authoryear To obtain author/year citation style instead of numeric. + +% \usepackage[a4paper]{geometry} +\usepackage[dvips]{graphicx} % to include images +%\usepackage{pslatex} % to use PostScript fonts + +\begin{document} + +%%\special{papersize=8.5in,11in} +%%\setlength{\pdfpageheight}{\paperheight} +%%\setlength{\pdfpagewidth}{\paperwidth} + +\conferenceinfo{}{} +\copyrightyear{2014} +\copyrightdata{978-1-nnnn-nnnn-n/yy/mm} +\doi{nnnnnnn.nnnnnnn} + +\titlebanner{Draft \#0, April 2014} +\preprintfooter{Draft \#0, April 2014} + +\title{Machi Chain Replication: management theory and design} +\subtitle{Includes ``humming consensus'' overview} + +\authorinfo{Basho Japan KK}{} + +\maketitle + +\section{Origins} +\label{sec:origins} + +This document was first written during the autumn of 2014 for a +Basho-only internal audience. Since its original drafts, Machi has +been designated by Basho as a full open source software project. This +document has been rewritten in 2015 to address an external audience. +For an overview of the design of the larger Machi system, please see +\cite{machi-design}. + +\section{Abstract} +\label{sec:abstract} + +We describe the self-management and self-reliance +goals of the algorithm: preserve data integrity, advance the current +state of the art, and supporting multiple consisistency levels. + +TODO Fix, after all of the recent changes to this document. + +A discussion of ``humming consensus'' follows next. This type of +consensus does not require active participation by all or even a +majority of participants to make decisions. Machi's chain manager +bases its logic on humming consensus to make decisions about how to +react to changes in its environment, e.g. server crashes, network +partitions, and changes by Machi cluster admnistrators. Once a +decision is made during a virtual time epoch, humming consensus will +eventually discover if other participants have made a different +decision during that epoch. When a differing decision is discovered, +new time epochs are proposed in which a new consensus is reached and +disseminated to all available participants. + +\section{Introduction} +\label{sec:introduction} + +\subsection{What does "self-management" mean?} +\label{sub:self-management} + +For the purposes of this document, chain replication self-management +is the ability for the $N$ nodes in an $N$-length chain replication chain +to manage the state of the chain without requiring an external party +to participate. Chain state includes: + +\begin{itemize} +\item Preserve data integrity of all data stored within the chain. Data + loss is not an option. +\item Stably preserve knowledge of chain membership (i.e. all nodes in + the chain, regardless of operational status). A systems + administrators is expected to make "permanent" decisions about + chain membership. +\item Use passive and/or active techniques to track operational + state/status, e.g., up, down, restarting, full data sync, partial + data sync, etc. +\item Choose the run-time replica ordering/state of the chain, based on + current member status and past operational history. All chain + state transitions must be done safely and without data loss or + corruption. +\item As a new node is added to the chain administratively or old node is + restarted, add the node to the chain safely and perform any data + synchronization/"repair" required to bring the node's data into + full synchronization with the other nodes. +\end{itemize} + +\subsection{Ultimate goal: Preserve data integrity of Chain Replicated data} + +Preservation of data integrity is paramount to any chain state +management technique for Machi. Even when operating in an eventually +consistent mode, Machi must not lose data without cause outside of all +design, e.g., all particpants crash permanently. + +\subsection{Goal: better than state-of-the-art Chain Replication management} + +We hope/believe that this new self-management algorithem can improve +the current state-of-the-art by eliminating all external management +entities. Current state-of-the-art for management of chain +replication chains is discussed below, to provide historical context. + +\subsubsection{``Leveraging Sharding in the Design of Scalable Replication Protocols'' by Abu-Libdeh, van Renesse, and Vigfusson} +\label{ssec:elastic-replication} +Multiple chains are arranged in a ring (called a "band" in the paper). +The responsibility for managing the chain at position N is delegated +to chain N-1. As long as at least one chain is running, that is +sufficient to start/bootstrap the next chain, and so on until all +chains are running. The paper then estimates mean-time-to-failure +(MTTF) and suggests a "band of bands" topology to handle very large +clusters while maintaining an MTTF that is as good or better than +other management techniques. + +{\bf NOTE:} If the chain self-management method proposed for Machi does not +succeed, this paper's technique is our best fallback recommendation. + +\subsubsection{An external management oracle, implemented by ZooKeeper} +\label{ssec:an-oracle} +This is not a recommendation for Machi: we wish to avoid using ZooKeeper. +However, many other open source software products use +ZooKeeper for exactly this kind of data replica management problem. + +\subsubsection{An external management oracle, implemented by Riak Ensemble} + +This is a much more palatable choice than option~\ref{ssec:an-oracle} +above. We also +wish to avoid an external dependency on something as big as Riak +Ensemble. However, if it comes between choosing Riak Ensemble or +choosing ZooKeeper, the choice feels quite clear: Riak Ensemble will +win, unless there is some critical feature missing from Riak +Ensemble. If such an unforseen missing feature is discovered, it +would probably be preferable to add the feature to Riak Ensemble +rather than to use ZooKeeper (and document it and provide product +support for it and so on...). + +\subsection{Goal: Support both eventually consistent \& strongly consistent modes of operation} + +Machi's first use case is for Riak CS, as an eventually consistent +store for CS's "block" storage. Today, Riak KV is used for "block" +storage. Riak KV is an AP-style key-value store; using Machi in an +AP-style mode would match CS's current behavior from points of view of +both code/execution and human administrator exectations. + +Later, we wish the option of using CP support to replace other data +store services that Riak KV provides today. (Scope and timing of such +replacement TBD.) + +We believe this algorithm allows a Machi cluster to fragment into +arbitrary islands of network partition, all the way down to 100\% of +members running in complete network isolation from each other. +Furthermore, it provides enough agreement to allow +formerly-partitioned members to coordinate the reintegration \& +reconciliation of their data when partitions are healed. + +\subsection{Anti-goal: minimize churn} + +This algorithm's focus is data safety and not availability. If +participants have differing notions of time, e.g., running on +extremely fast or extremely slow hardware, then this algorithm will +"churn" in different states where the chain's data would be +effectively unavailable. + +In practice, however, any series of network partition changes that +case this algorithm to churn will cause other management techniques +(such as an external "oracle") similar problems. +{\bf [Proof by handwaving assertion.]} +See also: Section~\ref{sub:time-model} + +\section{Assumptions} +\label{sec:assumptions} + +Given a long history of consensus algorithms (viewstamped replication, +Paxos, Raft, et al.), why bother with a slightly different set of +assumptions and a slightly different protocol? + +The answer lies in one of our explicit goals: to have an option of +running in an "eventually consistent" manner. We wish to be able to +make progress, i.e., remain available in the CAP sense, even if we are +partitioned down to a single isolated node. VR, Paxos, and Raft +alone are not sufficient to coordinate service availability at such +small scale. + +\subsection{The CORFU protocol is correct} + +This work relies tremendously on the correctness of the CORFU +protocol \cite{corfu1}, a cousin of the Paxos protocol. +If the implementation of +this self-management protocol breaks an assumption or prerequisite of +CORFU, then we expect that Machi's implementation will be flawed. + +\subsection{Communication model} + +The communication model is asynchronous point-to-point messaging. +The network is unreliable: messages may be arbitrarily dropped and/or +reordered. Network partitions may occur at any time. +Network partitions may be asymmetric, e.g., a message can be sent +from $A \rightarrow B$, but messages from $B \rightarrow A$ can be +lost, dropped, and/or arbitrarily delayed. + +System particpants may be buggy but not actively malicious/Byzantine. + +\subsection{Time model} +\label{sub:time-model} + +Our time model is per-node wall-clock time clocks, loosely +synchronized by NTP. + +The protocol and algorithm presented here do not specify or require any +timestamps, physical or logical. Any mention of time inside of data +structures are for human/historic/diagnostic purposes only. + +Having said that, some notion of physical time is suggested for +purposes of efficiency. It's recommended that there be some "sleep +time" between iterations of the algorithm: there is no need to "busy +wait" by executing the algorithm as quickly as possible. See below, +"sleep intervals between executions". + +\subsection{Failure detector model} + +We assume that the failure detector that the algorithm uses is weak, +it's fallible, and it informs the algorithm in boolean status +updates/toggles as a node becomes available or not. + +If the failure detector is fallible and tells us a mistaken status +change, then the algorithm will "churn" the operational state of the +chain, e.g. by removing the failed node from the chain or adding a +(re)started node (that may not be alive) to the end of the chain. +Such extra churn is regrettable and will cause periods of delay as the +humming consensus algorithm (decribed below) makes decisions. However, the +churn cannot {\bf (we assert/believe)} cause data loss. + +\subsection{Use of the ``wedge state''} + +A participant in Chain Replication will enter "wedge state", as +described by the Machi high level design \cite{machi-design} and by CORFU, +when it receives information that +a newer projection (i.e., run-time chain state reconfiguration) is +available. The new projection may be created by a system +administrator or calculated by the self-management algorithm. +Notification may arrive via the projection store API or via the file +I/O API. + +When in wedge state, the server will refuse all file write I/O API +requests until the self-management algorithm has determined that +humming consensus has been decided (see next bullet item). The server +may also refuse file read I/O API requests, depending on its CP/AP +operation mode. + +\subsection{Use of ``humming consensus''} + +CS literature uses the word "consensus" in the context of the problem +description at +{\tt http://en.wikipedia.org/wiki/ Consensus\_(computer\_science)\#Problem\_description}. +This traditional definition differs from what is described here as +``humming consensus''. + +"Humming consensus" describes +consensus that is derived only from data that is visible/known at the current +time. +The algorithm will calculate +a rough consensus despite not having input from all/majority +of chain members. Humming consensus may proceed to make a +decision based on data from only a single participant, i.e., only the local +node. + +See Section~\ref{sec:humming-consensus} for detailed discussion. + +\section{The projection store} + +The Machi chain manager relies heavily on a key-value store of +write-once registers called the ``projection store''. +Each participating chain node has its own projection store. +The store's key is a positive integer; +the integer represents the epoch number of the projection. The +store's value is either the special `unwritten' value\footnote{We use + $\bot$ to denote the unwritten value.} or else an +application-specific binary blob that is immutable thereafter. + +The projection store is vital for the correct implementation of humming +consensus (Section~\ref{sec:humming-consensus}). + +All parts store described below may be read by any cluster member. + +\subsection{The publicly-writable half of the projection store} + +The publicly-writable projection store is used to share information +during the first half of the self-management algorithm. Any chain +member may write a projection to this store. + +\subsection{The privately-writable half of the projection store} + +The privately-writable projection store is used to store the humming consensus +result that has been chosen by the local node. Only +the local server may write values into this store. + +The private projection store serves multiple purposes, including: + +\begin{itemize} +\item remove/clear the local server from ``wedge state'' +\item act as the store of record for chain state transitions +\item communicate to remote nodes the past states and current operational + state of the local node +\end{itemize} + +The private half of the projection store is not replicated. +Projections that are stored in the private projection store are +meaningful only to the local projection store and are, furthermore, +merely ``soft state''. Data loss in the private projection store +cannot result in loss of ``hard state'' information. Therefore, +replication of the private projection store is not required. The +replication techniques described by +Section~\ref{sec:managing-multiple-projection-stores} applies only to +the public half of the projection store. + +\section{Projections: calculation, storage, and use} +\label{sec:projections} + +Machi uses a ``projection'' to determine how its Chain Replication replicas +should operate; see \cite{machi-design} and +\cite{corfu1}. At runtime, a cluster must be able to respond both to +administrative changes (e.g., substituting a failed server box with +replacement hardware) as well as local network conditions (e.g., is +there a network partition?). + +The projection defines the operational state of Chain Replication's +chain order as well the (re-)synchronization of data managed by by +newly-added/failed-and-now-recovering members of the chain. This +chain metadata, together with computational processes that manage the +chain, must be managed in a safe manner in order to avoid unintended +data loss of data managed by the chain. + +The concept of a projection is borrowed +from CORFU but has a longer history, e.g., the Hibari key-value store +\cite{cr-theory-and-practice} and goes back in research for decades, +e.g., Porcupine \cite{porcupine}. + +\subsection{The projection data structure} +\label{sub:the-projection} + +{\bf NOTE:} This section is a duplicate of the ``The Projection and +the Projection Epoch Number'' section of \cite{machi-design}. + +The projection data +structure defines the current administration \& operational/runtime +configuration of a Machi cluster's single Chain Replication chain. +Each projection is identified by a strictly increasing counter called +the Epoch Projection Number (or more simply ``the epoch''). + +Projections are calculated by each server using input from local +measurement data, calculations by the server's chain manager +(see below), and input from the administration API. +Each time that the configuration changes (automatically or by +administrator's request), a new epoch number is assigned +to the entire configuration data structure and is distributed to +all servers via the server's administration API. Each server maintains the +current projection epoch number as part of its soft state. + +Pseudo-code for the projection's definition is shown in +Figure~\ref{fig:projection}. To summarize the major components: + +\begin{figure} +\begin{verbatim} +-type m_server_info() :: {Hostname, Port,...}. +-record(projection, { + epoch_number :: m_epoch_n(), + epoch_csum :: m_csum(), + creation_time :: now(), + author_server :: m_server(), + all_members :: [m_server()], + active_upi :: [m_server()], + active_all :: [m_server()], + down_members :: [m_server()], + dbg_annotations :: proplist() + }). +\end{verbatim} +\caption{Sketch of the projection data structure} +\label{fig:projection} +\end{figure} + +\begin{itemize} +\item {\tt epoch\_number} and {\tt epoch\_csum} The epoch number and + projection checksum are unique identifiers for this projection. +\item {\tt creation\_time} Wall-clock time, useful for humans and + general debugging effort. +\item {\tt author\_server} Name of the server that calculated the projection. +\item {\tt all\_members} All servers in the chain, regardless of current + operation status. If all operating conditions are perfect, the + chain should operate in the order specified here. +\item {\tt active\_upi} All active chain members that we know are + fully repaired/in-sync with each other and therefore the Update + Propagation Invariant (Section~\ref{sub:upi} is always true. +\item {\tt active\_all} All active chain members, including those that + are under active repair procedures. +\item {\tt down\_members} All members that the {\tt author\_server} + believes are currently down or partitioned. +\item {\tt dbg\_annotations} A ``kitchen sink'' proplist, for code to + add any hints for why the projection change was made, delay/retry + information, etc. +\end{itemize} + +\subsection{Why the checksum field?} + +According to the CORFU research papers, if a server node $S$ or client +node $C$ believes that epoch $E$ is the latest epoch, then any information +that $S$ or $C$ receives from any source that an epoch $E+\delta$ (where +$\delta > 0$) exists will push $S$ into the "wedge" state and $C$ into a mode +of searching for the projection definition for the newest epoch. + +In the humming consensus description in +Section~\ref{sec:humming-consensus}, it should become clear that it's +possible to have a situation where two nodes make proposals +for a single epoch number. In the simplest case, assume a chain of +nodes $A$ and $B$. Assume that a symmetric network partition between +$A$ and $B$ happens. Also, let's assume that operating in +AP/eventually consistent mode. + +On $A$'s network-partitioned island, $A$ can choose +an active chain definition of {\tt [A]}. +Similarly $B$ can choose a definition of {\tt [B]}. Both $A$ and $B$ +might choose the +epoch for their proposal to be \#42. Because each are separated by +network partition, neither can realize the conflict. + +When the network partition heals, it can become obvious to both +servers that there are conflicting values for epoch \#42. If we +use CORFU's protocol design, which identifies the epoch identifier as +an integer only, then the integer 42 alone is not sufficient to +discern the differences between the two projections. + +Humming consensus requires that any projection be identified by both +the epoch number and the projection checksum, as described in +Section~\ref{sub:the-projection}. + +\section{Managing multiple projection stores} +\label{sec:managing-multiple-projection-stores} + +An independent replica management technique very similar to the style +used by both Riak Core \cite{riak-core} and Dynamo is used to manage +replicas of Machi's projection data structures. +The major difference is that humming consensus +{\em does not necessarily require} +successful return status from a minimum number of participants (e.g., +a quorum). + +\subsection{Read repair: repair only unwritten values} + +The idea of ``read repair'' is also shared with Riak Core and Dynamo +systems. However, Machi has situations where read repair cannot truly +``fix'' a key because two different values have been written by two +different replicas. +Machi's projection store is write-once, and there is no ``undo'' or +``delete'' or ``overwrite'' in the projection store API.\footnote{It doesn't +matter what caused the two different values. In case of multiple +values, all participants in humming consensus merely agree that there +were multiple opinions at that epoch which must be resolved by the +creation and writing of newer projections with later epoch numbers.} +Machi's projection store read repair can only repair values that are +unwritten, i.e., storing $\bot$. + +The value used to repair $\bot$ values is the ``best'' projection that +is currently available for the current epoch $E$. If there is a single, +unanimous value $V_{u}$ for the projection at epoch $E$, then $V_{u}$ +is use to repair all projections stores at $E$ that contain $\bot$ +values. If the value of $K$ is not unanimous, then the ``highest +ranked value'' $V_{best}$ is used for the repair; see +Section~\ref{sub:projection-ranking} for a summary of projection +ranking. + +Read repair may complete successfully regardless of availability of any of the +participants. This applies to both phases, reading and writing. + +\subsection{Projection storage: writing} +\label{sub:proj-store-writing} + +All projection data structures are stored in the write-once Projection +Store that is run by each server. (See also \cite{machi-design}.) + +Writing the projection follows the two-step sequence below. + +\begin{enumerate} +\item Write $P_{new}$ to the local projection store. (As a side + effect, + this will trigger + ``wedge'' status in the local server, which will then cascade to other + projection-related behavior within that server.) +\item Write $P_{new}$ to the remote projection store of {\tt all\_members}. + Some members may be unavailable, but that is OK. +\end{enumerate} + +In cases of {\tt error\_written} status, +the process may be aborted and read repair +triggered. The most common reason for {\tt error\_written} status +is that another actor in the system has +already calculated another (perhaps different) projection using the +same projection epoch number and that +read repair is necessary. Note that {\tt error\_written} may also +indicate that another server has performed read repair on the exact +projection $P_{new}$ that the local server is trying to write! + +The writing phase may complete successfully regardless of availability +of any of the participants. + +\subsection{Reading from the projection store} +\label{sub:proj-store-reading} + +Reading data from the projection store is similar in principle to +reading from a Chain Replication-managed server system. However, the +projection store does not use the strict replica ordering that +Chain Replication does. For any projection store key $K_n$, the +participating servers may have different values for $K_n$. As a +write-once store, it is impossible to mutate a replica of $K_n$. If +replicas of $K_n$ differ, then other parts of the system (projection +calculation and storage) are responsible for reconciling the +differences by writing a later key, +$K_{n+x}$ when $x>0$, with a new projection. + +The reading phase may complete successfully regardless of availability +of any of the participants. +The minimum number of replicas is only one: the local projection store +should always be available, even if no other remote replica projection +stores are available. +If all available servers return a single, unanimous value $V_u, V_u +\ne \bot$, then $V_u$ is the final result. Any non-unanimous value is +considered disagreement and is resolved by writes to the projection +store by the humming consensus algorithm. + +\section{Phases of projection change} +\label{sec:phases-of-projection-change} + +Machi's use of projections is in four discrete phases and are +discussed below: network monitoring, +projection calculation, projection storage, and +adoption of new projections. The phases are described in the +subsections below. The reader should then be able to recognize each +of these phases when reading the humming consensus algorithm +description in Section~\ref{sec:humming-consensus}. + +\subsection{Network monitoring} +\label{sub:network-monitoring} + +Monitoring of local network conditions can be implemented in many +ways. None are mandatory, as far as this RFC is concerned. +Easy-to-maintain code should be the primary driver for any +implementation. Early versions of Machi may use some/all of the +following techniques: + +\begin{itemize} +\item Internal ``no op'' FLU-level protocol request \& response. +\item Explicit connections of remote {\tt epmd} services, e.g., to +tell the difference between a dead Erlang VM and a dead +machine/hardware node. +\item Network tests via ICMP {\tt ECHO\_REQUEST}, a.k.a. {\tt ping(8)} +\end{itemize} + +Output of the monitor should declare the up/down (or +available/unavailable) status of each server in the projection. Such +Boolean status does not eliminate fuzzy logic, probabilistic +methods, or other techniques for determining availability status. +Instead, hard Boolean up/down status +decisions are required only by the projection calculation phase +(Section~\ref{sub:projection-calculation}). + +\subsection{Calculating a new projection data structure} +\label{sub:projection-calculation} + +Each Machi server will have an independent agent/process that is +responsible for calculating new projections. A new projection may be +required whenever an administrative change is requested or in response +to network conditions (e.g., network partitions). + +Projection calculation will be a pure computation, based on input of: + +\begin{enumerate} +\item The current projection epoch's data structure +\item Administrative request (if any) +\item Status of each server, as determined by network monitoring +(Section~\ref{sub:network-monitoring}). +\end{enumerate} + +Decisions about {\em when} to calculate a projection are made +using additional runtime information. Administrative change requests +probably should happen immediately. Change based on network status +changes may require retry logic and delay/sleep time intervals. + +\subsection{Writing a new projection} +\label{sub:proj-storage-writing} + +The replicas of Machi projection data that are used by humming consensus +are not managed by Chain Replication --- if they +were, we would have a circular dependency! See +Section~\ref{sub:proj-store-writing} for the technique for writing +projections to all participating servers' projection stores. + +\subsection{Adoption a new projection} +\label{sub:proj-adoption} + +A projection $P_{new}$ is used by a server only if: + +\begin{itemize} +\item The server can determine that the projection has been replicated + unanimously across all currently available servers. +\item The change in state from the local server's current projection to new + projection, $P_{current} \rightarrow P_{new}$ will not cause data loss, + e.g., the Update Propagation Invariant and all other safety checks + required by chain repair in Section~\ref{sec:repair-entire-files} + are correct. +\end{itemize} + +Both of these steps are performed as part of humming consensus's +normal operation. It may be non-intuitive that the minimum number of +available servers is only one, but ``one'' is the correct minimum + number for humming consensus. + +\section{Humming Consensus} +\label{sec:humming-consensus} + +Humming consensus describes consensus that is derived only from data +that is visible/known at the current time. It's OK if a network +partition is in effect and that not all chain members are available; +the algorithm will calculate a rough consensus despite not +having input from all/majority of chain members. Humming consensus +may proceed to make a decision based on data from only one +participant, i.e., only the local node. + +\begin{itemize} + +\item When operating in AP mode, i.e., in eventual consistency mode, humming +consensus may reconfigure chain of length $N$ into $N$ +independent chains of length 1. When a network partition heals, the +humming consensus is sufficient to manage the chain so that each +replica's data can be repaired/merged/reconciled safely. +Other features of the Machi system are designed to assist such +repair safely. + +\item When operating in CP mode, i.e., in strong consistency mode, humming +consensus would require additional restrictions. For example, any +chain that didn't have a minimum length of the quorum majority size of +all members would be invalid and therefore would not move itself out +of wedged state. In very general terms, this requirement for a quorum +majority of surviving participants is also a requirement for Paxos, +Raft, and ZAB. See Section~\ref{sec:split-brain-management} for a +proposal to handle ``split brain'' scenarios while in CP mode. + +\end{itemize} + +If a decision is made during epoch $E$, humming consensus will +eventually discover if other participants have made a different +decision during epoch $E$. When a differing decision is discovered, +newer \& later time epochs are defined by creating new projections +with epochs numbered by $E+\delta$ (where $\delta > 0$). +The distribution of the $E+\delta$ projections will bring all visible +participants into the new epoch $E+delta$ and then eventually into consensus. + +The next portion of this section follows the same pattern as +Section~\ref{sec:phases-of-projection-change}: network monitoring, +calculating new projections, writing projections, then perhaps +adopting the newest projection (which may or may not be the projection +that we just wrote). +Beginning with Section~9.5\footnote{TODO correction needed?}, we will +explore TODO TOPICS. + +Additional sources for information humming consensus include: + +\begin{itemize} +\item ``On Consensus and Humming in the IETF'' \cite{rfc-7282}, for +background on the use of humming by IETF meeting participants during +IETF meetings. + +\item ``On `Humming Consensus', an allegory'' \cite{humming-consensus-allegory}, +for an allegory in homage to the style of Leslie Lamport's original Paxos +paper. +\end{itemize} + +\paragraph{Aside: origin of the analogy to composing music} +The ``humming'' part of humming consensus comes from the action taken +when the environment changes. If we imagine an egalitarian group of +people, all in the same room humming some pitch together, then we take +action to change our humming pitch if: + +\begin{itemize} +\item Some member departs the room (because we can witness the person +walking out the door) or if someone else in the room starts humming a +new pitch with a new epoch number.\footnote{It's very difficult for + the human ear to hear the epoch number part of a hummed pitch, but + for the sake of the analogy, let's assume that it can.} +\item If a member enters the room and starts humming with the same + epoch number but a different note. +\end{itemize} + +If someone were to transcribe onto a musical score the pitches that +are hummed in the room over a period of time, we might have something +that is roughly like music. If this musical score uses chord progressions +and rhythms that obey the rules of a musical genre, e.g., Gregorian +chant, then the final musical score is a valid Gregorian chant. + +By analogy, if the rules of the musical score are obeyed, then the +Chain Replication invariants that are managed by humming consensus are +obeyed. Such safe management of Chain Replication metadata is our end goal. + +\subsection{Network monitoring} + +See also: Section~\ref{sub:network-monitoring}. + +In today's implementation, there is only a single criterion for +determining the available/not-available status of a remote server $S$: +is $S$'s projection store available. If yes, then we assume that all +$S$ is available. If $S$'s projection store is not available for any +reason, we assume $S$ is entirely unavailable. This simple single +criterion appears to be sufficient for humming consensus, according to +simulations of arbitrary network partitions. + +\subsection{Calculating a new projection data structure} + +See also: Section~\ref{sub:projection-calculation}. + +TODO: +0. incorporate text from ORG file at all relevant places!!!!!!!!!! +1. calculating a new projection is straightforward +2. define flapping? +3. a simple criterion for flapping/not-flapping is pretty easy +4. if flapping, then calculate an ``inner'' projection +5. if flapping $\rightarrow$ not-flapping, then copy inner +$\rightarrow$ outer projection and reset flapping counter. + +\subsection{Writing a new projection} + +See also: Section~\ref{sub:proj-storage-writing}. + +TODO: +1. We write a new projection based on flowchart A* and B* states and +state transtions. + +TOOD: include the flowchart into the doc. We'll probably need to +insert it landscape? + +\subsection{Adopting a new projection} + +See also: Section~\ref{sub:proj-adoption}. + +TODO finish + +A new projection $P_E$ is adopted by a Machi server at epoch $E$ if +two requirements are met: + +\paragraph{\#1: All available copies of $P_E$ are unanimous/identical} + +If we query all available servers for their latest projection, then assume +that $E$ is the largest epoch number found. If we read public +projections for epoch $E$ from all available servers, and if all are +equal to some projection $P_E$, then projection $P_E$ is +(by definition) the best candidate for adoption by the local server. + +If we see a projection $P^2_E$ that has the same epoch $E$ but a +different checksum value, then we must consider $P^2_E \ne P_E$. +If we see multiple different values $P^*_E$ for epoch $E$, then the +projection calculation subsystem is notified. This notification +will trigger a calculation of a new projection $P_{E+1}$ which +may eventually be stored and therefore help +resolve epoch $E$'s ambiguous and unusable condition. + +\paragraph{\#2: The transition from current $\rightarrow$ new projection is +safe} + +The projection $P_E = P_{latest}$ is evaluated by numerous rules and +invariants, relative to the projection that the server is currently +using, $P_{current}$. If such rule or invariant is violated/false, +then the local server will discard $P_{latest}$. Instead, it will +trigger the projection calculation subsystem to create an alternative, +safe projection $P_{latest+1}$ that will hopefully create a unanimous +epoch $E+1$. + +See Section~\ref{sub:humming-rules-and-invariants} for detail about +these rules and invariants. + +TODO: +1. We write a new projection based on flowchart A* and B* and C1* states and +state transtions. + +\section{Just in case Humming Consensus doesn't work for us} + +There are some unanswered questions about Machi's proposed chain +management technique. The problems that we guess are likely/possible +include: + +\begin{itemize} + +\item Thrashing or oscillating between a pair (or more) of + projections. It's hoped that the ``best projection'' ranking system + will be sufficient to prevent endless thrashing of projections, but + it isn't yet clear that it will be. + +\item Partial (and/or one-way) network splits which cause partially + connected graphs of inter-node connectivity. Groups of nodes that + are completely isolated aren't a problem. However, partially + connected groups of nodes is an unknown. Intuition says that + communication (via the projection store) with ``bridge nodes'' in a + partially-connected network ought to settle eventually on a + projection with high rank, e.g., the projection on an island + subcluster of nodes with the largest author node name. Some corner + case(s) may exist where this intuition is not correct. + +\item CP Mode management via the method proposed in + Section~\ref{sec:split-brain-management} may not be sufficient in + all cases. + +\end{itemize} + +\subsection{Alternative: Elastic Replication} + +Using Elastic Replication (Section~\ref{ssec:elastic-replication}) is +our preferred alternative, if Humming Consensus is not usable. + +Elastic chain replication is a technique described in +\cite{elastic-chain-replication}. It describes using multiple chains +to monitor each other, as arranged in a ring where a chain at position +$x$ is responsible for chain configuration and management of the chain +at position $x+1$. + +\subsection{Alternative: Hibari's ``Admin Server'' + and Elastic Chain Replication} + +See Section 7 of \cite{cr-theory-and-practice} for details of Hibari's +chain management agent, the ``Admin Server''. In brief: + +\begin{itemize} +\item The Admin Server is intentionally a single point of failure in + the same way that the instance of Stanchion in a Riak CS cluster + is an intentional single + point of failure. In both cases, strict + serialization of state changes is more important than 100\% + availability. + +\item For higher availability, the Hibari Admin Server is usually + configured in an active/standby manner. Status monitoring and + application failover logic is provided by the built-in capabilities + of the Erlang/OTP application controller. + +\end{itemize} + +\section{``Split brain'' management in CP Mode} +\label{sec:split-brain-management} + +Split brain management is a thorny problem. The method presented here +is one based on pragmatics. If it doesn't work, there isn't a serious +worry, because Machi's first serious use case all require only AP Mode. +If we end up falling back to ``use Riak Ensemble'' or ``use ZooKeeper'', +then perhaps that's +fine enough. Meanwhile, let's explore how a +completely self-contained, no-external-dependencies +CP Mode Machi might work. + +Wikipedia's description of the quorum consensus solution\footnote{See + {\tt http://en.wikipedia.org/wiki/Split-brain\_(computing)}.} is nice +and short: + +\begin{quotation} +A typical approach, as described by Coulouris et al.,[4] is to use a +quorum-consensus approach. This allows the sub-partition with a +majority of the votes to remain available, while the remaining +sub-partitions should fall down to an auto-fencing mode. +\end{quotation} + +This is the same basic technique that +both Riak Ensemble and ZooKeeper use. Machi's +extensive use of write-registers are a big advantage when implementing +this technique. Also very useful is the Machi ``wedge'' mechanism, +which can automatically implement the ``auto-fencing'' that the +technique requires. All Machi servers that can communicate with only +a minority of other servers will automatically ``wedge'' themselves +and refuse all requests for service until communication with the +majority can be re-established. + +\subsection{The quorum: witness servers vs. full servers} + +In any quorum-consensus system, at least $2f+1$ participants are +required to survive $f$ participant failures. Machi can implement a +technique of ``witness servers'' servers to bring the total cost +somewhere in the middle, between $2f+1$ and $f+1$, depending on your +point of view. + +A ``witness server'' is one that participates in the network protocol +but does not store or manage all of the state that a ``full server'' +does. A ``full server'' is a Machi server as +described by this RFC document. A ``witness server'' is a server that +only participates in the projection store and projection epoch +transition protocol and a small subset of the file access API. +A witness server doesn't actually store any +Machi files. A witness server is almost stateless, when compared to a +full Machi server. + +A mixed cluster of witness and full servers must still contain at +least $2f+1$ participants. However, only $f+1$ of them are full +participants, and the remaining $f$ participants are witnesses. In +such a cluster, any majority quorum must have at least one full server +participant. + +Witness servers are always placed at the front of the chain. As stated +above, there may be at most $f$ witness servers. A functioning quorum +majority +must have at least $f+1$ servers that can communicate and therefore +calculate and store a new unanimous projection. Therefore, any server at +the tail of a functioning quorum majority chain must be full server. Full servers +actually store Machi files, so they have no problem answering {\tt + read\_req} API requests.\footnote{We hope that it is now clear that + a witness server cannot answer any Machi file read API request.} + +Any server that can only communicate with a minority of other servers will +find that none can calculate a new projection that includes a +majority of servers. Any such server, when in CP mode, would then move to +wedge state and remain wedged until the network partition heals enough +to communicate with the majority side. This is a nice property: we +automatically get ``fencing'' behavior.\footnote{Any server on the minority side + is wedged and therefore refuses to serve because it is, so to speak, + ``on the wrong side of the fence.''} + +There is one case where ``fencing'' may not happen: if both the client +and the tail server are on the same minority side of a network partition. +Assume the client and server $S_z$ are on the "wrong side" of a network +split; both are using projection epoch $P_1$. The tail of the +chain is $S_z$. + +Also assume that the "right side" has reconfigured and is using +projection epoch $P_2$. The right side has mutated key $K$. Meanwhile, +nobody on the "right side" has noticed anything wrong and is happy to +continue using projection $P_1$. + +\begin{itemize} +\item {\bf Option a}: Now the wrong side client reads $K$ using $P_1$ via + $S_z$. $S_z$ does not detect an epoch problem and thus returns an + answer. Given our assumptions, this value is stale. For some + client use cases, this kind of staleness may be OK in trade for + fewer network messages per read \ldots so Machi may + have a configurable option to permit it. +\item {\bf Option b}: The wrong side client must confirm that $P_1$ is + in use by a full majority of chain members, including $S_z$. +\end{itemize} + +Attempts using Option b will fail for one of two reasons. First, if +the client can talk to a server that is using $P_2$, the client's +operation must be retried using $P_2$. Second, the client will time +out talking to enough servers so that it fails to get a quorum's worth of +$P_1$ answers. In either case, Option B will always fail a client +read and thus cannot return a stale value of $K$. + +\subsection{Witness server data and protocol changes} + +Some small changes to the projection's data structure +are required (relative to the initial spec described in +\cite{machi-design}). The projection itself +needs new annotation to indicate the operating mode, AP mode or CP +mode. The state type notifies the chain manager how to +react in network partitions and how to calculate new, safe projection +transitions and which file repair mode to use +(Section~\ref{sec:repair-entire-files}). +Also, we need to label member server servers as full- or +witness-type servers. + +Write API requests are processed by witness servers in {\em almost but + not quite} no-op fashion. The only requirement of a witness server +is to return correct interpretations of local projection epoch +numbers, via the {\tt error\_bad\_epoch} and {\tt error\_wedged} error +codes. In fact, a new API call is sufficient for querying witness +servers: {\tt \{check\_epoch, m\_epoch()\}}. +Any client write operation sends the {\tt + check\_\-epoch} API command to witness servers and sends the usual {\tt + write\_\-req} command to full servers. + +\section{Repair of entire files} +\label{sec:repair-entire-files} + +There are some situations where repair of entire files is necessary. + +\begin{itemize} +\item To repair servers added to a chain in a projection change, + specifically adding a new server to the chain. This case covers both + adding a new, data-less server and re-adding a previous, data-full server + back to the chain. +\item To avoid data loss when changing the order of the chain's servers. +\end{itemize} + +Both situations can set the stage for data loss in the future. +If a violation of the Update Propagation Invariant (see end of +Section~\ref{sec:cr-proof}) is permitted, then the strong consistency +guarantee of Chain Replication is violated. Because Machi uses +write-once registers, the number of possible strong consistency +violations is small: any client that witnesses a written $\rightarrow$ +unwritten transition is a violation of strong consistency. But +avoiding even this one bad scenario is a bit tricky. + +Data +unavailability/loss when all chain servers fail is unavoidable. We +wish to avoid data loss whenever a chain has at least one surviving +server. Another method to avoid data loss is to preserve the Update +Propagation Invariant at all times. + +\subsection{Just ``rsync'' it!} +\label{ssec:just-rsync-it} + +A simple repair method might be perhaps 90\% sufficient. +That method could loosely be described as ``just {\tt rsync} +all files to all servers in an infinite loop.''\footnote{The + file format suggested in + \cite{machi-design} does not permit {\tt rsync} + as-is to be sufficient. A variation of {\tt rsync} would need to be + aware of the data/metadata split within each file and only replicate + the data section \ldots and the metadata would still need to be + managed outside of {\tt rsync}.} + +However, such an informal method +cannot tell you exactly when you are in danger of data loss and when +data loss has actually happened. If we maintain the Update +Propagation Invariant, then we know exactly when data loss is immanent +or has happened. + +Furthermore, we hope to use Machi for multiple use cases, including +ones that require strong consistency. +For uses such as CORFU, strong consistency is a non-negotiable +requirement. Therefore, we will use the Update Propagation Invariant +as the foundation for Machi's data loss prevention techniques. + +\subsection{Divergence from CORFU: repair} +\label{sub:repair-divergence} + +The original repair design for CORFU is simple and effective, +mostly. See Figure~\ref{fig:corfu-style-repair} for a full +description of the algorithm +Figure~\ref{fig:corfu-repair-sc-violation} for an example of a strong +consistency violation that can follow. (NOTE: This is a variation of +the data loss scenario that is described in +Figure~\ref{fig:data-loss2}.) + +\begin{figure} +\begin{enumerate} +\item Destroy all data on the repair destination FLU. +\item Add the repair destination FLU to the tail of the chain in a new + projection $P_{p+1}$. +\item Change projection from $P_p$ to $P_{p+1}$. +\item Let single item read repair fix all of the problems. +\end{enumerate} +\caption{Simplest CORFU-style repair algorithm.} +\label{fig:corfu-style-repair} +\end{figure} + +\begin{figure} +\begin{enumerate} +\item Write value $V$ to offset $O$ in the log with chain $[S_a]$. + This write is considered successful. +\item Change projection to configure chain as $[S_a,S_b]$. Prior to + the change, all values on FLU $S_b$ are unwritten. +\item FLU server $S_a$ crashes. The new projection defines the chain + as $[S_b]$. +\item A client attempts to read offset $O$ and finds an unwritten + value. This is a strong consistency violation. +%% \item The same client decides to fill $O$ with the junk value +%% $V_{junk}$. Now value $V$ is lost. +\end{enumerate} +\caption{An example scenario where the CORFU simplest repair algorithm + can lead to a violation of strong consistency.} +\label{fig:corfu-repair-sc-violation} +\end{figure} + +\begin{figure} +\begin{enumerate} +\item Projection $P_p$ says that chain membership is $[S_a]$. +\item A write of data $D$ to file $F$ at offset $O$ is successful. +\item Projection $P_{p+1}$ says that chain membership is $[S_a,S_b]$, via + an administration API request. +\item Machi will trigger repair operations, copying any missing data + files from FLU $S_a$ to FLU $S_b$. For the purpose of this + example, the sync operation for file $F$'s data and metadata has + not yet started. +\item FLU $S_a$ crashes. +\item The chain manager on $S_b$ notices $S_a$'s crash, + decides to create a new projection $P_{p+2}$ where chain membership is + $[S_b]$ + successfully stores $P_{p+2}$ in its local store. FLU $S_b$ is now wedged. +\item FLU $S_a$ is down, therefore the + value of $P_{p+2}$ is unanimous for all currently available FLUs + (namely $[S_b]$). +\item FLU $S_b$ sees that projection $P_{p+2}$ is the newest unanimous + projection. It unwedges itself and continues operation using $P_{p+2}$. +\item Data $D$ is definitely unavailable for now. If server $S_a$ is + never re-added to the chain, then data $D$ is lost forever. +\end{enumerate} +\caption{Data unavailability scenario with danger of permanent data loss} +\label{fig:data-loss2} +\end{figure} + +A variation of the repair +algorithm is presented in section~2.5 of a later CORFU paper \cite{corfu2}. +However, the re-use a failed +server is not discussed there, either: the example of a failed server +$S_6$ uses a new server, $S_8$ to replace $S_6$. Furthermore, the +repair process is described as: + +\begin{quote} +``Once $S_6$ is completely rebuilt on $S_8$ (by copying entries from + $S_7$), the system moves to projection (C), where $S_8$ is now used + to service all reads in the range $[40K,80K)$.'' +\end{quote} + +The phrase ``by copying entries'' does not give enough +detail to avoid the same data race as described in +Figure~\ref{fig:corfu-repair-sc-violation}. We believe that if +``copying entries'' means copying only written pages, then CORFU +remains vulnerable. If ``copying entries'' also means ``fill any +unwritten pages prior to copying them'', then perhaps the +vulnerability is eliminated.\footnote{SLF's note: Probably? This is my + gut feeling right now. However, given that I've just convinced + myself 100\% that fill during any possibility of split brain is {\em + not safe} in Machi, I'm not 100\% certain anymore than this ``easy'' + fix for CORFU is correct.}. + +\subsection{Whole file repair as servers are (re-)added to a chain} +\label{sub:repair-add-to-chain} + +\begin{figure*} +\centering +$ +[\overbrace{\underbrace{H_1}_\textbf{Head of Heads}, M_{11}, + \underbrace{T_1}_\textbf{Tail \#1}}^\textbf{Chain \#1 (U.P.~Invariant preserving)} +\mid +\overbrace{H_2, M_{21}, + \underbrace{T_2}_\textbf{Tail \#2}}^\textbf{Chain \#2 (repairing)} +\mid \ldots \mid +\overbrace{H_n, M_{n1}, + \underbrace{T_n}_\textbf{Tail \#n \& Tail of Tails ($T_{tails}$)}}^\textbf{Chain \#n (repairing)} +] +$ +\caption{Representation of a ``chain of chains'': a chain prefix of + Update Propagation Invariant preserving FLUs (``Chain \#1'') + with FLUs from $n-1$ other chains under repair.} +\label{fig:repair-chain-of-chains} +\end{figure*} + +\begin{figure} +\centering +$ +[\overbrace{\underbrace{H_1}_\textbf{Head}, M_{11}, T_1, + H_2, M_{21}, T_2, + \ldots + H_n, M_{n1}, + \underbrace{T_n}_\textbf{Tail}}^\textbf{Chain (U.P.~Invariant preserving)} +] +$ +\caption{Representation of Figure~\ref{fig:repair-chain-of-chains} + after all repairs have finished successfully and a new projection has + been calculated.} +\label{fig:repair-chain-of-chains-finished} +\end{figure} + +Machi's repair process must preserve the Update Propagation +Invariant. To avoid data races with data copying from +``U.P.~Invariant preserving'' servers (i.e. fully repaired with +respect to the Update Propagation Invariant) +to servers of unreliable/unknown state, a +projection like the one shown in +Figure~\ref{fig:repair-chain-of-chains} is used. In addition, the +operations rules for data writes and reads must be observed in a +projection of this type. + +\begin{itemize} + +\item The system maintains the distinction between ``U.P.~preserving'' + and ``repairing'' FLUs at all times. This allows the system to + track exactly which servers are known to preserve the Update + Propagation Invariant and which servers may/may not. + +\item All ``repairing'' FLUs must be added only at the end of the + chain-of-chains. + +\item All write operations must flow successfully through the + chain-of-chains from beginning to end, i.e., from the ``head of + heads'' to the ``tail of tails''. This rule also includes any + repair operations. + +\item In AP Mode, all read operations are attempted from the list of +$[T_1,\-T_2,\-\ldots,\-T_n]$, where these FLUs are the tails of each of the +chains involved in repair. +In CP mode, all read operations are attempted only from $T_1$. +The first reply of {\tt \{ok, <<...>>\}} is a correct answer; +the rest of the FLU list can be ignored and the result returned to the +client. If all FLUs in the list have an unwritten value, then the +client can return {\tt error\_unwritten}. + +\end{itemize} + +While the normal single-write and single-read operations are performed +by the cluster, a file synchronization process is initiated. The +sequence of steps differs depending on the AP or CP mode of the system. + +\subsubsection{Repair in CP mode} + +In cases where the cluster is operating in CP Mode, +CORFU's repair method of ``just copy it all'' (from source FLU to repairing +FLU) is correct, {\em except} for the small problem pointed out in +Section~\ref{sub:repair-divergence}. The problem for Machi is one of +time \& space. Machi wishes to avoid transferring data that is +already correct on the repairing nodes. If a Machi node is storing +20TBytes of data, we really do not wish to use 20TBytes of bandwidth +to repair only 1 GByte of truly-out-of-sync data. + +However, it is {\em vitally important} that all repairing FLU data be +clobbered/overwritten with exactly the same data as the Update +Propagation Invariant preserving chain. If this rule is not strictly +enforced, then fill operations can corrupt Machi file data. The +algorithm proposed is: + +\begin{enumerate} + +\item Change the projection to a ``chain of chains'' configuration + such as depicted in Figure~\ref{fig:repair-chain-of-chains}. + +\item For all files on all FLUs in all chains, extract the lists of + written/unwritten byte ranges and their corresponding file data + checksums. (The checksum metadata is not strictly required for + recovery in AP Mode.) + Send these lists to the tail of tails + $T_{tails}$, which will collate all of the lists into a list of + tuples such as {\tt \{FName, $O_{start}, O_{end}$, CSum, FLU\_List\}} + where {\tt FLU\_List} is the list of all FLUs in the entire chain of + chains where the bytes at the location {\tt \{FName, $O_{start}, + O_{end}$\}} are known to be written (as of the current repair period). + +\item For chain \#1 members, i.e., the + leftmost chain relative to Figure~\ref{fig:repair-chain-of-chains}, + repair files byte ranges for any chain \#1 members that are not members + of the {\tt FLU\_List} set. This will repair any partial + writes to chain \#1 that were unsuccessful (e.g., client crashed). + (Note however that this step only repairs FLUs in chain \#1.) + +\item For all file byte ranges in all files on all FLUs in all + repairing chains where Tail \#1's value is unwritten, force all + repairing FLUs to also be unwritten. + +\item For file byte ranges in all files on all FLUs in all repairing + chains where Tail \#1's value is written, send repair file byte data + \& metadata to any repairing FLU if the value repairing FLU's + value is unwritten or the checksum is not exactly equal to Tail \#1's + checksum. + +\end{enumerate} + +When the repair is known to have copied all missing data successfully, +then the chain can change state via a new projection that includes the +repaired FLU(s) at the end of the U.P.~Invariant preserving chain \#1 +in the same order in which they appeared in the chain-of-chains during +repair. See Figure~\ref{fig:repair-chain-of-chains-finished}. + +The repair can be coordinated and/or performed by the $T_{tails}$ FLU +or any other FLU or cluster member that has spare capacity. + +There is no serious race condition here between the enumeration steps +and the repair steps. Why? Because the change in projection at +step \#1 will force any new data writes to adapt to a new projection. +Consider the mutations that either happen before or after a projection +change: + +\begin{itemize} + +\item For all mutations $M_1$ prior to the projection change, the + enumeration steps \#3 \& \#4 and \#5 will always encounter mutation + $M_1$. Any repair must write through the entire chain-of-chains and + thus will preserve the Update Propagation Invariant when repair is + finished. + +\item For all mutations $M_2$ starting during or after the projection + change has finished, a new mutation $M_2$ may or may not be included in the + enumeration steps \#3 \& \#4 and \#5. + However, in the new projection, $M_2$ must be + written to all chain of chains members, and such + in-order writes will also preserve the Update + Propagation Invariant and therefore is also be safe. + +\end{itemize} + +\subsubsection{Repair in AP Mode} + +In cases the cluster is operating in AP Mode: + +\begin{enumerate} +\item Follow the first two steps of the ``CP Mode'' + sequence (above). +\item Follow step \#3 of the ``strongly consistent mode'' sequence + (above), but in place of repairing only FLUs in Chain \#1, AP mode + will repair the byte range of any FLU that is not a member of the + {\tt FLU\_List} set. +\item End of procedure. +\end{enumerate} + +The end result is a huge ``merge'' where any +{\tt \{FName, $O_{start}, O_{end}$\}} range of bytes that is written +on FLU $S_w$ but missing/unwritten from FLU $S_m$ is written down the full chain +of chains, skipping any FLUs where the data is known to be written. +Such writes will also preserve Update Propagation Invariant when +repair is finished. + +\subsection{Whole-file repair when changing server ordering within a chain} +\label{sub:repair-chain-re-ordering} + +This section has been cut --- please see Git commit history for discussion. + +\section{Chain Replication: why is it correct?} +\label{sec:cr-proof} + +See Section~3 of \cite{chain-replication} for a proof of the +correctness of Chain Replication. A short summary is provide here. +Readers interested in good karma should read the entire paper. + +\subsection{The Update Propagation Invariant} +\label{sub:upi} + +``Update Propagation Invariant'' is the original chain replication +paper's name for the +$H_i \succeq H_j$ +property mentioned in Figure~\ref{tab:chain-order}. +This paper will use the same name. +This property may also be referred to by its acronym, ``UPI''. + +\subsection{Chain Replication and strong consistency} + +The three basic rules of Chain Replication and its strong +consistency guarantee: + +\begin{enumerate} + +\item All replica servers are arranged in an ordered list $C$. + +\item All mutations of a datum are performed upon each replica of $C$ + strictly in the order which they appear in $C$. A mutation is considered + completely successful if the writes by all replicas are successful. + +\item The head of the chain makes the determination of the order of + all mutations to all members of the chain. If the head determines + that some mutation $M_i$ happened before another mutation $M_j$, + then mutation $M_i$ happens before $M_j$ on all other members of + the chain.\footnote{While necesary for general Chain Replication, + Machi does not need this property. Instead, the property is + provided by Machi's sequencer and the write-once register of each + byte in each file.} + +\item All read-only operations are performed by the ``tail'' replica, + i.e., the last replica in $C$. + +\end{enumerate} + +The basis of the proof lies in a simple logical trick, which is to +consider the history of all operations made to any server in the chain +as a literal list of unique symbols, one for each mutation. + +Each replica of a datum will have a mutation history list. We will +call this history list $H$. For the $i^{th}$ replica in the chain list +$C$, we call $H_i$ the mutation history list for the $i^{th}$ replica. + +Before the $i^{th}$ replica in the chain list begins service, its mutation +history $H_i$ is empty, $[]$. After this replica runs in a Chain +Replication system for a while, its mutation history list grows to +look something like +$[M_0, M_1, M_2, ..., M_{m-1}]$ where $m$ is the total number of +mutations of the datum that this server has processed successfully. + +Let's assume for a moment that all mutation operations have stopped. +If the order of the chain was constant, and if all mutations are +applied to each replica in the chain's order, then all replicas of a +datum will have the exact same mutation history: $H_i = H_J$ for any +two replicas $i$ and $j$ in the chain +(i.e., $\forall i,j \in C, H_i = H_J$). That's a lovely property, +but it is much more interesting to assume that the service is +not stopped. Let's look next at a running system. + +\begin{figure*} +\centering +\begin{tabular}{ccc} +{\bf {{On left side of $C$}}} & & {\bf On right side of $C$} \\ +\hline +\multicolumn{3}{l}{Looking at replica order in chain $C$:} \\ +$i$ & $<$ & $j$ \\ + +\multicolumn{3}{l}{For example:} \\ + +0 & $<$ & 2 \\ +\hline +\multicolumn{3}{l}{It {\em must} be true: history lengths per replica:} \\ +length($H_i$) & $\geq$ & length($H_j$) \\ +\multicolumn{3}{l}{For example, a quiescent chain:} \\ +length($H_i$) = 48 & $\geq$ & length($H_j$) = 48 \\ +\multicolumn{3}{l}{For example, a chain being mutated:} \\ +length($H_i$) = 55 & $\geq$ & length($H_j$) = 48 \\ +\multicolumn{3}{l}{Example ordered mutation sets:} \\ +$[M_0,M_1,\ldots,M_{46},M_{47},\ldots,M_{53},M_{54}]$ & $\supset$ & $[M_0,M_1,\ldots,M_{46},M_{47}]$ \\ +\multicolumn{3}{c}{\bf Therefore the right side is always an ordered + subset} \\ +\multicolumn{3}{c}{\bf of the left side. Furthermore, the ordered + sets on both} \\ +\multicolumn{3}{c}{\bf sides have the exact same order of those elements they have in common.} \\ +\multicolumn{3}{c}{The notation used by the Chain Replication paper is +shown below:} \\ +$[M_0,M_1,\ldots,M_{46},M_{47},\ldots,M_{53},M_{54}]$ & $\succeq$ & $[M_0,M_1,\ldots,M_{46},M_{47}]$ \\ + +\end{tabular} +\caption{The ``Update Propagation Invariant'' as + illustrated by Chain Replication protocol history.} +\label{tab:chain-order} +\end{figure*} + +If the entire chain $C$ is processing any number of concurrent +mutations, then we can still understand $C$'s behavior. +Figure~\ref{tab:chain-order} shows us two replicas in chain $C$: +replica $R_i$ that's on the left/earlier side of the replica chain $C$ +than some other replica $R_j$. We know that $i$'s position index in +the chain is smaller than $j$'s position index, so therefore $i < j$. +The restrictions of Chain Replication make it true that length($H_i$) +$\ge$ length($H_j$) because it's also that $H_i \supset H_j$, i.e, +$H_i$ on the left is always is a superset of $H_j$ on the right. + +When considering $H_i$ and $H_j$ as strictly ordered lists, we have +$H_i \succeq H_j$, where the right side is always an exact prefix of the left +side's list. This prefixing propery is exactly what strong +consistency requires. If a value is read from the tail of the chain, +then no other chain member can have a prior/older value because their +respective mutations histories cannot be shorter than the tail +member's history. + +\section{TODO: orphaned text} + +\subsection{1} + +For any key $K$, different projection stores $S_a$ and $S_b$ may store +nothing (i.e., {\tt error\_unwritten} when queried) or store different +values, $P_a \ne P_b$, despite having the same projection epoch +number. The following ranking rules are used to +determine the ``best value'' of a projection, where highest rank of +{\em any single projection} is considered the ``best value'': + +\begin{enumerate} +\item An unwritten value is ranked at a value of $-1$. +\item A value whose {\tt author\_server} is at the $I^{th}$ position + in the {\tt all\_members} list has a rank of $I$. +\item A value whose {\tt dbg\_annotations} and/or other fields have + additional information may increase/decrease its rank, e.g., + increase the rank by $10.25$. +\end{enumerate} + +Rank rules \#2 and \#3 are intended to avoid worst-case ``thrashing'' +of different projection proposals. + +\subsection{ranking} +\label{sub:projection-ranking} + +\subsection{rules \& invariants} +\label{sub:humming-rules-and-invariants} + + +\bibliographystyle{abbrvnat} +\begin{thebibliography}{} +\softraggedright + +\bibitem{riak-core} +Klophaus, Rusty. +"Riak Core." +ACM SIGPLAN Commercial Users of Functional Programming (CUFP'10), 2010. +{\tt http://dl.acm.org/citation.cfm?id=1900176} and +{\tt https://github.com/basho/riak\_core} + +\bibitem{rfc-7282} +RFC 7282: On Consensus and Humming in the IETF. +Internet Engineering Task Force. +{\tt https://tools.ietf.org/html/rfc7282} + +\bibitem{elastic-chain-replication} +Abu-Libdeh, Hussam et al. +Leveraging Sharding in the Design of Scalable Replication Protocols. +Proceedings of the 4th Annual Symposium on Cloud Computing (SOCC'13), 2013. +{\tt http://www.ymsir.com/papers/sharding-socc.pdf} + +\bibitem{corfu1} +Balakrishnan, Mahesh et al. +CORFU: A Shared Log Design for Flash Clusters. +Proceedings of the 9th USENIX Conference on Networked Systems Design +and Implementation (NSDI'12), 2012. +{\tt http://research.microsoft.com/pubs/157204/ corfumain-final.pdf} + +\bibitem{corfu2} +Balakrishnan, Mahesh et al. +CORFU: A Distributed Shared Log +ACM Transactions on Computer Systems, Vol. 31, No. 4, Article 10, December 2013. +{\tt http://www.snookles.com/scottmp/corfu/ corfu.a10-balakrishnan.pdf} + +\bibitem{machi-design} +Basho Japan KK. +Machi: an immutable file store +{\tt https://github.com/basho/machi/tree/ master/doc/high-level-machi.pdf} + +\bibitem{was} +Calder, Brad et al. +Windows Azure Storage: A Highly Available Cloud Storage Service with Strong Consistency +Proceedings of the 23rd ACM Symposium on Operating Systems Principles (SOSP'11), 2011. +{\tt http://sigops.org/sosp/sosp11/current/ 2011-Cascais/printable/11-calder.pdf} + +\bibitem{cr-theory-and-practice} +Fritchie, Scott Lystig. +Chain Replication in Theory and in Practice. +Proceedings of the 9th ACM SIGPLAN Workshop on Erlang (Erlang'10), 2010. +{\tt http://www.snookles.com/scott/publications/ erlang2010-slf.pdf} + +\bibitem{humming-consensus-allegory} +Fritchie, Scott Lystig. +On “Humming Consensus”, an allegory. +{\tt http://www.snookles.com/slf-blog/2015/03/ 01/on-humming-consensus-an-allegory/} + +\bibitem{the-log-what} +Kreps, Jay. +The Log: What every software engineer should know about real-time data's unifying abstraction +{\tt http://engineering.linkedin.com/distributed- + systems/log-what-every-software-engineer-should- + know-about-real-time-datas-unifying} + +\bibitem{kafka} +Kreps, Jay et al. +Kafka: a distributed messaging system for log processing. +NetDB’11. +{\tt http://research.microsoft.com/en-us/UM/people/ + srikanth/netdb11/netdb11papers/netdb11-final12.pdf} + +\bibitem{part-time-parliament} +Lamport, Leslie. +The Part-Time Parliament. +DEC technical report SRC-049, 1989. +{\tt ftp://apotheca.hpl.hp.com/gatekeeper/pub/ DEC/SRC/research-reports/SRC-049.pdf} + +\bibitem{paxos-made-simple} +Lamport, Leslie. +Paxos Made Simple. +In SIGACT News \#4, Dec, 2001. +{\tt http://research.microsoft.com/users/ lamport/pubs/paxos-simple.pdf} + +\bibitem{random-slicing} +Miranda, Alberto et al. +Random Slicing: Efficient and Scalable Data Placement for Large-Scale Storage Systems. +ACM Transactions on Storage, Vol. 10, No. 3, Article 9, July 2014. +{\tt http://www.snookles.com/scottmp/corfu/random- slicing.a9-miranda.pdf} + +\bibitem{porcupine} +Saito, Yasushi et al. +Manageability, availability and performance in Porcupine: a highly scalable, cluster-based mail service. +7th ACM Symposium on Operating System Principles (SOSP’99). +{\tt http://homes.cs.washington.edu/\%7Elevy/ porcupine.pdf} + +\bibitem{chain-replication} +van Renesse, Robbert et al. +Chain Replication for Supporting High Throughput and Availability. +Proceedings of the 6th Conference on Symposium on Operating Systems +Design \& Implementation (OSDI'04) - Volume 6, 2004. +{\tt http://www.cs.cornell.edu/home/rvr/papers/ osdi04.pdf} + +\end{thebibliography} + + +\end{document} diff --git a/doc/src.high-level/high-level-machi.tex b/doc/src.high-level/high-level-machi.tex new file mode 100644 index 0000000..c59c9ff --- /dev/null +++ b/doc/src.high-level/high-level-machi.tex @@ -0,0 +1,1525 @@ + +%% \documentclass[]{report} +\documentclass[preprint,10pt]{sigplanconf} +% The following \documentclass options may be useful: + +% preprint Remove this option only once the paper is in final form. +% 10pt To set in 10-point type instead of 9-point. +% 11pt To set in 11-point type instead of 9-point. +% authoryear To obtain author/year citation style instead of numeric. + +% \usepackage[a4paper]{geometry} +\usepackage[dvips]{graphicx} % to include images +%\usepackage{pslatex} % to use PostScript fonts + +\begin{document} + +%%\special{papersize=8.5in,11in} +%%\setlength{\pdfpageheight}{\paperheight} +%%\setlength{\pdfpagewidth}{\paperwidth} + +\conferenceinfo{}{} +\copyrightyear{2014} +\copyrightdata{978-1-nnnn-nnnn-n/yy/mm} +\doi{nnnnnnn.nnnnnnn} + +\titlebanner{Draft \#1, April 2014} +\preprintfooter{Draft \#1, April 2014} + +\title{Machi: an immutable file store} +\subtitle{High level design \& strawman implementation suggestions \\ + with focus on eventual consistency/''EC'' mode of operation} + +\authorinfo{Basho Japan KK}{} + +\maketitle + +\section{Origins} +\label{sec:origins} + +This document was first written during the autumn of 2014 for a +Basho-only internal audience. Since its original drafts, Machi has +been designated by Basho as a full open source software project. This +document has been rewritten in 2015 to address an external audience. +Furthermore, discussion of the ``chain manager'' service and of strong +consistency have been moved to a separate document, please see +\cite{machi-chain-manager-design}. + +\section{Abstract} +\label{sec:abstract} + +Our goal is a robust \& reliable, distributed, highly +available\footnote{Capable of operating in ``AP mode'' or + ``CP mode'' relative to the CAP Theorem, see + Section~\ref{sub:wedge}.} +large file +store based upon write-once registers, append-only files, +Chain Replication, and +client-server style architecture. All +members of the cluster store all of the files. Distributed load +balancing/sharding of files is {\em outside} of the scope of this system. +However, it is a high priority that this system be able to integrate +easily into systems that do provide distributed load balancing, e.g., +Riak Core. Although strong consistency is a major feature of Chain +Replication, this document will focus mainly on eventual consistency +features --- strong consistency design will be discussed in a separate +document. + +\section{Introduction} +\label{sec:introduction} + +\begin{quotation} +``I must not scope creep. Scope creep is the mind-killer. Scope creep + is the little-death that brings total obliteration. I will face my + scope.'' +\par +\hfill{--- Fred Hebert, {\tt @mononcqc}} +\end{quotation} +\subsection{Origin of the name ``Machi''} +\label{sub:name} + +``Machi'' is a Japanese word for +``village'' or ``small town''. A village is a rather self-contained +thing, but it is small, not like a city. + +One use case for Machi is for file storage, as-is. However, as Tokyo +City is built with a huge collection of machis, so then this project +is also designed to work well as part of a larger system, such as Riak +Core. Tokyo wasn't built in a day, after all, and definitely wasn't +built out of a single village. + +\subsection{Assumptions} +\label{sub:assumptions} + +Machi is a client-server system. All servers in a Machi cluster store +identical copies/replicas of all files, preferably large files. +This puts an effective limit on the size of a Machi cluster. +For example, five servers will replicate all files +for an effective replication $N$ factor of 5. + +Any mechanism to distribute files across a subset of Machi +servers is outside the scope of Machi and of this design. + +Machi's design assumes that it stores mostly large files. +``Large file'' means hundreds of MBytes or more +per file. The design ``sweet spot'' targets about +1 GByte/file and/or managing up to a few million files in a +single cluster. The maximum size of a single Machi file is +limited by the server's underlying OS and file system; a +practical estimate is 2Tbytes or less but may be larger. + +Machi files are write-once, read-many data structures; the label +``append-only'' is mostly correct. However, to be 100\% truthful +truth, the bytes a Machi file can be written temporally in any order. + +Machi files are always named by the server; Machi clients have no +direct control of the name assigned by a Machi server. Machi servers +determine the file name and byte offset to all client write requests. +(Machi clients may advise servers with a desired file name prefix.) + +Machi shall be a +robust and reliable system. Machi will not lose data until a +fundamental assumption has been violated, e.g., all servers have +crashed permanently. Machi's file replicaion algorithms can provide +strong or eventual consistency and is provably correct. Our only +task is to not put bugs into the implementation of the algorithms. Machi's +small pieces and restricted API and semantics will reduce +(we believe) the effort required to test +and verify the implementation. + +Machi should not have ``big'' external runtime dependencies when +practical. For example, the feature set of ZooKeeper makes it a +popular distributed systems coordination service. When possible, +Machi should try to avoid using such a big runtime dependency. For +the purposes of explaining ``big'', the Riak KV service is too big and +thus runs afoul of this requirement. + +Machi clients must assume that any interrupted or incomplete write +operation may be readable at some later time. Read repair or +incomplete writes may happen long after the client has finished or +even crashed. In effect, Machi will provide clients with +``at least once'' behavior for writes. + +Machi is not a Hadoop file system (HDFS) replacement. +%% \begin{itemize} +% \item +There is no mechanism for writing Machi files to a subset of + available storage servers: all servers in a Machi server store + identical copies/replicas of all files. +% \item +However, Machi is intended to play very nicely with a layer above it, + where that layer {\em does} handle file scattering and on-the-fly + file migration across servers and all of the nice things that + HDFS, Riak CS, and similar systems can do. + +\subsection{Defining a Machi file} + +A Machi ``file'' is an undifferentiated, one-dimensional array of +bytes. This definition matches the POSIX definition of a file. +However, the Machi API does not conform to the UNIX/POSIX file +I/O API. + +A list of client operations are shown in +Figure~\ref{fig:example-client-API}. This list may change, but it +shows the basic shape of the service. + +\begin{figure} +\begin{itemize} + \item Append bytes $B$ to a file with name prefix {\tt "foo"}. + \item Write bytes $B$ to offset $O$ of file $F$. + \item Read $N$ bytes from offset $O$ of file $F$. + \item List files: name, size, etc. +\end{itemize} +\caption{Nearly complete list of file API operations} +\label{fig:example-client-API} +\end{figure} + +The file read \& write granularity of Machi is one byte. (In CORFU +operation mode, perhaps, the granularity would be page size on the +order of 4 KBytes or 16 KBytes.) + +\begin{figure} + \begin{enumerate} + \item Client1: Write 1 byte at offset 0 of file $F$. +% \item Client1: Read 1 byte at offset 0 of file $F$. + \item Client2: Write 1 byte at offset 2 of file $F$. +% \item Client2: Read 1 byte at offset 2 of file $F$. + \item Client3: (an intermittently slow client) Write 1 byte at offset 1 of file $F$. +% \item Client3: Read 1 byte at offset 1 of file $F$. + \end{enumerate} +\caption{Example of temporally out-of-order file append sequence that + is valid within a Machi cluster.} +\label{fig:temporal-out-of-order} +\end{figure} + +\subsubsection{Append-only files} +\label{sub:assume-append-only} + +Machi's file writing semantics are append-only. +Machi's append-only behavior is spatial and is {\em not} +enforced temporally. For example, Figure~\ref{fig:temporal-out-of-order} +shows client operations +upon a single file, in strictly increasing wall clock time ticks. +Figure~\ref{fig:temporal-out-of-order}'s is perfectly valid Machi behavior. + +%% In this example, client 3 was +%% very quick and was actually the second client to request +%% appending to the file and therefore was assigned to write to +%% offset \#1. However, client 3 then became slow and didn't +%% actually write its data to offset 1 until after step 4. + +Any byte in a file may have three states: +\begin{enumerate} + \item unwritten: no value has been assigned to the byte. + \item written: exactly one value has been assigned to the byte. + \item trimmed: only used for garbage collection \& disk space + reclamation purposes +\end{enumerate} + +Transitions between these states are strictly ordered. Valid +orders are: + \begin{itemize} + \item unwritten $\rightarrow$ written + \item unwritten $\rightarrow$ trimmed + \item written $\rightarrow$ trimmed + \end{itemize} +%% The trim operation may be used internally to mark byte ranges +%% which have been marked ``no longer in use'', e.g. with a reference +%% count of zero. Such regions may be garbage collected by Machi +%% at its convenience.\footnote{Advanced feature, implementation TBD.} + +Client append operations are atomic: the transition from +one state to another happens for all bytes, or else no +transition is made for any bytes. + +\subsubsection{Machi servers choose all file names} + +A Machi server always chooses the full file name of file + that will have data appended to it. +A Machi server always chooses the offset within the file + that will have data appended to it. + +All file names chosen by Machi are unique, relative to itself. Any +duplicate file names can cause correctness violations.\footnote{For + participation in a larger system, Machi can construct file names that + are unique within that larger system, e.g. by embedding a unique + Machi cluster name or perhaps a UUID-style + string in the name.} + +\subsubsection{File integrity and bit-rot} +\label{sub:bit-rot} + +Clients may specify a per-write checksum of the data being written, +e.g., SHA1. These checksums will be appended to the file's +metadata. Checksums are first-class metadata and is replicated with +the same consistency and availability guarantees as its corresponding +file data. +Clients may optionally fetch the checksum of the bytes they +read. + +Bit-rot can and will happen. To guard against bit-rot on disk, strong + checksums are used to detect bit-rot at all possible places. +\begin{itemize} + \item Client-calculated checksums of appended data + \item Whole-file checksums, calculated by Machi servers for internal + sanity checking. See Section~\ref{sub:detecting-corrupted} for + commentary on how this may not be feasible. + \item Any other place that makes sense for the paranoid. +\end{itemize} + +Full 100\% protection against arbitrary RAM bit-flips is not a design +goal \ldots but would be cool for as research for the great and +glorious future. Meanwhile, Machi will use as many ``defense in +depth'' techniques as feasible. + +\subsubsection{File metadata} + +Files may have metadata associated with them. +Clients may request appending metadata to a file, for example, + {\tt \{file F, bytes X-Y, property list of 2-tuples\}}. +This metadata receives second-class handling with regard to +consistency and availability, as described below and in contrast to +the per-append checksums described in Section~\ref{sub:bit-rot} + +\begin{itemize} + \item File metadata is strictly append-only. + \item File metadata is always eventually consistent. + \item Temporal order of metadata entries is not preserved. + \item Multiple metadata stores for a file may be merged at any time. + \begin{itemize} + \item If a client requires idempotency, then the property list + should contain all information required to identify multiple + copies of the same metadata item. + \item Metadata properties should be considered CRDT-like: the + final metadata list should converge eventually to a single + list of properties. + \end{itemize} +\end{itemize} + +{\bf NOTE:} It isn't yet clear how much support early versions of +Machi will need for file metadata features. + +\subsubsection{File replica management via Chain Replication} +\label{sub:chain-replication} + +Machi uses Chain Replication (CR) internally to maintain file +replicas and inter-replica consistency. +A Machi cluster of $F+1$ servers can sustain the failure of up +to $F$ servers without data loss. + +A simple explanation of Chain Replication is that it is a variation of +single-primary/multiple-secondary replication with the following +restrictions: + +\begin{enumerate} +\item All writes are strictly performed by servers that are arranged + in a single order, known as the ``chain order'', beginning at the + chain's head and ending at the chain's tail. +\item All strongly consistent reads are performed only by the tail of + the chain, i.e., the last server in the chain order. +\item Inconsistent reads may be performed by any single server in the + chain. +\end{enumerate} + +Machi contains enough Chain Replication implementation to maintain its +chain state, strict file data integrity, and file metadata eventual +consistency. See also Section~\ref{sub:self-management}. + +The first version of Machi will use a single chain for managing all +files in the cluster. If the system is quiescent, +then all chain members store the same data: all +Machi servers will all store identical files. Later versions of Machi +may play clever games with projection data structures and algorithms +that interpret these projections to implement alternative replication +schemes. However, such clever games are scope creep and are therefore +research topics for the future. + +Machi will probably not\footnote{Final decision TBD} implement chain +replication using CORFU's description of its protocol. CORFU's +authors made an implementation choice to make the FLU servers +(Section~\ref{sub:flu}) as dumb as possible. The CORFU authors were +(in part) experimenting with the FLU server implemented by an FPGA; a +dumb-as-possible server was a feature. + +Machi does not have CORFU's minimalism as a design principle. +Therefore, it's likely that Machi will implement CR using the original +Chain Replication \cite{chain-replication} paper's pattern of message +passing, i.e., with direct server-to-server message +passing.\footnote{Also, the original CR algorithm's requirement for + message passing back up the chain to enforce write consistency is + not required: Machi's combination of client-driven data repair and + write-once registers make inter-server synchronization unnecessary.} +However, the +description of the protocols in this document will use CORFU-style +Chain Replication. The two variations are equivalent from a +correctness point of view --- what matters is the communication +pattern and total number of messages required per operation. +CORFU's +client-driven messaging patterns feel easier to describe and to +align with CORFU- and Tango-related research papers. + +\subsubsection{Data integrity self-management} +\label{sub:self-management} + +Machi servers automatically monitor each others health. Signs +of poor health will automatically reconfigure the Machi cluster +to avoid data loss and to provide maximum availability. +For example, if a server $S$ crashes and later +restarts, Machi will automatically bring the data on $S$ back to full sync. +This service will be provided by the ``chain manager'', which is +described in \cite{machi-chain-manager-design}. + +Machi will provide an administration API for managing Machi servers, e.g., +cluster membership, file integrity and checksum verification, etc. + +%% Machi's use of Chain Replication internally means that certain +%% combinations of server $S$ fails, $S$ restarts, recovery repair $R_s$ +%% starts to repair $S$'s data, +%% and a separate failure happen before the $R_s$ repair has +%% completed ... can lead to data loss. Such data loss events will +%% be avoided by fail-stop behavior of the entire Machi cluster +%% until external/human intervention can restart nodes that contain +%% at-risk-of-loss data. + +%% All of Machi's participants, client and server alike, fully observe +%% Machi's protocols, write-once enforcement, projection changes (see +%% below), ``wedge'' enforcement (see below), etc. + +\subsection{Out of Machi's scope} + +Anything not mentioned in this paper is outside of Machi's scope. +However, it's worth mentioning (again!) that the following are explicitly +considered out-of-scope for Machi. + + Machi does not distribute/shard files across disjoint sets of servers. + Distribution of files across Machi servers is left for a higher + level of abstraction, e.g. Riak Core. See also + Sections~\ref{sub:name} and \ref{sub:assumptions} and the quote at + the top of Section~\ref{sec:introduction}. + + Later versions of Machi may support erasure + coding directly, or Machi can be used as-is to store files that + client applications that are aware that they are manipulating + erasure coded data. In the latter case, + the client can read a 1 GByte file from a Machi cluster with a chain + length of $N$, erasure encode it in a + 15-choose-any-10 encoding scheme and concatenate them into a 1.5 GByte file, + then store each of the fifteen + 0.1 GByte chunks in a different Machi cluster, each with a chain + length of only $1$. Using separate Machi clusters makes the + burden of physical separation of each coded piece (i.e., ``rack + awareness'') someone/something else's problem. + +\section{Architecture: base components and ideas} + +This section presents the major architectural components. They are: + +\begin{itemize} +\item The FLU: the server that stores a single replica of a file. +(Section \ref{sub:flu}) +\item The Sequencer: assigns a unique file name + offset to each file + append request. +(Section \ref{sub:sequencer}) +\item The chain manager: monitors the health of the + chain and calculates new projections when failure is detected. +(Section \ref{sub:chain-manager}) +\item The Projection Store: a write-once key-value blob store, used by + Machi's chain manager for storing projections. +(Section \ref{sub:proj-store}) +\end{itemize} + +Also presented here are the major concepts used by Machi components: +\begin{itemize} +\item The Projection: the data structure that describes the current + state of the Machi chain. + Projections are stored in the write-once Projection Store. +(Section \ref{sub:projection}) +\item The Projection Epoch Number (a.k.a.~The Epoch): Each projection + is numbered with an epoch. +(Also section \ref{sub:projection}) +\item The Bad Epoch Error: a response when a protocol operation uses a + projection epoch number smaller than the current projection epoch. +(Section \ref{sub:bad-epoch}) +\item The Wedge: a response when a protocol operation uses a + projection epoch number larger than the current projection epoch. +(Section \ref{sub:wedge}) +\item AP Mode and CP Mode: the general mode of a Machi cluster may be + in ``AP Mode'' or ``CP Mode'', which are short-hand notations for + Machi clusters with eventual consistency or strong consistency + behavior. Both modes have different availability profiles and + slightly different feature sets. (Section \ref{sub:ap-cp-mode}) +\end{itemize} + +\subsection{The FLU} +\label{sub:flu} + +The basic idea of the FLU is borrowed from CORFU. The base CORFU +data server is called a ``flash unit''. For Machi, the equivalent +server is nicknamed a FLU, a ``FiLe replica Unit''. A FLU is +responsible for maintaining a single replica/copy of each file +(and its associated metadata) stored in a Machi cluster. + +The FLU's API is very simple: see Figure~\ref{fig:flu-api} for its +data types and operations. This description is not 100\% complete but +is sufficient for discussion purposes. + +\begin{figure*}[] +\begin{verbatim} +-type m_bytes() :: iolist(). +-type m_csum() :: {none | sha1 | sha1_excl_final_20, binary(20)}. +-type m_epoch() :: {m_epoch_n(), m_csum()}. +-type m_epoch_n() :: non_neg_integer(). +-type m_err_r() :: error_unwritten | error_trimmed. +-type m_err_w() :: error_written | error_trimmed. +-type m_file_info() :: {m_name(), Size::integer(), ...}. +-type m_fill_err() :: error_not_permitted. +-type m_generr() :: error_bad_epoch | error_wedged | + error_bad_checksum | error_unavailable. +-type m_name() :: binary(). +-type m_offset() :: non_neg_integer(). +-type m_prefix() :: binary(). +-type m_rerror() :: m_err_r() m_generr(). +-type m_werror() :: m_generr() | m_err_w(). + +-spec append(m_prefix(), m_bytes(), m_epoch()) -> {ok, m_name(), m_offset()} | + m_werror(). +-spec fill(m_name(), m_offset(), integer(), m_epoch()) -> ok | m_fill_err() | + m_werror(). +-spec list_files() -> {ok, [m_file_info()]} | m_generr(). +-spec read(m_name(), m_offset(), integer(), m_epoch()) -> {ok, binary()} | m_rerror(). +-spec trim(m_name(), m_offset(), integer(), m_epoch()) -> ok | m_generr(). +-spec write(m_name(), m_offset(), m_bytes(), m_csum(), + m_epoch()) -> ok | m_werror(). + +-spec proj_get_largest_key() -> m_epoch_n() | error_unavailable. +-spec proj_get_largest_keyval() -> {ok, m_epoch_n(), binary()} | +-spec proj_list() -> {ok, [m_epoch_n()]}. +-spec proj_read(m_epoch_n()) -> {ok, binary()} | m_err_r(). +-spec proj_write(m_epoch_n(), m_bytes(), m_csum()) -> ok | m_err_w() | + error_unwritten | error_unavailable. +\end{verbatim} +\caption{FLU data and projection operations as viewed as an API and data types (excluding metadata operations)} +\label{fig:flu-api} +\end{figure*} + +The FLU must enforce the state of each byte of each file. +Transitions between these states are strictly ordered. +See Section~\ref{sub:assume-append-only} for state transitions and +the restrictions related to those transitions. + +The FLU also keeps track of the projection epoch number (number and checksum +both, see also Section~\ref{sub:flu-divergence}) of the last modification to a +file. This projection number is used for quick comparisons during +repair (Section~\ref{sec:repair}) to determine if files are in sync or +not. + +\subsubsection{Divergence from CORFU} +\label{sub:flu-divergence} + +In Machi, the type signature of {\tt + m\_epoch()} includes both the projection epoch number and a checksum +of the projection's contents. This checksum is used in cases where +Machi is configured to run in ``AP mode'', which allows a running Machi +cluster to fragment into multiple running sub-clusters during network +partitions. Each sub-cluster can choose an epoch projection number +$P_{side}$ for its side of the cluster. + +After the partition is +healed, it may be true that epoch numbers assigned to two different +projections $P_{left}$ and $P_{right}$ +are equal. However, their checksum signatures will differ. If a +Machi client or server detects a difference in either the epoch number +or the epoch checksum, it must wedge itself (Section~\ref{sub:wedge}) +until a new projection with a larger epoch number is available. + +\subsection{The Sequencer} +\label{sub:sequencer} + +For every file append request, the Sequencer assigns a unique +{\tt \{file-name,byte-offset\}} location tuple. + +Each FLU server runs a sequencer server. Typically, only the +sequencer of the head of the chain is used by clients. However, for +development and administration ease, each FLU should have a sequencer +running at all times. If a client were to use a sequencer other than +the chain head's sequencer, no harm would be done. + +The sequencer must assign a new file name whenever any of the +following events happen: +\begin{itemize} +\item The current file size is too big, per cluster administration policy. +\item The sequencer or the entire FLU restarts. +\item The FLU receives a projection or client API call + that includes a newer/larger projection epoch + number than its current projection epoch number. +\end{itemize} + +The sequencer assignment given to a Machi client is valid only for the +projection epoch in which it was assigned. Machi FLUs must enforce +this requirement. If a Machi client's write attempt is interrupted in +the middle by a projection change, then the following rules must be +used to continue: + +\begin{itemize} +\item If the client's write has been successful on at least the head + FLU in the chain, then the client may continue to use the old + location. The client is now performing read repair of this location in + the new epoch. (The client may be required to add a ``read repair'' option + to its requests to bypass the FLUs usual enforcement of the + location's epoch.) +\item If the client's write to the head FLU has not started yet, or if + it doesn't know the status of the write to the head (e.g., timeout), + then the client must abandon the current location assignment and + request a new assignment from the sequencer. +\end{itemize} + +If the client eventually wishes to write a contiguous chunk of $Y$ +bytes, but only $X$ bytes ($X < Y$) are available right now, the +client may make a sequencer request for the larger $Y$ byte range +immediately. The client then uses this file~+~byte range assignment +to write the $X$ bytes now and all of the remaining $Y-X$ bytes at +some later time. + +\subsubsection{Divergence from CORFU} +\label{sub:sequencer-divergence} + +CORFU's sequencer is not +necessary in a CORFU system and is merely a performance optimization. + +In Machi, the sequencer is required because it assigns both a file +byte offset and also a full file name. The client can request a +certain file name prefix, e.g. {\tt "foo"}. The sequencer must make +the file name unique across the entire Machi system. A Machi cluster +has a name that is shared by all servers. The client's prefix +wish is combined with the cluster name, sequencer name, and a +per-sequencer strictly unique ID (such as a counter) to form an opaque +suffix. +For example, +\begin{quote} +{\tt "foo.m=machi4.s=flu-A.n=72006"} +\end{quote} + +One reviewer asked, ``Why not just use UUIDs?'' Any naming system +that generates unique file names is sufficient. + +\subsection{The Projection Store} +\label{sub:proj-store} + +Each FLU maintains a key-value store of write-once registers +for the purpose of storing +projections. Reads \& writes to this store are provided by the FLU +administration API. The projection store runs on each server that +provides FLU service, for several reasons. First, the +projection data structure +need not include extra server names to identify projection +store servers or their locations. +Second, writes to the projection store require +notification to a FLU of the projection update anyway. +Third, certain kinds of writes to the projection store indicate +changes in cluster status which require prompt changes of state inside +of the FLU (e.g., entering wedge state). + +The store's basic operation set is simple: get, put, get largest key +(and optionally its value), and list all keys. +The projection store's data types are: + +\begin{itemize} +\item key = the projection number +\item value = the entire projection data structure, serialized as an + opaque byte blob stored in write-once register. The value is + typically a few KBytes but may be up to 10s of MBytes in size. + (A Machi projection data structure will likely be much less than 10 + KBytes.) +\end{itemize} + +As a write-once register, any attempt to write a key $K$ when the +local store already has a value written for $K$ will always fail +with a {\tt error\_written} status. + +Any write of a key whose value is larger than the FLU's current +projection number will move the FLU to the wedged state +(Section~\ref{sub:wedge}). + +The contents of the projection blob store are maintained by neither +Chain Replication techniques nor any other server-side technique. All +replication and read repair is done only by the projection store +clients. Astute readers may theorize that race conditions exist in +such management; see Section~\ref{sec:projections} for details and +restrictions that make it practical. + +\subsection{The chain manager} +\label{sub:chain-manager} + +Each FLU runs an administration agent, the chain manager, that is +responsible for monitoring the health of the entire Machi cluster. +Each chain manager instance is fully autonomous and communicates with +other chain managers indirectly via writes and reads to its peers' +projection stores. + +If a change of state is noticed (via measurement) or is requested (via +the administration API), one or more actions may be taken: + +\begin{itemize} +\item Enter wedge state (Section~\ref{sub:wedge}). +\item Calculate a new projection to fit the new environment. +\item Attempt to store the new projection locally and remotely. +\item Read a newer projection from local + remote stores (and possibly + perform read repair). +\item Adopt a new unanimous projection, as read from all + currently available readable blob stores. +\item Exit wedge state. +\end{itemize} + +See also Section~\ref{sec:projections} and also the Chain Manager +design document \cite{machi-chain-manager-design}. + +\subsection{The Projection and the Projection Epoch Number} +\label{sub:projection} + +The projection data +structure defines the current administration \& operational/runtime +configuration of a Machi cluster's single Chain Replication chain. +Each projection is identified by a strictly increasing counter called +the Epoch Projection Number (or more simply ``the epoch''). + +\begin{figure} +\begin{verbatim} +-type m_server_info() :: {Hostname, Port,...}. +-record(projection, { + epoch_number :: m_epoch_n(), + epoch_csum :: m_csum(), + creation_time :: now(), + author_server :: m_server(), + all_members :: [m_server()], + active_upi :: [m_server()], + active_all :: [m_server()], + down_members :: [m_server()], + dbg_annotations :: proplist() + }). +\end{verbatim} +\caption{Sketch of the projection data structure} +\label{fig:projection} +\end{figure} + +Projections are calculated by each FLU using input from local +measurement data, calculations by the FLU's chain manager +(see below), and input from the administration API. +Each time that the configuration changes (automatically or by +administrator's request), a new epoch number is assigned +to the entire configuration data structure and is distributed to +all FLUs via the FLU's administration API. Each FLU maintains the +current projection epoch number as part of its soft state. + +Pseudo-code for the projection's definition is shown in +Figure~\ref{fig:projection}. To summarize the major components: + +\begin{itemize} +\item {\tt epoch\_number} and {\tt epoch\_csum} The epoch number and + projection checksum are unique identifiers for this projection. +\item {\tt creation\_time} Wall-clock time, useful for humans and + general debugging effort. +\item {\tt author\_server} Name of the server that calculated the projection. +\item {\tt all\_members} All servers in the chain, regardless of current + operation status. If all operating conditions are perfect, the + chain should operate in the order specified here. + (See also the limitations in \cite{machi-chain-manager-design}, + ``Whole-file repair when changing FLU ordering within a chain''.) +\item {\tt active\_upi} All active chain members that we know are + fully repaired/in-sync with each other and therefore the Update + Propagation Invariant \cite{machi-chain-manager-design} is always true. + See also Section~\ref{sec:repair}. +\item {\tt active\_all} All active chain members, including those that + are under active repair procedures. +\item {\tt down\_members} All members that the {\tt author\_server} + believes are currently down or partitioned. +\item {\tt dbg\_annotations} A ``kitchen sink'' proplist, for code to + add any hints for why the projection change was made, delay/retry + information, etc. +\end{itemize} + +\subsection{The Bad Epoch Error} +\label{sub:bad-epoch} + +Most Machi protocol actions are tagged with the actor's best knowledge +of the current epoch. However, Machi does not have a single/master +coordinator for making configuration changes. Instead, change is +performed in a fully asynchronous manner by +each local chain manager. During a cluster +configuration change, some servers will use the old projection number, +$P_p$, whereas others know of a newer projection, $P_{p+x}$ where $x>0$. + +When a protocol operation with $P_{p-x}$ arrives at an actor who knows +$P_p$, the response must be {\tt error\_bad\_epoch}. This is a signal +that the actor using $P_{p-x}$ is indeed out-of-date and that a newer +projection must be found and used. + +\subsection{The Wedge} +\label{sub:wedge} + +If a FLU server is using a projection $P_p$ and receives a protocol +message that mentions a newer projection $P_{p+x}$ that is larger than its +current projection value, then it enters ``wedge'' state and stops +processing all new requests. The server remains in wedge state until +a new projection (with a larger/higher epoch number) is discovered and +appropriately acted upon. +(In the Windows Azure storage system \cite{was}, this state is called +the ``sealed'' state.) + +\subsection{``AP Mode'' and ``CP Mode''} +\label{sub:ap-cp-mode} + +Machi's first use cases require only eventual consistency semantics +and behavior, a.k.a.~``AP mode''. However, with only small +modifications, Machi can operate in a strongly consistent manner, +a.k.a.~``CP mode''. + +The chain manager service (Section \ref{sub:chain-manager}) is +sufficient for an ``AP Mode'' Machi service. In AP Mode, all mutations +to any file on any side of a network partition are guaranteed to use +unique locations (file names and/or byte offsets). When network +partitions are healed, all files can be merged together +(while considering the details discussed in +Section~\ref{ssec:just-rsync-it}) in any order +without conflict. + +``CP mode'' will be extensively covered in~\cite{machi-chain-manager-design}. +In summary, to support ``CP mode'', we believe that the chain manager +service proposed by~\cite{machi-chain-manager-design} can guarantee +strong consistency at all times. + +\section{Sketches of single operations} +\label{sec:sketches} + +\subsection{Single operation: append a single sequence of bytes to a file} +\label{sec:sketch-append} + +%% NOTE: append-whiteboard.eps was created by 'jpeg2ps'. +\begin{figure*}[htp] +\resizebox{\textwidth}{!}{ + \includegraphics[width=\textwidth]{figure6} + %% \includegraphics[width=\textwidth]{append-whiteboard} + } +\caption{Flow diagram: append 123 bytes onto a file with prefix {\tt "foo"}.} +\label{fig:append-flow} +\end{figure*} + +To write/append atomically a single sequence/hunk of bytes to a file, +here's the sequence of steps required. +See Figure~\ref{fig:append-flow} for a diagram that illustrates this +example; the same example is also shown in +Figure~\ref{fig:append-flowMSC} using MSC style (message sequence chart). +In +this case, the first FLU contacted has a newer projection epoch, +$P_{13}$, than the $P_{12}$ epoch that the client first attempts to use. + +\begin{enumerate} + +\item The client chooses a file name prefix. This prefix gives the +sequencer implicit advice of where the client wants data to be +placed. For example, if two different append requests are for file +prefixes $Pref1$ and $Pref2$ where $Pref1 \ne Pref2$, then the two byte +sequences will definitely be written to different files. If +$Pref1 = Pref2$, +then the sequencer may choose the same file for both (but no +guarantee of how ``close together'' the two requests might be time-wise). + +\item (cacheable) Find the list of Machi member servers. This step is +only needed at client initialization time or when all Machi members +are down/unavailable. This step is out of scope of Machi, i.e., found +via another source: local configuration file, DNS, LDAP, Riak KV, ZooKeeper, +carrier pigeon, papyrus, etc. + +\item (cacheable) Find the current projection number and projection data +structure by fetching it from one of the Machi FLU server's +projection store service. This info +may be cached and reused for as long as Machi API operations do not +result in {\tt error\_bad\_epoch}. + +\item Client sends a sequencer op\footnote{The {\tt append()} API + operation is performed by the server as if it were two different API +operations in sequence: {\tt sequence()} and {\tt write()}. The {\tt + append()} operation is provided as an optimization to reduce latency +by reducing messages sent \& received by a client.} +to the sequencer process on the head of +the Machi chain (as defined by the projection data structure): +{\tt \{sequence\_req, Filename\_Prefix, Number\_of\_Bytes\}}. The reply +includes {\tt \{Full\_Filename, Offset\}}. + +\item The client sends a write request to the head of the Machi chain: +{\tt \{write\_req, Full\_Filename, Offset, Bytes, Options\}}. The +client-calculated checksum is a recommended option. + +\item If the head's reply is {\tt ok}, then repeat for all remaining chain +members in strict chain order. + +\item If all chain members' replies are {\tt ok}, then the append was +successful. The client now knows the full Machi file name and byte +offset, so that future attempts to read the data can do so by file +name and offset. + +\item Upon any non-{\tt ok} reply from a FLU server, the client must +either perform read repair or else consider the entire append +operation a failure. +If the client +wishes, it may retry the append operation using a new location +assignment from the sequencer or, if permitted by Machi restrictions, +perform read repair on the original location. If this read repair is +fully successful, then the client may consider the append operation +successful. + +\item (optional) +If a FLU server $FLU$ is unavailable, notify another up/available +chain member that $FLU$ appears unavailable. This info may be used by +the chain manager service to change projections. If the client +wishes, it may retry the append op or perhaps wait until a new projection is +available. + +\item If any FLU server reports {\tt error\_written}, then either of two +things has happened: +\begin{itemize} + \item The appending client $C_w$ was too slow after at least one + successful write. + Client $C_r$ attempted a read, noticed the partial write, and + then engaged in read repair. Client $C_w$ should also check all + replicas to verify that the repaired data matches its write + attempt -- in all cases, the values written by $C_w$ and $C_r$ are + identical. + \item The appending client $C_w$ was too slow when attempting to write + to the head of the chain. + Another client, $C_r$, attempted a read. + $C_r$ observes that the tail's value was + unwritten and observes that the head's value was also unwritten. + Then $C_r$ initiated a ``fill'' operation to write junk into + this offset of + the file. The fill operation succeeded, and now the slow + appending client $C_w$ discovers that it was too slow via the + {\tt error\_written} response. +\end{itemize} + +\end{enumerate} + +\section{Projections: calculation, storage, then use} +\label{sec:projections} + +Machi uses a ``projection'' to determine how its Chain Replication replicas +should operate; see Section~\ref{sub:chain-replication} and +\cite{corfu1}. At runtime, a cluster must be able to respond both to +administrative changes (e.g., substituting a failed server box with +replacement hardware) as well as local network conditions (e.g., is +there a network partition?). The concept of a projection is borrowed +from CORFU but has a longer history, e.g., the Hibari key-value store +\cite{cr-theory-and-practice} and goes back in research for decades, +e.g., Porcupine \cite{porcupine}. + +See \cite{machi-chain-manager-design} for the design and discussion of +all aspects of projection management and storage. + +\section{Chain Replication repair: how to fix servers after they crash +and return to service} +\label{sec:repair} + +%% Section~\ref{sec:safety-of-transitions} mentions that there are some +%% not-obvious ways that a Machi cluster could inadvertently lose data. +%% It is possible to avoid data loss in all cases, short of all servers +%% being destroyed by a fire. +The theory of why it's possible to avoid +data loss with chain replication is summarized in this section, +followed by a discussion of Machi-specific details that must be +included in any production-quality implementation. + +\subsection{When to trigger read repair of single values} + +Assume that some client $X$ wishes to fetch a datum that's managed +by Chain Replication. Client $X$ must discover the chain's +configuration for that datum, then send its read request to the tail +replica of the chain, $R_{tail}$. + +In CORFU and in Machi, the store is a set of write-once registers. +Therefore, the only possible responses that client $X$ might get from a +query to the chain's $R_{tail}$ are: + +\begin{enumerate} +\item {\tt error\_unwritten} +\item {\tt \{ok, <<...data bytes...>>\}} +\item {\tt error\_trimmed} (in environments where space + reclamation/garbage collection is permitted) +\end{enumerate} + +Let's explore each of these responses in the following subsections. + +\subsubsection{Tail replica replies {\tt error\_unwritten}} + +There are only a few reasons why this value is possible. All are +discussed here. + +\paragraph{Scenario 1: The block truly hasn't been written yet} + +A read from any other server in the chain will also yield {\tt + error\_unwritten}. + +\paragraph{Scenario 2: The block has not yet finished being written} + +A read from any other server in the chain may yield {\tt + error\_unwritten} or may find written data. (In this scenario, the +head server has written data, but we don't know the state of the middle +and tail server(s).) The client ought to perform read repair of this +data. (See also, scenario \#4 below.) + +During read repair, the client's writes operations may race with the +original writer's operations. However, both the original writer and +the repairing client are always writing the same data. Therefore, +data corruption by concurrent client writes is not possible. + +\paragraph{Scenario 3: A client $X_w$ has received a sequencer's + assignment for this + location, but the client has crashed somewhere in the middle of + writing the value to the chain.} + +The correct action to take here depends on the value of the $R_{head}$ +replica's value. If $R_{head}$'s value is unwritten, then the writing +client $X_w$ crashed before writing to $R_{head}$. The reading client +$X_r$ must ``fill'' the page with junk bytes or else do nothing. + +If $R_{head}$'s value is indeed written, then the reading client $X_r$ +must finish a ``read repair'' operation before the client may proceed. +See Section~\ref{sub:read-repair-single} for details. + +\paragraph{Scenario 4: A client has received a sequencer's assignment for this + location, but the client has become extremely slow (or is + experiencing a network partition, or any other reason) and has not + yet updated $R_{tail}$ $\ldots$ but that client {\em will eventually + finish its work} and will eventually update $R_{tail}$.} + +It should come as little surprise that reading client $C_r$ +cannot know whether the writing client $C_w$ +has really crashed or if $C_w$ is merely very slow. +It is therefore very nice that +the action that $C_r$ must take in either case is the same --- see the +scenario \#2 for details. + +\subsubsection{Tail replica replies {\tt \{ok, <<...>>\}}} + +There is no need to perform single item read repair in this case. +The Update Propagation Invariant guarantees that this value is the one +strictly consistent value for this register. + +\subsubsection{Tail replica replies {\tt error\_trimmed}} + +There is no need to perform single item read repair in this case. + +{\bf NOTE:} It isn't yet clear how much support early versions of +Machi will need for GC/space reclamation via trimming. + +\subsection{How to read repair a single value} +\label{sub:read-repair-single} + +If a value at $R_{tail}$ is unwritten, then the answer to ``what value +should I use to repair the chain's value?'' is simple: the value at the +head $R_{head}$ is the value $V_{head}$ that must be used. The client +then writes $V_{head}$ to all other members of the chain $C$, in +order. + +The client may not proceed with its upper-level logic until the read +repair operation is successful. If the read repair operation is not +successful, then the client must react in the same manner as if the +original read attempt of $R_{tail}$'s value had failed. + +\subsection{Repair of entire files} +\label{sub:repair-entire-files} + +There are some situations where repair of entire files is necessary. + +\begin{itemize} +\item To repair FLUs added to a chain in a projection change, + specifically adding a new FLU to the chain. This case covers both + adding a new, data-less FLU and re-adding a previous, data-full FLU + back to the chain. +\item To avoid data loss when changing the order of the chain's servers. +\end{itemize} + +The full file repair discussion in \cite{machi-chain-manager-design} +argues for correctness in both eventually consistent and strongly +consistent environments. Discussion in this section will be limited +to eventually consistent environments (``AP mode'') . + +\subsubsection{``Just `rsync' it!''} +\label{ssec:just-rsync-it} + +The ``just {\tt rsync} it!'' method could loosely be described as, +``run {\tt rsync} on all files to all servers.'' This simple repair +method is nearly sufficient enough for Machi's eventual consistency +mode of operation. There's only one small problem that {\tt rsync} +cannot handle by itself: handling late writes to a file. It is +possible that the same file could contain the following pattern of +written and unwritten data on two different replicas $A$ and $B$: + +\begin{itemize} +\item Server $A$: $x$ bytes written, $y$ bytes unwritten +\item Server $B$: $x$ bytes unwritten, $y$ bytes written +\end{itemize} + +If {\tt rsync} is used as-is to replicate this file, then one of the +two written sections will lost, i.e., overwritten by NUL bytes. Obviously, we +don't want this kind of data loss. However, we already have a +requirement that Machi file servers must enforce write-once behavior +on all file byte ranges. The same metadata used to maintain written and +unwritten state can be used to merge file state safely so that both the $x$ +and $y$ byte ranges will be correct after repair. + +\subsubsection{The larger problem with ``Just `rsync' it!''} + +Assume for a moment that the {\tt rsync} utility could indeed preserve +Machi written chunk boundaries as described above. A larger +administration problem still remains: this informal method cannot tell +you exactly when you are in danger of data loss or when data loss has +actually happened. If we maintain the Update Propagation Invariant +(as argued in \cite{machi-chain-manager-design}), +then we always know exactly when data loss is immanent or has +probably happened. + +\section{On-disk storage and file corruption detection} +\label{sec:on-disk} + +An individual FLU has a couple of goals: store file data and metadata +as efficiently as possible, and make it easy to detect and fix file +corruption. + +FLUs have a lot of flexibility to implement their on-disk data formats in +whatever manner allow them to be safe and fast. Any scheme that +allows safe management of file names, per-file data chunks, and +per-data-chunk metadata is sufficient. +\footnote{The proof-of-concept implementation at GitHub in the {\tt + prototype/demo-day} directory uses two files in the local file + system per Machi file: one for Machi file data and one for + checksum metadata.} + +\subsection{First draft/strawman proposal for on-disk data format} +\label{sub:on-disk-data-format} + +{\bf NOTE:} The suggestions in this section are ``strawman quality'' +only. + +\begin{figure*} +\begin{verbatim} +|<--- Data section --->|<---- Metadata section (starts at fixed offset) ----> + |<- trailer --> +V1,C1 | V2,C2 | ||| C1t,O1a,O1z,C1 | C2t,O2a,O2z,C2 | Summ | SummBytes |eof + |<- trailer --> +V1,C1 | V2,C2 | V3,C3 ||| C1t,O1a,O1z,C1 | C2t,O2a,O2z,C2 | C3t,O3a,O3z,C3 | Summ | SummBytes |eof +\end{verbatim} +\caption{File format draft \#1, a snapshot at two different times.} +\label{fig:file-format-d1} +\end{figure*} + +See Figure~\ref{fig:file-format-d1} for an example file layout. +Prominent features are: + +\begin{itemize} +\item The data section is a fixed size, e.g. 1 GByte, so the metadata + section is known to start at a particular offset. + The sequencers on all FLUs must also be aware of of this file size + limit. +\item Data section $V_n,C_n$ tuples: client-written data plus the 20 + byte SHA1 hash of that data, concatenated. The client must be aware + that the hash is the final 20 bytes of the value that it reads + \ldots but this feels like a small price to pay to have the checksum + co-located exactly adjacent to the data that it protects. + The client may elect not to store the checksum explicitly in the + file body, knowing that there is likely a performance penalty when + it wishes to fetch the checksum via the file metadata API. +\item Metadata section $C_{nt},O_{na},O_{nz},C_n$ tuples: + The chunk's + checksum type (e.g. SHA1 for all but the final + 20 bytes),\footnote{Other types may include: no checksum, checksum + of the entire value, and checksums using other hash algorithms.} + the starting + offset (``a''), ending offset (``z'') of a chunk, and the + chunk's SHA1 checksum (which is intentionally duplicated in this + example in both sections). The approximate size is + $4 + 4 + 1 + 20 = 25$ bytes per metadata entry. +\item Metadata section {\tt Summ}: a compact summary of the + unwritten/written status of all bytes in the file, e.g., using byte + range encoding for contiguous regions of writes. +\item Metadata section {\tt SummBytes}: the number of bytes backward + to look for the start of the {\tt Summ} summary. +\item {\tt eof} The end of file. +\end{itemize} + +When a chunk write is requested by a client, the FLU must verify that +the byte range has entirely ``unwritten'' status. If that information +is not cached by the FLU somehow, it can be easily read by reading the +trailer, which is always positioned at the end of the file. + +If the FLU is queried for checksum information and/or chunk boundary +information, and that info is not cached, then the FLU can simply read +all data beyond the start of the metadata section. For a 1 GByte file +written in 1 MByte chunks, the metadata section +would be approximately 25 KBytes. For 4 KByte pages (CORFU style), the +metadata section would be approximately 6.4 MBytes. + +Each time that a new chunk(s) is written within the data section, no +matter its offset, the old {\tt Summ} and {\tt SummBytes} trailer is +overwritten by the offset$+$checksum metadata for the new chunk(s) +followed by the new trailer. Overwriting the trailer is justified in +that if corruption happens in the metadata section, the +system's worst-case reaction would be as if +the corruption had happened in the data section: the file +is invalid, and Machi will repair the file from another replica. +A more likely scenario is that some early part of the file is correct, +and only a part of the end of the file requires repair from another +replica. + +\subsection{If the client does not provide a checksum?} + +If the client doesn't provide a checksum, then it's almost certainly a +good idea to have the FLU calculate the checksum before writing. The +$C_t$ value should be a type that indicates that the checksum was not +calculated by the client. In all other fields, the metadata section +data would be identical. + +\subsection{Detecting corrupted files (``checksum scrub'')} +\label{sub:detecting-corrupted} + +This task is a bit more difficult than with a typical append-only, +file-written-in-order file. In most append-only situations, the file +is really written in a strict order, both temporally and spatially, +from offset 0 to the (eventual) +end-of-file. The order in which the bytes were written is the same +order as the bytes are fed into a checksum or +hashing function, such as SHA1. + +However, a Machi file is not written strictly in order from offset 0 +to some larger offset. Machi's append-only file guarantee is +{\em guaranteed in space, i.e., the offset within the file} and is +definitely {\em not guaranteed in time}. + +The file format proposed in Figure~\ref{fig:file-format-d1} +contains the checksum of each client write, using the checksum value +that the client or the FLU provides. A FLU could then: + +\begin{enumerate} +\item Read the metadata section to discover all written chunks and + their checksums. +\item For each written chunk, read the chunk and calculate the + checksum (with the same algorithm specified by the metadata). +\item For any checksum mismatch, ask the FLU to trigger a repair from + another FLU in the chain. +\end{enumerate} + +The corruption detection should run at a lower priority than normal +FLU activities. FLUs should implement a basic rate limiting +mechanism. + +FLUs should also be able to schedule their checksum scrubbing activity +periodically and limit their activity to certain times, per a +only-as-complex-as-it-needs-to-be administrative policy. + +\section{Load balancing read vs. write ops} +\label{sec:load-balancing} + +Consistent reads in Chain Replication require reading only from the +tail of the chain. This requirement can cause workload imbalances for +any chain longer than length one under high read-only workloads. For +example, for chain $[F_a, F_b, F_c]$ and a 100\% read-only workload, +FLUs $F_a$ and $F_b$ will be completely idle, and FLU $F_c$ must +handle all of the workload. + +Because all bytes of a Machi file is immutable, the extra +synchronization between servers as suggested by \cite{cr-craq} are not +needed. +Machi's use of write-once registers makes any server choice correct. +The implementation is +therefore free to make any load balancing choice for read operations, +as long as the read repair protocol is honored. + +\section{Integration strategy with Riak Core and other distributed systems} +\label{sec:integration} + +We have repeatedly stated that load balancing/sharding files across +multiple Machi clusters is out of scope of this document. This +section ignores that warning and explores a couple of extremely simple +methods to implement a cluster-of-Machi-clusters. Note that the +method sketched in Section~\ref{sub:integration-random-slicing} has +been implemented in the Machi proof-of-concept implementation at +GitHub in the {\tt prototype/demo-day} directory. + +\subsection{Assumptions} + +We assume that any technique is able to perform extremely basic +parsing of the file names that Machi sequencers create. The example +shown in Section~\ref{sub:sequencer-divergence} depicts a client write +specifying the file prefix {\tt "foo"}; Machi assigns that write to a +file name such as: +\begin{quote} +{\tt "foo.m=machi4.s=flu-A.n=72006"} +\end{quote} + +Given a Machi file name, the client-specified prefix will always be +easily parseable, e.g., all characters to the left of the first +dot/period character. However, anything following the separator +character should strictly be considered opaque. + +\subsection{Machi and the Riak Core ring} +\label{sub:integration-riak-core} + +\paragraph{Simplest scheme:} +Get rid of the power-of-2 partition number restriction of the Riak +Core ring data structure. Have exactly one partition per Machi +cluster, where the ring data includes each Machi cluster name. We +{\em don't bother} using successive partitions on the ring for +deciding the membership of any of the Machi clusters: that is a Riak KV +style pattern that is not applicable here. + +Also, it would be handy to remove the current Core assumption of equal +partition sizes. + +Parse the Machi file name $F$ (per above) to find the original +file prefix $F_{prefix}$ given to Machi at write time. +Hash the empty bucket {\tt <<>>} and key $F_{prefix}$ to +calculate the preflist. Take only the head of +the preflist, which names the Machi cluster $M$ that stores $F$. Ask +one of $M$'s nodes for the current projection (if not alrady cached). +Then fetch the desired byte range(s) from $F$. + +To add/remove Machi clusters, use ring resizing. + +\subsection{Machi and Random Slicing} +\label{sub:integration-random-slicing} + +\paragraph{Simplest scheme:} +Instead of using the machinery of Riak Core to hash a Machi file name +$F$ to some Machi cluster $M$, let's suggest Random Slicing +\cite{random-slicing}. It appears that \cite{random-slicing} was +co-invented at about the same time that Hibari +\cite{cr-theory-and-practice} implemented it. + +The data structure to describe a Random Slicing scheme is pretty +small, about 100 KBytes in a convenient but space-inefficient +representation in Erlang for a few hundred chains. +A pure function implementation with domain of Machi file +name plus Random Slicing map and range of all available Machi clusters +is straightforward. + +Parse the Machi file name $F$ (per above) to find the original +file prefix $F_{prefix}$ given to Machi at write time. +To move/relocate files from one Machi server to another, two different +Random Slicing maps, $RSM_{old}$ and $RSM_{new}$. For each Machi file +in all Machi clusters, if +%% Break the math mode below to make line breaks easier..... +$MAP(F_{prefix},$ $RSM_{old})$ $=$ $MAP(F_{prefix},$ $RSM_{new})$, +then the file does not need to move. + +A file migration process iterates over all files where the value of +$MAP(F, RSM_{new})$ differs. All Machi files are immutable, which +makes the coordination effort much easier than many other distributed +systems. For file lookup, try using the $RSM_{new}$ first. If the +file doesn't exist there, use $RSM_{old})$. An honest race may +then force a second attempt with $RSM_{new}$ again. + +Multiple migrations can be concurrent, at the expense of additional +latency. The generalization of the move/relocate algorithm above is: + +\begin{enumerate} +\item For each $RSM_j$ mapping for the ``new'' location map list, + query the Machi cluster $MAP(F_{prefix}, RSM_j)$ and take the + first {\tt \{ok,\ldots\}} response. If no results are found, then \ldots +\item For each $RSM_i$ mapping for the ``old'' location map list, + query the Machi cluster $MAP(F_{prefix}, RSM_i)$ and take the + first {\tt \{ok,\ldots\}} response. If no results are found, then \ldots +\item To deal with races when moving files and then removing them from + the ``old'' locations, perform step \#1 again to look in the new + location(s). +\item If the data is not found at this stage, then the data does not exist. +\end{enumerate} + +\subsubsection{Problems with the ``simplest scheme''} + +The major drawback to the ``simplest schemes'' sketched above is a +problem of uneven file distributions across the cluster-of-clusters. +The risk of this imbalance is directly proportional to the risk of +clients that make poor prefix choices. The worst case is if all +clients always request the same prefix. Research for effective, +well-balancing file prefix choices is an area for future work. + +\section{Recommended reading \& related work} + +A big reason for the large size of this document is that it includes a +lot of background information. +People tend to be busy, and sitting down to +read 4--6 research papers to get familiar with a topic \ldots doesn't +happen very quickly. We recommend you read the papers mentioned in +this section and in the ``References'' section, but if our job is +done well enough, it isn't necessary. + +Familiarity with the CAP Theorem, the concepts \& semantics \& +trade-offs of eventual consistency and strong consistency in the +context of asynchronous distributed systems, network partitions and +failure detection in asynchronous distributed systems, and ``split +brain'' syndrome are all assumed.\footnote{Heh, let's see how well +{\em the authors} actually know those things\ldots.} + +The replication protocol for Machi is based almost entirely on the CORFU +ordered log protocol \cite{corfu1}. If the reader is familiar with +the content of this paper, understanding the implementation details of +Machi will be easy. The longer paper \cite{corfu2} goes into much +more detail --- Machi developers are strongly recommended to read this paper +also. + +CORFU is, in turn, a very close cousin of the Paxos distributed +consensus protocol \cite{paxos-made-simple}. Understanding Paxos is +not required for understanding Machi, but reading about it can certainly +increase your good karma. + +CORFU also uses the Chain Replication algorithm +\cite{chain-replication}. This paper is recommended for Machi +developers who need to understand the guarantees and restrictions of +the protocol. For other readers, it is recommended for good karma. + + Machi's function +roughly corresponds to the Windows Azure Storage (WAS) paper \cite{was} +``stream layer'' as described in section~4. +The main features from that section that WAS does support are file +distribution/sharding across multiple servers and erasure coding; both +are explicitly outside of Machi's scope. + +The Kafka paper \cite{kafka} is highly recommended reading for why +you'd want to have an ordered log service and how you'd build one +(though this particular paper is too short to describe how it's +actually done). +Machi feels like a better foundation to build a +distributed immutable file store than Kafka's internals, but +that's debate for another forum. The blog posting by Kreps +\cite{the-log-what} is long but does a good job of explaining +the why and how of using a strongly ordered distributed log to build +complicated-seeming distributed systems in an easy way. + +The Hibari paper \cite{cr-theory-and-practice} describes some of the +implementation details of chain replication that are not explored in +detail in the CR paper. It is also recommended for Machi developers, +especially sections 2 and 12. + +\bibliographystyle{abbrvnat} +\begin{thebibliography}{} +\softraggedright + +\bibitem{elastic-chain-replication} +Abu-Libdeh, Hussam et al. +Leveraging Sharding in the Design of Scalable Replication Protocols. +Proceedings of the 4th Annual Symposium on Cloud Computing (SOCC'13), 2013. +{\tt http://www.ymsir.com/papers/sharding-socc.pdf} + +\bibitem{corfu1} +Balakrishnan, Mahesh et al. +CORFU: A Shared Log Design for Flash Clusters. +Proceedings of the 9th USENIX Conference on Networked Systems Design +and Implementation (NSDI'12), 2012. +{\tt http://research.microsoft.com/pubs/157204/ corfumain-final.pdf} + +\bibitem{machi-chain-manager-design} +Basho Japan KK. +Machi Chain Replication: management theory and design +{\tt https://github.com/basho/machi/tree/ master/doc/high-level-chain-mgr.pdf} + +\bibitem{corfu2} +Balakrishnan, Mahesh et al. +CORFU: A Distributed Shared Log +ACM Transactions on Computer Systems, Vol. 31, No. 4, Article 10, December 2013. +{\tt http://www.snookles.com/scottmp/corfu/ corfu.a10-balakrishnan.pdf} + +\bibitem{was} +Calder, Brad et al. +Windows Azure Storage: A Highly Available Cloud Storage Service with Strong Consistency +Proceedings of the 23rd ACM Symposium on Operating Systems Principles (SOSP'11), 2011. +{\tt http://sigops.org/sosp/sosp11/current/ 2011-Cascais/printable/11-calder.pdf} + +\bibitem{cr-theory-and-practice} +Fritchie, Scott Lystig. +Chain Replication in Theory and in Practice. +Proceedings of the 9th ACM SIGPLAN Workshop on Erlang (Erlang'10), 2010. +{\tt http://www.snookles.com/scott/publications/ erlang2010-slf.pdf} + +\bibitem{the-log-what} +Kreps, Jay. +The Log: What every software engineer should know about real-time data's unifying abstraction +{\tt http://engineering.linkedin.com/distributed- + systems/log-what-every-software-engineer-should- + know-about-real-time-datas-unifying} + +\bibitem{kafka} +Kreps, Jay et al. +Kafka: a distributed messaging system for log processing. +NetDB’11. +{\tt http://research.microsoft.com/en-us/UM/people/ + srikanth/netdb11/netdb11papers/netdb11-final12.pdf} + +\bibitem{paxos-made-simple} +Lamport, Leslie. +Paxos Made Simple. +In SIGACT News \#4, Dec, 2001. +{\tt http://research.microsoft.com/users/ lamport/pubs/paxos-simple.pdf} + +\bibitem{random-slicing} +Miranda, Alberto et al. +Random Slicing: Efficient and Scalable Data Placement for Large-Scale Storage Systems. +ACM Transactions on Storage, Vol. 10, No. 3, Article 9, July 2014. +{\tt http://www.snookles.com/scottmp/corfu/random- slicing.a9-miranda.pdf} + +\bibitem{porcupine} +Saito, Yasushi et al. +Manageability, availability and performance in Porcupine: a highly scalable, cluster-based mail service. +7th ACM Symposium on Operating System Principles (SOSP’99). +{\tt http://homes.cs.washington.edu/\%7Elevy/ porcupine.pdf} + +\bibitem{cr-craq} +Jeff Terrace and Michael J.~Freedman +Object Storage on CRAQ. +In Usenix ATC 2009. +{\tt https://www.usenix.org/legacy/event/usenix09/ tech/full\_papers/terrace/terrace.pdf} + +\bibitem{chain-replication} +van Renesse, Robbert et al. +Chain Replication for Supporting High Throughput and Availability. +Proceedings of the 6th Conference on Symposium on Operating Systems +Design \& Implementation (OSDI'04) - Volume 6, 2004. +{\tt http://www.cs.cornell.edu/home/rvr/papers/ osdi04.pdf} + +\end{thebibliography} + +%% \pagebreak + +%% \section{Appendix: MSC diagrams} +%% \label{sec:appendix-msc} + +\begin{figure*}[tp] +\resizebox{\textwidth}{!}{ + \includegraphics{append-flow} + } +\caption{MSC diagram: append 123 bytes onto a file with prefix {\tt + "foo"}. In error-free cases and with a correct cached projection, the + number of network messages is $2 + 2N$ where $N$ is chain length.} +\label{fig:append-flowMSC} +\end{figure*} + +\begin{figure*}[tp] +\resizebox{\textwidth}{!}{ + \includegraphics{read-flow} + } +\caption{MSC diagram: read 123 bytes from a file} +\label{fig:read-flowMSC} +\end{figure*} + +\begin{figure*}[tp] +\resizebox{\textwidth}{!}{ + \includegraphics{append-flow2} + } +\caption{MSC diagram: append 123 bytes onto a file with prefix {\tt + "foo"}, using the {\tt append()} API function and also + using FLU$\rightarrow$FLU direct communication (i.e., the original + Chain Replication's messaging pattern). In error-free cases and with + a correct cached projection, the number of network messages is $N+1$ + where $N$ is chain length.} +\label{fig:append-flow2MSC} +\end{figure*} + + +\end{document} diff --git a/doc/src.high-level/read-flow.eps b/doc/src.high-level/read-flow.eps new file mode 100644 index 0000000..1a0edf4 --- /dev/null +++ b/doc/src.high-level/read-flow.eps @@ -0,0 +1,145 @@ +%!PS-Adobe-3.0 EPSF-2.0 +%%BoundingBox: 0 0 420.000000 166.599991 +%%Creator: mscgen 0.18 +%%EndComments +0.700000 0.700000 scale +0 0 moveto +0 238 lineto +600 238 lineto +600 0 lineto +closepath +clip +%PageTrailer +%Page: 1 1 +/Helvetica findfont +10 scalefont +setfont +/Helvetica findfont +12 scalefont +setfont +0 238 translate +/mtrx matrix def +/ellipse + { /endangle exch def + /startangle exch def + /ydia exch def + /xdia exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y translate + xdia 2 div ydia 2 div scale + 1 -1 scale + 0 0 1 startangle endangle arc + savematrix setmatrix +} def +(client) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 75 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +75 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(Projection) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 225 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +225 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(ProjStore_C) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 375 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +375 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +(FLU_C) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup dup newpath 525 -17 moveto 2 div neg 0 rmoveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +525 -15 moveto dup stringwidth pop 2 div neg 0 rmoveto show +newpath 75 -22 moveto 75 -49 lineto stroke +newpath 225 -22 moveto 225 -49 lineto stroke +newpath 375 -22 moveto 375 -49 lineto stroke +newpath 525 -22 moveto 525 -49 lineto stroke +newpath 75 -35 moveto 225 -35 lineto stroke +newpath 225 -35 moveto 215 -41 lineto stroke +(get current) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 122 -33 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +122 -33 moveto show +newpath 75 -49 moveto 75 -76 lineto stroke +newpath 225 -49 moveto 225 -76 lineto stroke +newpath 375 -49 moveto 375 -76 lineto stroke +newpath 525 -49 moveto 525 -76 lineto stroke +newpath 225 -62 moveto 75 -62 lineto stroke +newpath 75 -62 moveto 85 -68 lineto stroke +(ok, #12...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 126 -60 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +126 -60 moveto show +newpath 75 -76 moveto 75 -103 lineto stroke +newpath 225 -76 moveto 225 -103 lineto stroke +newpath 375 -76 moveto 375 -103 lineto stroke +newpath 525 -76 moveto 525 -103 lineto stroke +newpath 75 -89 moveto 525 -89 lineto stroke +newpath 525 -89 moveto 515 -95 lineto stroke +(read "foo.seq_a.009" offset=447 bytes=123 epoch=12) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 157 -87 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +157 -87 moveto show +newpath 75 -103 moveto 75 -130 lineto stroke +newpath 225 -103 moveto 225 -130 lineto stroke +newpath 375 -103 moveto 375 -130 lineto stroke +newpath 525 -103 moveto 525 -130 lineto stroke +newpath 525 -116 moveto 75 -116 lineto stroke +newpath 75 -116 moveto 85 -122 lineto stroke +1.000000 0.000000 0.000000 setrgbcolor +(bad_epoch, 13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 261 -114 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +1.000000 0.000000 0.000000 setrgbcolor +261 -114 moveto show +0.000000 0.000000 0.000000 setrgbcolor +newpath 75 -130 moveto 75 -157 lineto stroke +newpath 225 -130 moveto 225 -157 lineto stroke +newpath 375 -130 moveto 375 -157 lineto stroke +newpath 525 -130 moveto 525 -157 lineto stroke +newpath 75 -143 moveto 375 -143 lineto stroke +newpath 375 -143 moveto 365 -149 lineto stroke +(get epoch #13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 187 -141 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +187 -141 moveto show +newpath 75 -157 moveto 75 -184 lineto stroke +newpath 225 -157 moveto 225 -184 lineto stroke +newpath 375 -157 moveto 375 -184 lineto stroke +newpath 525 -157 moveto 525 -184 lineto stroke +newpath 375 -170 moveto 75 -170 lineto stroke +newpath 75 -170 moveto 85 -176 lineto stroke +(ok, #13...) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 201 -168 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +201 -168 moveto show +newpath 75 -184 moveto 75 -211 lineto stroke +newpath 225 -184 moveto 225 -211 lineto stroke +newpath 375 -184 moveto 375 -211 lineto stroke +newpath 525 -184 moveto 525 -211 lineto stroke +newpath 75 -197 moveto 525 -197 lineto stroke +newpath 525 -197 moveto 515 -203 lineto stroke +(read "foo.seq_a.009" offset=447 bytes=123 epoch=13) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 157 -195 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +157 -195 moveto show +newpath 75 -211 moveto 75 -238 lineto stroke +newpath 225 -211 moveto 225 -238 lineto stroke +newpath 375 -211 moveto 375 -238 lineto stroke +newpath 525 -211 moveto 525 -238 lineto stroke +newpath 525 -224 moveto 75 -224 lineto stroke +newpath 75 -224 moveto 85 -230 lineto stroke +(ok, <<...123...>>) dup stringwidth +1.000000 1.000000 1.000000 setrgbcolor +pop dup newpath 257 -222 moveto 0 rlineto 0 11 rlineto neg 0 rlineto closepath fill +0.000000 0.000000 0.000000 setrgbcolor +257 -222 moveto show diff --git a/doc/src.high-level/sigplanconf.cls b/doc/src.high-level/sigplanconf.cls new file mode 100644 index 0000000..cbe4031 --- /dev/null +++ b/doc/src.high-level/sigplanconf.cls @@ -0,0 +1,1312 @@ +%----------------------------------------------------------------------------- +% +% LaTeX Class/Style File +% +% Name: sigplanconf.cls +% +% Purpose: A LaTeX 2e class file for SIGPLAN conference proceedings. +% This class file supercedes acm_proc_article-sp, +% sig-alternate, and sigplan-proc. +% +% Author: Paul C. Anagnostopoulos +% Windfall Software +% 978 371-2316 +% paul [atsign] windfall.com +% +% Created: 12 September 2004 +% +% Revisions: See end of file. +% +% This work is licensed under the Creative Commons Attribution License. +% To view a copy of this license, visit +% http://creativecommons.org/licenses/by/3.0/ +% or send a letter to Creative Commons, 171 2nd Street, Suite 300, +% San Francisco, California, 94105, U.S.A. +% +%----------------------------------------------------------------------------- + + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{sigplanconf}[2013/07/02 v2.8 ACM SIGPLAN Proceedings] + +% The following few pages contain LaTeX programming extensions adapted +% from the ZzTeX macro package. + +% Token Hackery +% ----- ------- + + +\def \@expandaftertwice {\expandafter\expandafter\expandafter} +\def \@expandafterthrice {\expandafter\expandafter\expandafter\expandafter + \expandafter\expandafter\expandafter} + +% This macro discards the next token. + +\def \@discardtok #1{}% token + +% This macro removes the `pt' following a dimension. + +{\catcode `\p = 12 \catcode `\t = 12 + +\gdef \@remover #1pt{#1} + +} % \catcode + +% This macro extracts the contents of a macro and returns it as plain text. +% Usage: \expandafter\@defof \meaning\macro\@mark + +\def \@defof #1:->#2\@mark{#2} + +% Control Sequence Names +% ------- -------- ----- + + +\def \@name #1{% {\tokens} + \csname \expandafter\@discardtok \string#1\endcsname} + +\def \@withname #1#2{% {\command}{\tokens} + \expandafter#1\csname \expandafter\@discardtok \string#2\endcsname} + +% Flags (Booleans) +% ----- ---------- + +% The boolean literals \@true and \@false are appropriate for use with +% the \if command, which tests the codes of the next two characters. + +\def \@true {TT} +\def \@false {FL} + +\def \@setflag #1=#2{\edef #1{#2}}% \flag = boolean + +% IF and Predicates +% -- --- ---------- + +% A "predicate" is a macro that returns \@true or \@false as its value. +% Such values are suitable for use with the \if conditional. For example: +% +% \if \@oddp{\x} \else \fi + +% A predicate can be used with \@setflag as follows: +% +% \@setflag \flag = {} + +% Here are the predicates for TeX's repertoire of conditional +% commands. These might be more appropriately interspersed with +% other definitions in this module, but what the heck. +% Some additional "obvious" predicates are defined. + +\def \@eqlp #1#2{\ifnum #1 = #2\@true \else \@false \fi} +\def \@neqlp #1#2{\ifnum #1 = #2\@false \else \@true \fi} +\def \@lssp #1#2{\ifnum #1 < #2\@true \else \@false \fi} +\def \@gtrp #1#2{\ifnum #1 > #2\@true \else \@false \fi} +\def \@zerop #1{\ifnum #1 = 0\@true \else \@false \fi} +\def \@onep #1{\ifnum #1 = 1\@true \else \@false \fi} +\def \@posp #1{\ifnum #1 > 0\@true \else \@false \fi} +\def \@negp #1{\ifnum #1 < 0\@true \else \@false \fi} +\def \@oddp #1{\ifodd #1\@true \else \@false \fi} +\def \@evenp #1{\ifodd #1\@false \else \@true \fi} +\def \@rangep #1#2#3{\if \@orp{\@lssp{#1}{#2}}{\@gtrp{#1}{#3}}\@false \else + \@true \fi} +\def \@tensp #1{\@rangep{#1}{10}{19}} + +\def \@dimeqlp #1#2{\ifdim #1 = #2\@true \else \@false \fi} +\def \@dimneqlp #1#2{\ifdim #1 = #2\@false \else \@true \fi} +\def \@dimlssp #1#2{\ifdim #1 < #2\@true \else \@false \fi} +\def \@dimgtrp #1#2{\ifdim #1 > #2\@true \else \@false \fi} +\def \@dimzerop #1{\ifdim #1 = 0pt\@true \else \@false \fi} +\def \@dimposp #1{\ifdim #1 > 0pt\@true \else \@false \fi} +\def \@dimnegp #1{\ifdim #1 < 0pt\@true \else \@false \fi} + +\def \@vmodep {\ifvmode \@true \else \@false \fi} +\def \@hmodep {\ifhmode \@true \else \@false \fi} +\def \@mathmodep {\ifmmode \@true \else \@false \fi} +\def \@textmodep {\ifmmode \@false \else \@true \fi} +\def \@innermodep {\ifinner \@true \else \@false \fi} + +\long\def \@codeeqlp #1#2{\if #1#2\@true \else \@false \fi} + +\long\def \@cateqlp #1#2{\ifcat #1#2\@true \else \@false \fi} + +\long\def \@tokeqlp #1#2{\ifx #1#2\@true \else \@false \fi} +\long\def \@xtokeqlp #1#2{\expandafter\ifx #1#2\@true \else \@false \fi} + +\long\def \@definedp #1{% + \expandafter\ifx \csname \expandafter\@discardtok \string#1\endcsname + \relax \@false \else \@true \fi} + +\long\def \@undefinedp #1{% + \expandafter\ifx \csname \expandafter\@discardtok \string#1\endcsname + \relax \@true \else \@false \fi} + +\def \@emptydefp #1{\ifx #1\@empty \@true \else \@false \fi}% {\name} + +\let \@emptylistp = \@emptydefp + +\long\def \@emptyargp #1{% {#n} + \@empargp #1\@empargq\@mark} +\long\def \@empargp #1#2\@mark{% + \ifx #1\@empargq \@true \else \@false \fi} +\def \@empargq {\@empargq} + +\def \@emptytoksp #1{% {\tokenreg} + \expandafter\@emptoksp \the#1\@mark} + +\long\def \@emptoksp #1\@mark{\@emptyargp{#1}} + +\def \@voidboxp #1{\ifvoid #1\@true \else \@false \fi} +\def \@hboxp #1{\ifhbox #1\@true \else \@false \fi} +\def \@vboxp #1{\ifvbox #1\@true \else \@false \fi} + +\def \@eofp #1{\ifeof #1\@true \else \@false \fi} + + +% Flags can also be used as predicates, as in: +% +% \if \flaga \else \fi + + +% Now here we have predicates for the common logical operators. + +\def \@notp #1{\if #1\@false \else \@true \fi} + +\def \@andp #1#2{\if #1% + \if #2\@true \else \@false \fi + \else + \@false + \fi} + +\def \@orp #1#2{\if #1% + \@true + \else + \if #2\@true \else \@false \fi + \fi} + +\def \@xorp #1#2{\if #1% + \if #2\@false \else \@true \fi + \else + \if #2\@true \else \@false \fi + \fi} + +% Arithmetic +% ---------- + +\def \@increment #1{\advance #1 by 1\relax}% {\count} + +\def \@decrement #1{\advance #1 by -1\relax}% {\count} + +% Options +% ------- + + +\@setflag \@authoryear = \@false +\@setflag \@blockstyle = \@false +\@setflag \@copyrightwanted = \@true +\@setflag \@explicitsize = \@false +\@setflag \@mathtime = \@false +\@setflag \@natbib = \@true +\@setflag \@ninepoint = \@true +\newcount{\@numheaddepth} \@numheaddepth = 3 +\@setflag \@onecolumn = \@false +\@setflag \@preprint = \@false +\@setflag \@reprint = \@false +\@setflag \@tenpoint = \@false +\@setflag \@times = \@false + +% Note that all the dangerous article class options are trapped. + +\DeclareOption{9pt}{\@setflag \@ninepoint = \@true + \@setflag \@explicitsize = \@true} + +\DeclareOption{10pt}{\PassOptionsToClass{10pt}{article}% + \@setflag \@ninepoint = \@false + \@setflag \@tenpoint = \@true + \@setflag \@explicitsize = \@true} + +\DeclareOption{11pt}{\PassOptionsToClass{11pt}{article}% + \@setflag \@ninepoint = \@false + \@setflag \@explicitsize = \@true} + +\DeclareOption{12pt}{\@unsupportedoption{12pt}} + +\DeclareOption{a4paper}{\@unsupportedoption{a4paper}} + +\DeclareOption{a5paper}{\@unsupportedoption{a5paper}} + +\DeclareOption{authoryear}{\@setflag \@authoryear = \@true} + +\DeclareOption{b5paper}{\@unsupportedoption{b5paper}} + +\DeclareOption{blockstyle}{\@setflag \@blockstyle = \@true} + +\DeclareOption{cm}{\@setflag \@times = \@false} + +\DeclareOption{computermodern}{\@setflag \@times = \@false} + +\DeclareOption{executivepaper}{\@unsupportedoption{executivepaper}} + +\DeclareOption{indentedstyle}{\@setflag \@blockstyle = \@false} + +\DeclareOption{landscape}{\@unsupportedoption{landscape}} + +\DeclareOption{legalpaper}{\@unsupportedoption{legalpaper}} + +\DeclareOption{letterpaper}{\@unsupportedoption{letterpaper}} + +\DeclareOption{mathtime}{\@setflag \@mathtime = \@true} + +\DeclareOption{natbib}{\@setflag \@natbib = \@true} + +\DeclareOption{nonatbib}{\@setflag \@natbib = \@false} + +\DeclareOption{nocopyrightspace}{\@setflag \@copyrightwanted = \@false} + +\DeclareOption{notitlepage}{\@unsupportedoption{notitlepage}} + +\DeclareOption{numberedpars}{\@numheaddepth = 4} + +\DeclareOption{numbers}{\@setflag \@authoryear = \@false} + +%%%\DeclareOption{onecolumn}{\@setflag \@onecolumn = \@true} + +\DeclareOption{preprint}{\@setflag \@preprint = \@true} + +\DeclareOption{reprint}{\@setflag \@reprint = \@true} + +\DeclareOption{times}{\@setflag \@times = \@true} + +\DeclareOption{titlepage}{\@unsupportedoption{titlepage}} + +\DeclareOption{twocolumn}{\@setflag \@onecolumn = \@false} + +\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} + +\ExecuteOptions{9pt,indentedstyle,times} +\@setflag \@explicitsize = \@false +\ProcessOptions + +\if \@onecolumn + \if \@notp{\@explicitsize}% + \@setflag \@ninepoint = \@false + \PassOptionsToClass{11pt}{article}% + \fi + \PassOptionsToClass{twoside,onecolumn}{article} +\else + \PassOptionsToClass{twoside,twocolumn}{article} +\fi +\LoadClass{article} + +\def \@unsupportedoption #1{% + \ClassError{proc}{The standard '#1' option is not supported.}} + +% This can be used with the 'reprint' option to get the final folios. + +\def \setpagenumber #1{% + \setcounter{page}{#1}} + +\AtEndDocument{\label{sigplanconf@finalpage}} + +% Utilities +% --------- + + +\newcommand{\setvspace}[2]{% + #1 = #2 + \advance #1 by -1\parskip} + +% Document Parameters +% -------- ---------- + + +% Page: + +\setlength{\hoffset}{-1in} +\setlength{\voffset}{-1in} + +\setlength{\topmargin}{1in} +\setlength{\headheight}{0pt} +\setlength{\headsep}{0pt} + +\if \@onecolumn + \setlength{\evensidemargin}{.75in} + \setlength{\oddsidemargin}{.75in} +\else + \setlength{\evensidemargin}{.75in} + \setlength{\oddsidemargin}{.75in} +\fi + +% Text area: + +\newdimen{\standardtextwidth} +\setlength{\standardtextwidth}{42pc} + +\if \@onecolumn + \setlength{\textwidth}{40.5pc} +\else + \setlength{\textwidth}{\standardtextwidth} +\fi + +\setlength{\topskip}{8pt} +\setlength{\columnsep}{2pc} +\setlength{\textheight}{54.5pc} + +% Running foot: + +\setlength{\footskip}{30pt} + +% Paragraphs: + +\if \@blockstyle + \setlength{\parskip}{5pt plus .1pt minus .5pt} + \setlength{\parindent}{0pt} +\else + \setlength{\parskip}{0pt} + \setlength{\parindent}{12pt} +\fi + +\setlength{\lineskip}{.5pt} +\setlength{\lineskiplimit}{\lineskip} + +\frenchspacing +\pretolerance = 400 +\tolerance = \pretolerance +\setlength{\emergencystretch}{5pt} +\clubpenalty = 10000 +\widowpenalty = 10000 +\setlength{\hfuzz}{.5pt} + +% Standard vertical spaces: + +\newskip{\standardvspace} +\setvspace{\standardvspace}{5pt plus 1pt minus .5pt} + +% Margin paragraphs: + +\setlength{\marginparwidth}{36pt} +\setlength{\marginparsep}{2pt} +\setlength{\marginparpush}{8pt} + + +\setlength{\skip\footins}{8pt plus 3pt minus 1pt} +\setlength{\footnotesep}{9pt} + +\renewcommand{\footnoterule}{% + \hrule width .5\columnwidth height .33pt depth 0pt} + +\renewcommand{\@makefntext}[1]{% + \noindent \@makefnmark \hspace{1pt}#1} + +% Floats: + +\setcounter{topnumber}{4} +\setcounter{bottomnumber}{1} +\setcounter{totalnumber}{4} + +\renewcommand{\fps@figure}{tp} +\renewcommand{\fps@table}{tp} +\renewcommand{\topfraction}{0.90} +\renewcommand{\bottomfraction}{0.30} +\renewcommand{\textfraction}{0.10} +\renewcommand{\floatpagefraction}{0.75} + +\setcounter{dbltopnumber}{4} + +\renewcommand{\dbltopfraction}{\topfraction} +\renewcommand{\dblfloatpagefraction}{\floatpagefraction} + +\setlength{\floatsep}{18pt plus 4pt minus 2pt} +\setlength{\textfloatsep}{18pt plus 4pt minus 3pt} +\setlength{\intextsep}{10pt plus 4pt minus 3pt} + +\setlength{\dblfloatsep}{18pt plus 4pt minus 2pt} +\setlength{\dbltextfloatsep}{20pt plus 4pt minus 3pt} + +% Miscellaneous: + +\errorcontextlines = 5 + +% Fonts +% ----- + + +\if \@times + \renewcommand{\rmdefault}{ptm}% + \if \@mathtime + \usepackage[mtbold,noTS1]{mathtime}% + \else +%%% \usepackage{mathptm}% + \fi +\else + \relax +\fi + +\if \@ninepoint + +\renewcommand{\normalsize}{% + \@setfontsize{\normalsize}{9pt}{10pt}% + \setlength{\abovedisplayskip}{5pt plus 1pt minus .5pt}% + \setlength{\belowdisplayskip}{\abovedisplayskip}% + \setlength{\abovedisplayshortskip}{3pt plus 1pt minus 2pt}% + \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} + +\renewcommand{\tiny}{\@setfontsize{\tiny}{5pt}{6pt}} + +\renewcommand{\scriptsize}{\@setfontsize{\scriptsize}{7pt}{8pt}} + +\renewcommand{\small}{% + \@setfontsize{\small}{8pt}{9pt}% + \setlength{\abovedisplayskip}{4pt plus 1pt minus 1pt}% + \setlength{\belowdisplayskip}{\abovedisplayskip}% + \setlength{\abovedisplayshortskip}{2pt plus 1pt}% + \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} + +\renewcommand{\footnotesize}{% + \@setfontsize{\footnotesize}{8pt}{9pt}% + \setlength{\abovedisplayskip}{4pt plus 1pt minus .5pt}% + \setlength{\belowdisplayskip}{\abovedisplayskip}% + \setlength{\abovedisplayshortskip}{2pt plus 1pt}% + \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} + +\renewcommand{\large}{\@setfontsize{\large}{11pt}{13pt}} + +\renewcommand{\Large}{\@setfontsize{\Large}{14pt}{18pt}} + +\renewcommand{\LARGE}{\@setfontsize{\LARGE}{18pt}{20pt}} + +\renewcommand{\huge}{\@setfontsize{\huge}{20pt}{25pt}} + +\renewcommand{\Huge}{\@setfontsize{\Huge}{25pt}{30pt}} + +\else\if \@tenpoint + +\relax + +\else + +\relax + +\fi\fi + +% Abstract +% -------- + + +\renewenvironment{abstract}{% + \section*{Abstract}% + \normalsize}{% + } + +% Bibliography +% ------------ + + +\renewenvironment{thebibliography}[1] + {\section*{\refname + \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}}% + \list{\@biblabel{\@arabic\c@enumiv}}% + {\settowidth\labelwidth{\@biblabel{#1}}% + \leftmargin\labelwidth + \advance\leftmargin\labelsep + \@openbib@code + \usecounter{enumiv}% + \let\p@enumiv\@empty + \renewcommand\theenumiv{\@arabic\c@enumiv}}% + \bibfont + \clubpenalty4000 + \@clubpenalty \clubpenalty + \widowpenalty4000% + \sfcode`\.\@m} + {\def\@noitemerr + {\@latex@warning{Empty `thebibliography' environment}}% + \endlist} + +\if \@natbib + +\if \@authoryear + \typeout{Using natbib package with 'authoryear' citation style.} + \usepackage[authoryear,square]{natbib} + \bibpunct{(}{)}{;}{a}{}{,} % Change fences to parentheses; + % citation separator to semicolon; + % eliminate comma between author and year. + \let \cite = \citep +\else + \typeout{Using natbib package with 'numbers' citation style.} + \usepackage[numbers,sort&compress,square]{natbib} +\fi +\setlength{\bibsep}{3pt plus .5pt minus .25pt} + +\fi + +\def \bibfont {\small} + +% Categories +% ---------- + + +\@setflag \@firstcategory = \@true + +\newcommand{\category}[3]{% + \if \@firstcategory + \paragraph*{Categories and Subject Descriptors}% + \@setflag \@firstcategory = \@false + \else + \unskip ;\hspace{.75em}% + \fi + \@ifnextchar [{\@category{#1}{#2}{#3}}{\@category{#1}{#2}{#3}[}} + +\def \@category #1#2#3[#4]{% + {\let \and = \relax + #1 [\textit{#2}]% + \if \@emptyargp{#4}% + \if \@notp{\@emptyargp{#3}}: #3\fi + \else + :\space + \if \@notp{\@emptyargp{#3}}#3---\fi + \textrm{#4}% + \fi}} + +% Copyright Notice +% --------- ------ + + +\def \ftype@copyrightbox {8} +\def \@toappear {} +\def \@permission {} +\def \@reprintprice {} + +\def \@copyrightspace {% + \@float{copyrightbox}[b]% + \vbox to 0.0001in{% + \vfill + \parbox[b]{0pc}{% + \scriptsize + \if \@preprint + [%Copyright notice will appear here + %once 'preprint' option is removed. +]\par + \else + \@toappear + \fi + \if \@reprint + \noindent Reprinted from \@conferencename, + \@proceedings, + \@conferenceinfo, + pp.~\number\thepage--\pageref{sigplanconf@finalpage}.\par + \fi}}% + \end@float} + +\newcommand{\reprintprice}[1]{% + \gdef \@reprintprice {#1}} + +\reprintprice{\$15.00} + +\long\def \toappear #1{% + \def \@toappear {#1}} + +\toappear{% + \noindent \@permission \par + \vspace{2pt} + \noindent \textsl{\@conferencename}, \quad \@conferenceinfo. \par + \noindent Copyright \copyright\ \@copyrightyear\ ACM \@copyrightdata + \dots \@reprintprice.\par + \noindent http://dx.doi.org/10.1145/\@doi } + +\newcommand{\permission}[1]{% + \gdef \@permission {#1}} + +\permission{% + Permission to make digital or hard copies of all or part of this work for + personal or classroom use is granted without fee provided that copies are + not made or distributed for profit or commercial advantage and that copies + bear this notice and the full citation on the first page. Copyrights for + components of this work owned by others than ACM must be honored. + Abstracting with credit is permitted. To copy otherwise, or republish, to + post on servers or to redistribute to lists, requires prior specific + permission and/or a fee. Request permissions from permissions@acm.org.} + +% These are two new rights management and bibstrip text blocks. + +\newcommand{\exclusivelicense}{% + \permission{% + Permission to make digital or hard copies of all or part of this work for + personal or classroom use is granted without fee provided that copies are + not made or distributed for profit or commercial advantage and that copies + bear this notice and the full citation on the first page. Copyrights for + components of this work owned by others than the author(s) must be honored. + Abstracting with credit is permitted. To copy otherwise, or republish, to + post on servers or to redistribute to lists, requires prior specific + permission and/or a fee. Request permissions from permissions@acm.org.} + \toappear{% + \noindent \@permission \par + \vspace{2pt} + \noindent \textsl{\@conferencename}, \quad \@conferenceinfo. \par + \noindent Copyright is held by the owner/author(s). Publication rights licensed to ACM. \par + \noindent ACM \@copyrightdata \dots \@reprintprice.\par + \noindent http://dx.doi.org/10.1145/\@doi}} + +\newcommand{\permissiontopublish}{% + \permission{% + Permission to make digital or hard copies of part or all of this work for + personal or classroom use is granted without fee provided that copies are + not made or distributed for profit or commercial advantage and that copies + bear this notice and the full citation on the first page. Copyrights for + third-party components of this work must be honored. + For all other uses, contact the owner/author(s).}% + \toappear{% + \noindent \@permission \par + \vspace{2pt} + \noindent \textsl{\@conferencename}, \quad \@conferenceinfo. \par + \noindent Copyright is held by the owner/author(s). \par + \noindent ACM \@copyrightdata.\par + \noindent http://dx.doi.org/10.1145/\@doi}} + +% The following permission notices are +% for the traditional copyright transfer agreement option. + +% Exclusive license and permission-to-publish +% give more complicated permission notices. +% These are not covered here. + +\newcommand{\ACMCanadapermission}{% + \permission{% + ACM acknowledges that this contribution was authored or + co-authored by an affiliate of the Canadian National + Government. As such, the Crown in Right of Canada retains an equal + interest in the copyright. Reprint requests should be forwarded to + ACM.}} + +\newcommand{\ACMUSpermission}{% + \permission{% + ACM acknowledges that this contribution was authored or + co-authored by a contractor or affiliate of the United States + Government. As such, the United States Government retains a + nonexclusive, royalty-free right to publish or reproduce this + article, or to allow others to do so, for Government purposes + only.}} + +\newcommand{\USpublicpermission}{% + \permission{% + This paper is authored by an employee(s) of the United States + Government and is in the public domain. Non-exclusive copying or + redistribution is allowed, provided that the article citation is + given and the authors and the agency are clearly identified as its + source.}% + \toappear{% + \noindent \@permission \par + \vspace{2pt} + \noindent \textsl{\@conferencename}, \quad \@conferenceinfo. \par + \noindent ACM \@copyrightdata.\par + \noindent http://dx.doi.org/10.1145/\@doi}} + +\newcommand{\authorversion}[4]{% + \permission{% + Copyright \copyright\ ACM, #1. This is the author's version of the work. + It is posted here by permission of ACM for your personal use. + Not for redistribution. The definitive version was published in + #2, #3, http://dx.doi.org/10.1145/#4.}} + +% Enunciations +% ------------ + + +\def \@begintheorem #1#2{% {name}{number} + \trivlist + \item[\hskip \labelsep \textsc{#1 #2.}]% + \itshape\selectfont + \ignorespaces} + +\def \@opargbegintheorem #1#2#3{% {name}{number}{title} + \trivlist + \item[% + \hskip\labelsep \textsc{#1\ #2}% + \if \@notp{\@emptyargp{#3}}\nut (#3).\fi]% + \itshape\selectfont + \ignorespaces} + +% Figures +% ------- + + +\@setflag \@caprule = \@true + +\long\def \@makecaption #1#2{% + \addvspace{4pt} + \if \@caprule + \hrule width \hsize height .33pt + \vspace{4pt} + \fi + \setbox \@tempboxa = \hbox{\@setfigurenumber{#1.}\nut #2}% + \if \@dimgtrp{\wd\@tempboxa}{\hsize}% + \noindent \@setfigurenumber{#1.}\nut #2\par + \else + \centerline{\box\@tempboxa}% + \fi} + +\newcommand{\nocaptionrule}{% + \@setflag \@caprule = \@false} + +\def \@setfigurenumber #1{% + {\rmfamily \bfseries \selectfont #1}} + +% Hierarchy +% --------- + + +\setcounter{secnumdepth}{\@numheaddepth} + +\newskip{\@sectionaboveskip} +\setvspace{\@sectionaboveskip}{10pt plus 3pt minus 2pt} + +\newskip{\@sectionbelowskip} +\if \@blockstyle + \setlength{\@sectionbelowskip}{0.1pt}% +\else + \setlength{\@sectionbelowskip}{4pt}% +\fi + +\renewcommand{\section}{% + \@startsection + {section}% + {1}% + {0pt}% + {-\@sectionaboveskip}% + {\@sectionbelowskip}% + {\large \bfseries \raggedright}} + +\newskip{\@subsectionaboveskip} +\setvspace{\@subsectionaboveskip}{8pt plus 2pt minus 2pt} + +\newskip{\@subsectionbelowskip} +\if \@blockstyle + \setlength{\@subsectionbelowskip}{0.1pt}% +\else + \setlength{\@subsectionbelowskip}{4pt}% +\fi + +\renewcommand{\subsection}{% + \@startsection% + {subsection}% + {2}% + {0pt}% + {-\@subsectionaboveskip}% + {\@subsectionbelowskip}% + {\normalsize \bfseries \raggedright}} + +\renewcommand{\subsubsection}{% + \@startsection% + {subsubsection}% + {3}% + {0pt}% + {-\@subsectionaboveskip} + {\@subsectionbelowskip}% + {\normalsize \bfseries \raggedright}} + +\newskip{\@paragraphaboveskip} +\setvspace{\@paragraphaboveskip}{6pt plus 2pt minus 2pt} + +\renewcommand{\paragraph}{% + \@startsection% + {paragraph}% + {4}% + {0pt}% + {\@paragraphaboveskip} + {-1em}% + {\normalsize \bfseries \if \@times \itshape \fi}} + +\renewcommand{\subparagraph}{% + \@startsection% + {subparagraph}% + {4}% + {0pt}% + {\@paragraphaboveskip} + {-1em}% + {\normalsize \itshape}} + +% Standard headings: + +\newcommand{\acks}{\section*{Acknowledgments}} + +\newcommand{\keywords}{\paragraph*{Keywords}} + +\newcommand{\terms}{\paragraph*{General Terms}} + +% Identification +% -------------- + + +\def \@conferencename {} +\def \@conferenceinfo {} +\def \@copyrightyear {} +\def \@copyrightdata {[to be supplied]} +\def \@proceedings {[Unknown Proceedings]} + + +\newcommand{\conferenceinfo}[2]{% + \gdef \@conferencename {#1}% + \gdef \@conferenceinfo {#2}} + +\newcommand{\copyrightyear}[1]{% + \gdef \@copyrightyear {#1}} + +\let \CopyrightYear = \copyrightyear + +\newcommand{\copyrightdata}[1]{% + \gdef \@copyrightdata {#1}} + +\let \crdata = \copyrightdata + +\newcommand{\doi}[1]{% + \gdef \@doi {#1}} + +\newcommand{\proceedings}[1]{% + \gdef \@proceedings {#1}} + +% Lists +% ----- + + +\setlength{\leftmargini}{13pt} +\setlength\leftmarginii{13pt} +\setlength\leftmarginiii{13pt} +\setlength\leftmarginiv{13pt} +\setlength{\labelsep}{3.5pt} + +\setlength{\topsep}{\standardvspace} +\if \@blockstyle + \setlength{\itemsep}{1pt} + \setlength{\parsep}{3pt} +\else + \setlength{\itemsep}{1pt} + \setlength{\parsep}{3pt} +\fi + +\renewcommand{\labelitemi}{{\small \centeroncapheight{\textbullet}}} +\renewcommand{\labelitemii}{\centeroncapheight{\rule{2.5pt}{2.5pt}}} +\renewcommand{\labelitemiii}{$-$} +\renewcommand{\labelitemiv}{{\Large \textperiodcentered}} + +\renewcommand{\@listi}{% + \leftmargin = \leftmargini + \listparindent = 0pt} +%%% \itemsep = 1pt +%%% \parsep = 3pt} +%%% \listparindent = \parindent} + +\let \@listI = \@listi + +\renewcommand{\@listii}{% + \leftmargin = \leftmarginii + \topsep = 1pt + \labelwidth = \leftmarginii + \advance \labelwidth by -\labelsep + \listparindent = \parindent} + +\renewcommand{\@listiii}{% + \leftmargin = \leftmarginiii + \labelwidth = \leftmarginiii + \advance \labelwidth by -\labelsep + \listparindent = \parindent} + +\renewcommand{\@listiv}{% + \leftmargin = \leftmarginiv + \labelwidth = \leftmarginiv + \advance \labelwidth by -\labelsep + \listparindent = \parindent} + +% Mathematics +% ----------- + + +\def \theequation {\arabic{equation}} + +% Miscellaneous +% ------------- + + +\newcommand{\balancecolumns}{% + \vfill\eject + \global\@colht = \textheight + \global\ht\@cclv = \textheight} + +\newcommand{\nut}{\hspace{.5em}} + +\newcommand{\softraggedright}{% + \let \\ = \@centercr + \leftskip = 0pt + \rightskip = 0pt plus 10pt} + +% Program Code +% ------- ---- + + +\newcommand{\mono}[1]{% + {\@tempdima = \fontdimen2\font + \texttt{\spaceskip = 1.1\@tempdima #1}}} + +% Running Heads and Feet +% ------- ----- --- ---- + + +\def \@preprintfooter {} + +\newcommand{\preprintfooter}[1]{% + \gdef \@preprintfooter {#1}} + +\if \@preprint + +\def \ps@plain {% + \let \@mkboth = \@gobbletwo + \let \@evenhead = \@empty + \def \@evenfoot {\scriptsize + \rlap{\textit{\@preprintfooter}}\hfil + \thepage \hfil + \llap{\textit{\@formatyear}}}% + \let \@oddhead = \@empty + \let \@oddfoot = \@evenfoot} + +\else\if \@reprint + +\def \ps@plain {% + \let \@mkboth = \@gobbletwo + \let \@evenhead = \@empty + \def \@evenfoot {\scriptsize \hfil \thepage \hfil}% + \let \@oddhead = \@empty + \let \@oddfoot = \@evenfoot} + +\else + +\let \ps@plain = \ps@empty +\let \ps@headings = \ps@empty +\let \ps@myheadings = \ps@empty + +\fi\fi + +\def \@formatyear {% + \number\year/\number\month/\number\day} + +% Special Characters +% ------- ---------- + + +\DeclareRobustCommand{\euro}{% + \protect{\rlap{=}}{\sf \kern .1em C}} + +% Title Page +% ----- ---- + + +\@setflag \@addauthorsdone = \@false + +\def \@titletext {\@latex@error{No title was provided}{}} +\def \@subtitletext {} + +\newcount{\@authorcount} + +\newcount{\@titlenotecount} +\newtoks{\@titlenotetext} + +\def \@titlebanner {} + +\renewcommand{\title}[1]{% + \gdef \@titletext {#1}} + +\newcommand{\subtitle}[1]{% + \gdef \@subtitletext {#1}} + +\newcommand{\authorinfo}[3]{% {names}{affiliation}{email/URL} + \global\@increment \@authorcount + \@withname\gdef {\@authorname\romannumeral\@authorcount}{#1}% + \@withname\gdef {\@authoraffil\romannumeral\@authorcount}{#2}% + \@withname\gdef {\@authoremail\romannumeral\@authorcount}{#3}} + +\renewcommand{\author}[1]{% + \@latex@error{The \string\author\space command is obsolete; + use \string\authorinfo}{}} + +\newcommand{\titlebanner}[1]{% + \gdef \@titlebanner {#1}} + +\renewcommand{\maketitle}{% + \pagestyle{plain}% + \if \@onecolumn + {\hsize = \standardtextwidth + \@maketitle}% + \else + \twocolumn[\@maketitle]% + \fi + \@placetitlenotes + \if \@copyrightwanted \@copyrightspace \fi} + +\def \@maketitle {% + \begin{center} + \@settitlebanner + \let \thanks = \titlenote + {\leftskip = 0pt plus 0.25\linewidth + \rightskip = 0pt plus 0.25 \linewidth + \parfillskip = 0pt + \spaceskip = .7em + \noindent \LARGE \bfseries \@titletext \par} + \vskip 6pt + \noindent \Large \@subtitletext \par + \vskip 12pt + \ifcase \@authorcount + \@latex@error{No authors were specified for this paper}{}\or + \@titleauthors{i}{}{}\or + \@titleauthors{i}{ii}{}\or + \@titleauthors{i}{ii}{iii}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{viii}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{viii}{ix}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{xi}{}\or + \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% + \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{xi}{xii}% + \else + \@latex@error{Cannot handle more than 12 authors}{}% + \fi + \vspace{1.75pc} + \end{center}} + +\def \@settitlebanner {% + \if \@andp{\@preprint}{\@notp{\@emptydefp{\@titlebanner}}}% + \vbox to 0pt{% + \vskip -32pt + \noindent \textbf{\@titlebanner}\par + \vss}% + \nointerlineskip + \fi} + +\def \@titleauthors #1#2#3{% + \if \@andp{\@emptyargp{#2}}{\@emptyargp{#3}}% + \noindent \@setauthor{40pc}{#1}{\@false}\par + \else\if \@emptyargp{#3}% + \noindent \@setauthor{17pc}{#1}{\@false}\hspace{3pc}% + \@setauthor{17pc}{#2}{\@false}\par + \else + \noindent \@setauthor{12.5pc}{#1}{\@false}\hspace{2pc}% + \@setauthor{12.5pc}{#2}{\@false}\hspace{2pc}% + \@setauthor{12.5pc}{#3}{\@true}\par + \relax + \fi\fi + \vspace{20pt}} + +\def \@setauthor #1#2#3{% {width}{text}{unused} + \vtop{% + \def \and {% + \hspace{16pt}} + \hsize = #1 + \normalfont + \centering + \large \@name{\@authorname#2}\par + \vspace{5pt} + \normalsize \@name{\@authoraffil#2}\par + \vspace{2pt} + \textsf{\@name{\@authoremail#2}}\par}} + +\def \@maybetitlenote #1{% + \if \@andp{#1}{\@gtrp{\@authorcount}{3}}% + \titlenote{See page~\pageref{@addauthors} for additional authors.}% + \fi} + +\newtoks{\@fnmark} + +\newcommand{\titlenote}[1]{% + \global\@increment \@titlenotecount + \ifcase \@titlenotecount \relax \or + \@fnmark = {\ast}\or + \@fnmark = {\dagger}\or + \@fnmark = {\ddagger}\or + \@fnmark = {\S}\or + \@fnmark = {\P}\or + \@fnmark = {\ast\ast}% + \fi + \,$^{\the\@fnmark}$% + \edef \reserved@a {\noexpand\@appendtotext{% + \noexpand\@titlefootnote{\the\@fnmark}}}% + \reserved@a{#1}} + +\def \@appendtotext #1#2{% + \global\@titlenotetext = \expandafter{\the\@titlenotetext #1{#2}}} + +\newcount{\@authori} + +\iffalse +\def \additionalauthors {% + \if \@gtrp{\@authorcount}{3}% + \section{Additional Authors}% + \label{@addauthors}% + \noindent + \@authori = 4 + {\let \\ = ,% + \loop + \textbf{\@name{\@authorname\romannumeral\@authori}}, + \@name{\@authoraffil\romannumeral\@authori}, + email: \@name{\@authoremail\romannumeral\@authori}.% + \@increment \@authori + \if \@notp{\@gtrp{\@authori}{\@authorcount}} \repeat}% + \par + \fi + \global\@setflag \@addauthorsdone = \@true} +\fi + +\let \addauthorsection = \additionalauthors + +\def \@placetitlenotes { + \the\@titlenotetext} + +% Utilities +% --------- + + +\newcommand{\centeroncapheight}[1]{% + {\setbox\@tempboxa = \hbox{#1}% + \@measurecapheight{\@tempdima}% % Calculate ht(CAP) - ht(text) + \advance \@tempdima by -\ht\@tempboxa % ------------------ + \divide \@tempdima by 2 % 2 + \raise \@tempdima \box\@tempboxa}} + +\newbox{\@measbox} + +\def \@measurecapheight #1{% {\dimen} + \setbox\@measbox = \hbox{ABCDEFGHIJKLMNOPQRSTUVWXYZ}% + #1 = \ht\@measbox} + +\long\def \@titlefootnote #1#2{% + \insert\footins{% + \reset@font\footnotesize + \interlinepenalty\interfootnotelinepenalty + \splittopskip\footnotesep + \splitmaxdepth \dp\strutbox \floatingpenalty \@MM + \hsize\columnwidth \@parboxrestore +%%% \protected@edef\@currentlabel{% +%%% \csname p@footnote\endcsname\@thefnmark}% + \color@begingroup + \def \@makefnmark {$^{#1}$}% + \@makefntext{% + \rule\z@\footnotesep\ignorespaces#2\@finalstrut\strutbox}% + \color@endgroup}} + +% LaTeX Modifications +% ----- ------------- + +\def \@seccntformat #1{% + \@name{\the#1}% + \@expandaftertwice\@seccntformata \csname the#1\endcsname.\@mark + \quad} + +\def \@seccntformata #1.#2\@mark{% + \if \@emptyargp{#2}.\fi} + +% Revision History +% -------- ------- + + +% Date Person Ver. Change +% ---- ------ ---- ------ + +% 2004.09.12 PCA 0.1--4 Preliminary development. + +% 2004.11.18 PCA 0.5 Start beta testing. + +% 2004.11.19 PCA 0.6 Obsolete \author and replace with +% \authorinfo. +% Add 'nocopyrightspace' option. +% Compress article opener spacing. +% Add 'mathtime' option. +% Increase text height by 6 points. + +% 2004.11.28 PCA 0.7 Add 'cm/computermodern' options. +% Change default to Times text. + +% 2004.12.14 PCA 0.8 Remove use of mathptm.sty; it cannot +% coexist with latexsym or amssymb. + +% 2005.01.20 PCA 0.9 Rename class file to sigplanconf.cls. + +% 2005.03.05 PCA 0.91 Change default copyright data. + +% 2005.03.06 PCA 0.92 Add at-signs to some macro names. + +% 2005.03.07 PCA 0.93 The 'onecolumn' option defaults to '11pt', +% and it uses the full type width. + +% 2005.03.15 PCA 0.94 Add at-signs to more macro names. +% Allow margin paragraphs during review. + +% 2005.03.22 PCA 0.95 Implement \euro. +% Remove proof and newdef environments. + +% 2005.05.06 PCA 1.0 Eliminate 'onecolumn' option. +% Change footer to small italic and eliminate +% left portion if no \preprintfooter. +% Eliminate copyright notice if preprint. +% Clean up and shrink copyright box. + +% 2005.05.30 PCA 1.1 Add alternate permission statements. + +% 2005.06.29 PCA 1.1 Publish final first edition of guide. + +% 2005.07.14 PCA 1.2 Add \subparagraph. +% Use block paragraphs in lists, and adjust +% spacing between items and paragraphs. + +% 2006.06.22 PCA 1.3 Add 'reprint' option and associated +% commands. + +% 2006.08.24 PCA 1.4 Fix bug in \maketitle case command. + +% 2007.03.13 PCA 1.5 The title banner only displays with the +% 'preprint' option. + +% 2007.06.06 PCA 1.6 Use \bibfont in \thebibliography. +% Add 'natbib' option to load and configure +% the natbib package. + +% 2007.11.20 PCA 1.7 Balance line lengths in centered article +% title (thanks to Norman Ramsey). + +% 2009.01.26 PCA 1.8 Change natbib \bibpunct values. + +% 2009.03.24 PCA 1.9 Change natbib to use the 'numbers' option. +% Change templates to use 'natbib' option. + +% 2009.09.01 PCA 2.0 Add \reprintprice command (suggested by +% Stephen Chong). + +% 2009.09.08 PCA 2.1 Make 'natbib' the default; add 'nonatbib'. +% SB Add 'authoryear' and 'numbers' (default) to +% control citation style when using natbib. +% Add \bibpunct to change punctuation for +% 'authoryear' style. + +% 2009.09.21 PCA 2.2 Add \softraggedright to the thebibliography +% environment. Also add to template so it will +% happen with natbib. + +% 2009.09.30 PCA 2.3 Remove \softraggedright from thebibliography. +% Just include in the template. + +% 2010.05.24 PCA 2.4 Obfuscate class author's email address. + +% 2011.11.08 PCA 2.5 Add copyright notice to this file. +% Remove 'sort' option from natbib when using +% 'authoryear' style. +% Add the \authorversion command. + +% 2013.02.22 PCA 2.6 Change natbib fences to parentheses when +% using 'authoryear' style. + +% 2013.05.17 PCA 2.7 Change standard and author copyright text. + +% 2013.07.02 TU 2.8 More changes to permission/copyright notes. +% Replaced ambiguous \authorpermission with +% \exclusivelicense and \permissiontopublish + +