Docsity

Distributed Systems riassunti, Appunti di Database Distribuiti

Anteprima parziale del testo

Scarica Distributed Systems riassunti e più Appunti in PDF di Database Distribuiti solo su Docsity!

Sapienza University of Rome

Distributed Systems Notes

Alessandro Dori

Instructor:

Prof. Giuseppe Antonio Di Luna

Academic Year 2025/

Contents

Chapter 1

Introduction

Distributed computing addresses algorithms for a set of processes that seek to achieve some form of cooperation. Some of the processes of a distributed system might stop operating, for instance, by crashing or beign disconnected, while others might stay alive and keep operating. This very notion of partial failures is a characteristic of a distributed system.

Definition 1. A distributed system is a set of spatially separate entities, each of these with a certain computational power that are able to communicate and to coordinate among themselves for reaching a common goal.

Leslie Lamport on Distributed Systems

A distributed system is one in which the failure of a computer you didn’t even know existed can render your own computer unusable.

— Leslie Lamport

When a subset of the processes have failed, or become disconnected, the challenge is usually for the processes that are still operating, or connected to the majority of the processes, to synchronize their activity in a consistent way. Due to the asynchrony of the processes, the possibility of failures in the communication infrastructure, and perhaps even malicious actions by faulty processes, it may be impossible to accurately detect process failures; in particular, there is often no way to distinguish a process failure from a network failure. Even worse, a process that is under the control of a malicious adversary may misbehave deliberately, in order to disturb the communication among the remaining processes. The challenge in distributed computing is precisely to devise algorithms that provide the processes that remain operating with enough consistent information so that they can cooperate correctly and solve common tasks.

  • Examples of Distributed Systems:
    • The Internet
    • The World Wide Web
    • Peer-to-peer systems (e.g., BitTorrent)
    • Cloud computing platforms (e.g., AWS, Google Cloud)
    • Distributed databases (e.g., Cassandra, MongoDB)
    • Blockchain networks (e.g., Bitcoin, Ethereum)
  • Common points across definitions
    • Set of entities: computers, machines, software;
    • Distributed: spatially separated, independent;
    • Common Goal: communication, coordination, resource sharing;
6 CHAPTER 1. INTRODUCTION

1.1 Distributed Programming Abstractions

By capturing properties that are common to a large significant range of systems, abstractions help distin- guish the fundamental from the accessory, and prevent system designers and engineers from reinventing the same solutions for slight variants of the very same problems.

The processes of a distributed program abstract the active entities that perform computations. A process may represent a computer, a processor within a computer, or simply a specific thread of execution within a processor. In the context of network security, a process may also represent a trust domain, a principal, or one administrative unit. To cooperate on some common task, the processes may typically need to exchange messages using some communication network. Links abstract the physical and logical network that supports communication among processes. It is possible to represent multiple realizations of a distributed system by capturing different properties of processes and links, for instance, by describing how these elements may operate or fail under different environmental conditions.

The cooperation among processes can sometimes be modeled as a distributed agreement problem. For instance, the processes may need to agree on whether a certain event did (or did not) take place, to agree on a common sequence of actions to be performed (from a number of initial alternatives), or to agree on the order by which a set of inputs need to be processed. It is desirable to establish more sophisticated forms of agreement from solutions to simpler agreement problems, in an incremental manner.

1.1.1 Inherent Distribution

Applications that require sharing or dissemination of information among several participant processes are a fertile ground for the emergence of problems that required distributed programming abstractions.

Information Dissemination. In distributed applications with information dissemination require- ments, processes may play one of the following roles: information producers (publishers), information consumers (subscribers). Publisher produce information in the form of notifications. Subscribers register their interest in receiving certain notifications. Independently of the subscription method, it is very likely that several subscribers are interested in the same notifications, which the system should broadcast to them. In this case, we are typically interested in having all subscribers of the same information receive the same set of messages. Otherwise the system will provide an unfair service, as some subscribers could have access to a lot more information than other subscribers. Unless this reliability property is given for free by the underlying infrastructure, the sender and the subscribers must coordinate to agree on which messages should be delivered. For instance, with the dissemination of an audio stream, processes are typically interested in receiving most of the information but are able to tolerate a bounded amount of message loss. The corresponding abstraction is typically called a best-effort broadcast. The dissemination of some stock exchange information may require a more reliable form of broadcast, called reliable broadcast, which guarantees that if a correct process receives a message, then all correct processes receive it.

Process Control. Process control applications are those where several software processes have to control the executionn of a physical activity. Typically, every process is connected to some sensor. The processes might, for instance, need to exchange the values output by their assigned sensors and output some common value, despite the fact that, due to the inaccuracy of failure of their local sensors, they may have observed slightly different input values. This cooperation should be achieved despite some sensors (or associated control processes) having crashed or not observed anything. This type of cooperation can be simplified if all processes agree on the same set of inputs for the control algorithm, a requirement captured by the consensus abstraction.

