Skip to content

Commit

Permalink
Added CS162 lec 23 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
hrushikeshrv committed May 21, 2024
1 parent 726000e commit ff1dc93
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CS162/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Taught by Prof. John Kubiatowicz at UC Berkeley in Fall, 2020
18. [Lecture 19 - Filesystems 1: Performance, Queueing Theory, Filesystem Design]({% link CS162/lec19.md %})
19. [Lecture 20 - Filesystems 2: Filesystem Design, Case Studies]({% link CS162/lec20.md %})
20. [Lecture 21 - Filesystems 3: Case Studies, Buffering, Reliability, Transactions]({% link CS162/lec21.md %})
21. [Lecture 22 - Transactions, End-to-End Arguments, Distributed Decision Making]({% link CS162/lec22.md %})
21. [Lecture 22 - Transactions, End-to-End Arguments, Distributed Decision Making]({% link CS162/lec22.md %})
22. [Lecture 23 - Distributed Decision Making, Networking, TCP/IP]({% link CS162/lec23.md %})
2 changes: 0 additions & 2 deletions CS162/lec22.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ A file system that uses a log in this way to support transactions is called a tr
If we take the concept of a log further, we can make the log itself the file system. It is one continuous sequence of blocks that data is just appended, not modified. As actions are taken (files or directories are created, read, deleted), those actions are also appended to the log. The present state of the file system is then inferred by replaying the actions stored in the log.

As you might expect, this type of filesystem is efficient for writes but not so efficient for reads. However, a good block cache with enough space can make this file system feasible, especially when used with flash memory instead of a hard disk drive. An implementation of a log structured file system is F2FS, a flash file system used in many mobile devices, including the Pixel 3.

## Distributed Systems
32 changes: 32 additions & 0 deletions CS162/lec23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: default
title: "Lecture 23 - Distributed Decision Making, Networking, TCP/IP"
parent: UCB CS 162 - Operating Systems and Systems Programming
nav_order: 22
---

# Distributed Decision Making, Networking, TCP/IP

## General's Paradox
The general's paradox is a problem in which two generals have to decide on a particular time to coordinate their attack. They can only exchange physical messages through messengers, who can be captured by the enemy. If they successfully decide on a time to attack, they will succeed. If they cannot decide on a time and attack at different times, they will fail.

The general's paradox doesn't have a solution. Since the messengers can be captured, you can never be sure that the last message you sent was received. So even if you send an ACK, you can never be sure that the other person got the ACK.

![General's Paradox](./media/lec23-1.png)

## Two-Phase Commit
The two-phase commit protocol was developed by Jim Gray, a Turing award winner and Berkeley alumni. The two-phase commit protocol solves a problem related to the General's paradox, since we cannot solve the general's paradox itself.

The 2PC algorithm has one coordinator node and n workers who are trying to decide whether to commit or abort a transaction. The transaction can be a database transaction, a distributed file system transaction, or any other action that can be committed or aborted.

The high-level overview of the algorithm is -

1. The coordinator asks all workers if they want to commit or abort
2. All workers decide individually if they are ready to commit or if they want to abort
3. All workers reply with their desired action
4. If the coordinator receives "commit" from all workers, it sends a "global-commit" message to each worker, which causes each worker to commit their transaction
5. If the coordinator receives at least one "abort", it sends a "global-abort" message to each worker, which causes each worker to abort their transaction

All workers and the coordinator have an internal log in which they record their decision so that they will remember their decision even after a crash.

![2PC algorithm](./media/lec23-2.png)
Binary file added CS162/media/lec23-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS162/media/lec23-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff1dc93

Please sign in to comment.