Synchronization Chapter 5. - 1 - Contents qClock Synchronization qLogical Clocks qGlobal State qElection Algorithms qMutual Exclusion qDistributed Transactions.

Slides:



Advertisements
Similar presentations
Dr. Kalpakis CMSC621 Advanced Operating Systems Synchronization.
Advertisements

1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same.
Distributed Computing
Synchronization. Why Synchronize? Often important to control access to a single, shared resource. Also often important to agree on the ordering of events.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
Distributed Systems Spring 2009
Chapter 5  Synchronization 1 Synchronization Chapter 5.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
1. Explain why synchronization is so important in distributed systems by giving an appropriate example When each machine has its own clock, an event that.
Synchronization. Physical Clocks Solar Physical Clocks Cesium Clocks International Atomic Time Universal Coordinate Time (UTC) Clock Synchronization Algorithms.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Synchronization Part 2 REK’s adaptation of Claypool’s adaptation ofTanenbaum’s Distributed Systems Chapter 5 and Silberschatz Chapter 17.
Synchronization Chapter 5.
Synchronization Tanenbaum Chapter 5. Synchronization Multiple processes sometimes need to agree on order of a sequence of events. This requires some synchronization,
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
1 Synchronization  Clock Synchronization  and algorithm.
Clock Synchronization and algorithm
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
1 Synchronization Synchronization in centralized systems is easy. Synchronization in distributed systems is much more difficult to achieve. Why do we need.
CS4513 Distributed Computer Systems Synchronization (Ch 5)
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Synchronization.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
Contents Clock Synchronization Logical Clocks Global State
Synchronization Chapter 6
1 Synchronization. 2 Why Synchronize?  Often important to control access to a single, shared resource.  Also often important to agree on the ordering.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
OS2- Sem , R. Jalili Synchronization Chapter 5.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Real-Time & MultiMedia Lab Synchronization Chapter 5.
1 Mutual Exclusion: A Centralized Algorithm a)Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b)Process.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Global State (1) a)A consistent cut b)An inconsistent cut.
Synchronization CSCI 4780/6780. Mutual Exclusion Concurrency and collaboration are fundamental to distributed systems Simultaneous access to resources.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Distributed Systems Principles and Paradigms Chapter 05 Synchronization.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
Synchronization Chapter 5.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Synchronization Chapter 5. Table of Contents Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
3. Synchronization in Distributed Systems
Chapter 5 Synchronization Presenter: Maria Riaz. Distributed Systems – Fall 2004 – Prof. SY Lee2 Sequence of Presentation Synchronization Clock Synchronization.
Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.
Election Distributed Systems. Algorithms to Find Global States Why? To check a particular property exist or not in distributed system –(Distributed) garbage.
Synchronization. Clock Synchronization In a centralized system time is unambiguous. In a distributed system agreement on time is not obvious. When each.
Synchronization CSCI 4900/6900. Transactions Protects data and allows processes to access and modify multiple data items as a single atomic transaction.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Lecture on Synchronization Submitted by
Synchronization Tanenbaum Chapter 5. Synchronization Multiple processes sometimes need to agree on order of a sequence of events. This requires some synchronization,
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Last Class: Canonical Problems
Mutual Exclusion What is mutual exclusion? Single processor systems
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Chapter 5 (through section 5.4)
Prof. Leonardo Mostarda University of Camerino
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

Synchronization Chapter 5

- 1 - Contents qClock Synchronization qLogical Clocks qGlobal State qElection Algorithms qMutual Exclusion qDistributed Transactions qConclusion qCritical Idea

- 2 - Clock synchronization qA simple question: Is it possible to synchronize all the clocks in a distributed system ?

- 3 - Physical Clocks (1) qSome concept: Timer; counter, holding register; clock tick; clock skew. qProb:  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  TAI: the mean number of sticks of the cesium 133 clocks (since 1/1/1958) divided by 9,192,631,770

- 4 - Physical Clocks (2) TAI: highly stable but late  leap second By the way: raising their frequency from 60Hz or 50 Hz  61Hz or 51Hz

- 5 - 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 qProbs: 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

- 6 - 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

- 7 - Averaging Algorithms qAt the beginning of each interval, every machine broadcasts the current time according to its clock. qThen it starts a local timer to collect all other broadcasts that arrive during some interval S. qThe simplest algorithm is just to average the values from all other machines. qOne of the most widely used algorithms in the Internet is the Network Time Protocol (NTP).