8 CHAPTER 1. INTRODUCTION

According to this model, each component is constructed as a state-machine whose transitions are trig- gered by the reception of events. Events may carry information such as a data message, or group membership information, in one or more attributes. Events are denoted by ⟨EventType | Attributes,.. .⟩.

Often an event with the same name is used by more than one component. For events defined for component co, we, therefore, usually write:

⟨co,EventType | Attributes,.. .⟩

Each event is processed through a dedicated handler by the process. A handler is formulated in terms of a sequence of instructions introduced by upon event, which describes the event, followed by pseudocode with instructions to be executed. The processing of an event may result in new events being created and triggering the same or different components. Every event triggered by a component of the same process is eventually processed, if the process is correct.

The pseudo code of a sample component co 1 that consists of two event handlers looks like this:

upon event ⟨co 1 , Event 1 | att^11 , att^21 ,.. .⟩ do do something; trigger ⟨co 2 , Event 2 | att^12 , att^22 ,.. .⟩;

upon event ⟨co 1 , Event 3 | att^13 , att^23 ,.. .⟩ do do something else; trigger ⟨co 2 , Event 4 | att^14 , att^24 ,.. .⟩;

For writing complex algorithms, we sometimes use handlers that are triggered when some condition in the implementation becomes true, but do not respond to an external event originating from another module. The condition for an internal event is usually defined on local variables maintained by the algorithm. Such a handler consists of an upon statement followed by a condition; in a sample component co, it might look like this:

upon condition do do something;

An upon event statement triggered by an event from another module can also be qualified with a condition on local variables. This handler executes its instructions only when the external event has been triggered and the condition holds. Such a conditional event handler of a component co has the following form:

upon event ⟨co, Event | att^11 , att^21 ,.. .⟩ such that condition do do something;

An algorithm that uses conditional event handlers relies on the run-time system to buffer external events until the condition on internal variables becomes satisfied. We use this convention because it simplifies the presentation of many algorithms, but the approach should not be taken as a recipe for actually implementing a practical system: such a run-time system might need to maintain unbounded buffers. But, it is not difficult to avoid conditional event handlers in an implementation. Every conditional event handler can be transformed into a combination of a (pure) event handler and two handlers for internal events in three steps: (1) introduce a local variable for storing the external event when it occurs and install an event handler triggered by the external event without any condition; (2) introduce a local variable for storing that the condition on the internal variables has become true; and (3) add a local event handler that responds to the internal event denoting that the external event has occurred and the internal condition has been satisfied.

1.2.2 Programming Interface

The APIs of our components include two types of events, requests and indications; their detailed seman- tics depend on the component at which they occur:

  • A request event is triggered by a component to request a service from another component, typically at the same process. The request event is usually triggered by an event handler of the requesting component.
1.2. SOFTWARE COMPONENTS 9
  • An indication event is triggered by a component to indicate that some event has occurred, typically at the same process. The indication event is usually triggered by an event handler of the indicating component.

Requests and indications do not always carry payload data; they may also indicate conditions for syn- chronizing two layers with each other. For example, the broadcast abstraction may confirm that its service has been concluded reliably by triggering a specialized indication event for the layer above. In this way, a broadcast implementation can require that the application layer waits until a broadcast re- quest is confirmed before triggering the next broadcast request. An analogous mechanism can be used to synchronize the delivery of broadcast messages to the application layer above. When the application layer takes a long time to process a message, for example, the application may trigger a specialized re- quest event for the broadcast abstraction to signal that the processing has completed and the application is now ready for the next broadcast message to be delivered.

Chapter 2

Basic Abstractions

2.1 Model

2.1.1 System and Processes

Definition 2. A system is a set of processes that communicate and coordinate to achieve a common goal.

  • We have n processes (where n is fixed and we know the identities) in Π = {p 0 , p 1 ,... , pn− 1 } with distinct identities.
  • Processes communicate using a communication graph G = (Π, E) where E ⊆ Π × Π (usually, G is a complete graph).
  • The communication happens by exchanging messages on communication links (edges of G), and messages are uniquely identified, say, by their original sender process using a sequence number or a local clock, together with the process identifier.

A process is a (possibly infinite) State Machine (I/O Automation).

  • Internal states - set Q
  • Initial state - Qi ⊂ Q
12 CHAPTER 2. BASIC ABSTRACTIONS
  • Messages - set of all possible messages M in the form

⟨sender, receiver, payload⟩

  • InBufj - multiset of delivered messages
  • OutBufj - multiset of ”inflight” messages (messages sent but not delivered).

Pj (q ∈ Q ∪ Qin, InBufj ) =

q

′ ∈ Q, Send msg ⊂ M

