Layers:
physical: bit synchronization, bit rate control, bus, simplex/half-duplex/full-duplex (implemented by physical wires)
data-link: Logical Link Control (LLC), Media Access Control (MAC) (implemented by switch)
network (IP): routing, logical IP address (implemented by router)
transport: port number, break message into segments and reassemble, TCP, UDP (implemented by operating system)
session: maintaining sessions, authentications, security, HTTP, RPC (application-implemented)
presentation: Translation layer, encryption/decryption, compression (application-implemented)
application: your code (application-implemented)
Cristian's Time Sync: The accuracy is \pm (RTT/2-\min)
Berkeley Algorithm:
master can sync with UTC server (assume no RTT), not necessary
a group of servers are elected into 1 master and other slave servers.
master send its current time master to all slaves.
slaves respond with time differences dxs.
master receive 2 things: time difference, and calculated roundtrip time RTT.
master average (median) the time difference and add RTT/2, then broadcast the adjusted time to slaves.
Network Time Protocol (NTP): hierarchy of server using Cristian's
Decentralized Mutual Exclusion: ask for majority
Bully Leader Election: Nobody want to be the leader, but everybody can appoint a leader. Everybody must accept appointment unless you can hand the task of the leader to other people.
Ring Algorithm Election: passing paper around, write names on it, select at the end.
Total Ordered Multicast using Total Order Lamport (TO-Lamport) Clock: mark command with lamport clock, keep a queue to process in order by broadcast send and ack to all server.
Lamport Mutual Exclusion: Total Ordered Multicast with slight change, assuming no replicate data among servers
instead of sending command, we send p_i want to access critical region
when processing command, we allow p_i to access critical region
only ACK to one server (sender) instead of broadcasting ACK (only the requester need to know when it can access critical region, assuming no malicious server)
p_i want to access critical region, but might not have consistent ACKED status on every p_i want to access critical region.ACK and have its p_i want to access critical region being the oldest in the queuebroadcast RELEASE lock to all servers once sender has done with critical region
upon receive RELEASE, remove element in the queue no matter whether p_i want to access critical region is ACKED
Ricart & Agrawala Mutual Exclusion: assume no message lost, mul
REQUEST to all serversYESRESUEST:YES if it is not interested in data.YES if it is interested in data, but has not gotten permission, and the lamport clock is the current REQUEST is lower than itself's REQUEST.REQUEST is greater than itself's REQUEST.Token Ring Algorithm: critical section by passing key
ACID Properties:
Atomicity: transaction either complete or abort. It should abort with no side-effect
Consistency: Each transaction preserves a set of invariants about global
Isolation: each transection executes as if it were the only one with the ability to read/write shared global state
Durability: committed transaction's effect will persist
2-phase Locking (2PL): growing, shrinking
Strong Strict 2-phase Locking (SS2PL): we only release all locks at once after all operations finished (still need acquire in order)
One-phase Commit: coordinator force everybody to commit
2-phase Commit: request, vote, broadcast. (blocking when fail after vote "yes")
Log contains:
a <BEGIN> is written before every transaction start
a <COMMIT> is written before every transaction commit
a <DATA> is written for every change to a single object containing
UNDO)REDO)a <CHECKPOINT> is written once a while, stopping all transaction, to keep log short. (You still need to check for un-committed change before <CHECKPOINT> line)
during recovery (REDO or UNDO), we also write to log so that we can handle failure during recovery too
a <TXN-END> is written after <COMMIT> is successfully written to disk (so in recovery, if we see this tag, we can safely ignore this transaction), we don't need to flush this before <COMMIT>.
| Name | Where | Definition |
|---|---|---|
| flushedLSN | Memory | Last LSN in log on disk (change every flush) |
| pageLSN | page | lastest LSN to page (change every record) |
| recLSN | page | first LSN that is dirty (change every flush) |
| lastLSN | Transaction | lastest LSN to txn (every txn's record) |
| MasterRecord | Disk | latest checkpoint (change every checkpoint) |
| prevLSN | Transaction | LSN pointer during reverse, per transaction |
| undoNext | Transaction | what to undo next during recovery (prevLSN) |
Transaction Table (TT): in memory, store
transactionID that is active (not committed)
lastLSN of transactionID
Dirty Page Table (DPT): in memory store
pageID: ID of a dirty page
recLSN: first LSN that made page dirty
Recovery Phrases:
TNX-END: remove txn from ATTUPDATE, UNDO: add txn to ATT (if not already in, set recLSN = LSN)COMMIT: change status to COMMITCHECKPOINT_END: add ATT/DPT infomation of checkpoint to current ATT/DPTATT: all transaction that is active during crashDPT: dirty pages that might not have made it to diskDPT, orDPT, but LSN less than recLSN (already made into disk)UNDO: sync to disk and don't need to UNDO again for next crash
1. write log to disk
2. write page to disk
3. append CLR: <TXN-END> to diskCLR in log (that is not already <TNX-END>) during UNDO, don't UNDO it. Because you already REDO it in redo phrase. Instead, go to undoNext field in the record and start UNDO from there.Phrases:
Prepre Phrase
n and a value vPREPARE(n) to all acceptorsn if greater then record it, since it only want to accept latest proposal. response with accepted proposal with value (n_acc, v_acc)v = max_{n_acc}(v_acc) if exist. (since v_acc is possibly be chosen already)Accept Phrase
(n, v) to all acceptorsaccept if n > n', reject and return current maximum proposal id n_acc.// TODO: review practice exam, do cheatsheet, review homework
Table of Content