




























































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





























































Appunti di Luca Ferrari - Lorenzo La Corte - Davide Scarrà
A distributed system is a collection of autonomous computing nodes or elements that appears to its users as a single coherent system.
A transaction for us is an independent modification in a system that stores data. While it may modify several parts of the system, we think of it as a single modification.
A tomicity, C onsistency, I solation, D urability. Acid property is the classic set of properties to implement transactions because it makes it easier to think about them.
In a system, you cannot have all of consistency, availability and partition tolerance
We only use a single server, incrementing its memory when it’s needed. At some point the cost is not manageable, or a single server solution still doesn’t work. You can’t afford to lose money because there’s a black-out or a flood.
A desirable alternative would be to divide work between multiple servers:
→ read - fast : clients connect with a server and get a value for a specific key. This process permits fast reads but slow writes and we have to find a way of implementing shared logs.
We need to find a way to implement a shared memory so we will introduce some algorithms that have this aim.
Paxos is about reaching consensus and creating a shared log in an asynchronous distributed system. → Basic Paxos reaches consensus on one line of a shared log. → Multi-Paxos reaches consensus on multiple lines of a shared log.
Suppose we are in a fail-stop scenario : at any point in time one of our computers can fail which means that it will no longer send messages to other computers or participate in the protocol until it comes back alive, but all computers remember where they were when they left off. In addition, the network can fail , and when the network fails, it looks like the node at the far end of a network link is failed so the protocol doesn't really care if a node fails or the network that talks to that node has failed. We need to reach consensus in this scenario. Say you have an old mobile phone, and want to decide with your friends whether to go for pizza or sushi; you want to all agree and go to the same place. A possible solution is majority voting , and this works but the problem is that nodes can stop work (fail): any message may get lost or arrive even after days. Our network can be arbitrarily slow, we want to be able to tolerate the fact that sometimes packets get lost and come back after a long time. For example, our old mobile phone doesn’t work and so my messages arrive very late. But:
Case 3 - Failure of proposer in prepare phase In this particular case somebody else will take the role of the proposer. In particular (43.2, “pizza”) is the new proposal. 43 is the new round - 2 is the number of the machine proposing - “pizza” is the proposed value. Case 4 - Failure of proposer in accept phase In this particular case, when server 1 (proposer) fails:
So server 2 proposes another value and so server 3 sees the conflict and makes it explicit, notifying the other machines (server 2 in this case). In particular server 3 answer contains both the round identifiers of the two proposals and the already accepted value (“sushi”). Once server 2 knows there’s a conflict it accepts the old proposal because server 3 already accepted it.
Paxos can solve the leader election problem. In general it works on all cases: the worst (theoretically) can happen is a livelock where everyone’s stuck doing a loop of actions in parallel. Multi-Paxos builds a full log of decisions and it’s way faster (one round-trip per transaction). On the other hand Multi-Paxos is way more complex developing, debugging and testing hard and so there are very few implementations of it.
RAFT is an easier and more comprehendible algorithm than Paxos. It has three main roles which are the leader , the follower , and the candidate. In the first case everything goes fine:
Leader requests to append entries to followers. Followers receive entries and answer back to the leader. When everyone’s table is up to date the leader commits the entry with a heartbeat, so everyone knows it’s persistent. Each node saves and shows to others the last committed entry.
Let’s analyze the Worst case possible: Leader ends up in a partition with minority of node so he can’t finalize/commit new rows:
A new Leader is elected and can finalize new rows, while at the same time the other partition can’t commit entries because they are in minority: When the network is established again logs are being synchronized through this process: L1 becomes a follower because has the minor term and everyone’s table is updated with the only things committed (by the partition with majority of nodes):
When an entire machine fails it should take back all actions from other nodes and recover its state. The problem is that often the actions done can be a lot so recovery time increases as log length increases. When we have very large logs it may be inefficient to restore them at once and the best option is to save intermediate states with checkpoints ; to do this we need to:
It simplifies the implementation but needs an alternative solution to wait for conditions.
All operations on the same client will be serialize in FIFO order:
Clients can request to be notified of changes: when a change happens the client gets notified; they get notification of a change before seeing the result.
Zookeeper implementation starts from the idea of a distributed file system , to coordinate apps and then this idea was edited in order to make it work. ZooKeeper designers have seen that their engineers were using the NFS to coordinate their applications but this worked only partly. So, Zookeeper works like a filesystem for small pieces of data , with some modifications:
Is built through the use of hierarchical namespace. Znodes are like both file and directories:
Ephemeral : Znode is deleted when the creator fails. if a worker is created by a session, if the session fails or ends also the workers are deleted. also the locks are ephemeral. Sequence : append a monotonically-increasing counter. locks are enumerated in sequential order.
Observation of data : A worker starts and gets the configuration:
Note: every node only watches the one in front of the queue.
These are more relaxed locks which we need for reading. We don’t want anybody to write while we are reading, but it is possible to read while someone is also reading.
All servers have a full copy of the state in memory. Uses a consensus protocol that’s similar to RAFT → there’s a leader. In this case, we mean leader in architecture, while before (in the configuration) we were talking about ZNodes’s leader. Update is committed when a majority of servers saved the change :
Read → contact one of the servers and he just answers:
If the number of servers grows:
One write at a time in the whole system : when you are writing somewhere, you can’t read ; these are unreasonable for a huge system.
Pieces of information are annotated with time:
A system created to evaluate time with high reliability. The key idea is bounded uncertainty : TrueTime.now() returns an interval: [earliest, latest] Meaning: time is between earliest and latest. Each datacenter has a set of time master machines:
One of the time masters could be wrong: to weed out liars, an algorithm is needed. Problem: given n [𝑎𝑖, 𝑏𝑖]intervals, find the sub-interval that is consistent with most cases:
𝑖
𝑖
𝑀
𝑀
After the clock is synchronized, the uncertainty grows according to worst-case assumptions on computers’ clock drift : the clock tends to lose precision after long periods but locks that ‘go crazy’ are very rare (6 times less than CPUs that do), TrueTime Precision :