text
stringlengths 2
132k
| source
dict |
|---|---|
delivery of messages con-forms with their causal order relations. Two messages which are not causally related, are said to be concurrent. The causal order broadcast does not de-fine any delivery constraints on concurrent messages. 4.6.1 Specification The causal order broadcast specification studied here guarantees the same properties as regular reliable broadcast , together with a Causal Delivery prop-erty. Its properties are: • Causal Delivery : No process delivers a message mj , unless every other message mi, such that m1− > m j , is delivered. • Agreement : All correct processes deliver the same set of broadcast messages. 74 • Validity : If a correct process p broadcasts message m, this eventually gets delivered by all correct processes in the system. • Integrity : For any message m, every process delivers m at most once, and only if it was previously broadcast. 4.6.2 Algorithm Figure 4.10: The causal order broadcast algorithm The listing in figure 4.10, gives the no-waiting algorithm for causal order broadcast specification. The idea behind the algorithm is very simple. Every process which needs to broadcast, always broadcasts a set of all messages already broadcast and delivered, together with the message to be broadcast. When a receiver receives the message and the set, it first checks whether any of the messages in the set are undelivered, if so it first delivers them. Finally, it delivers the message itself. 75 Internally the algorithm stores two sets Delivered and Past . The Delivered set is used to store all messages which have been delivered. The Past set holds pairs of messages and sender PID’s. When a message is to be broadcast, the Past set is reliably broadcast, together with the message as a single tuple (line 17). When this message is delivered by the receivers, first these check
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
whether the message has already been delivered (line 21 onwards). Following this, all messages inside the received Past set are checked with the messages which were delivered. Any messages not yet delivered will be delivered immediately (line 24). This is why in line 21, all messages are checked to determine whether they had been previously delivered or not. Finally, the message itself is also delivered (line 27). When a message is delivered, it is included in the Past message and Delivered set. One should note, that in line 22, messages are taken out of the Past set and delivered. The order in which these messages are delivered is crucial. Messages should be delivered in the same order in which they were added to the Past set by the sender. Note also, despite that a broadcast also sends the message to the sender process itself, the algorithm immediately adds an entry into the Past set for that message. This is done because in the time window between the submission and delivery (by the same process), the process may submit another message, and hence the previously sent message needs to be present in the Past set. 4.6.2.1 Pruning the Past set The main concern with the algorithm is the indefinite nature of the Past set. Furthermore, this set is transferred on the network, with every broadcast - posing an ever growing message size as time progresses. This problem, presses to devise means to limit the size of this set. The listing in figure 4.11, gives a method to ”garbage collect” the Past set. The idea is to have every process to acknowledge to all other processes as soon as it delivers a message. When acknowledgements for a message, are received from all other correct processes, that particular message can be removed from
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the Past set. This way, the size of the Past is no longer indefinite, but rather decreases as all processes acknowledge delivery. 76 Figure 4.11: Garbage collection algorithm for the Past set 77 This mechanism keeps a mapping between every message and the processes which acknowledged it ( Ack ). As soon as a message is delivered, but not acknowledged, an acknowledgement is reliably broadcast to all processes (lines 19-21). When this message is received, its sender is recorded in the Ack map for that message, and if all correct processes have acknowledged that message, then it is removed from the Past set (lines 23-27). Figure 4.12: Run of the causal order broadcast algorithm Figure 4.12 gives a run of the causal order algorithm. Basically, it re-illustrates the same example given earlier in this chapter, but using the causal order broadcast. The dashed lines represent acknowledges from pro-cesses. For clarity, only the acknowledges to process P1 are shown. Process P1 broadcasts two messages. Note that the first message arrives at process P2 after the second message. However, since the second message’s past set, contains the first message, process P2 first delivers the first message and then the second message. At point A, P1 receives acknowledgments for the first message from all other participants, and hence can remove the first message from its Past set. At point B, all acknowledges for the second messages, are received by P1, and hence it can remove this message from its Past set. 4.6.3 Erlang Implementation The no-waiting algorithm for causal order broadcast was implemented in Erlang using the framework outlined in this project. The distributed garbage collection scheme for the Past set was also implemented. The sets module was used to implement the Delivered and Past sets. The Ack map was implemented with the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Dict module. It was mentioned that messages should be delivered from the Past set in the same order in which they were added. This was achieved by having 78 every process keeping a counter of the messages entered in its own Past set. Moreover, when a message is to be added to this set, the counter is added together with the message as a single tuple. This set is sent when a causal order broadcast is made. The receiver will then convert the received Past set to a list, and sort messages in the list in ascending order, according to this number. Finally, messages are recursively read from the list, and the original message is delivered. One other thing to note is that the algorithm outlined here, does not allow identical messages to be broadcast from the same process. However note, that due to the technique just outline for ensuring the ordered delivery of messages in the Past set, no two messages broadcast from the same process can be identical. This is because, in the least, the count for the last message, will be greater than any of the previous messages. Finally, note that the initialisation of the Ack map, requires that an empty set will be mapped with every possible message (figure 4.10, line 12). How-ever, in practice, since a Dict is used, initially every message will be mapped with nothing (not empty set). Hence, when an entry for a message is to be entered for the first time (by checking whether it is currently mapped with nothing), first the empty set is mapped. 4.6.4 Implementation Optimisations As noted, the Delivered set will hold a copy of all message delivered. As done in the implementation of previous algorithms, a hash of the message is kept, instead of the message
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
itself. This relieves some of the memory requirement of the algorithm. Moreover, as soon as a message can be removed from the Past set, its equivalent set in the Ack set is removed as well. The problem of the Past set has been tackled with the use of the garbage collection mechanism outlined. However, the Delivered set, still has indefi-nite memory requirements. A tentative solution to this problem is suggested for future work (see section 9). 4.6.5 Evaluation The causal order broadcast guarantees that every message delivered obeys the causal ordering relation, apart from guaranteeing the same properties as regular reliable broadcast. The agreement , validity and integrity properties 79 are guaranteed because of the underlying use of a regular reliable broadcast abstraction. The causal delivery property is guaranteed thanks to the Past set, which enables any causally related message which has not yet been delivered, to be delivered. In terms of performance evaluation, the basic algorithm exchanges the same amount of messages as the regular reliable broadcast algorithm - ie has a best case of |Π| (in a failure free run) and a worst case of |Π|2 message exchanges. However, with the garbage collection scheme |Π|2 message acknowledges need to be exchanged for every message broadcast. # 4.7 Conclusion In this chapter, a number of Reliable Broadcast specifications were inves-tigated. First, the best effort Broadcast was outlined. This is the weakest broadcast abstraction and only guarantees correctness if the sender does not crash whilst broadcasting. Then the regular reliable broadcast was studied. This specification guarantees that all correct processes agree on the set of delivered messages. Following this, the uniform reliable broadcast was in-vestigated. This broadcast abstraction guarantees that no faulty process delivers a message which a correct process does not. Finally, the causal or-der broadcast was outlined. This
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
reliable broadcast specification guarantees that all messages delivered, obey the causal order relation. Established algorithms for each specification, were studied and implemented in Erlang, using the implementation framework developed for this project. Insights about the implementation, together with tweaks and optimisations taken, were also outlined. 80 Chapter 5 # Consensus # 5.1 Introduction In this chapter, another class of agreement algorithms will be investigated: Consensus. Consensus deals with having a system of processes which at-tempt to decide on using a value, from various proposals. Each process may propose a value, however, it is up to the consensus algorithm to decide on which value all the processes should choose. Unless proper care is taken, situations may arise which cause processes to choose different values. In the light of process failures and network asyn-chrony, algorithms need to be studied to tackle the consensus problem reli-ably. In this chapter, various consensus specifications will be outlined. Estab-lished algorithms for these specifications will investigated, and finally also implemented in Erlang. # 5.2 Interface Below is the generic interface for all consensus algorithms implemented in this chapter: • External Events Handled – init() Initializes the algorithm. 81 – propose(Value) Assigns Value as the proposal of the calling process. • Callbacks Expected – decide( Decision ) Indicates that the consensus algorithm terminated and decide with value Decision Note that certain algorithms require a Decision Function as a param-eter to init . This decision function is used to choose a value from a set of proposals. In order to guarantee agreement, this decision function should be identical for all processes. # 5.3 A Slight change It might be noted, that the standard interface outlined, does not give way to two or more instances of consensus to be in execution. This is because, there is no way by which
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
to distinguish, whether a propose is intended for one consensus instance or the other. For this reason, in practice, all calls and callbacks to consensus have another argument - the consensus identifier. This argument will always come first in the argument list. Hence if a process needs to propose to a three different instances of consen-sus, it should simply trigger propose three times, each time with a different consensus identifier. In the implementation framework, the Main process takes care to check whether a consensus gen server for the particular iden-tifier is started. If it is not started, it will start another instance for that consensus identifier. From this point on, all calls with that particular con-sensus identifier, are directed to the existing consensus gen server process. This simple scheme makes it possible to have multiple instances of consensus running at the same time. # 5.4 Regular Consensus 5.4.1 Overview The Regular Consensus specification provides the basic mechanism for dis-tributed process agreement. Processes propose different values and one of 82 these values is globally chosen (decided) and returned to all processes. 5.4.2 Specification The regular consensus specification ensures the same properties as a regular reliable broadcast , but to a consensus scenario. The properties which are guaranteed by regular consensus are: • Termination : There exists a time at which all correct processes de-cide some value. • Validity : A decided value must be a proposed value. • Integrity : Processes decide only once. • Agreement : All correct processes agree on the same value. 5.4.3 Flooding Algorithm In this project an asynchronous message flooding algorithm, proposed in , was implemented. This algorithm is based on the simpler floodset consensus solving algorithm. The floodset algorithm assumes a synchronous commu-nication model, hence its correctness is not guaranteed in an asynchronous system 1.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Moreover, the floodset algorithm assumes an upperbound on the number of failures and does not utilize a failure detector. Despite all these problems, the floodset algorithm still sets the basis for the flooding consen-sus algorithm implemented here. For this reason, it will be briefly outlined. Following this, the changes done to achieve an asynchronous algorithm will also be explained. 5.4.3.1 Simple algorithms based on Reliable Broadcast Protocols In the previous chapters, various reliable broadcast protocols were outlined. At this point, one might ask whether a reliable broadcast algorithm can be used to implement the Regular consensus specification. It may appear that a simple solution can be provided by having processes which broadcast their proposals using some fault tolerant broadcast such as regular reliable > 1Due to the forcing failure detector used here, in this case this would not be a problem. However, in general, synchronous algorithms cannot be used in asynchronous systems 83 broadcast . This broadcast ensures that all correct processes will see the same broadcast messages. Hence, if all processes simply use this protocol and broadcast their proposal to all, it is ensured that all processes will eventually get an identical set of proposals (and hence can decide on a value based on the same set of proposals), even when there are process failures. However, there is one subtlety which makes the use of such protocols inappropriate. This is because if a process crashes without managing to actually send its proposals to anyone, the other processes would not be able to tell whether a message from this process is underway or not. Despite that, the failure detector of these processes should eventually signal that this process has crashed, this would still not break the tie. Given that a message could actually be on its way on the network,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the waiting processes would not know whether these can proceed or wait to receive something from the crashed process. Figure 5.1: Invalidity of Reliable Broadcast algorithms for imple-mentation of consensus protocols This problem is illustrated in figure 5.1. Here the most basic case, with just two processes is considered. The two processes here are assumed to perform regular consensus using a reliable broadcast abstraction as explained above. Process P1 is faulty and crashes at point A. However, from process P2 point of view, it cannot determine whether this process has sent its proposal or not. Even though at point B, P2’s failure detector signals that process P1 has crashed, it can make no assumption as to whether process P1 has sent its proposals or not, and hence will not be able to decide. At this point, one might attempt to ”patch” this problem by ignoring mes-sages received from crashed processes, however this would break the algo-rithm so badly, that it gives way for inconsistent decisions to be taken. This 84 is because it might happen that a process detects a crashed process and ignores its future message, whereas another process might first receive the messages and then detect the node to have failed. Of course, since the first process has ignored messages the second did not, the processes will have different proposal sets on which to decide. An example of this run is shown in figure 5.2. Figure 5.2: Invalidity of implementing consensus algorithms using Reliable Broadcast Algorithms, even when ignoring messages from crashed processes In figure 5.2, three processes propose values by broadcasting their messages. Process P1 fails shortly after finishing its broadcast. Process P2 receives P1’s message, before actually detecting that this has failed. At this point it can decide because it has received all proposals. On the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
other hand, process P3,detects that that P1 failed (Point A) before receiving its proposal. Moreover, if this proposal will be received, it will be ignored, and hence P3 can make a decision based on its current proposal set. Given that it has not seen proposals from process P1, its proposal set will be different than that of P2 and hence, it could decide differently. For this reason, the reliable broadcast algorithms cannot be used directly to build consensus algorithms, but we will need to look at alternative algo-rithms to solve this problem. 5.4.3.2 The Floodset Algorithm The idea behind the floodset algorithm is to ensure that all processes as-semble an identical set of proposals and decide on that set. The algorithm consists of rounds. In each round all processes broadcast ( best-effort broad-cast ), their proposal sets. The floodset algorithm also assumes upper bound 85 f on the number of process failures. The number of rounds required by the floodset algorithm depends on f .If no failures occur, then just one round would be enough; in which every process waits for the proposal sets of the other processes, and then decides some value. If failures occur, these could cause processes to only broadcast their message to a subset of the participants. Such a situation will cause processes to have different proposal sets, and hence may possibly decide differently. The floodset algorithm overcomes this problem by performing f + 1 rounds. This way, at least one round is ensured not to contain any failures, and hence all proposal sets will be identical from this point on. Listing 5.3 gives an adaptation of the floodset algorithm (given by Lynch in ). Note that the initialisation of the floodset algorithm requires two pa-rameters: Max failures and Func . Max failures will initialize the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
maximum number of failures (referred to as f ). Func is the decision function which will be applied to set of proposals, when all proposals have been gathered. These two parameters are held in the state, together with other data ele-ments: Proposals set with the proposed values from the other processes, the current Round number and Correct this round set containing the PID’s of processes from whom a proposal was received in the current round. The algorithm here works by gathering proposals which are broadcast using the best effort broadcast() . The proposal sets received are stored together with the currently seen proposals in the handler of the best effort broadcast deliver event (line 27). Every time a Proposal set is received, its owner is marked as being correct by storing its PID in the Correct this round set (line 28). When this set is filled with all the processes (ie it is equal to Π), or the synchronous time limit for receiving messages has been exceeded (line 30), then the current round is over. As a reminder, note that the floodset algorithm is devised as a solution for consensus in synchronous systems, and hence there is a well defined deadline for receiving messages. Here, it is assumed that once this limit is exceeded, the timedout receiving propo-sition (line 30) will evaluate to true. At the end of the round, it should be checked whether this is the last round, (round f + 1), in which case the decision function should be applied to the proposal set, and the decide() event is callbacked (lines 33-34). If this is not the final round, then the Correct this round set should be emptied, Round number incremented and Proposals set broadcast. 86 Figure 5.3: The Floodset Algorithm 87 Figure 5.4: A run of
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the floodset algorithm with one process failure Figure 5.4 gives a run of the floodset algorithm between three processes and with f = 1. Processes P1 and P2 broadcast successfully, however, process P3 only sends its proposals to P2 (Point A). Hence at the end of round 1, the processes do not have identical proposal sets. In round 2, which is the final round, P3’s proposal set is sent to P1, by P2 and hence all proposal sets are identical and the decision function can be applied. The floodset algorithm solves consensus for any number of crash failures in a synchronous system. In particular, if f = |Π| − 1 then this algorithm will solve consensus for all possible failures in the system. However, its reliance on synchronous deadlines makes it unsuitable for usage in an asynchronous system. Moreover the lack of failure detection results in lots of message exchanges and communication steps (rounds). The following section will describe an algorithm, based on the original floodset algorithm, which tackles these problems and implements the regular consensus specification. 5.4.3.3 Algorithm This section outlines the flooding algorithm for Regular consensus. This algorithm is based on the synchronous floodset algorithm, but addresses its shortcomings for asynchronous systems. This algorithm is also free from the inconsistency issues discussed when investigating the possibility of us-ing reliable broadcast algorithms to implement consensus protocols (see sec-tion 5.4.3.1). Listing 5.5 gives the flooding algorithm for regular consensus. This algo-rithm reduces the number of rounds required over the number of rounds required by the floodset algorithm. This is done by using an array Cor- 88 Figure 5.5: The Flooding Consensus Algorithm 89 rect this round with indexes being the round numbers and the elements be-ing sets with PID’s of the processes whose proposal has been received. The Proposals set
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
is also an array with the round numbers as indexes and ele-ments being the proposals received for the corresponding round. When a value is proposed (lines 28 to 30), the value is added to the first Proposals set and broadcast. Note that when broadcasting (line 30), the message consists of three elements: an atom identifying the message type ( proposal set ), the Round Number and the set of proposals. When this message is received ( beb deliver handler lines 32-34), the received proposals are inserted in the corresponding Proposals set for the received round number. The PID of the sender are also inserted in the Correct this round set for the received round number. A round ends whenever proposals are received from all currently correct processes and there has not been a decision (line 36). If a failure has been detected (ie the correct processes for the round and one before do not match (line 38), then another round is required. The proposals seen so far, are broadcast so as to disseminate its Proposals and enable other processes to progress. It should be noted that all previous proposals will be ”brought forward” in the new round - this is because when a process broadcasts its proposal set (line 45), this will also be received by this same process. Note that unlike the floodset algorithm, there is no strict deadline for receiv-ing the proposal messages. Instead, for each process, the algorithm either receives proposals or detects that it has crashed. The eventual delivery prop-erty of the link guarantees that if proposals are sent, these will be received, whereas the properties of the perfect failure detector guarantee that any crashed node will be detected. This guarantees that one of these two possi-bilities will hold for all the processes during a round,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
eventually terminating it. If for the last two rounds, no failure is detected (ie there are two successive equal sets of PID’s, in the Correct this round structure) then a decision can be made (lines 38-41). The decision is made by applying the decision function Func (which was passed as an argument to init() ) on the final set of proposals. After a process decides, it broadcasts this decision (line 41) to the other pro-cesses. This is done because the process which managed to decide, might have received proposals from a process which only managed to send its pro-90 posals to this process before crashing. Hence, these processes would detect the crashed process and not decide. However, in the following round, instead of receiving the proposals of the process which decided, these will receive the decision and hence trigger decide() without need for further rounds. Figure 5.6: A run of the Flooding Algorithm with one process fail-ure Figure 5.6 shows a run of the flooding consensus algorithm between four pro-cesses. Here, the first three processes are correct and manage to broadcast their proposal. However, process P4 crashes whilst broadcasting its propos-als and only manages to send its proposal to P3 (point A). As soon as this message is received by process P3, this process would have received proposals from all correct processes. Moreover, since Correct this round = Π, this process can now decide. At point B, P3 decides and broadcasts its decision to the other processes. In the meantime, processes P1 and P2 detected the crash of P4 and hence moved on to round 2 without being able to make a decision (Note that strictly speaking, these processes broadcast their pro-posals on the beginning of round 2, but this is irrelevant in this example and hence is left
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
out for the sake of simplicity). In the second round, these processes receive the decision and hence decide immediately. Note that it is not possible for two processes to decided differently. This is because for a process to decide, there must be two consecutive rounds without detecting a failure. Moreover, at the end of the first round, the proposals are broadcasted to all. Hence, even if the failure detectors of different processes do not detect the same failed processes, the proposal sets would still be exchanged at the end of the first round and hence if the two 91 decide, they will decide the same. 5.4.3.4 Erlang Implementation The implementation of this algorithm, in Erlang, uses lots of the modules and techniques already outlined in the implementation of previous algo-rithms such as the usage of the sets module, for the Correct set. The Correct this round and Proposals arrays where implemented using Er-lang’s Array module. This provides a data structure with conventional array like access, which is much more convenient and efficient to use for this pur-pose than the conventional lists. Another important feature demonstrated in this algorithm is the use of the decision function Func . This function should be passed as a parameter to init() , and then used when deciding. In Erlang, this can be implemented using Higher Order Functions in almost the same way as shown here. 5.4.3.5 Implementation Optimisations As opposed to the reliable broadcast, every consensus algorithm has definite stopping point during its execution - after that a decision is reached, nothing will affect the decision. Thus, after that a decision is reached, all that needs to be kept is the Decided variable. The rest of the elements of the state can be given the value null , and Erlang’s garbage collector will take
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
care to free memory it previously occupied. Note that such a technique could not be done with the reliable broadcast implementations, because all algorithms require data structures whose con-tent was required to guarantee correctness. In this case however, just storing the decision (or a flag indicating that the consensus algorithm has dedided) is enough. 5.4.3.6 Evaluation The flooding algorithm for regular consensus ensures that all correct pro-cesses will decide on the same value. It also guarantees all properties of consensus. Termination is guaranteed because each process will progress to the |Π|’th round, unless a decision is reached earlier. At this point, it will decided and hence terminate. Validity is satisfied because the Proposals is only populated with proposals received - and no message is erroneously 92 created on its own. Validity is guaranteed because once Decided is assigned a decision, the predicate in line 48 will never evaluate to true, and hence the algorithm would not decide again. Agreement is guaranteed because in every round a process waits to receive the proposals from all processes. If a process decides, then this means that it has received proposals from all correct processes for two consecutive rounds, at which point it will broad-cast its decision. If two or more processes decide, then their proposal sets should be identical because these would have received proposals from the same processes - and hence should have taken the same decision. In terms of performance, the algorithm will terminate after just one round of execution, if no process crashes. Every process crash, will introduce another round of execution. With respect to the number of messages exchanged, in every round |Π|2 proposal messages are sent. When a decision is reached, another |Π|2 decided messages are transferred. In the worst case, the algo-rithm requires |Π| rounds. 5.4.4 Hierarchical
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Algorithm The previous section outlined a valid algorithm for Regular Consensus . Here another algorithms is presented, which despite having different characteris-tics, still satisfies the Regular Consensus specification. The Hierarchical consensus algorithm, exchanges less messages than the flooding algorithm. However, the decision taken, does not depend on the collective proposals of the participants, but rather, on just the proposal of one participant. The algorithm guarantees that this proposal will be the decision taken by all processes, whatever the other processes may propose. The algorithm works by sequentially ordering all processes. The first pro-cesses in the ordering will have a priority in attempting to impose their pro-posal as a decision - this can be seen as a hierarchy of processes, where the higher up the processes are, the more the chance they have of imposing their proposal on others. The algorithm works in rounds, where in each round a particular process broadcasts its current proposal and locally callbacks the decide() event. Initially the first process in the hierarchy broadcasts its proposal and decides. No other process decides in this round, but as soon as they receive the proposal from the current round leader, they change their internal proposal to the value received from the round leader. A process moves on to the next round, either when it receives the value proposed by 93 the current round leader, or when it detects that the current round leader crashed. The listing in figure 5.7 gives the hierarchical consensus algorithm. Inter-nally every process keeps the current Proposal , as well as the rank of the process which proposed it ( Proposer ). Note that a way to rank processes is assumed, here it is assumed that a rank(Pid) function exists, which returns the rank of the passed PID. The algorithm also keeps an array
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
with the round number as index, and a boolean flag as element, indicating whether the proposal has been received from the corresponding round leader. At every round, the process whose rank is equal to the round number (line 31) is the round leader. The round progresses as soon as the leader process has a value to propose, or crashes. The first leader will send its proposed value to all other processes and decide (lines 32-34). Upon receiving this proposal, the receiver processes, whose rank is higher than that of the leader, may update their Proposal and Proposer values (lines 39-45). This will only happen if the receiver has not yet received a proposal from a node with a higher rank. If the received has already seen a proposal from a process with a higher rank, then it is implied that either the current sender has crashed and the next leader has taken over or that the two proposals are the same - in both cases the proposal received should be ignored. If the proposal from the current round leader has been received, or the current round leader is detected to have crashed, then the algorithm moves on to the next round (lines 36-37). Note that at every round, the round leader will again broadcast its current proposal and callback the decide() event. The reason for each process having to wait for ”its” round to decide, rather than decide() ing immediately after it receives the proposal from the current round leader, is because of failures. This is further highlighted in the run given in figure 5.8. The run in figure 5.8, shows three processes. Note that there is an assumed hierarchical ranking as follows: rank (P1) < rank (P2) < rank (P3). Hence the first round leader is P1. This starts
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
broadcasting its proposal but crashes shortly afterwards. Note that this proposal actually reaches P3 but not P2 (point A). At this point, P3 adopts P1 proposal and moves on to round 2, but does not callback the decide() event. In round 1, process P2 detects that P1 crashed, and so can move on to round 2 as well. In round 2, P2 94 Figure 5.7: The Hierarchical Consensus Algorithm 95 Figure 5.8: A run of the Hierarchical Consensus algorithm with leader failure is the round leader. Since P2 did not receive the proposal from P1, it will decide() and broadcast, its own proposal as a decision. Process P3 receives this proposal at point B, and hence it adopts this new proposal since it comes from a process with a higher ranking than its existing proposal. In round 3, process P3 decides its current proposal, which is the one originating from P2. Hence in this run, P2’s proposal is taken by all correct processes. This shows why all processes need to wait for their round in order to decide() and not decide() as soon as the proposal from the leader is received = as show with process P3.As can be seen from the run in figure 5.8, not all processes are required to propose a value ( P3 does not propose). Essentially, if there is no failure, only the first process in the hierarchy needs to propose, and all the rest will adopt its proposal. If there are failures, then only the originator of the proposal reaching the first non-faulty process in the hierarchy, needs to propose. Notice that the round leader, would propose it current proposal, which it may have adopted from previous round leader, and not the proposal which was triggered by the user of that process. Also note
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
that if the round leader does not yet have a proposed value, then the algorithm will wait for that process to propose() . 5.4.4.1 Erlang Implementation The hierarchical consensus algorithm implementation uses the Erlang mod-ules outlined so far - the main ones being the sets module for the Detected 96 set and array module for the Delivered array. All elements of the Delivered array can be easily initialized to false, given that the array is of fixed size. One notable thing to mention is the implementation of the rank() function itself. In this work, the rank function is passed as a parameter to the init function, in order to allow the user to define his own ranking function. Asimple practical implementation of the ranking function, would be to simply sort the node names given on startup (see appendix A), and give rank each node according to this ordering. 5.4.4.2 Implementation Optimisations The hierarchical consensus algorithm, given here exchanges |Π| messages at every round. However, one should note that when broadcasting the proposal, this can only affect the processes with higher ranks, since the other processes will simply ignore them. Hence, the leader should only send to the proposal to processes with higher ranks , and save on message exchanges. 5.4.4.3 Evaluation The hierarchical consensus algorithm exchanges less messages than the flood-ing algorithm. However, the decision does not depend on the proposals of all the processes, but rather on the proposal of a single process, which imposes this value on all correct processes. In situations where it does make a dif-ference if not all proposals are seen, then this algorithm should be preferred over the flooding algorithm for consensus. The hierarchical consensus algorithm guarantees all properties of regular consensus . It guarantees termination because at every round, a process either receives
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the decision from the current round leader or else detects that this has crashed - either conditions are guaranteed by the eventual delivery of links and the strong completeness property of the failure detector. At this point it moves on to the following round and hence eventually the process will become a leader and the algorithm will terminate. Validity is guaranteed because the decision is always the proposal of the round leader. Integrity is satisfied because a Decided flag is kept to prevent a process from deciding multiple times. Finally, agreement is satisfied, because every process always adopts the decision of its leader and propose this decision - hence all correct processes will decide the same value. 97 In terms of performance evaluation, the algorithm requires |Π| rounds for all processes to decide. Moreover, at each round |Π| proposals are exchanged (assuming the process broadcasts its decision to all processes). # 5.5 Uniform Consensus 5.5.1 Overview The Uniform consensus specification, strengthens the regular consensus spec-ification by ensuring decision agreement amongst all processes. The regular consensus specification allows processes to decide and crash, without being able to propagate their decision - causing the rest of the processes to possibly decide on a different value. The uniform consensus specification prevents this from happening - once a process decides, all processes are guaranteed to decide with that same value, even if there are process failures. 5.5.2 Specification The uniform consensus specification aims to achieve properties similar to those which uniform reliable broadcast brings to regular reliable broadcast .In guarantees that a faulty process could not have taken a decision different from that taken by all correct processes. Uniform consensus replaces the agreement property of regular consensus ,with a stronger agreement ( uniform agreement ) property. The properties guaranteed by: • Termination : There
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
exists a time, at which all correct processes decide some value. • Validity : A decided value must be a proposed value. • Integrity : Processes decide only once. • Uniform Agreement : All processes agree on the same value. 5.5.3 Algorithm The listing in figure ?? , gives a uniform flooding consensus algorithm. This algorithm is based on the floodset algorithm for solving consensus in syn-chronous systems. In particular, it is based on the case where f = |Π| − 1, 98 Figure 5.9: The Uniform Flooding consensus algorithm 99 which would requires |Π| rounds. Conceptually, it can be seen that for a decision to take place, then there can be a maximum of |Π| − 1 failures (oth-erwise there would not be any process left alive to decide). Hence, letting f = |Π| − 1, would ensure that the floodset algorithm handles all possible failures. Moreover, all processes only decide during the final round, at which point it is guaranteed that all processes have an identical Proposals set. At each round, processes exchange their internal proposal sets. After |Π| rounds, all processes will have identical Proposals sets, because there should have been at least one round in which there are no failures and all Proposals sets were exchanged. Hence, at this point all processes will decide the same value - satisfying the uniform agreement property. At each round of the floodset algorithm, every process either receives the proposal set from every other participant, or else the round times out and the algorithm moves on to the following round. In the algorithm for uniform consensus , a failure detector is used to determine whether to wait to receive the proposals from a process or not. Internally, a Correct set is kept with the PID’s of all processes which the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
failure detector does not detect as having failed. Moreover, similar to the floodset algorithm, an array of sets (Delivered ) is kept to store the PID’s of processes from whom the proposals were received at every round (lines 29-31). A process moves on to the following round when it determines that it has received a proposal from all correct processes (line 33). Figure 5.10: A run of the uniform flooding consensus with one pro-cess failure Figure 5.10 gives a run of the algorithm for uniform consensus for three 100 processes. Hence this algorithm requires three rounds to terminate. Process P3 fails in the first round, after that its proposal is only received by P2. In this round, process P2 receives proposals from all processes and hence can move to the next round. Process P1 does not receive a proposal from P2,but detects that it has crashed, and hence can also move to the following round. In the second round, there is no failure and hence all correct processes manage to see the whole set of proposals. Nevertheless, the proposals sets are exchanged another time in round 3. Processes P1 and P2 decide in this final round and can be sure that no faulty process has decided a value different from their decided value. 5.5.4 Erlang Implementation This algorithm was implemented using the framework outlined for imple-menting these algorithms in Erlang. As in other algorithms, all event han-dlers were implemented as gen server cast handlers. The sets module was used for the implementation of the Proposals and Correct sets. The Deliv-ered array was implemented using the Erlang/OTP Array module. It should also be noted that the decision function, which is passed as a parameter to the init event, was implemented as a higher order function. 5.5.5 Implementation Optimizations As a simple
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
memory optimisation, it is noted that the algorithm internally keeps a Delivered set with the PID’s of processes at every round. However, as soon as a process moves on to the following round, it would no longer need this set, and hence could be discarded. Hence, at the beginning of every round, the entry for the Delivered set of the previous round is emptied (set to the atom null), and the Erlang garbage collector will take care of freeing the occupied memory. Moreover, after deciding, the same technique can be done to all the sets used internally by this algorithm. 5.5.6 Evaluation The algorithm for uniform consensus ensures that if a process decides, all other processes will decide with that same value. This is precisely the uni-form agreement property of uniform consensus. This property is satisfied because the algorithm ensures that there is a round in which there are no 101 failures, hence all proposals sets become identical in that round, and hence all processes which decide would decide with the same value. Moreover, this property is only guaranteed with a perfect failure detector . Since the failure detector in this project is not purely perfect, it could be that a pro-cess incorrectly detects another as having failed, and hence does not wait to receive proposals from this supposedly failed process. Even though that in this project, once a process detects another one as having crashed, it sends it a kill message, this message can take a long time to be delivered. If this happens, the process which was supposed to have crashed, can still have time to decide on a different proposal set then the other process’ proposal set. Figure 5.11: Violation of uniform agreement due the weak accuracy of the failure detector The run in figure 5.11 indicates
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the violation of the uniform agreement property due to an inaccurate failure detector. Initially, processes P1 and P2 incorrectly detect one another as having crashed, and send kill messages, which take very long to be delivered (shown by the dashed lines). This causes both processes to move on to the following rounds before waiting for one another. Both processes reach the final round, and decide without having seen each others proposals. Hence, each decide on a different proposal sets, leading to different decisions. This simple example shows the true necessity of a perfect failure detector, because this would not have such accuracy problems. The other properties of uniform consensus are also satisfied by this algo-rithm. Termination is guaranteed because all processes eventually progress from one round to the following because of the eventual delivery of messages or of the detection of processes which have crashed (failure detector com-pleteness . Validty is guaranteed because proposal sets are only populated 102 with actual proposals. Finally, integrity is guaranteed since is a specific check (line 33) to ensure that if the process has already decided, then it would not decide again. In terms of performance evaluation, the algorithm requires a fixed number of rounds. In fact, the best and worst cases of the algorithm are the same (it always requires |Π| rounds. In each round, every process broadcasts to all other processes, hence |Π|2 messages are exchanged in every round. This results in the algorithm exchanging |Π|3 messages in total. # 5.6 Total Order Broadcast 5.6.1 Overview In the previous chapter, different specifications of reliable broadcast pro-tocols were outlined. In this section, another reliable broadcast protocol will be outlined: total order broadcast 2. As its name suggests, this reliable broadcast specification guarantees that all distributed processes deliver all broadcast messages in the same
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
order. Note that such a protocol would be stronger than the causal order specification because it guarantees ordering amongst all messages, not just those which are causally related. Given such a guarantee, this protocol can be very useful when certain non-commutative operations are to be carried out - given a total order broadcast protocol these operations can be globally executed in the same order. 5.6.2 Specification The Total Order Broadcast specification is similar to that of the Regular Re-liable Broadcast but with a global message delivery ordering. In the Regular Reliable Broadcast there existed the possibility that due to the asynchrony of the network, different processes deliver messages in a different order. This situation can be seen in the run in figure 5.12 below. Here, processes P1 and P3 each start a regular reliable broadcast . Focusing on processes P2 and P4, note that due the asynchrony of the network, these processes deliver the messages in different orders. Note also that these broadcasts are not causally related (no other message is exchanged between either node to define such a relation), hence the use of a causal order broadcast protocol would not > 2In certain texts, this protocol is referred to as Atomic Broadcast 103 resolve this problem. Figure 5.12: Violation of total ordering with regular reliable broad-cast due to the asynchrony of the network The Total Order Broadcast specification guarantees a total order property which would ensure the identical order of messages delivered by all processes. The properties satisfied by the total order specification are: • Total Order : For any two messages m1 and m2, if a process delivers m1 before m2, then all other process deliver these messages in that same order. • Validity : If a correct process p broadcasts message m, this eventually gets delivered by
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
all correct processes in the system. • Integrity : For any message m, every process delivers m at most once, and only if it was previously broadcast. • Agreement : All correct processes deliver the same set of broadcast messages. # 5.7 Algorithm The listing in figure 5.13 gives a regular consensus based algorithm for the total order broadcast specification. This algorithm uses both the regular reliable broadcast and regular consensus behaviours. Conceptually the al-gorithm works by first reliably disseminating messages which need to be broadcast. Following this, every process proposes a set of messages, it has 104 Figure 5.13: Total Order Broadcast Algorithm 105 seen, using a regular reliable consensus algorithm. The decision of this al-gorithm, is the set of messages which will be delivered by all processes in the current round. This set is identical for all processes and hence a deter-ministic ordering function on this set will always order the messages in the same way everywhere. Internally, the algorithm keeps two sets Unordered and Delivered . The Un-ordered set is used to hold pending messages in every round, before proposing them using the regular consensus algorithm. Note that a Wait flag is used (lines 31 and 32) to prevent the algorithm from proposing a new set of mes-sages whilst a consensus is taking place. However, during this time period, more messages might be broadcast and hence the need for the Unordered set. When the broadcast event is triggered (line 22), this causes the message to be broadcast using the regular reliable broadcast specification (line 23). This is done so that the rest of the processes will have an undelivered mes-sage in their Unordered set and hence propose their Unordered set. The Unordered set might not be proposed immediately, as explained earlier, but the consensus proposal for the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
current round will eventually be made. At this point, the necessity of executing a consensus might be unclear since messages are being broadcast reliably. However, it must be noted that these messages might arrive in different orders at different processes. Hence these must be ordered in some way or another. This cannot be done unless every process has an identical set on which to apply an ordering function. In order to achieve this set, at the end of the round every process proposes its set using regular consensus .Note that the decision function of this consensus should return a set of messages from the set of all proposed messages. Here the decision function is passed as a parameter to the init event (line 20). A very simple imple-mentation can be to simply return the set of all proposals, however if this is very large, one could consider to just return a subset of all the proposed messages, at a time. As soon as this set is decided, the rc decide event is triggered (line 35). All messages in this set should be included in the Delivered set and removed from the Unordered set to prevent them from being erroneously re-proposed again (lines 36-37). All messages in this set can now be delivered (lines 38-39). It should be noted that here messages are extracted from the Decided set using 106 some deterministic order - hence in the same order at all processes. At this point, the algorithm enters a new round, in which the same operations are carried out again. Figure 5.14: A run of the consensus-based Total Order Broadcast Algorithm Figure 5.14 gives a run of a round of the consensus-based total order broad-cast algorithm. Processes P1 and P3 broadcast messages. The delivery of these messages causes the processes to
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
propose it as a value for consensus. Processes P1 and P2 propose P1’s message since these deliver this message first, whereas process P3 proposes its own message. At this point, the pro-cesses execute a regular consensus algorithm. Note that processes deliver reliable broadcast messages, whilst executing their consensus (example P2 at point A), but such messages do not trigger another proposal event. When the execution of consensus is ready, and a set of messages is de-cided, the message can be deterministically deliver ed in the same order by all processes. # 5.8 Erlang Implementation Implementing this algorithm in Erlang, uses techniques explained for the implementation of algorithms outlined so far. This algorithm uses two be-haviours, defined previously in this work - regular reliable broadcast and regular consensus . The implementation also uses Erlang/OTP sets module for the implementation of the Unordered and Delivered set. The algorithm requires that messages are extracted from the Decided set in a deterministic order. In practice, this is done by converting the Decided set to a list and then sorting this list. In this implementation, messages are 107 sorted in an ascending order depending on their content. This sorting is re-quired because the sets to list/1 function does not guarantee a deterministic ordering. # 5.9 Implementation Optimisations The algorithm maintains a Delivered set of messages to avoid redelivering a message multiple time. This set however grows indefinitely and would require an ever growing amount of memory. In order to relieve this require-ment, it suffices to only store hashes of messages. Hashes can be easily computing in Erlang by using the crypto module. # 5.10 Evaluation The total order broadcast specification provides a reliable broadcast algo-rithm with strict ordering guarantees - every process delivers messages in the same order. This total order property is guaranteed processes
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
use a consensus abstraction to determine the set of messages to deliver at every round, and then use a deterministic function to deliver all messages in this set in the same order. This also guarantees agreement amongst processes on the messages delivered. Validity is guaranteed because every message is first disseminated to all other processes using a regular reliable broadcast (hence all correct processes will see this message). Integrity is guaranteed because processes only propose messages which they receive from on another. With regards to performance, the algorithm exchanges exactly the same number of messages as a those exchange by a reliable broadcast algorithm and a regular consensus algorithm. Hence, in the best case (no failures), it would require |Π| + |Π|2 message exchanges. # 5.11 Conclusion This chapter explored the Consensus class of agreement algorithms. First, the regular reliable consensus specification was outlined. Two algorithms were explained for this specification: the flooding algorithm and hierarchical algorithm. Each of these have different characteristics in terms of the way the decision is made, and also in terms of performance. Following this the 108 uniform consensus specification was outlined. It guarantees that no faulty process decides with a decision different than that of all correct processes. A reliable broadcast specification was also studied: total order broadcast .This broadcast specification guarantees a global ordering of the messages delivered by all processes. A consensus based algorithm for this reliable broadcast specification, was analysed. All the algorithms presented in this chapter, were implemented in the imple-mentation framework outlined for this project. A number of implementation considerations were mentioned, as well as some simple implementation op-timisations. 109 Chapter 6 # Atomic Commit # 6.1 Introduction The last agreement problem to be studied in this work involves is the Atomic Commit problem. The Atomic Commit problem deals
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
in deter-mining whether all processes can carry out a particular operation, or not. If so, all processes would carry out the operation and are said to have com-mitted. If at least on process cannot commit, then the operation should be aborted by all processes. This problem is typically encountered in a distributed database environ-ment, where all processes are required to carry out an operation as a group . If committed, this operation is seen as having been carried out by all processes together, and hence is seen as an atomic operation. This chapter investigates different algorithms for this specification. Var-ious considerations on popular synchronous implementations are outlined. Finally, an asynchronous algorithm is also studied and implemented in Er-lang. # 6.2 Interface The generic interface of the atomic commit algorithms is given below: • External Events Handled – init() Initializes the algorithm 110 – commit() Starts a commit request. • Callbacks Expected – can commit() returns boolean This callback event is used to determine whether the current pro-cess can commit or not. Inside its handler, the process should check whether it can commit and return a boolean, where true indicates that it can commit and false indicates that it cannot. – decide( Value ) where Value ∈ { 0, 1} This callback marks the end of the commit algorithm. The de-cided value indicates the outcome of the commit. If V alue = 1 then the commit action should be carried out, whereas if V alue =0 then the commit should be aborted. # 6.3 Specification An algorithm for the Atomic Commit specification should satisfy the follow-ing properties : • Uniform Agreement : All processes decide take the same decision on whether to commit or abort. • Integrity : If a process decides to abort, it cannot decide to commit later on,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
and vice versa. • Abort Validity : The operation should be aborted only if a process cannot commit or a process crashes. • Commit Validity : The operation can be committed only if all pro-cesses agree to commit and no process crashes. • Termination : All correct processes decide on whether to commit or abort. # 6.4 Synchronous Approaches In the context of synchronous systems, there are two common protocols for solving the atomic commit problem. These are the Two Phase Commit 111 and Three Phase Commit protocols. The Three phase commit protocol is an improvement of the Two Phase Commit problems, since it resolves a blocking issue inherent in the latter protocol. For this reason, the Two Phase commit protocol is referred to as a Blocking protocol, whereas the Three Phase commit protocol is a Non-blocking protocol. Both these algorithms are divided in two roles: the Coordinator role and the Cohort role. The Coordinator is the initiator of the commit request. It acts as a leader of the current commit action and orchestrates actions to the cohorts. The Cohort ’s role is that of checking whether the commit request can be locally carried out or not, and indicating this to the coordinator. It also aborts or commits the action as requested by the coordinator. 6.4.1 Two Phase Commit Algorithm As explained earlier, this algorithm can be separated into two roles. First, the Coordinator role is described. The Coordinator part of the Two Phase commit algorithm is given in the listing in figure 6.1. Figure 6.1: The coordinator’s role in the Two Phase Commit algo-rithm 112 As its name suggests, the actions within the Two Phase commit algorithm can be divided into two consecutive phases. The first phase starts when the commit event is triggered (line 14). In this phase,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
a query to commit message is broadcast to all cohorts. This message indicates that a commit operation is underway and that the cohorts should check whether the commit operation can take place locally or not. The cohorts should then reply with a reply yes or a reply no message indicating that the cohort can carry out the operation or not respectively. As soon as a reply yes message is received, the PID of the sender of such message is included in an internal Replied set. If the coordinator receives a reply yes message from all processes, then it can move to the second phase (lines 20-21). In this phase, the coordinator sends a commit message which instructs the cohorts to actually commit the operation. On the other hand, if the coordinator receives a reply no message (line 23), then the commit operation should be aborted. This is done by sending an abort message to the cohorts, instructing them to discard the commit operation. Note that on line 23, the abort message is sent also if phase 1 timesout. This means, that not all cohorts reply within a fixed time frame, after being sent the can commit message. Such a timeout, in a synchronous system, means that a cohort crashed and hence the commit operation needs to be aborted. The algorithm for the cohort role, corresponds with the messages sent by the algorithm of the coordinator. The Cohort part of the Two Phase Commit algorithm is given in the listing in figure 6.2. Firstly, the algorithm handles the can commit message from the coordina-tor. This message causes the cohort to callback the can commit event (line 27). This event is a check, to ensure whether the commit operation can be done. If the can commit event returns true (the cohort can
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
commit), then a reply yes message is sent, otherwise a reply no message is sent (lines 28-34). In the second phase, the algorithm callbacks decide(1) or decide(0), de-pending on whether a commit or abort messages were received from the coordinator, respectively. Figure 6.3 gives a run of the two phase commit algorithm. Process P1 is the coordinator of the commit operation. It starts by broadcasting the commit message to all processes including itself. The cohorts reply with a 113 Figure 6.2: The cohort role of the two phase commit algorithm Figure 6.3: A run of the Two Phase commit algorithm 114 reply message to the coordinator. The coordinator receives replies from all cohorts at point A, and so the algorithm moves to the second phase. In this phase, assuming that all cohorts could commit, the coordinator broadcasts the commit message which trigger, the decide callback events at all cohorts. 6.4.1.1 Blocking concerns The use of the best effort broadcast raises concerns on the failure resiliency of the algorithm, in particular on the event of coordinator failure in the middle of this broadcast. It can be noticed, that despite the algorithm would not commit or abort the operation, it would block waiting for such messages from the coordinator. In particular, if a process receives a can commit message and is ready to commit, but never receives the commit confirmation message from the coordinator, it cannot decide whether to commit or not. This happens because if it decides to commit, other processes might have received an abort message in the mean time. Conversely, if it decides to abort, then it could be that other processes did actually receive a commit message. This would leave the process waiting blocked without taking any action. The coordinator might recover in the meantime and be able
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
to resolve the issue. If this does not happen, however, the cohorts will remain waiting, whilst possibly holding resources for ever. It should also be noted, that if the best effort broadcast protocol is replaced by a reliable broadcast protocol, then there might still be cases where the cohorts remain blocked. In particular, if the coordinator crashes before send-ing a single commit or abort message, then all cohorts would remain waiting for these messages. Moreover, even if the cohorts are augmented with a failure detector, these would still not be able to avoid these blocking prob-lems, because this cannot provide information as to at what point during its execution, the coordinator actually crashed. 6.4.2 Three Phase Commit Algorithm The Three Phase Commit algorithm extends its two phase counterpart so as to solve the blocking problems. It also replaces the best effort broadcast swith reliable broadcast s as suggested in the previous section. The three phase commit algorithm provides well-defined actions for every possible situation, so that if blocking conditions similar to those of the two phase commit arise, 115 then process would be able to determine what action to take. Figure 6.4: The coordinator role of the Three Phase commit algo-rithm The listing in figure 6.4, gives the coordinator part of the three phase commit algorithm. The first two phase is very much identical to that of the two phase commit algorithm except for the usage of the regular reliable broadcast . Also, another set Ackd is locally kept by the coordinator. This set is used to determine when the coordinator should move on to the third phase. When in the second phase, the coordinator sends out a prepare message. The actual difference between the two phase and three phase commit algo-rithms is this prepare message. Consider a variant of
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the two phase commit 116 algorithm which uses regular reliable broadcast instead of best effort broad-cast . Such a variant would still be incorrect, even if there are strictly defined timing boundaries for the maximum time taken for the reply from the coor-dinator to be received. Note that if the coordinator fails in the middle of the broadcast, but manages to send commit messages to some of the cohorts, then these processes will now relay these messages to all other cohorts. Since for this algorithm, a synchronous system is being assumed, a boundary for receiving a message through a relay process can be established. How-ever, this still does not solve the problem. Considering the case where the coordinator manages to send the commit message to just one cohort process and then crashes, it could happen that this cohort also crashes before relay-ing the message to the other processes. However, it could have managed to commit the action before crashing. Since the only relay process has crashed, the rest of the processes would not be informed to commit, and would re-main blocked. If these decide to abort the operation after that the operation timesout, there would not be agreement with the crashed process (since this actually committed). It is not difficult to see that this is the same prob-lem solved by the Uniform Broadcast protocol. In fact, if a uniform reliable broadcast is used in the two phase commit , the blocking problem would be solved. Essentially, this is what the three phase commit is implicitly doing. The prepare phase serves to turn the broadcast of the commit message, into a uniform broadcast. All processes which receive a prepare message, will ”promise to commit” even if these do not receive any message from the co-ordinator in the third phase. On the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
other hand, if processes do not receive this prepare message, their default action will be to abort the operation. The coordinator waits to receive acknowledges from all processes, and when this happens it moves to the third phase and sends out the commit message (lines 34-35). Note that the coordinator will send abort messages if there is a timeout (coordinator does not receive a reply or acknowledge from a cohort in the second and third phases) or in the case that it receives a negative reply (lines 22-23) in the first phase. Note that in the second phase, cohorts can only send ack messages. Cohorts can only prevent the operation from taking place by sending a no reply in the first phase. If the server does not receive an ack from some process, it times out in phase 2 and sends an abort message (lines 31-32). Hence, once the coordinator is in the second phase, the operation to be committed can 117 only be abort ed if the coordinator does not receive ack from some cohort (is detected to have crashed by the coordinator). If the coordinator crashes without sending out commit messages, the operation will still be committed by all cohorts as soon as the second phase times out. Figure 6.5: The cohort role of the Three phase commit algorithm The listing in figure 6.5, gives the cohort part of the three phase commit algorithm. There is minor difference from the two phase commit algorithm. The difference is the use of the regular reliable broadcast, as explained ear-lier. The cohort processes also send ack messages to the coordinator after receiving the prepare message. Moreover, it should be noted that there are well defined actions to be taken when phase 1 and phase 2 timeout (the next expected message is
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
not re-ceived from the coordinator within some time boundary). In case the cohort timeout while in phase 1 (no prepare or abort message is received from the coordinator), then the operation will be aborted by all cohorts. Conversely, if the cohorts timeout while in phase 2 (no commit or abort message is received from the coordinator), then the operation will committed by all cohorts. This is expressed using phase timeouts on lines 50 and lines 53. A failure free run of the three phase commit algorithm is given in figure 6.6. In this run, process P1 is the coordinator. It starts the commit algorithm by reliably broadcasting the commit message to all cohorts including itself. All cohorts reply with the result of their can commit callback. In phase 2, 118 Figure 6.6: A run of the Three Phase commit algorithm assuming all cohorts agreed to commit, the coordinator sends the prepare message to all cohorts. All cohorts reply with an ack message. At this point, the coordinator moves on to phase 3 and sends commit messages to all cohorts. As soon as the cohorts receive this message, a decide(1) event is triggered. 6.4.2.1 Erlang Implementation Despite that in this project, the focus is on algorithm for the asynchronous model, the Three Phase commit algorithm was implemented due to its widespread usage. The algorithm utilizes the sets module for the internal Replied and Ackd sets. A short clarification might be needed on the implementation of the phase timeouts. In the framework presented for the implementation of these algo-rithms, this can be done by keeping an integer variable in the state, whose value signifies the current phase of the algorithm. As soon as the algorithm enters a new phase, it spawns a process which waits for a fixed time and then casts
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
a message to the local gen server with the value of the phase in which it was triggered. The handler of this cast, would check whether the internal phase is the same as that received in the cast, and if so then the particular timeout action for that phase is carried out. Otherwise, no action is taken. 119 6.4.2.2 Application in Asynchronous Systems As mentioned earlier, both the two phase commit and three phase commit algorithms are relevant for synchronous systems. It is rather easy to show that the three phase commit algorithm will incur problems in asynchronous systems. This is because the phase timeouts cannot be implemented reliably. As an example, in an asynchronous system, since network delivery times are unbounded, some of the cohorts can timeout during a phase (due to network delays), whereas others do not. If this happens in the last phase, when the coordinator sends abort messages, the cohorts which timeout will commit whereas those which manage to receive the abort message, will abort the operation. Surprisingly enough, the two phase commit algorithm, achieves correctness even on an asynchronous system. If the cohorts do not impose any receive timeouts (as in the case presented in this project), then the cohorts might still block (if the coordinator crashes), but still do not break correctness since no arbitrary action is taken - none of the processes decides to commit or abort on its own. For this reason, a number of real world implementations make use of the two phase commit algorithm despite its blocking problems . # 6.5 Asynchronous Consensus Based Algorithm 6.5.1 Overview In the previous section, two algorithms tackling the commit problem in a synchronous environment, were investigated. In this section, an algorithm for asynchronous systems, based on the algorithms in the previous section, is
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
outlined. Similar to the three phase commit algorithm, this algorithm is also non-blocking. The idea behind the algorithm is very similar to a two phase commit algo-rithm, which utilizes a regular reliable broadcast for the first phase and a uniform broadcast for the second phase. This idea has already been outlined in the previous section, and it was noted that this would be identical to a three phase commit . However, this would not suffice for an asynchronous system because if the coordinator crashes in the second phase before sending abort or commit messages, the cohorts cannot determine whether they will 120 ever receive any of these messages, since in such a system there cannot be a phase timeout. Even when their failure detector determines that the coor-dinator crashed, these processes cannot take any action (abort or commit) because any of these messages can be on its way on the network, or relayed from some other process. This problem can be solved by using a uniform consensus in the second phase. The idea is that at this stage every process will propose 0 (if it cannot commit) or 1 (if it can commit), to the uniform consensus . The decision function of this uniform consensus will decide 1, if and only if 0 is not proposed. Once there is a decision, this will indicate whether the processes should commit (decision is 1) or abort (decision is 0). However, it can be noted that this way, a cohort can crash and fail to propose a value to the underlying consensus, and the consensus would still decide 1 (commit). This is because when the uniform consensus algorithm (and any other consensus algorithm) detects a participant failure, it simply does not wait to receive a proposal from that particular participant but still progresses
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
to achieve a decision. In order to resolve this issue, it should be ensured that all cohorts have a value to propose (indicating whether they can commit or not). This can be done by having cohorts broadcast this proposal to one another before actually proposing it to the uniform consensus abstraction. This way, ev-ery process first waits to receive a proposal from all other cohorts before proposing to the consensus . Moreover, if while waiting for proposals, a co-hort detects that another cohort crashed, it would immediately propose 0 to ensure that the commit is aborted. Now that every cohort is waiting to receive a proposal from all other cohorts, the requirement of doing the uniform consensus might be a bit unclear since every cohort would already have all proposals. However, it suffices to notice that whilst one cohort can receive a proposal from all, another cohort might detect that that one cohort failed and not wait for its proposal. Should the decision be taken at this point, the former cohort will commit whilst the latter will abort, violating agreement. This indicates that issuing a uniform consensus is still required. 121 6.5.2 Algorithm The asynchronous algorithm is divided into the coordinator and cohort roles. Nevertheless, the roles are rather blurred because the coordinator no longer has the role of receiving and orchestrating actions to the cohorts, rather the cohorts act in a choreographic and non-blocking manner. In fact, the only distinction between a cohort and a coordinator is that the latter starts the algorithm (performs the first phase of the three phase commit ) but does not wait to receive from the cohort - from this point on its role is identical to that of a cohort. Figure 6.7: The coordinator’s role in the consensus based non-blocking atomic commit algorithm
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
The listing in figure 6.7 gives the coordinator role in this algorithm. Note that this listing also gives the state definition and initialisation of for the whole algorithm. Internally the algorithm keeps two sets, Voted and Correct ,both used by the cohorts. It also keeps a flag indicating whether the cohort has proposed or not. Note also that the uniform consensus algorithm is passed the Min function which returns the smallest element of a set - this will make the consensus always decide 0 if it is proposed, otherwise 1. 122 The only code directly related with the role of the coordinator is the handler of the external commit event (lines 22-23). This simply performs a reliable broadcast to start the commit request, by sending a commit message. Figure 6.8: The cohort’s role in the consensus based non-blocking atomic commit algorithm The listing in figure 6.8 gives the cohort role of this algorithm. Lines 24-31 give the handler of the commit message which is reliably broadcast by the coordinator. This causes the node to callback the can commit event. The can commit callback should check whether the commit operation can take place and return a boolean indicating this result as explained in section 6.2. After that the can commit callback returns, its result should be broadcast to all other participants, to show the other processes that it has a proposal. 123 All cohorts will wait to receive these proposals from each other. As soon as this proposal is received, its sender is added to the Voted set (line 39). If the proposal received is 0, indicating a request to abort, then the process does not need to wait for further proposals but can immediately propose 0 to the uniform consensus - because the commit should be aborted (lines 35-37). If
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
a proposal to commit (with value 1) is received from all correct processes, and no process has been detected to have failed, then the process will de-duce that the operation can be committed, and propose 1 to the uniform consensus abstraction. Otherwise, if some process is detected to have failed, then it will propose 0 to the underlying uniform consensus (lines 43-51). When the uniform consensus decides with a value, that value is the decision of the commit. This value is returned directly by the decide callback of the commit operation. Figure 6.9: A run of the non-blocking consensus based algorithm of the Atomic Commit specification Figure 6.9 gives a run of the consensus based non-blocking atomic commit algorithm. This run consists of three processes, where P1 is the coordinator. Initially P1 starts starts a commit request by reliably broadcasting the com-mit message to all processes. When this message is delivered, each process callbacks the can commit event and broadcasts its result through a best effort broadcast abstraction. As soon as each process receives these results from all processes, it will propose a value to the uniform consensus abstraction. This happens at points A, B and C for processes P1, P2 and P3 respectively. At this point, the processes propose their value to the Uniform Consen-sus abstraction, which eventually decides whether the operation should be committed or aborted. 124 6.5.3 Erlang Implementation The consensus based algorithm for non-blocking atomic commit was im-plemented in Erlang using the techniques outlined throughout this project. The framework outlined for implementing these event based algorithms, was used. The sets module was used to implement the Correct and Voted sets. The algorithms previously implemented were reused trough the use of Erlang behaviours. 6.5.4 Evaluation The consensus-based non-blocking atomic commit algorithm provides a de-centralized approach towards the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
non-blocking atomic commit specification. It satisfies the properties of the non-blocking atomic commit specification and guarantees that either all processes commit or abort the operation. It guarantees uniform agreement due to the underlying use of the uniform consensus abstraction.It guarantees abort-validity because all processes first wait to receive the result of the can commit callback from each other. It pro-poses 0 as soon as it detects a failure or receives 0. The usage of the Min as a decision function ensures that if 0 is proposed, it will be the decided value. This decision function also guarantees commit-validity . Termination is guar-anteed because whilst waiting, eventually processes are either detected as having failed (due to the completeness property of the failure detector) or their proposal is received. The uniform consensus abstraction also guaran-tees termination hence its usage would not violate the specified termination property. Finally, integrity is guaranteed also due to the integrity property of the uniform consensus abstraction. In terms of performance evaluation, the algorithm can be split into three parts. First, the transmission of the commit message requires the usage of a regular reliable broadcast algorithm. In the best case, this requires |Π| message exchanges and |Π|2 in the worst case. Then each process broad-casts using best effort broadcast . This requires |Π|2 message exchanges in all. Finally, the uniform consensus algorithm is used which requires |Π|3 message exchanges. Hence, despite providing some strong guarantees, this algorithm is rather expensive in terms of message exchanges. Due to the ini-tial broadcasts, it also requires at least two more steps than the |Π| rounds required by the uniform consensus .125 6.6 Conclusion In this chapter, the Atomic Commit specification was investigated. First an analysis of the algorithms tackling this problem in an asynchronous en-vironment, was done. First the two phase
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
commit algorithm was studied, and its problems were outlined. Following this the three phase commit algo-rithms was also investigated. Finally, an asynchronous algorithm for Atomic Commit was studied. This algorithm is based on the uniform consensus specification. These algorithms were implemented using the implementation framework outlined for this project. The intricacies as well as problems of some of these algorithms, were outlined. Moreover, any special implementation techniques were also described in this chapter. 126 Chapter 7 # Testing and Case-Study # 7.1 Introduction The last three chapters outlined three different classes of distributed agree-ments, and assessed various specifications for each class. Algorithms for each of these specifications were described and implemented using the im-plementation framework outlined earlier. These implemented algorithms form a suite of Erlang modules, in the form of behaviours, which are readily accessible for any distributed application requiring these algorithms. This chapter will study the testing strategy taken for this project. Testing consists of different phases, each of which will be explained here. In the second part of this chapter, a simple test scenario is outlined. The overall layout of this case-study and, in particular, the usage of the suite of protocols implemented here, is explained. This usage is then evaluated in the following chapter. # 7.2 Testing Throughout the development of any application, testing is a crucial activ-ity for ensuring the quality and correctness of the system being developed. Ideally, testing is well planned and a systematic approach towards system testing is devised. This section will outline the testing approach followed and explain how it was carried out during the implementation of this project. 127 7.2.1 Test Strategy In this project, a bottom-up testing approach was followed. Tests were carried out alongside the programming itself. A bottom up strategy starts with testing the individual components of a
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
system and then test at higher levels of abstraction. This approach was taken, so as to be able to carry out the testing of the system in parallel with the coding of the algorithms. In the context of this project, three levels of testing were performed. These are: 1. Function Testing : The testing of individual functions on their own 2. Module Testing : Testing a group of functions which together form a module 3. System Testing : Testing the distributed system together. In order to carry out these tests, different tools and techniques were used. The following sections explain these techniques in more detail and present examples of how this testing was carried out. 7.2.2 Function Testing Function testing encapsulates all tests which are done to assess the robust-ness of individual functions. In general, sometimes this involves testing a group of two or three functions together due to their cohesive nature, how-ever, these functions together do not achieve some practical distinct task which deserves its own module. Rather, function testing should ensure that every function gives the desired results with all possibilities of input. In this project, function testing was done in two ways. Firstly, the most trivial form of function testing are tests performed ”by hand” immediately after writing a function. Such ad-hoc tests have low coverage and are not really structured, however, these do test that the function works at least works for certain forms of data. Such tests are carried out by directly in-voking the function from the shell and testing it with different parameters and their expected outcome. The second form of function testing was done using Quickcheck. Quickcheck is a tool devised to test Erlang code. It provides different tools for different types of tests. For function testing the generator tool ( eqc gen
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
) was used. 128 This is a tool which automatically generates a large number of testcases, and ensures that the function obeys a particular property. For example, an eqc gen with a property for testing the conversion of a list to a set, might look like: ?FORALL({Values}), {list(char())}, sets:from_list(Values) == sets:from_list(reverse(Values)). This example, creates a generator of string Values which comes up with various different strings, focusing on boundary cases ( [ ?]). For each case, it checks that the conversion of a string to a set of characters, will give the same set as when the reversed string is converted. Quickcheck will attempt to find a counter example for which this property does not hold. When a counter example is found, it will be reported to the user. However, Quickcheck does not stop here. It will attempt to minimize the counter example, so that the user will be able to track where the error lies. The test specified above, was actually devised for this project. Surprisingly enough, this property is not guaranteed by the sets module - ordering affects set equality. Quickcheck provided the following counter example: sets:from_list([a,q]) /= sets:from_list(reverese[a,q]) A question about this problem was asked on the well known trapexit.com Erlang forum, and the workaround suggested was used. It turns out that the sets module uses a balancing structure which is affected by the order in which elements are added. Hence, equality cannot be checked using the == operator, but rather through the use of other function calls provided by the sets module. The eqc gen test might seem limited to functions about which one can ex-press some form of property. However, to test a function f , one can use a property like f (V alues ) == f (V alues ) to ensure that the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
function does not trigger an exception for all the Values generated by this Quickcheck tool. This way, all tests will still run, and if an exception is triggered, it will be reported. Throughout testing, another tool which was widely used was the Erlang debugger. The Erlang development suite comes with a fully flushed debugger 129 which provides all functionality typically offered by such debuggers, such as single stepping through code, breakpoints and variable inspection. Though this is not a testing technique, this debugger did help a lot tracking down problematic code after function testing, and hence deserved a mention! 7.2.3 Module Testing A group of function which together perform some specific task, are usually grouped into a module. In this project, every algorithm was written in a separate module, hence, throughout this project, module testing actually tested the functionality of a complete algorithm. For this form of testing, Quickcheck was again rather crucial. However this time, another tool offer by Quickcheck, was used: the eqc statem tool. This tool tests Erlang processes which internally maintain a state - as is being done by the gen server of every algorithm. With this tool, a simple state machine is defined to express the behaviour of the process. For example, here a state machine to model the behaviour of the gen server process handling regular reliable broadcasts is given. First, the state of the process will be defined. This state need not be the complete state stored by the process being tested, but just the part which needs to be tested. For this example the state will consist of simply the Correct set, which holds the PID’s of all correct processes. The state machine will invoke the broadcast and crash functions with different interleavings, whilst ensuring the correctness of the process. The state
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
definition and initial states are given below: -record(state, {correct}). ... initial_state() -> #state{correct=node_utils:get_all_peers() }. This code will initialise the first Correct set as having a list with the PID’s of all nodes. Following this, the state transitions are defined: next_state(S, _, {call, r_rb, broadcast,[Data]}) -> S; next_state(S, _, {call, r_rb, crash, [Pid]} ) -> 130 S#state{ correct = lists:delete(Pid, S#state.correct) }. This next state function defines two transitions, one which takes place when the broadcast function is invoked, whilst the other takes place when the crash function is invoked. The first clause of the next state function defines the effect of the broadcast function call on the internal state of eqc statem . The first parameter, S, is the current state. The second parameter is not needed (it holds the return value of the call in the third parameter). The third parameter is a tuple indicating that a call is to be made. The tuple consists of the atom call , the module, function name and a list of arguments to the function. Thus, this transition is taken when r rb:broadcast(Data) is called. Note that this function simply returns the state passed, indicating that this call does not affect the internal testing state. The second clause gives the state transition to be taken when a call to crash is made. This call does affect the internal state - if a call to crash is made, the PID of the process which crashed is removed from the internal list of PID’s. At this point, the internal state and how different calls will affect this state, have been defined. What remains is to create a test case generator. This is done by specifying what commands (functions) eqc statem can invoke. These commands are specified by defining the command function. A sample command
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
function definition is given below: command{S)-> oneof( [{call, r_rb, broadcast, [random_string()]}, {call, r_rb, crash, [random_element(S#state.correct)]}]). The command function indicates that the issued test commands should be one of those specified in the list passed to the oneof function. This list specifies the two commands which can be invoked: broadcast and crash .Note that in this definition, generators for the parameters are defined. The random string function should generate random string which are passed as parameters to the broadcast function. The crash function is passed a random element from the list of PID’s in the state. These snippets are an example of the usage of the eqc statem tool for mod-ule testing in this project. Quickcheck’s eqc statem tool provides an effective means by which to test the stateful nature of the various algorithms imple-mented in this project. Whenever a particular sequence of calls triggers and 131 exception, this is reported. Quickcheck will also attempt to ”shrink” this sequence of calls, further simplifying the task of tracing the error itself. 7.2.4 System Testing System testing attempts to verify the correctness of the complete suite of algorithms implemented here. Though the module tests did at times involve a number of modules, since certain modules cannot operate without others, system testing tests the complete system of modules altogether. The system of processes used for the algorithms here were first tested in a localised environment (on the same machine). In Erlang, code can be written in a way so that is requires minimal change when deployed on a localized or distributed environment. This can be achieved because Erlang’s PID’s hold information about the node where the process is located. If the global module is used, almost no code change would be required, because processes can be reference by using globally (anywhere in the whole
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
distributed system) registered names. Hence, following this localized approach, the system was tested in real dis-tributed environment. The deployment in a distributed system, makes the system prone to different forms of failures which are not present in a localised environment. Throughout testing, since crash-failures were assumed, a node failure could be simulated by simply closing the Erlang shell for the system of processes on that node. Nevertheless, with such an approach, certain con-ditions could be very difficult to be simulated. For example, the algorithm for regular reliable broadcast should ensure, that if a sender crashed after broadcasting to just one of its peers, that peer should be able to relay the message to all other processes, when it detects that the sender crashed. Crashing the sender exactly after sending to only one other process is rather difficult to do . Thus, for the purpose of testing, a number of delays were inserted into such points in code. For example, a delay was inserted after sending a message to a process. This gives time to close the shell of the sender, exactly after having sent to just one process. Finally, testing and debugging a system which is composed of remotely lo-cated machines, can require a rather strenuous effort to keep hold of the data being output on the different locations. However, the node diag mod-ule, provides a means by which to start distributed nodes from one shell 132 (refer appendix A). This is achieved through the use of Erlang’s rpc mod-ule. A particular characteristic of Erlang, is that a process which is created remotely, will have its standard output automatically redirected to the re-mote shell from where it was created (from where the rpc was issued). This provides a centralized way to ”debug” distributed processes. This way, the debug data output
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
by remote processes will all be sent to the shell which started them (which is referred to as the ”monitor shell”). When outputting debug data, every process precedes this data with the name of the node from were it is originating, so that one can keep track from where the debug data on the monitor shell, is originating. 7.2.5 Conclusion This section outlined the testing approach taken throughout this project. Moreover, the various tools and techniques used, which helped in testing and debugging, were outlined. The next section will outline the design of a real-world application for the algorithms implemented. Apart from serving as a test case for a number of the algorithms implemented, it will help to first handedly assess the benefits achieved from utilizing the implemented distributed protocol suite. # 7.3 Case-Study 7.3.1 Overview In the Background chapter, various examples usages of the agreement al-gorithms implemented here, were presented. Here, the basic semantics of the serverless distributed file system p2pfs were informally described. In this section, this example will be studied in detail, and an implementation making use of the protocol suite implemented for this project, is described. 7.3.2 Description of the p2pfs filesystem p2pfs is a distributed file system with fault tolerant characteristics. p2pfs operates in a peer-to-peer basis, where every distributed node coordinates with others to ensure that the local view of the filesystem is consistent with that of the other nodes. This file system is assumed to operate in a sys-tem model identical to that assumed for the development of the agreement 133 algorithms implemented in this project. It works in an asynchronous envi-ronment and assumes fail-stop node failures - this implementation will focus on the graceful degradation as different nodes fail. For simplicity’s sake, this file system is assumed to consist of just one
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
root directory with no subdirectories. Files can be created, accessed and deleted from within this directory and all these changes should be reflected on all participating nodes. A filesystem, typically handles a number of calls which are issued by the operating system. The filesystem implemented here will only handle a small subset of these calls. The calls handled by the filesystem implemented here are: 1. open This is a call to open a file. It is issued by a process which needs to access a file, before performing any reading or writing of the file. 2. read This call reads data from the file. 3. write This call writes data to the file. All data written should be reflected at all distributed nodes. 4. close Closes the file, and terminates the current access to a file. 5. unlink Deletes a file from the filesystem. The file should be deleted from all nodes, if not currently open by some node. 6. mount Mounts the file system at a particular directory (called operating direc-tory ). If before mounting, this directory contains existing files, these will be sent to all other nodes. 7.3.3 Assumptions and Considerations Prior to implementation, a number of issues regarding the semantics of the proposed filesystem, had to be taken into consideration. Moreover, to sim-plify this test-case, a number of assumptions also had to be made. 134 Firstly, one should note that when mount ing the file system, different nodes may have files with the same name already present in their operating direc-tory. According to the semantics outlined above, these files should be sent to all other nodes. However, since there cannot be two files with the same name in the same directory, only one version of the file is to be kept. How-ever, care should be taken to
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
ensure that all nodes keep the same version of the file. So as to ensure this, it is assumed that the most recent version of the file should be kept. Note that though the clocks of the nodes are not assumed to be synchronized, this would still ensure that the same version of the file is kept by all nodes. In the rare case that two files have the same timestamp, the file whose md5 hash is greater than the other, is kept. In practice, first a call to mount is made, specifying the directory where the file system should be mounted. Following this, any of the other operations may be requested. However, it is assumed that the filesystem is first mounted at all nodes, before any of the other operations are issued. It should also be noted that due to the nature of the test-case, a number of race conditions could arise. For example, if a node issues a read on a file, does some other work, and then issues another read on the same file, it could be that data was written to the file in the meantime. This would lead to the second call to be reading from a different version of the file. This situation also happens in a localized file system, if two processes open the same file and save at different times, these would be overwriting eachother’s work. This can be solved by using file locks, however for this scenario, this would result in distributed file locks. These are beyond the scope of this work, and are not implemented. Finally, it should be noted that the operating system may issue two or more concurrent calls to the file system. Since these two calls could be possibly operating on the same file, if a write
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
occurs whiilst a read is taking place, this could cause the read to return inconsistent data (data from two versions). For this reason, though the operating system may issue concurrent calls, these calls are serialized by the filesystem and handled one after the other. This would ensure that one read, would always return data from one consistent version of the file. 135 Figure 7.1: Organisational Layout of the Test Case 136 7.4 Implementation The organisational layout for the implementation of the proposed test case, is given in figure 7.1. It shows the interaction of different processes and components, all of which will be explained in more detail in this section. At the topmost level, is the Operating System. This is the ”User’s View” of the filesystem, where files are created, accessed and deleted using application software such as text editors, image editors and so on. Whenever each of these software applications access any of the files in the filesystem, this triggers a system call which typically handles the call being requested (such as reading and writing). Our testcase application needs to be able to capture such requests and handles them - example when a write is done, this is sent to all other nodes. However, these calls are handled by the kernel level and hence it is typically very difficult to program a filesystem from scratch. For this purpose, FUSE was used. FUSE (File System in Userspace) inter-cepts the file system operations and lets them be handled by specially pro-grammed application (the FUSE process ). In this test-case, this is exactly what is needed, since operations such as writing to a file, will be intercepted and broadcast to all other nodes. Hence the FUSE process will have handlers for the file system calls specified. The problem is that the FUSE
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
process has to be written in C, not in Erlang. However, Erlang has a mechanism by which to interface to external pro-grams. This is called the Ports Interface , which allows data to be sent and received to and from an external program. The external application needs to encode this data in a special way (which is done by C libraries which come with Erlang). The Ports Interface process will then decode this data and take the necessary actions. In this case, the external application with which the Erlang code is going to be interfacing with, is the FUSE Process .The FUSE Process will send information about the operation requested by the Operating System, to the Ports Interface process .The Ports Interface process will decode this information, and pass the re-quested call to the Filesystem Handler Erlang process. The Filesystem Han-dler is a process which receives external calls and handles them sequentially. It is based on the gen server behaviour, with which was used extensively in this project. Hence, for example, when the Port Interface makes a call to the Filesystem Handler process, to indicate that a write was made, the 137 latter will broadcast this write to the other nodes. the Filesystem Handler process will make direct use of the distributed agree-ment protocol suite implemented for this project. It will trigger events and handle the callback events of the distributed agreement protocol suite. As an example, when the operating system writes to a file, a broadcast event should be triggered. On the other hand, when some other node writes to a file, this node will receive a write message from that other node through the deliver callback of the broadcast mechanism being used. The callbacks will indicate that the current node should update its view of the filesystem. In
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
this filesystem, such updates can be reduced to deleting a file and writing data to a file. Both the deletion and writing data to a local file, can be handled from within an Erlang shell, through the use of the files OTP module. In reality, not all file system operations require interaction with other nodes. Some of the operations only require a local action. These operations can be handled solely by the fuse process process. The table in figure 7.2, gives the actions required to be taken by the FUSE process and filesystem handler ,for all the filesystem calls. Figure 7.2: Actions to be taken for all filesystem operations As can be seen from the table in figure 7.2, the mount operation requires the FUSE process to perform some initialisation to start the file system. This is a standard initialisation required by all FUSE filesystems. As mentioned, the FUSE process will notify the filesystem handler about this mount. Moreover, it has been outlined, that initially any files already present in the Operating Directory , need to be sent to all other nodes. Moreover, there was the issue of identical filenames, which needed to be solved by keeping the versions which have the latest timestamp. Hence, the filesystem handler needs to 138 use a regular flooding consensus in order to decide which files to use. Thus, as an action for the mount call, this process proposes all the filenames, file contents and timestamps (as three lists). A flooding consensus is required, because all files need to be seen before taking a decision. The decision function should choose the files which have the latest timestamp. As can be seen in figure 7.2, the open , read and close events do not require any action to be taken by the filesystem handler process.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
In fact, these can invoke the usual calls for carrying these operations locally. As has been mentioned, the write call needs to be handled by some form of reliable broadcast. It could be noted, that unless a total ordering is ensured, different nodes will possibly end with different versions of the file, after that all operations have completed. Hence, a total order broadcast algorithm will be used for broadcasting the filename and data which needs to be written at a particular offset. When this message is delivered by a remote node, it will write this data to the specified file, at the specified offset. Finally the last operation is the file deletion or the unlink call. This requires to first check that the file is not open by all nodes, and if so, deleted from all nodes. If however, the file is open at some node, the delete operation should not be carried out by any node. Such an operation can be easily solved through an atomic commit. Hence, the filesystem handler issues an call to a consensus based non-blocking atomic commit . The can commit callback event will check whether the file is open at that node, and if the file is not open, then the file will be deleted. Figure 7.3: Action taken for callbacks triggered by protocol suite The table in figure 7.3 gives the actions to be carried out for every callback event received by the filesystem handler process. The first callback, the rc decide is invoked when the run of regular consensus chooses a list of initial filenames and their content. These files should be written into the 139 operating folder. The to deliver callback indicates that some other node has issued a write on a file. Hence the action for this callback is to
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
write the data, at the specified offest into the requested file. The last two callbacks, can commit and decide deal with the consensus based commit issued to determine whether a file can be deleted or not. The handler of the can commit callback, should check whether the file is open by the local node and return a boolean indicating whether it is open or not. The decide callback will indicate whether the file should be deleted - a value of 1 indicates that the file should be deleted. This way, the test case scenario can be built. This case study involves various components, but these all revolve around the distributed agreement protocol suite implemented in this project. # 7.5 Conclusion This chapter presented different ways for assessing the distributed agreement protocol suite. In the first part, different types of testing done throughout development, were outlined. In the second part, a real world test envi-ronment, involving a serverless distributed filesystem, was described and implemented. 140 Chapter 8 # Evaluation # 8.1 Overview This chapters attempts to assess various aspects of this project. The im-plementation of the testcase scenario, gives an insight on the applicability of the distributed suite of agreement protocols. This chapter attempts to outline most of these considerations. The benefits and challenges faced are evaluated and the applicability and usability of the distributed agreement protocols is investigated. Their actual benefit for distributed programming is also analysed. # 8.2 Benefits Achieved The distributed agreement protocol suite, played a major role in the devel-opment of the filesystem. Approaching the development of the filesystem, with this library at hand, provides various advantages to having to build everything from scratch. 8.2.1 Separation of Concerns This project involved analyzing commonly encountered distributed comput-ing problems. These problem are widely known and have already been studied
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
extensively. The solutions to these problems, however, are rather intricate and require a deep understanding of the difficulties which arise when attempting to give solutions to these problems. Primarily, alterna-tive approached to solving distributed agreement problems are analysed. 141 This project pinpoints these problems by giving counter-examples of runs which would cause the ultimate goal not be reached (example not achieving agreement in a run of consensus) and leave the system in an inconsistent state. It could be noted, that these intricacies are sometimes rather subtle to note, because of the complicate sequence of events which trigger them, yet when they occur they could cause different kinds of problems. Doing distributed programming requires a clear understanding of the application domain and of the intricacies associated with distributed systems. The for-mer will change from application to application, but the latter are common to all forms of distributed systems. The protocol suite implemented in this work, relieves the programmer from having to deal with these distributed system caveats. Whilst the programmer concentrates on the application logic, he would utilize the adequate algorithms from the suite, which un-seeingly handle the intricacies incurred. At run time, the algorithms in the implemented protocol suite, act as orchestrators for the application code triggering parts of the users code at designated points in the algorithm. 8.2.2 Shorten development time Utilizing this library, first of all helped developing this application in frac-tion of the time, had it not been available. Coming up with fault tolerant code, is rather hard since one generally needs to cater for a large number of possible interleavings. This makes coding such systems rather hard and non-straight forward. Having this protocol suite readily available for the development of the filesystem, helped in modelling the system in terms of the functionality provided by this suite.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
This relieves having to devise the distributed agreement algorithms themselves, but rather the programmer focuses on writing interfacing codes (or wrappers) for triggering events in the existing algorithms and handling events these callback. 8.2.3 Structured Code This suite of distributed protocols also provides fault tolerant guarantees. Attempting to achieve these fault tolerant characteristics without this suite, would have required us to constantly issuing to write checks to ensure that a consistent state has been maintained after every operation. Undoubtedly, there is a high possibility of these checks not being correct, in that these do 142 not cater for all the exceptional cases. But apart from this, the code would lack clarity and be less structured. This is because, ”traditional” techniques for checking whether a call has succeeded would need to taken. For example, the typical approach is to wrap every call which attempts to receive from the network, with timeouts. Moreover, all functions which attempt to send, will need to incorporate some logic to ensure that this sending completed successfully. Having all this code, interspersed with the application logic code, makes the latter less and less easy to follow. In the code written for the filesystem testcase, no concern had to be ex-pressed about node failures. On the contrary, the distributed algorithms in the suite handle failures on their own. For example, the application code always issues a broadcast in the same way, despite the number of failed or correct nodes - it is the internal code of the broadcast algorithm, which handles sending to just the correct nodes. 8.2.4 Agreement Algorithm Abstractions Moreover, the concept of abstraction applies when using these algorithms. A programmer using these algorithm does not need to know how these work internally, and all the intricacies these try to address. However, had the filesystem been
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
built from scratch, the programmer would have needed to understand these problems in their totality, and make sure that all effects are catered for. However, with this suite of algorithms, it suffices for the programmer to simply know the basic semantics of the algorithm and its interface, in order to produce a correct piece of code. 8.2.5 Code Reuse The suite of algorithms aids in putting code reuse to practice. When devel-oping a distributed application with such a suite of algorithm, reusing the existing algorithm helps in reducing the size of the code and making it more maintainable. Code reuse is also a key aspect within the coding of the suite itself - most algorithms make use of one another, and various Erlang/OTP module are also used. 143 8.2.6 Simplifies testing The development of code with this suite, also helped reduce on testing. Test-ing distributed code also poses a challenge and requires careful planning and analysis. Using a library which has been already rigorously tested, definitely gives an advantage over writing all distributed agreement algorithms from scratch, and having to test these algorithms as well. Such a suite will help reduce the amount of bugs and hence also reduce the time taken to track down and fix these bugs. 8.2.7 Conclusion Finally, it should be noted that thought the programmer does not need the internal details, he need to be very well acquainted with the properties of these algorithms. Moreover, just because a reliable algorithm is used, it does not mean that the application using it will automatically inherit all its prop-erties. The actions done by the application code itself, also play a great role in the final properties of the application. However, ultimately, it should be noted that given that care is taken to choose the right abstraction, and
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
that all interactions with other node, is made through these abstractions, then the final code will be much easier to write, whilst providing the correctness ensured by the underlying algorithm. # 8.3 Assessing the Implementation Framework In this project, an implementation framework was devised - in which all agreement algorithms were then implemented. This framework provides a common ground for developing all agreement algorithm in Erlang. Here the effectiveness of this framework is evaluated, with respect to implementing the standard algorithm into this framework. 8.3.1 Bridging Theory and Practice This framework provides a standard way by which to implement algorithm which are rather theoretical. For example, these algorithms expect the ex-istence of a perfect failure detector to guarantee correctness. Part of this framework, consisted of extending Erlang’s built-in failure detection mecha-nism to match the properties of the failure detector expected here, as much 144 as possible. Moreover, through the use of the gen server , it provides ways by which to give event-like semantics to all calls - where function are handled sequentially. Another example, is of the standard way to implement the predicate triggered events. 8.3.2 Code Reuse This framework makes the implemented algorithms easily reusable. Each algorithm has a well defined interface by which its functionality can be ac-cessed. The callbacks of every algorithms are specified in the form of Erlang behaviours, hence the user is allowed to input ”custom” code into the al-gorithm, whilst reusing the existing code of the algorithm itself. Moreover, internally these algorithms also make use of one another through this tech-nique of behaviours. 8.3.3 Structured and Maintainable Code All algorithms implemented have a similar structure. This makes it easier to understand and follow the code. Moreover, internally these algorithms are modelled in the form of gen server behaviours. Apart that, the gen server
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
provided part of the implementation semantics required, it also is a very commonly used and well documented Erlang behaviour. Hence this makes the code more structured and more maintainable. # 8.4 Evaluating the usage of Erlang Having implementing this suite of algorithms in Erlang, the applicability of Erlang can be evaluated from a better standpoint. In this section, a ”post-mortem” analysis of the relevance of Erlang and the benefits it provided, is presented. Firstly the Erlang’s support for both localized (concurrent) and distributed programming should be mentioned. This helped structure the testing of this project. The algorithms implemented, were first tested locally and then eventually in a distributed environment, with minimal code change. This project really availed itself of the OTP libraries which come with Er-lang. As explained, all the algorithms used various of built in modules for some data structure - such as the sets , Array and Dict . Moreover, Erlang also 145 provides various libraries which facilitate distributed programming such as the global module (for distributed process name registration). Furthermore, the implementation of the algorithms in this project, also make extensive use of the gen server behaviour. Of course, similar libraries could be written (or used if they already exist) in other programming languages. However, given that all these are standard modules in Erlang, these would help in making the code more maintainable and facilitates future modifications. Certain aspects of the Erlang syntax were found very helpful during the implementation of this project. For example, Erlang abstracts from the ”complexities” associated with distributed communication such as byte or-dering, marshalling and . In fact, the communication constructs are as simple as those found in pseudo-code, or in process calculi. One aspect which was not really felt, was the significance of the single assignment, with regards to producing correct
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
code. It is claimed that this helps tracking down bugs, because only a single action could have assigned a value to a variable . However, this particular benefits was not really felt. Furthermore, this made the code rather obscure at time. For example, figure 8.1a gives a line taken from the flooding consensus algorithm, as presented here. Its actual implementation in erlang (figure 8.1b), takes three lines, and is much less readable. Figure 8.1: a) line 29 of the flooding consensus algorithm. b) Its actual implementation in Erlang Erlang’s pattern matching feature, was used extensively. For example, all handle casts make use of pattern matching for to choose which handler to invoke for each particular message type. Together with pattern matching, guards were also occasionally used. These two constructs really did help improving the readability of code. Another effective feature of functional programming used throughout this 146 project are Higher Order Functions. These were used for the decision func-tion of consensus algorithms. Finally, the lack of strict typing in Erlang, was also seen as an advantage in itself. This is because it provides a means by which to write generic functions which are not bound to a particular data type. So for example, once a broadcast function was written, this would work with any form of data be it numeric, a list or even a high order function. # 8.5 How practical are the algorithms? All the algorithms implemented here are based on theoretical algorithms -each utilizing some various forms of mathematical constructs which might require extra work to be implemented using the tools provided in conven-tional programming languages. With Erlang being a functional language, this work is reduced significantly since it provides native and library con-structs to implement mathematical constructs such as sets, maps and the notion of higher
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
order functions. It also provides theory-like abstractions for distributed communication such as simple communication primitives, and process labelling. All this reduces the leap required from theory to practice. Nevertheless, in theory usually one tends to prioritize correctness before performance requirements concerns. Whilst it is true that Premature opti-mization is the root of all evil (Donald Knuth), a correct algorithm which requires an unreasonable amount of memory to operate, exchanges enough messages to hog most networks and takes forever to complete, is very much likely to be scrapped in real life. 8.5.1 Network Requirement Here it is important to distinguish between worst case scenarios and normal or real world scenarios. Starting from broadcast algorithms, we see that most algorithms require from |Π| to |Π|2 message exchanges. The lazy broadcast algorithm for Regular Reliable Broadcast, has a best case which is the lower bound for broadcast algorithms, |Π|. Its worst case scenario is when all process fail in sequence (very rare in practice) and would now require |Π|2 message exchanges. It is noted the properties of the broadcast algorithm 147 are strengthened, the amount of messages required increase. This is, in fact, what happens in the case of the All-Ack algorithm for the Uniform Broadcast abstraction which suddenly has an average of |Π| message exchanges the price for strengthening the agreement from just between correct process to all participants (both correct and faulty). Similar behaviour can be seen also with the consensus algorithms. In the case of Regular Consensus, three algorithms were presented, each having their own characteristics and network requirements. The flooding algorithm is the most network demanding (requiring 2 |Π|2| message exchanges in a run without failures), but in turn, is the only one in which the decision depends on all proposals. The Hierarchical consensus algorithm, reduces the number of
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
messages exchanges of the flooding consensus algorithm by half, however the decision is imposed by one of the participants without considering all other proposals first. The algorithm for the total order broadcast uses an existing regular consen-sus algorithm and a regular reliable broadcast algorithm. Thus, consensus-based algorithm for the total order broadcast exchanges all the messages exchanged by these underlying algorithms, as well as its own set of mes-sages (which turn out to be |Π|). Similarly, the consensus based algorithm for the non-blocking atomic commit, utilizes a uniform consensus algorithm. Hence, this algorithm ultimately exchanges all the messages exchanged by the uniform consensus algorithm, as well as another |Π2| messages. This highlights the importance, that in practice one should choose the just right protocol, and not use anything stronger than required. This is because, whilst not affecting correctness, it would introduce unnecessary overheads, which apart from increasing the network requirement, also affect the runtime performance of the algorithm. So far, the primary network requirement concern has been the amount of message exchanges. The actual size of the message was always dependent, for the most part, on the size of the data being broadcasted by the user. How-ever, the Causal Order Broadcast algorithm also leaves one pondering about the actual size of the messages exchanged. Without any optimisations, as time progressed, this algorithm transferred message of ever increasing sizes. In this case, these ever growing messages were catered for, by using a garbage collection scheme to start pruning content of the messages exchanged. How-ever, as noted, this is mechanism introduces new message exchanges which 148 could increase the load on the network. Moreover, under conditions of heavy network load network delays would cause this mechanism to slow down and hence larger messages could be relayed on the network worsening the delays!
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
8.5.2 Memory Requirement In the presentation of the algorithms given here, a lot of concern was ex-pressed regarding the memory requirement of certain algorithms. It is noted, that in the implementation of these algorithms, as soon as some structure is no longer needed, it is removed from the recursive state (held by the gen server behaviour). This would help relieve certain algorithms from the amount of memory required. However, there are cases where it is not possi-ble to free certain structure in a way that these remain consuming memory for ever. An example of such structures are sets holding all the messages which were delivered (such as the Delivered set in the regular reliable broad-cast). It is not possible to do away with these structures, even when the algorithm terminates, due to the asynchrony of the system. Figure 8.2: Incorrect double delivery, due to freeing the internal Deliver set Consider the run of the lazy algorithm for regular reliable broadcast in figure 8.2. Here, process P1 manages to send a message to P2 and P3, but crashes shortly afterwards. Process P2 receives and delivers this message. At point A, it also detects that P1 crashed, and hence relays this message to P3. Process P3 receives this message and delivers it. However, at point B, the original message from process P1 arrives and unless there is a set with all delivered messages, P3 would end up delivering the same message again, as shown. Such structures pose a limit on the practical side of the algorithm. In order to solve this problem, one would require to devise higher algorithms 149 which would ensure that the removal of elements from such structures, would not result in inconsistent behaviour such as multiple deliveries. Due to time constraints, in this project this problem could not
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
be solved to its totality, however a possible solution is mentioned as part of the future work. # 8.6 Assessing the failure detector implemented In this project, we chose to work on top of Erlangs native failure detection mechanism, to build a perfect failure detector. The field of failure detectors is a research area on its own there are various algorithms and important results which would need to be studied before implementing a failure detec-tor. For this work, it was decided to keep focus on the algorithms being investigated and analyse these algorithms in future work. After all, the role of the failure detector abstraction is this to help separate process monitor-ing from the algorithm itself. However, most of the algorithms implemented here require a perfect failure detector in order to guarantee correctness. This means that the failure detector should satisfy both the Completeness and Accuracy properties (see section ). The Erlang failure detection mechanism utilizes a sheer heartbeat mechanism if a heartbeat is not received from a process, then that process is taken as crashed. This approach is rather problematic, because network delays could cause the failure detector to think that a process has crashed, when in fact it would still be running. At this point, a simple procedure to attempt achieving a perfect failure detector was taken: as soon as a failure detector suspects a process, that process is sent a message which forces it to crash. This would strengthen the accuracy, since a suspected process would now truly crash. Note that since the process will actually crash after that it is detected, it would still continue its operation until it receives the message to crash possibly even sending out further messages. However, since the system is asynchronous, and the failure detector is also asynchronous, such behaviour could
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
be allowed similar to having message reordering, a failure detector can always be fast enough to detect a failure, before all pending messages are received. However such a perfect detector is not truly perfect. There could be cases where it could break the underlying algorithm. A particular example was mentioned in section 5.5.6. This happens because the process which is de-tected as having failed, carries on in its execution, and ends up taking con-150 flicting actions which violate the properties of the algorithm. This approach of constructing a Perfect Failure Detector is in reality just a work around - since a failure detector operating on a busy network, would cause it to kill other processes due to the network delays. In such networks, it would be difficult to build a perfect failure detector, and usually one uses some form of adaptable timeout mechanism to construct eventually perfect failure detectors. However most algorithms described in this work, only work with perfect failure detectors. Using a weaker failure detector, gener-ally breaks the algorithm. However, there might be cases where with some minor changes, the algorithm would still work fine with weaker failure detec-tors. Example, in the case of lazy reliable broadcast algorithm, suspecting a process would cause all messages received from that process to be rebroad-cast. Hence as long as this broadcast also attempts to send to the suspected processes, an eventually perfect failure detector can be used. Nevertheless, such a failure detector could also cause the algorithm not to reach its goal, example a consensus algorithm would not reach agreement. In fact, it can be seen that the flooding consensus algorithm might not decide if processes are suspected as crashed, but have not really crashed. The same happens with the hierarchical consensus algorithm. # 8.7 Conclusion This chapter evaluated different aspects
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
dealing with this project. Primar-ily, the applicability of the implemented suite of protocols was assessed in relation to its usage in the implementation of the test case scenario. Erlang as a language of implementation was evaluated as well, and its promised strengths, were assessed. The established algorithms were evaluated in terms of their performance, and finally, insight was given regarding the failure de-tector used throughout this project. 151 Chapter 9 # Conclusion and Future Work No matter the amount of work that is done, there is almost always room for improvement, In this section various possible improvements for this project are outlined. Following this, the relevance of the work done is highlighted, and then finally, this work is concluded. # 9.1 Alternative Failure Detector In this project, a Perfect Failure Detector was assumed throughout. Most algorithms only work if such a failure detector is available. Moreover, a very simple approach to attempt to achieve a Failure Detector, was taken. In reality, failure detectors are an area of research on their own. Failure detector algorithm are proposed in various literature, and these should be taken into consideration for future work. Moreover, weaker failure detectors, such as the Eventually Perfect failure detector, should be studied. These might be more practical to build in the real world, however, the algorithms for the Agreement problems presented here, are much more complicated to build with such a failure detector. # 9.2 Approaching the indefinite growing of the state Some of the algorithms outlined in this project, were more focused on achiev-ing correctness, rather than seeking a practical implementation. In fact, some of the algorithms store all messages received - resulting in internal structures which grow indefinitely and require infinite memory. In this work, 152 different kinds of optimisations were attempted, such as keeping hashes of
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
messages instead of the messages themselves. However, this does not re-ally solve the problem and further investigation of this aspect needs to be studied. As an example, consider the algorithm for regular reliable broadcast . This algorithm required a Delivered sets which holds all messages which were delivered, and prevents messages from being incorrectly delivered multiple times. For future work, a simple scheme is proposed in which all processes acknowledge that they have received the message. When all processes have received the message, then the local copy of the message would not be needed any more and could be deleted. However, there could be situations where this message which was deleted from the Delivered set, is received again, and would be erroneously delivered again. Such a situation is shown for the regular reliable broadcast algorithm in figure 9.1. Figure 9.1: Need for the Deliver set Here, the dashed lines indicate acknowledges for the message which was initially broadcast by P1. For the sake of clarity, only the acknowledges directed towards P3 are shown. In this run, process P3 receives acknowledges from all other processes at point A. Hence it may remove this message from its internal Delivered set . However, this same message is received again, shortly afterwards, and hence would result in incorrectly redelivering this message. For future work, we propose to assess to use of timestamps (such as Lamport timestamps) to be able to determine that this message has already been delivered. The idea is that every process keeps a timestamp for every node, and the message received is only delivered if it has a later timestamp. This 153 method, however, would require that message sent by the same sender, do not get reordered in the network - however such a property can be easily satisfied by a
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
transmission control protocol. Hence here, we suggest the study of this idea even further, so as to possibly come up with a solution for these ever growing sets. # 9.3 Different Failure Model In this project, only crash failures were taken into consideration. A process was not expected, or even allowed, to recover once it had crashed. Doing so, it might break the algorithm being executed. However, there is a lot of study on agreement algorithms with transient or even byzantine failures. Once again, the algorithms for these failure models, are much more complicated than those for the crash failure model. However, as part of the future work, it would be interesting to investigate these failure models as well. # 9.4 Analyse further specifications and agreement problems The work done in this project, by no means covers all specifications or stud-ies all of the agreement algorithms. Various variations or even completely different problems exist. For example, in this project, no probabilistic al-gorithm was studied. However, in very large network, one usually has to resort to such algorithms because of the massive amount of messages, and computation rounds which would be otherwise required. # 9.5 Relevance of work done The work done in this project, studies the way a system of processes can cooperate together, to solve different classes of agreement problems, in the presence of failures and unreliability. In a time, where most applications are moving away from a centralized approach to a more distributed environment, guaranteeing correctness in a distributed system is always becoming more of a priority. 154 The work presented here, provides a suite of algorithms through which correctness can be achieved without the need for central coordinators. This entails a degree of fault tolerant operation, because nodes can fail, and the system could still remain in
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
operation. Nowadays, various technologies work on this principle, such as cloud com-puting, decentralized distributed databases and peer to peer technologies. Hence such a suite immediately has strong applicability for the development of such systems. Moreover, it could be used to explore the possibility of de-centralising existing system, so as to achieve fault tolerant characteristics as well being able to guarantee a reliable distributed service. # 9.6 Conclusion In this project, the problems associated with distributed programming were analysed. In particular, the distributed agreement problems were studied in detail. Erlang was chosen as the implementation language, and a common framework for these algorithms, was developed using this language. A number of distributed agreement specifications were then studied in de-tails. Following this, algorithms for each of these specifications were also in-vestigated and actually implemented in the framework developed in Erlang. This provided a suite of reusable protocols which tackle these agreement problems. The relevance of this suite was then assessed with a real world scenario. Using this suite, a decentralized file system was implemented. The benefits achieved from such a suite, were then evaluated. 155 Appendix A # Using the protocol suite Here the details on how to use the protocol suite developed in this project, are outlined. # A.1 Prerequisites: • Erlang/OTP framework • Open SSL: required by Erlang’s Crypto Module, which is used in this project. • Protocol Suite (found in the code directory) # A.2 Setting Up Make sure that the following files are set up: 1. Erlang hosts file: This file is located in the home directory and is name .hosts.erlang. The domain name of all machines with which the system needs to connect should be put here 2. Erlang cookie file: This file is located in the home directory under the name .erlang.cookie. This should contain a
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
random string. The content of this file should be the same on all nodes 156 A.3 Starting a shell In the command prompt write the following. erl -sname NODENAME -peers PEER1 PEER2 PEER3 A.3.1 Explanation This starts the Erlang shell and assigns it the name NODENAME. Here the name of the shell of all peers should also be specified in the form of arguments to the -peers switch. Note that if the shells are not on the same domain, then =name should be used instead of -sname, and all names should be given as fully qualified domain names. # A.4 Initializing the Suite of protocols In each Erlang Shell, write node_utils:start_node(). Alternatively, if a shell is to be used as the monitor node (used for debug-ging, all output is directed to that shell), the following should be entered to initialize all Erlang shells: node_utils:start_all_nodes(). 157 Bibliography Gregory R. Andrews. Distributed programming languages. In ACM 82: Proceedings of the ACM ’82 conference , pages 113–117, New York, NY, USA, 1982. ACM. Joe Armstrong. Programming Erlang - Software for a Concurrent World . The Pragmatic Bookshelf, 2007. Joe Armstrong, Bjarne Dcker, Thomas Lind-gren, and Hkan Millroth. Erlang whitepaper. paper.html . Joe Armstrong and To Helen. Making reliable distributed systems in the presence of software errors, 2003. Joe Armstrong and Steve Vinoski. The road that we didn’t go down. . Tushar Deepak Chandra, Vassos Hadzilacos, and Sam Toueg. The weakest failure detector for solving consensus. In PODC ’92: Proceed-ings of the eleventh annual ACM symposium on Principles of distributed computing , pages 147–158, New York, NY, USA, 1992. ACM. Tushar Deepak Chandra and Sam Toueg. Unreliable failure detectors for reliable distributed systems. J. ACM , 43(2):225–267, 1996. Bernadette Charron-Bost. Agreement problems in fault-tolerant dis-tributed systems.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
In SOFSEM , pages 10–32, 2001. Cynthia Dwork, Nancy Lynch, and Larry Stockmeyer. Consensus in the presence of partial synchrony. J. ACM , 35(2):288–323, 1988. D. Farina. A case for erlang. 158 Michael J. Fischer, Nancy A. Lynch, and Nancy A. Lynch. A lower bound for the time to assure interactive consistency. Information Pro-cessing Letters , 14:183–186, 1981. Michael J. Fischer, Nancy A. Lynch, and Michael S. Paterson. Im-possibility of distributed consensus with one faulty process. J. ACM ,32(2):374–382, 1985. Jim Gray. Why do computers stop and what can be done about it? In Symposium on Reliability in Distributed Software and Database Sys-tems , pages 3–12, 1986. Rachid Guerraoui and Lu´ ıs Rodrigues. Introduction to Reliable Dis-tributed Programming . Springer-Verlag New York, Inc., Secaucus, NJ, USA, 2006. Maurice Herlihy. The art of multiprocessor programming. In PODC ’06: Proceedings of the twenty-fifth annual ACM symposium on Principles of distributed computing , pages 1–2, New York, NY, USA, 2006. ACM. S. Krishnaprasad. Concurrent/distributed programming illustrated us-ing the dining philosophers problem. J. Comput. Small Coll. , 18(4):104– 110, 2003. Leslie Lamport. Time, clocks, and the ordering of events in a distributed system. Commun. ACM , 21(7):558–565, 1978. Leslie Lamport, Robert Shostak, and Marshall Pease. The byzantine generals problem. ACM Trans. Program. Lang. Syst. , 4(3):382–401, 1982. Nancy A. Lynch. Distributed Algorithms . Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 1996. Nilsson Niclas. The multicore crisis: Scala vs erlang. . Klaus Renzel. Error handling for business information systems - a pattern language. 1996. Fred B. Schneider. Byzantine generals in action: implementing fail-stop processors. ACM Trans. Comput. Syst. , 2(2):145–154, 1984. 159
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Title: Introduction to reliable and secure distributed programming URL Source: Markdown Content: [Programming languages for distributed computing systems]( ACM Computing Surveys, 1989 When distributed systems first appeared, they were programmed in traditional sequential languages, usually with the addition of a few library procedures for sending and receiving messages. As distributed applications became more commonplace and more sophisticated, this ad hoc approach became less satisfactory. Researchers all over the world began designing new programming languages specifically for implementing distributed applications. These languages and their history, their underlying principles, their design, and their use are the subject of this paper. We begin by giving our view of what a distributed system is, illustrating with examples to avoid confusion on this important and controversial point. We then describe the three main characteristics that distinguish distributed programming languages from traditional sequential languages, namely, how they deal with parallelism, communication, and partial failures. Finally, we discuss 15 representative distributed languages to give ... [A Fault-Tolerant Approach to Distributed Applications]( 2013 Distributed computing infrastructures support system and network fault-tolerance, e.g., grids and clouds. They transparently repair and prevent communication and system software errors. They also allow duplication and migration of jobs and data to prevent hardware failures. However, only limited work has been done so far on application resilience, i.e., the ability to resume normal execution after errors and abnormal executions in distributed environments. This paper addresses issues in application resilience, i.e., fault-tolerance to algorithmic errors and to resource allocation failures. It addresses solutions for error detection and management. It also overviews a platform used to deploy, execute, monitor, restart and resume distributed applications on grids and cloud infrastructures in case of unexpected behavior. [Distributed co-operating processes and transactions]( 1983 As part of our research in the Archons [Jensen 82] project o n decentralized computers,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
we have developed a relational model o f data consistency to replace the conventional serialization mode l for reasoning about the relationships among distributed syste m data objects in general and state variables in particular. We no t only permit but encourage such relationships to be probabilistic , in the interest of efficiency. This model leads to a new formulatio n of cooperating processes, and thence to the notion of cooperating transactions : cooperating processes whose actions are made atomic for the sake of reliability. We believe that cooperating processes are valuable in a computer network, but essential in a decentralized computer [Jensen 82] where the conceptually singular but physically dispersed global operating system requires a transaction facility in the kernel [Jensen 801. Thes e ideas are illustrated by examples from our initial experience i n applying the model to the Accent network operating system an d other system software of the Spice personal computing network. This document is intended to be an overview of the synchronization effort in the Archons project, and future publications wil l elaborate on many of the individual points touched on here. 1. Introductio n In distributed systems, multiple entities (at any particular level o f abstraction) perform tasks by cooperating in various ways so a s to improve concurrency, reliability, and modularity, as well as t o accommodate physical dispersal. Cooperation implies some for m of synchronization among processes or synchronization of concurrent access to shared data objects. The former type of cooperation has been pursued primarily in centralized uniprocesso r and multiprocessor computers, while most distributed systems are computer networks and thus focus on the latter type. Furthermore, computer networks (and centralized computers to a lesse r extent) typically exhibit a form of cooperation exemplified b y autonomous client and server functions. Instead,
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
the Archon s This work was sponsored in part by : the USAF Rome Air Development Cente r under contract F30002. 81-C .0297 ; and the US Naval Ocean Systems Center under contract number N66001-81-C-0484 ; and the US Defense Advanced Researc h Projects Agency under contract F33615. 81 JG 1539. Permission to copy without fee all or part of this material is grante d provided that the copies are not made or distributed for direc t commercial advantage, the ACM copyright notice and the title of th e publication and its date appear, and notice is given that copying is b y permission of the Association for Computing Machinery. To cop y otherwise, or to republish, requires a fee and/or specific permission . [Programming Languages for Distributed Applications]( New Generation Computing, 1998 Much progress has been made in distributed computing in the areas of distribution structure, open computing, fault tolerance, and security. Yet, writing distributed applications remains difficult because the programmer has to manage models of these areas explicitly. A major challenge is to integrate the four models into a coherent development platform. Such a platform should make it possible to cleanly separate an application’s functionality from the other four concerns. Concurrent constraint programming, an evolution of concurrent logic programming, has both the expressiveness and the formal foundation needed to attempt this integration. As a first step, we have designed and built a platform that separates an application’s functionality from its distribution structure. We have prototyped several collaborative tools with this platform, including a shared graphic editor whose design is presented in detail. The platform efficiently implements Distributed Oz, which extends the Oz language with constructs to express the distribution structure and with basic primitives for open computing, failure detection and handling, and resource control. Oz appears to the
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
programmer as a concurrent object-oriented language with dataflow synchronization. Oz is based on a higher-order, state-aware, concurrent constraint computation model. Building Secure Resources to Ensure Safe Computations in Distributed and Potentially Corrupted Environments and the verifiers able to securely re-execute piece of tasks in a trusted way. This article focus on the effective construction of strongly secured resources. Our approach combine both software and hardware components to cover the full spectrum of security constraints. The proposed computing platform is validated over a medical application and some experimental results are presented. Sequentialization and Synchronization for Distributed Programs: Bakst, Alexander Goldberg | Advisor(s): Jhala, Ranjit | Abstract: Distributed systems are essential for building services that can handle the ever increasing number of people and devices connected to the internet as well as the associated growth in data accumulation. However, building distributed programs is hard, and building confidence in the correctness of an algorithm or implementation is harder still. One fundamental reason is the highly asynchronous nature of distributed execution. Timing differences caused by network delays and variation in compute power can trigger behaviors that were unanticipated by the programmer.Unfortunately, techniques for building confidence are all up against the same problem: the combinatorial explosion in the number of behaviors of a distributed system.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Testing and model checking techniques can not hope to weed out all behaviors when the state space is infinite. At the other end of the spectrum, constructing proofs by hand is a daunting ... [Robust Distributed Computing and]( 1996 I Sensors that supply data to computer systems are inherently unreliable. When sensors are distributed, reliability is further compromised. How can a system tell good sensor data from faulty? A hybrid algorithm combines proposed iolutions to address the problem. [Invited paper for New Generation Computing 1 Programming Languages for Distributed Applications]( 1998 Much progress has been made in distributed computing in the areas of distribution structure, open computing, fault tolerance, and security. Yet, writing distributed applications remains difficult because the programmer has to manage models of these areas explicitly. A major challenge is to integrate the four models into a coherent development platform. Such a platform should make it possible to cleanly separate an application’s functionality from the other four concerns. Concurrent constraint programming, an evolution of concurrent logic programming, has both the expressiveness and the formal foundation needed to attempt this integration. As a first step, we have designed and built a platform that separates an application’s functionality from its distribution structure. We have prototyped several collaborative tools with this platform, including a shared graphic editor whose design is presented in detail. The platform efficiently implements Distributed Oz, which extends the Oz langu... [Topic 8: Distributed Systems and Algorithms]( Lecture Notes in Computer Science, 2006 Parallel computing is strongly influenced by the challenges of distributed systems, such as a need for a Single System Image, resource sharing and allocation, failures and a need for fault tolerance, long latencies, network partition, disconnected operation, demands of users wishing to solve more computationally and communication demanding problems, and opportunities created by grids and
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Web services. Distributed computing is the computing mainstream now; it is based on different forms of distributed systems: clusters, grids, peer-to-peer systems, web services, service oriented architectures. This topic provides a forum for research and practice, of interest to both academia and industry, about distributed computing and distributed algorithms. Submissions were encouraged in all areas of distributed systems and algorithms relevant to parallel computing, with emphasis on design and practice of distributed algorithms, analysis of the behaviour of distributed systems and algorithms, distributed fault-tolerance, distributed operating systems and databases, scalability, concurrency and performance in distributed systems, resource sharing and load balancing in distributed systems, distributed algorithms in telecommunications, distributed mobile computing, resource and service discovery, security in distributed systems, and standards and middleware for the distribution of parallel computations. Twenty papers were submitted in this topic. The subjects were varied, but a common theme of many of them is recovery, resource allocation, mutual exclusion, garbage collection and coordination. Other themes include load balancing, scheduling and consensus algorithms. Eight papers have been accepted.
|
{
"page_id": null,
"source": 7318,
"title": "from dpo"
}
|
Title: ObstructionFreedom URL Source: Markdown Content: **Note:** You are looking at a static copy of the former PineWiki site, used for class notes by James Aspnes Obstruction-freedom An implementation is **obstruction-free** if, starting from any reachable configuration, any process can finish in a bounded number of steps if all of the other processes stop. This definition was proposed in 2003 by [Herlihy, Luchangco, and Moir]( In lower bounds (e.g., [JayantiTanToueg]( this is often called **solo-terminating**. Both of these properties exclude traditional lock-based algorithms, where some process grabs a lock, updates the data structure, and then release the lock; if this process halts, no more operations finish. Both properties are also weaker than wait-freedom. It is not hard to show that lock-free
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
is a stronger condition that obstruction-freedom: given a lock-free implementation, if we can keep some single process running forever in isolation, we get an infinite execution with only finitely many completed operations. So we have a hierarchy wait-free > lock-free > obstruction-free > locking. 1. Why build obstruction-free algorithms? ----------------------------------------- The pitch is similar to the pitch for building locking algorithms: an obstruction-free algorithm might be simpler to design, implement, and reason about than a more sophisticated algorithm with stronger properties. Unlike locking algorithms, an obstruction-free algorithm won't fail because some process dies holding the lock; instead, it fails if more than one process runs the algorithm at the same time. This possibility may be something we can avoid by building a **contention manager**, a high-level protocol that detects contention and delays some processes to avoid it (say, using randomized exponential back-off). 2. Examples ----------- 2.1. Lock-free implementations ------------------------------ Pretty much anything using compare-and-swap or LL/SC ends up being lock-free. A simple example would be a counter, where an increment operation does * x ← load-linked(c) * store-conditional(c, x+1) This is lock-free (the only way to prevent a store-conditional from succeeding is if some other store-conditional succeeds, giving infinitely many successful increments) but not wait-free (I can starve). It's also obstruction-free, but since it's already lock-free we don't care about that. Similarly, suppose we are doing [AtomicSnapshots]( We know that there exist wait-free implementations of atomic snapshots, but they are subtle and confusing. So we want to do something simpler, and hope that we at least get obstruction-freedom. If we do double-collects, that is, we have updates just write to a register and have snapshots repeatedly collect until they get two collects in a row with the same values, then any snapshot that finishes is correct (assuming no updaters ever
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
write the same value twice, which we can enforce with nonces). This isn't wait-free, because we can keep a snapshot going forever by doing a lot of updates. It _is_ lock-free, because we have to keep doing updates to make this happen. We can make this merely obstruction-free if we work hard (there is no reason to do this, but it illustrates the difference between lock-freedom—good—and obstruction-freedom—not so good). Suppose that every process keeps a count of how many collects it has done in a register that is included in other process's collects (but not its own). Then two concurrent scans can stall each other forever (the implementation is not lock-free), but if only one is running it completes two collects in O(n) operations without seeing any changes (it is obstruction-free). Similar things happen with SoftwareTransactionalMemory. If however I am not very clever and allow some values to get written outside of transactions, then I might only be obstruction-free. So far we don't have any good examples of why we would want to be obstruction-free if our algorithm is based on CAS. So let's describe the case Herlihy et al. suggested. 2.2. An obstruction-free deque ------------------------------ A _deque_ is a generalized queue that supports push and pop at both ends (thus it can be used as either a queue or a stack, or both). A classic problem in shared-memory objects is to build a deque where operations at one end of the deque don't interfere with operations at
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
the other end. While there exist lock-free implementation with this property, there is a particularly simple implementation using CAS that is only obstruction-free. Here's the idea: we represent the deque as an infinitely-long array of compare-and-swap registers (this is a simplification from the paper, which gives a bounded implementation of a bounded deque). The middle of the deque holds the actual contents. To the right of this region is an infinite sequence of _right null_ (RN) values, which are assumed never to appear as a pushed value. To the left is a similar infinite sequence of _left null_ (LN) values. Some magical external mechanism (called an _oracle_ in the paper) allows processes to quickly find the first null value at either end of the non-null region; the correctness of the protocol does not depend on the properties of the oracle, except that it has to point to the right place at least some of the time in a solo execution. We also assume that each cell holds a version number whose only purpose is to detect when somebody has fiddled with the cell while we aren't looking (if we use LL/SC, we can drop this). Here is the code for right-push and right-pop (the code for left-push and left-pop is symmetric): right-push(v) * while true do: * k ← oracle(right) * prev ← a[k-1] * next ← a[k] * if prev.value ≠ RN and next.value = RN: * if CAS(a[k-1], prev, [prev.value, prev.version+1]): * if CAS(a[k], next, [v, next.version+1]): * we win, go home * else keep trying right-pop() * while true do: * k ← oracle(right) * cur ← a[k-1] * next ← a[k] * if cur.value ≠ RN and next.value = RN: * if cur.value = LN and A[k-1] = cur: * return empty * else if CAS(a[k],
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
next, [RN, next.version+1]): * if CAS(a[k-1], cur, [RN, cur.version+1]): * return cur.value * else keep trying It's easy to see that in a solo execution, if the oracle doesn't lie, either operation finishes and returns a plausible value after O(1) operations. So the implementation is obstruction-free. But is it also correct? To show that it is, we need to show that any execution leaves the deque in a sane state, in particular that it preserves the invariant that the deque consists of left-nulls followed by zero or more values followed by right-nulls, and that the sequence of values in the queue is what it should be. This requires a detailed case analysis of which operations interfere with each other, which can be found in the original paper. But we can give some intuition here. The two CAS operations in right-push or right-pop succeed only if neither register was modified between the preceding read and the CAS. If both registers are unmodified at the time of the second CAS, then the two CAS operations act like a single two-word CAS, which replaces the previous values (top, RN) with (top, value) in right-push or (top, val) with (top, RN) in right-pop; in either case the operation preserves the invariant. So the only way we get into trouble is if, for example, a right-push does a CAS on a[k-1] (verifying that it is unmodified and incrementing the version number), but then some other operation changes a[k-1] before the CAS on a[k]. If this other operation is also a right-push, we are happy, because it must have the same value for k (otherwise it would have failed when it saw a non-null in a[k-1]), and only one of the two right-pushes will succeed in applying the CAS to a[k]. If the other operation is
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
a right-pop, then it can only change a[k-1] after updating a[k]; but in this case the update to a[k] prevents the original right-push from changing a[k]. With some more tedious effort we can similarly show that any interference from a left-push or left-pop either causes the interfering operation or the original operation to fail. This covers 4 of the 16 cases we need to consider. The remaining cases will be brushed under the carpet to avoid further suffering. 3. Boosting obstruction-freedom to wait-freedom ----------------------------------------------- Naturally, having an obstruction-free implementation of some object is not very helpful if we can't guarantee that some process eventually gets its unobstructed solo execution. In general, we can't expect to be able to do this without additional assumptions; for example, if we could, we could solve consensus using the racing-counters algorithm with no randomization at all.( So we need to make some sort of assumption about timing, or find somebody else who has already figured out the right assumption to make. Those somebodies turn out to be Faith Ellen Fich, Victor Luchangco, Mark Moir, and Nir Shavit, who show how to boost obstruction-freedom to wait-freeom in their paper [Obstruction-free algorithms can be practically wait-free]( from DISC 2005. The timing assumption is **unknown-bound semisynchrony**, which means that in any execution there is some maximum ratio R between the shortest and longest time interval between any two consecutive steps of the same non-faulty process, but the processes don't know what this ratio is.( In particular, if I can execute more than R steps without you doing anything, I can reasonably conclude that you are dead—the semisynchrony assumption thus acts as a kind of weak failure detector. The fact that R is unknown might seem to be an impediment to using this failure detector, but we can get
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
around this. The idea is to start with a small guess for R; if a process is suspected but then wakes up again, we increment the guess. Eventually, the guessed value is larger than the correct value, so no live process will be falsely suspected after this point. To get solo execution, when a process detects a conflict (because their operation didn't finish quickly), it enters into a "panic mode" where processes take turns trying to finish unmolested. A fetch-and-add register is used as a timestamp generator, and only the process with the smallest timestamp gets to proceed. However, if this process is too sluggish, other processes may give up and overwrite its low timestamp with ∞, temporarily ending its turn. If the sluggish process is in fact alive, it can restore its low timestamp and kill everybody else, allowing it to make progress until some other process declares it dead again. The simulation works because eventually the mechanism for detecting dead processes stops suspecting live ones (using the technique described above), so the live process with the winning timestamp finishes its operation without interference. This allows the next process to proceed, and eventually all live processes complete any operation they start, giving the wait-free property. Here is the actual code. It's a rather long algorithm but most of the details are just bookkeeping. invoke(op) * if ¬PANIC: * execute up to B steps of the underlying algorithm * if we are done: * return * PANIC ← true _# enter panic mode_ * my-timestamp ← fetch-and-increment() * A[i] ← 1 _# reset my activity counter_ * while true: * T[i] ← my-timestamp * min-timestamp ← my-timestamp * winner ← i * for j ← 1..n, j≠i: _# look for winner, slaughter non-winners_ * other-timestamp ← T[j] * if other-timestamp
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
< min-timestamp: * T[winner] ← ∞ _# not looking so winning any more_ * min-timestamp ← other-timestamp * winner ← j * else * if other-timestamp < ∞: * T[j] ← ∞ * if i = winner: * repeat: * execute up to b steps of the underlying algorithm * if we are done: * T[i] ← ∞ * PANIC ← false * return * else * A[i] ← A[i] + 1 * PANIC ← true * until while T[i] = ∞: * else: * repeat: * a ← A[winner] * wait a steps * winner-timestamp ← T[winner] * until a = A[winner] or winner-timestamp ≠ min-timestamp * if winner-timestamp = min-timestamp: * T[winner] ← ∞ _# left loop because a didn't change; kill winner for inactivity_ The preamble before entering PANIC mode is a fast-path computation that allows a process that actually is running in isolation to skip testing any timestamps or doing any extra work (except for the one register read of PANIC). The assumption is that the constant B is set high enough that any process generally will finish its operation in B steps without interference. If there is interference, then the timestamp-based mechanism kicks in: we grab a timestamp out of the convenient fetch-and-add register and start slugging it out with the other processes. (A side note: while the algorithm as presented in the paper assumes a fetch-and-add register, any timestamp generator that delivers increasing values over time will work. So if we want to limit ourselves to registers, we could generate timestamps by taking snapshots of previous timestamps, adding 1, and appending process ids for tie-breaking.) Once I have a timestamp, I try to knock all the higher-timestamp processes out of the way (by writing ∞ to their timestamp registers). If I see a smaller
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
timestamp than my own, I'll drop out myself (T[i] ← ∞), and fight on behalf of its owner instead. At the end of the j loop, either I've decided I am the winner, in which case I try to finish my operation (periodically checking T[i] to see if I've been booted), or I've decided somebody else is the winner, in which case I watch them closely and try to shut them down if they are too slow (T[winner] ← ∞). I detect slow processes by inactivity in A[winner]; similarly, I signal my own activity by incrementing A[i]. The value in A[i] is also used as an increasing guess for the time between increments of A[i]; eventually this exceeds the R(b+O(1)) operations that I execute between incrementing it. We still need to prove that this all works. The essential idea is to show that whatever process has the lowest timestamp finishes in a bounded number of steps. To do so, we need to show that other processes won't be fighting it in the underlying algorithm. Call a process _active_ if it is in the loop guarded by the "if i = winner" statement. Lemma 1 from the paper states: Lemma 1 If processes i and j are both active, then T[i] = ∞ or T[j] = ∞. Proof Assume without loss of generality that i last set T[i] to my-timestamp in the main loop after j last set T[j]. In order to reach the active loop, i must read T[j]. Either T[j] = ∞ at this time (and we are done, since only j can set T[j] < ∞), or T[j] is greater than i's timestamp (or else i wouldn't think it's the winner). In the second case, i sets T[j] = ∞ before entering the active loop, and again the
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
claim holds. The next step is to show that if there is some process i with a minimum timestamp that executes infinitely many operations, it increments A[i] infinitely often (thus eventually making the failure detector stop suspecting it). This gives us Lemma 2 from the paper: Lemma 2 Consider the set of all processes that execute infinitely many operations without completing an operation. Suppose this set is non-empty, and let i hold the minimum timestamp of all these processes. Then i is not active infinitely often. Proof Suppose that from some time on, i is active forever, i.e., it never leaves the active loop. Then T[i] < ∞ throughout this interval (or else i leaves the loop), so for any active j, T[j] = ∞ by the preceding lemma. It follows that any active T[j] leaves the active loop after b+O(1) steps of j (and thus at most R(b+O(1)) steps of i). Can j re-enter? If j's timestamp is less than i's, then j will set T[i] = ∞, contradicting our assumption. But if j's timestamp is greater than i's, j will not decide it's the winner and will not re-enter the active loop. So now we have i alone in the active loop. It may still be fighting with processes in the initial fast path, but since i sets PANIC every time it goes through the loop, and no other process resets PANIC (since no other process is active), no process enters the fast path after some bounded number of i's steps, and every process in the fast path leaves after at most R(B+O(1)) of i's steps. So eventually i is in the loop alone forever—and obstruction-freedom means that it finishes its operation and leaves. This contradicts our initial assumption that i is active forever. So now we want
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
to argue that our previous assumption that there exists a bad process that runs forever without winning leads to a contradiction, by showing that the particular i from the Lemma actually finishes (note that the Lemma doesn't quite do this—we only show that i finishes if it stays active long enough, but maybe it doesn't stay active). Suppose i is as in the preceding Lemma. The Lemma says that i leaves the active loop infinitely often. So in particular it increments A[i] infinitely often. After some finite number of steps, A[i] exceeds the limit R(b+O(1)) on how many steps some other process can take between increments of A[i]. For each other process j, either j has a lower timestamp than i and thus finishes in a finite number of steps (from the premise of the choice of i), or j has a higher timestamp than i. Once we have cleared out all the lower-timestamp processes, we follow the same logic as in the proof of the Lemma to show that eventually (a) i sets T[i] < ∞ and PANIC = true, (b) each remaining j observes T[i] < ∞ and PANIC = true and reaches the waiting loop, (c) all such j wait long enough (since A[i] is now very big) that i can finish its operation. This contradicts the assumption that i never finishes the operation and completes the proof. 3.1. Cost --------- If the parameters are badly tuned, the potential cost of this construction is quite bad. For example, the slow increment process for A[i] means that the time a process spends in the active loop even after it has defeated all other processes can be as much as the square of the time it would normally take to complete an operation alone—and every other process may pay
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
R times this cost waiting. This can be mitigated to some extent by setting b high enough that a winning process is likely to finish in its first unmolested pass through the loop (recall that it doesn't detect that the other processes have reset T[i] until after it makes its attempt to finish). An alternative might be to double A[i] instead of incrementing it at each pass through the loop. However, it is worth noting (as the authors do in the paper) that nothing prevents the underlying algorithm from incorporating its own contention management scheme to ensure that most operations complete in B steps and PANIC mode is rarely entered. So we can think of the real function of the construction as serving as a backstop to some more efficient heuristic approach that doesn't necessarily guarantee wait-free behavior in the worst case. 4. Lower bounds for lock-free protocols --------------------------------------- So far we have seen that obstruction-freedom buys us an escape from the impossibility results that plague wait-free constructions, while still allowing practical implementations of useful objects under plausible timing assumptions. Yet all is not perfect: it is still possible to show non-trivial lower bounds on the costs of these implementations in the right model. We will present one of these lower bounds, the linear-contention lower bound of [Faith Ellen Fich, Danny Hendler, Nir Shavit. Linear lower bounds on real-world implementations of concurrent objects, FOCS 2005.]( First we have to define what is meant by contention. 4.1. Contention --------------- A limitation of real shared-memory systems is that physics generally won't permit more than one process to do something useful to a shared object at a time. This limitation is often ignored in computing the complexity of a shared-memory distributed algorithm (and one can make arguments for ignoring it in systems where
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
communication costs dominate update costs in the shared-memory implementation), but it is useful to recognize it if we can't prove lower bounds otherwise. Complexity measures that take the cost of simultaneous access into account go by the name of **contention**. The particular notion of contention used in the Fich et al. paper is an adaptation of the contention measure of Dwork et al., Contention in shared-memory algorithms, JACM 1997. Note that this change only strengthens the bound they eventually prove, which shows that in the worst case, obstruction-free implementations of operations on objects in a certain class incur a linear number of memory stalls (possibly spread across multiple base objects). 4.2. The class G ---------------- The Fich et al. bound is designed to be as general as possible, so the authors define a class _G_ of objects to which it applies. As is often the case in mathematics, the underlying meaning of G is "a reasonably large class of objects for which this particular proof works," but the formal definition is given in terms of when certain operations of the implemented object are affected by the presence or absence
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
of other operations—or in other words, when those other operations need to act on some base object in order to let later operations know they occurred. An object is in the class G if it has some operation Op and initial state s such that for any two processes p and q and every sequence of operations AφA', where (a) φ is an instance of Op executed by p, (b) no operation in A or A' is executed by p, (c) no operation in A' is executed by q,<3 no two operations in A' are executed by the same process; then there exists a sequence of operations Q by q such that for every sequence HφH' where (a) HH' is an interleaving of Q and the sequences AA'|r for each process r, (b) H' contains no operations of q, and (c) no two operations in H' are executed by the same process; then the return value of φ to p changes depending on whether it occurs after Aφ or Hφ. This is where "makes the proof work" starts looking like a much simpler definition. The intuition is that deep in the guts of the proof, we are going to be injecting some operations of q into an existing execution (hence adding Q), and we want to do it in a way that forces q to operate on some object that p is looking at (hence the need for Aφ to return a different value than Hφ), without breaking anything else that is going on (all the rest of the conditions). The reason for pulling all of these conditions out of the proof into a separate definition is that we also want to be able to show that particular classes of real objects satisfy the conditions required by the
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
proof, without having to put a lot of special cases into the proof itself. Lemma A mod-m fetch-and-increment object (with m ≥ n) is in G. Proof This is a classic proof-by-unpacking-the-definition. Pick some execution AφA' satisfying all the conditions, and let a be the number of fetch-and-increments in A and a' the number in A'. Note a' ≤ n-2, since all operations in A' are by different processes. Now let Q be a sequence of n-a'-1 fetch-and-increments by q, and let HH' be an interleaving of Q and the sequences AA'|r for each r, where H' includes no two operation of the same process and no operations at all of q. Let h, h' be the number of fetch-and-increments in H, H', respectively. Then h+h' = a+a'+(n-a'-1) = n+a-1 and h' ≤ n-2 (since H' contains at most one fetch-and-increment for each process other than p and q). This gives h ≥ (n+a+1)-(n-2) = a+1 and h ≤ n+a-1, and the return value of φ after Hφ is somewhere in this range mod m. But none of these values is equal to a mod m (that's why we specified m ≥ n, although as it turns out m ≥ n-1 would have been enough), so we get a different return value from Hφ than from Aφ. As a corollary, we also get stock fetch-and-increment registers, since we can build mod-m registers from them by taking the results mod m. A second class of class-G objects is obtained from snapshot: Lemma Single-writer snapshot objects are in G.4, so
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
it must be in H. Nobody can overwrite the result of the update (single-writer!), so it follows that Hφ returns a different snapshot from Aφ. 4.3. The lower bound proof -------------------------- Theorem For any obstruction-free implementation of some object in class G from RMW base objects, there is an execution in which some operation incurs n-1 stalls.5 that incur at most n-1 stalls. Curiously, we can even spread the stalls out in a fairly arbitrary way over multiple objects, while still incurring at most n-1 stalls. For example, a counter implemented using a single counter (which is a RMW object) gets exactly n-1 stalls if n-1 processes try to increment it at the same time, delaying the remaining process. At the other extreme, a counter implemented by doing a collect over n-1 single-writer registers (also RMW objects) gets at least n-1 stalls—distributed as one per register—if each register has a write delivered to it while the reader waiting to read it during its collect. So we have to allow for the possibility that stalls are concentrated or scattered or something in between, as long as the total number adds up at least n-1. The proof supposes that the theorem is not true and then shows how to boost an execution with a maximum number k < n-1 stalls to an execution with k+1 stalls, giving a contradiction. (Alternatively, we can read the proof as giving a mechanism for generating an (n-1)-stall execution by repeated boosting, starting from the empty execution.) This is pretty much the usual trick: we assume that there is a class of bad executions, then look for an extreme member of this class, and show that it isn't
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
as extreme as we thought. In doing so, we can restrict our attention to particularly convenient bad executions, so long as the existence of some bad execution implies the existence of a convenient bad execution. Formally, the authors define a _k-stall execution_ for process p as an execution Eσ 1...σ i where E and σ i are sequence of operations such that: 1. p does nothing in E, 2. Sets of processes S j, j = 1..i, whose union S=∪S j has size k, are each covering objects O j after E with pending non-trivial operations, 3. Each σ j consists of p applying events by itself until it is about to apply an event to O j, after which each process in S j accesses O j, after which p accesses O j. 4. All processes not in S are idle after E, 5. p starts at most one operation of the implemented object in σ 1...σ i, and 6. In every extension of E in which p and the processes in S don't take steps, no process applies a non-trivial event to any base object accessed in σ 1...σ i. (We will call this the **weird condition** below.) So this definition includes both the fact that p incurs k stalls and some other technical details that make the proof go through. The fact that p incurs k stalls follows from observing that it incurs |S j| stalls in each segment σ j, since all processes in S j access O j just before p does. We'll now show that if a k-stall execution exists, for k 0. Note that some k-stall execution exists, because the empty execution is a 0-stall execution (with i=0) by the definition. Start
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
with some k-stall execution Eσ 1...σ i,. Extend this execution by a sequence of operations σ in which p runs in isolation until it finishes its operation φ (which it may start in σ if it hasn't done so already), then each process in S runs in isolation until it completes its operation. Now linearize the high-level operations completed in Eσ 1...σ i σ and factor them as AφA' as in the definition of class G. Let q be some process not equal to p or contained in any S j. Then there is some sequence of high-level operations Q of q such that Hφ does not return the same value as Aφ for any interleaving HH' of Q with the sequences of operations in AA' satisfying the conditions in the definition. We want to use this fact to shove at least one more memory stall into Eσ 1...σ i σ, without breaking any of the other conditions that would make the resulting execution a (k+k')-stall execution. Consider the extension τ of E where q runs alone until it finishes every operation in Q. Then τ applies no nontrivial events to any base object accessed in σ 1...σ k, (from the weird condition on k-stall executions) and the value of each of these base objects is the same after E and Eτ, and thus is also the same after Eσ 1...σ k and Eτσ 1...σ k. Now let σ' be the extension of Eτσ 1...σ k defined analogously to σ: p finishes, then each process in each S j finishes. Let HφH' factor the linearization of Eτσ 1...σ i σ'. Observe that HH' is an interleaving of Q and the high-level operations in AA', that H' contains no operations by q (they all finished in τ, before φ started), and
|
{
"page_id": null,
"source": 7319,
"title": "from dpo"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.