880 likes | 1.11k Views
Synchronization. Chapter 5. Contents. Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion Distributed Transactions Conclusion Critical Idea. Clock synchronization.
E N D
Synchronization Chapter 5
Contents • Clock Synchronization • Logical Clocks • Global State • Election Algorithms • Mutual Exclusion • Distributed Transactions • Conclusion • Critical Idea
Clock synchronization • A simple question: Is it possible to synchronize all the clocks in a distributed system ?
Physical Clocks (1) • Some concept: Timer; counter, holding register; clock tick; clock skew. • Prob: • How do we synchronize them with real-world clocks • How do we synchronize the clocks with each other • Mean solar second: measuring a large numbers of day taking average dividing by 86400 • TAI: the mean number of sticks of the cesium 133 clocks (since 1/1/1958) divided by 9,192,631,770
Physical Clocks (2) TAI: highly stable but late leap second By the way: raising their frequency from 60Hz or 50Hz 61Hz or 51Hz
Cristian’s Algorithm • No more than δ/2ρ each machine sends a message to the time server (which has a WWV receiver) asking for the current time • Probs: time must never run backward and it’s take a nonzero amount of time for the time server’s reply to get back to the sender
The Berkeley Algorithm a)The time daemon asks all the other machines for their clock values b)The machines answer c)The time daemon tells everyone how to adjust their clock
Averaging Algorithms • At the beginning of each interval, every machine broadcasts the current time according to its clock. • Then it starts a local timer to collect all other broadcasts that arrive during some interval S. • The simplest algorithm is just to average the values from all other machines. • One of the most widely used algorithms in the Internet is the Network Time Protocol (NTP).
Assign time to dist. Sys. • If a happens before b in the same process, C(a) < C(b). • If a and b represent the sending and receiving of a message, respectively, C(a) < C(b). • For all distinctive events a and b, C(a) ≠ C(b).
Totally order Multicasting Timestamp can be used to implement totally ordered multicast
Vector timestamps • VT(a) < VT(b) a: causally precede event b • Properties of vector timestamps • Vi[i] is the number of events that have occurred so far at Pi • If Vi[j] = k then Pj knows that k events have occurred at Pj • Message r (from PJ): reaction of message a (PI) • PK process message r if: • vt(r)[j] = Vk[j] + 1 • vt(r)[i] ≤ Vk[i] for all i≠j
Global State (1) • A consistent cut • An inconsistent cut
Global State (2) • Organization of a process and channels for a distributed snapshot
Global State (3) • Process Q receives a marker for the first time and records its local state • Q records all incoming message • Q receives a marker for its incoming channel and finishes recording the state of the incoming channel
Election Algorithms • Election algorithms: algorithms for electing a coordinator (using this as a generic name for the special process). • Election algorithms attempt to locate the process with the highest process number and designate it as coordinator. • Goal: to ensure that when an election starts, it concludes with all processes agreeing on who the new coordinator is to be.
The Bully Algorithm (1) • The bully election algorithm • Process 4 holds an election • Process 5 and 6 respond, telling 4 to stop • Now 5 and 6 each hold an election
The Bully Algorithm (2) • Process 6 tells 5 to stop • Process 6 wins and tells everyone
Ring Algorithm • We assume that the processes are physically or logically ordered, so that each process knows who is successor is. • When any process notices that the coordinator is not functioning, it builds ELECTION message containing its own process num and sends message to its successor. • If successor is down, the sender skips over the successor and goes to the next number along the ring, or the one after that, until a running process is located. • At each step , the sender adds its own process num to the list in the message effectively making itself a candidate to be elected as a coordinator.
Mutual ExclusionCentralized Algorithm • Process 1 asks the coordinator for permission to enter a critical region. Permission is granted • Process 2 then asks permission to enter the same critical region. The coordinator does not reply. • When process 1 exits the critical region, it tells the coordinator, when then replies to 2
Distributed Algorithm • When a process wants to enter a critical region, it builds a message containing the name of the critical region it wants to enter , its process number, and the current time. • Sends the message to all other processes, conceptually including itself. • The sending of message is assumed to be reliable. • When a process receives a request message from other process, the action it takes depends on its state with respect to the critical region named in the message. • Three cases have to be distinguished.
Distributed Algorithm contd • 1. If the receiver is not in the critical region and does not want to enter it, it sends back an OK message to the sender. • 2. If the receiver is already in the critical region, it does not reply. Instead, it queues the request. • 3. If the receiver wants to enter the critical region but has not yet done so, it compares the timestamp in the incoming message, the lowest one wins. If the incoming message is lower, the receiver sends back an OK message. If its own message has a lowest timestamp, the receiver queues the incoming request and sends nothing.
Distributed Algorithm example • Two processes want to enter the same critical region at the same moment. • Process 0 has the lowest timestamp, so it wins. • When process 0 is done, it sends an OK also, so 2 can now enter the critical region.
Token Ring Algorithm • An unordered group of processes on a network. • A logical ring constructed in software.
Comparison A comparison of three mutual exclusion algorithms.
The Transaction Model (1) Updating a master tape is fault tolerant.
The Transaction Model (2) Examples of primitives for transactions.
Four Characteristics • Atomic:to the outside world, the transaction happens indivisibly • Consistent: the transaction does not violate system invariants • Isolated: concurrent transactions do not interfere with each other • Durable: once a transaction commits, the changes are permanent
Limitations of Flat Transactions Main limitation: do not allow partial results to be committed or aborted • In the case of updating all of the hyperlinks to a webpage W, which moved to a new location
Classification of Transactions • A nested transaction • A distributed transaction
ImplementationPrivate Workspace A file is only for read not modify there is no need for a private copy a) The file index and disk blocks for a three-block file b) The situation after a transaction has modified block 0 and appended block 3 b) After committing
Writeahead Log a) A transaction b) – d) The log before each statement is executed
Concurrency Control (1) General organization of managers for handling transactions
Concurrency Control (2) General organization of managers for handling distributed transactions
Serializability • The whole idea behind concurrency control is to properly schedule conflicting operations (two read operations never conflict ) • Synchronization can take place either through mutual exclusion mechanisms on shared data (i.e locking) • Or explicitly ordering operations using timestamps
Two-phase locking • A transaction T is granted a lock if there is no conflict • The scheduler will never release a lock for data item x, until the data manager acknowledges it has performed the operation for which the lock was set • Once the scheduler has released a lock on behalf of a transaction T, it will never grant another lock on behalf of T
Strict two-phase locking • In centralized 2PL: a single site is responsible for granting and releasing locks • In primary 2PL: each data item is assigned a primary copy • In distributed 2PL: the schedulers on each machine not only take care that locks are granted and released, but also that the operation is forwarded to the (local) data manager
Pessimistic Timestamp Ordering Concurrency control using timestamps.
Conclusion • Lamport timestamps: if a happen before b C(a) < C(b). • Determining the global state can be done by synchronizing all processes so that each collects its own local state, along with the messages that are currently in transit. • Synchronization between processes choose a coordinator election algorithms • Mutual Exclusion algorithms: can be centralized or distributed
Conclusion & Critical Idea • A transaction consists of a series of operations • A transaction is durable, meaning that if it completes, its effects are permanent • Two-phase locking can lead to dead lock • Acquiring all locks in some canonical order to prevent hold-and-wait cycles • Using deadlock detection by maintaining an explicit graph for cycles • Inheritance Priority Protocol
Consistency and Replication Chapter 6
Content • Definition of Consistency and Replication • Understand Replication • Reason for Replication & Problem of Replication • The only solution for Replication Problem • Consistency Model • Data-centric models & Client-centric models • Distribution Protocols • Distributing updates to replicas • Consistency Protocols • Implementation of consistency models
Consistency and Replication • Introduction: • Replication: • Replication of data Reason for Replication: • Enhance reliability or improve performance • Consistency: • Consistency of replicated data Reason for Consistency: • Keep replicas to be the same
Understanding Replication • Introduction: • Object Replication • Purpose:managing data in distributedsystem • Consider objects instead of data alone • Benefit of encapsulating and operating data • Consistency Problem: Whenever a replica is updated, that replica becomes different from the others. SynchronizationProblem Two Approaches focus on who will deal with it: • Object-specific Replication • Middleware Replication
Understanding Replication Two Approaches • A distributed system for replication-aware distributed objects. • A distributed system responsible for replica management
Only solution for Consistency Problem • Introduction: • Synchronous replication consistency • Key idea: a single atomic operation, or transaction • Difficulties: • need to synchronize all replicas • a lot of communication time • expensive in terms of performance • Only solution: • Loosen the consistency constraints • need notto be executed as atomic operations • copies may not always same
Consistency Models • Introduction: • Consistency Model: • A contract between processes and the data store. • Two kind of Models: • Data-centric Consistency Models • Guarantee for a number of processes • Simultaneously update • Sequential consistency • Client-centric Consistency Models • Guarantee for a single processes • Lack simultaneous updates
Data-centric Consistency Models The general organization of a logical data store, physically distributed and replicated across multiple processes.
Data-centric Consistency Models • Data-centric Consistency Models (7 kinds) • Strict Consistency • Linearizability and Sequential Consistency • Causal Consistency • FIFO Consistency • Weak Consistency • Release Consistency • Entry Consistency Loosen constraints