OutBufj = OutBufj ∪ Send msg

InBufj = ∅

2.1.2 Asynchronous Executions

Execution

There is an adversary that schedule a set of events (scheduler):

  • Delivery of a msg - Del(m, i, j): move message m from OutBufi to InBufj ;
  • Execution of a local step - Exec(i): process i executes one step of its state machine.

A configuration Ct is a vector of n components. Component j indicates the state of processes j (that is Ct[j] (qi, InBuf fj , OutBufj )).

It is convenient for presentation simplicity to assume the existence of a global clock, outside the control of the processes. This clock provides a global and linear notion of time that regulates the execution of the algorithms. The steps of the processes are executed according to ticks of the global clock: one step per clock tick.

Unless specified otherwise, we will consider deterministic algorithms. That is, for every step performed by any given process, the local computation executed by the process, the local state after the computation, and the message sent by this process are uniquely determined by the message received by the process and its local state prior to executing the step.

14 CHAPTER 2. BASIC ABSTRACTIONS

2.2 Abstracting Processes

2.2.1 Process Failures

A process executes the distributed algorithm assigned to it through the set of components implementing the algorithm within that process. A failure occurs whenever the process does not behave according to the algorithm. Our unit of failure is the process. When the process fails, all its components fail at the same time. Process abstractions differ according to the nature of the faults that cause them to fail. Possible failures range from a crash, where a process simply stops to execute any steps, over an omission to take some steps, a crash with subsequent recovery, to arbitrary and even adversarial behavior.

2.2.2 Crashes

The simplest way of failing for a process is when the process stops executing steps. The process executes its algorithm correctly, including the exchange of messages with other processes, until some time t, after which it stops executing any local computation and does not send any message to other processes. In other words, the process crashes at time t and never recovers after that time. We call this a crash fault, and talk about a crash-stop process abstraction. With this abstraction, a process is said to be faulty if it crashes at some time during the execution. It is said to be correct if it never crashes and executes an infinite number of steps.

2.2.3 Omissions

An omission fault occurs when a process does not send (or receive) a message that it is supposed to send (or receive) according to its algorithm. In general, omission faults are due to buffer overflows or network congestion that cause messages to be lost.

2.2.4 Crashes with Recoveries

In this case, we say that a process is faulty if either the process crashes and never recovers or the process keeps infinitely often crashing and recovering. Otherwise, the process is said to be correct. Basically, such a process is eventually always up and running. A process that crashes and recovers a finite number of times is correct in this model. Upon recovery, we assume that a process is aware that it has crashed and recovered and the module connet determine if the upper layer has processed the message or decision before crashing or not. There are at least two ways to deal with this issue:

  1. One solution is to change the interfaces between modules. Instead of delivering a message or a decision to the upper layer, the module may instead store the message or the decision in stable storage, which can also be accessed by the upper layer. The upper layer should subsequently access the stable storage and consume the delivered information.
  2. A different approach consists in having the module periodically deliver a message or a decision to the upper layer until the latter explicitly asks for the stopping of the delivery. That is, the distributed programming abstraction implemented by the module is responsible for making sure the application will make use of the delivered information. Of course, the application layer needs to filter out duplicates in this case.

2.2.5 Eavesdropping Faults

When a distributed system operates in an untrusted environment, some of its components may become exposed to an adversary or even fall under its control. A relatively benign form of adversarial action occurs when a process leaks information obtained in an algorithm to an outside entity. The outsider may eavesdrop on multiple processes in this way and correlate all leaked pieces of information with each other. Faults of this kind threaten the confidentiality of the data handled by an algorithm, such as the

2.3. CRYPTOGRAPHIC ABSTRACTIONS 15

privacy of messages that are disseminated by a broadcast algorithm or the secrecy of data written to a storage abstraction. We call this an eavesdropping fault of a process. An eavesdropping fault cannot be detected by observing how an affected process behaves in an algorithm, as the process continues to perform all actions according to its instructions. Eavesdropping can be prevented by cryptography, in particular by encrypting communication messages and stored data.

2.2.6 Arbitrary (Byzantine) Faults

A process is said to fail in an arbitrary manner if it may deviate in any conceivable way from the algorithm assigned to it. The arbitrary-fault behavior is the most general one. When we use it, we make no assumptions on the behavior of faulty processes, which are allowed any kind of output and, therefore, can send any kind of message.

Not surprisingly, arbitrary faults are the most expensive to tolerate, but this is the only acceptable option when unknown or unpredictable faults may occur. One also considers them when the system is vulnerable to attacks, where some of its processes may become controlled by malicious users that deliberately try to prevent correct system operation.