- 8 - Assign time to dist. Sys. qIf a happens before b in the same process, C(a) < C(b). qIf 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).

- 9 - Totally order Multicasting  Timestamp can be used to implement totally ordered multicast

Vector timestamps qVT(a) < VT(b)  a: causally precede event b qProperties of vector timestamps V i [i] is the number of events that have occurred so far at P i If V i [j] = k then P j knows that k events have occurred at P j qMessage r (from P J ): reaction of message a (P I )  P K process message r if: vt(r)[j] = V k [j] + 1 vt(r)[i] ≤ V k [i] for all i ≠ j

Global State (1) a)A consistent cut b)An inconsistent cut

Global State (2) a)Organization of a process and channels for a distributed snapshot

Global State (3) b)Process Q receives a marker for the first time and records its local state c)Q records all incoming message d)Q receives a marker for its incoming channel and finishes recording the state of the incoming channel

Election Algorithms qElection algorithms: algorithms for electing a coordinator (using this as a generic name for the special process). qElection algorithms attempt to locate the process with the highest process number and designate it as coordinator. qGoal: 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) qThe bully election algorithm qProcess 4 holds an election qProcess 5 and 6 respond, telling 4 to stop qNow 5 and 6 each hold an election

The Bully Algorithm (2) d)Process 6 tells 5 to stop e)Process 6 wins and tells everyone

Ring Algorithm

a)Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b)Process 2 then asks permission to enter the same critical region. The coordinator does not reply. c)When process 1 exits the critical region, it tells the coordinator, when then replies to 2 Mutual Exclusion Centralized Algorithm

Distributed Algorithm a)Two processes want to enter the same critical region at the same moment. b)Process 0 has the lowest timestamp, so it wins. c)When process 0 is done, it sends an OK also, so 2 can now enter the critical region.

Token Ring Algorithm a)An unordered group of processes on a net work. b)A logical ring constructed in software.

Comparison A comparison of three mutual exclusion algorithms. Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized32Coordinator crash Distributed2 ( n – 1 ) Crash of any process Group communica tion Token ring 1 to  0 to n – 1 Lost token, proces s crash

The Transaction Model (1) Updating a master tape is fault tolerant.

The Transaction Model (2) Examples of primitives for transactions. PrimitiveDescription BEGIN_TRANSACTIONMake the start of a transaction END_TRANSACTIONTerminate the transaction and try to commit ABORT_TRANSACTIONKill the transaction and restore the old values READRead data from a file, a table, or otherwise WRITEWrite data to a file, a table, or otherwise

Four Characteristics qAtomic:to the outside world, the transaction happens indivisibly qConsistent: the transaction does not violate system invariants qIsolated: concurrent transactions do not interfere with each other qDurable: 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 BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi; END_TRANSACTION (a) BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi full => ABORT_TRANSACTION (b)

Classification of Transactions a)A nested transaction b)A distributed transaction

Implementation Private 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 x = 0; y = 0; BEGIN_TRANSACTION; x = x + 1; y = y + 2 x = y * y; END_TRANSACTION; (a) Log [x = 0 / 1] (b) Log [x = 0 / 1] [y = 0/2] (c) Log [x = 0 / 1] [y = 0/2] [x = 1/4] (d)

Concurrency Control (1) General organization of managers for handling transactions

Concurrency Control (2) General organization of managers for handling distributed transactions

Serializability qThe whole idea behind concurrency control is to properly schedule conflicting operations (two read operations never conflict ) qSynchronization can take place either through mutual exclusion mechanisms on shared data (i.e locking) qOr explicitly ordering operations using timestamps

Two-phase locking qA transaction T is granted a lock if there is no conflict qThe 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 qOnce 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 qIn centralized 2PL: a single site is responsible for granting and releasing locks qIn primary 2PL: each data item is assigned a primary copy qIn 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 qLamport timestamps: if a happen before b  C(a) < C(b). qDetermining 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. qSynchronization between processes  choose a coordinator  election algorithms qMutual Exclusion algorithms: can be centralized or distributed

Conclusion & Critical Idea qA transaction consists of a series of operations qA transaction is durable, meaning that if it completes, its effects are permanent qTwo-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