An arbitrary fault is not necessarily intentional and malicious: it can simply be caused by a bug in the implementation, the programming language, or the compiler. This bug can thus cause the process to deviate from the algorithm it was supposed to execute. Faults that are triggered by benign bugs can sometimes be detected, and their effects eliminated, by the process itself or by other processes, through double-checking of results and added redundancy.

2.3 Cryptographic Abstractions

Algorithms that operate in untrusted environments, where messages may be exposed to a malicious adver- sary, rely on cryptographic methods for their protection. The basic cryptographic primitives considered here are: hash functions, MACs, and digital signatures.

The physical implementations of the cryptographic abstractions usually rely on some keys being present at all processes.

2.3.1 Hash Functions

A cryptographic hash function maps a bit string of arbitrary length to a short, unique representation. The functionality provides only a single operation H; its invocation takes a bit string x of arbitrary length as an input parameter and returns a value h, which is a short bit string of fixed length in practice. A hash function is collision-free in the sense that no process, not even one subject to arbitrary faults, can find two distinct values x and x′^ such that H(x) = H(x′).

Formally, one can imagine that the hash function is implemented by a distributed oracle accessible to every process, which maintains a list L of all inputs x that have been queried so far by any process. When a process invokes H on a value x ∈ L, then H responds with the index of x in L; otherwise, H appends x to L and returns its index. The index is represented in binary and padded to a fixed length, which must be large enough such that the space of indices is never exhausted in the execution of any algorithm using the hash function. This ideal implementation models the collision-resistance property of hash functions, but no other properties of real-world hash functions.

2.3.2 Message-Authentication Codes (MACs)

A message-authentication code (MAC) authenticates data between two entities. It is based on a shared symmetric key, which is known only to the sender and to the receiver of a message, but to nobody else. For a message of its choice the sender can compute an authenticator for the receiver. Given an authenticator and a message, the receiver can verify that the message has indeed been authenticated by the sender. It is infeasible for any other entity than the sender and the verifier to come up with a

2.4. ABSTRACTING COMMUNICATION 17

2.4 Abstracting Communication

The abstraction of a link is used to represent the network components of the distributed system. Every pair of processes is connected by a bidirectional link, a topology that provides full connectivity to the processes. In practice, different topologies may implement this abstraction, possibly using routing algorithms.

Messages exchanged between processes over a link are unique. Every message includes enough informa- tion for the recipient of a message to uniquely identify its sender.

When two processes exchange messages in a request–reply manner, they will usually have means to identify which reply message is a response to which request message. This can be achieved by having the processes generate timestamps or unique identifiers, based on sequence numbers, local clocks, or a source of randomness. This assumption alleviates the need for explicitly introducing such timestamps in the algorithm.

2.4.1 Link Failures

In a distributed system, it is possible for messages to be lost when transiting through the network. However, it is reasonable to assume that the probability for a message to reach its destination is nonzero because it is very unlikely that all messages exchanged among two processes are systematically lost unless there is a severe network failure. A simple way to overcome the inherent unreliability of the network is to keep on retransmitting messages until they reach their destinations.

In the following, we introduce five different link abstractions, three of them implemented by the crash- stop process abstraction, one for the crash-recovery abstraction, and one for the Byzantine process abstraction. All are point-to-point abstractions, meaning that they provide communication between a pair of processes.

We will first describe the abstractions of fail-loss links, which captures the basic idea that messages might be lost but the probability for a message not to be lost is nonzero. Then, we describe higher- level abstractions that could be implemented over fair-loss links using retransmission mechanisms. More precisely, we consider stubborn and perfect links abstractions, and show how they can be implemented on top of fair-loss links. These three anstractions assume a crash-fault process abstraction.

We define the properties of each of our link abstractions using two kinds of events:

  • ⟨Send⟩ request event to send a message to another process;
  • ⟨Deliver⟩ indication event that delivers a message.

A process invokes the send request of a link abstraction to request the sending of a message using that abstraction. When the process invokes the request, we say that the process sends the message. It is then up to the link abstraction to transmit the message to the target process, according to the actual specification of the abstraction. The deliver indication is triggered by the algorithm implementing the abstraction on a destination process. When this event occurs on a process p for a message m, we say that process p delivers message m.

2.4.2 Fair-Loss Links

The fair-lossy links abstraction is the weakest variant of the link abstraction considered here. Its interface consists of two events:

  • a request event, used to send messages
  • an indication event, used to deliver the messages
18 CHAPTER 2. BASIC ABSTRACTIONS

Fair-loss links are characterized by three properties. The fair-loss property guarantees that a link does not systematically drop every message. Therefore, if the sender process and the recipient process are both correct, and if the sender keeps retransmitting a message, the message is eventually^1 delivered. The finite duplication property intuitively ensures that the network does not repeatedly perform more retransmissions than that performed by the sending process. Finally, the no creation property ensures that no message is created or corrupted by the network.

(^1) Mean that the message will be delivered sooner or later.