Real-Time & MultiMedia Lab Synchronization Chapter 5.

Slides:



Advertisements
Similar presentations
More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Advertisements

1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
Lock-Based Concurrency Control
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.
Synchronization. Why Synchronize? Often important to control access to a single, shared resource. Also often important to agree on the ordering of events.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Synchronization. Physical Clocks Solar Physical Clocks Cesium Clocks International Atomic Time Universal Coordinate Time (UTC) Clock Synchronization Algorithms.
Database management concepts Database Management Systems (DBMS) An example of a database (relational) Database schema (e.g. relational) Data independence.
Transaction Management and Concurrency Control
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.
Distributed Systems1 Chapter 7: Distributed Transactions Transaction concepts Centralized/Distributed Transaction Architecture Schedule concepts Locking.
Synchronization Chapter 5.
Transaction Management
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 12 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
1 Synchronization  Clock Synchronization  and algorithm.
CS4513 Distributed Computer Systems Synchronization (Ch 5)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
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.
Synchronization Chapter 6 Part III Transactions. –Most of the lecture notes are based on slides by Prof. Jalal Y. Kawash at Univ. of Calgary –Some slides.
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
Massively Distributed Database Systems - Transaction management Spring 2014 Ki-Joune Li Pusan National University.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
1 Mutual Exclusion: A Centralized Algorithm a)Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b)Process.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
1 Transactions Chapter Transactions A transaction is: a logical unit of work a sequence of steps to accomplish a single task Can have multiple.
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.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Distributed synchronization and mutual exclusion 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.
XA Transactions.
Synchronization Chapter Contents qClock Synchronization qLogical Clocks qGlobal State qElection Algorithms qMutual Exclusion qDistributed Transactions.
Synchronization Chapter 5. Table of Contents Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
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.
CSC 8420 Advanced Operating Systems Georgia State University Yi Pan Transactions are communications with ACID property: Atomicity: all or nothing Consistency:
Lecture on Synchronization Submitted by
Transactions Chapter 12 Transactions and Concurrency Control.
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.
Atomic Tranactions. Sunmeet Sethi. Index  Meaning of Atomic transaction.  Transaction model Types of storage. Transaction primitives. Properties of.
Transaction Management
Last Class: Canonical Problems
Synchronization Chapter 5C
Mutual Exclusion What is mutual exclusion? Single processor systems
Chapter 10 Transaction Management and Concurrency Control
Database management concepts
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Synchronization outline
Presentation transcript:

Real-Time & MultiMedia Lab Synchronization Chapter 5

Real-Time & MultiMedia Lab Election Algorithms Often need one process as a coordinator All processes in distributed systems may be equal Assume have some “ID” that is a number Need way to “elect” process with the highest number as leader

Real-Time & MultiMedia Lab The Bully Algorithm (1) The bully election algorithm Process 4 notices 7 down Process 4 holds an election Process 5 and 6 respond, telling 4 to stop Now 5 and 6 each hold an election

Real-Time & MultiMedia Lab Global State (3) Process 6 tells process 5 to stop Process 6 wins and tells everyone Eventually “biggest” (bully) wins If processes 7 comes up, starts elections again everyone

Real-Time & MultiMedia Lab A Ring Algorithm Election algorithm using a ring. Coordinator down, start ELECTION Send message down ring, add ID Once around, change to COORDINATOR (biggest) Even if two ELECTIONS started at once, everyone will pick same leader

Real-Time & MultiMedia Lab Mutual Exclusion: A Centralized 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 d)But centralized, single point of failure

Real-Time & MultiMedia Lab A Distributed Algorithm 1.Processes 0 and 2 want to enter the same critical region at the same moment. 2.Process 1 doesn’t want to, says “OK”. Process 0 has the lowest timestamp, so it wins. Queues up “OK” for 2. 3.When process 0 is done, it sends an OK to 2 so can now enter the critical region. 4.(Again, can modify to say “denied”)

Real-Time & MultiMedia Lab A Toke Ring Algorithm An unordered group of processes on a network. A logical ring constructed in software. Process must have token to enter. If don’t want to enter, pass token along. If host down, recover ring. If token lost, regenerate token. If in critical section long

Real-Time & MultiMedia Lab Comparison A comparison of three mutual exclusion algorithms. Centralized most efficient Token ring efficient when many want to use critical region Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized32Coordinator crash Distributed2 ( n – 1 ) Crash of any process Token ring 1 to  0 to n – 1 Lost token, process crash

Real-Time & MultiMedia Lab The Transaction Model (1) Updating a master tape is fault tolerant.

Real-Time & MultiMedia Lab The Transaction Model Gives you mutual exclusion plus… Consider using PC (Quicken) to: Withdraw $a from account 1 Deposit $a to account 2 If interrupt between 1) and 2), $a gone! Multiple items in single, atomic action It all happens, or none If process backs out, as if never started

Real-Time & MultiMedia Lab The Transaction Model (2) Examples of primitives for transactions. Above may be system calls, libraries or statements in a language (Sequential Query Language or SQL) 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

Real-Time & MultiMedia Lab The Transaction Model (3) a)Transaction to reserve three flights commits b)Transaction aborts when third flight is unavailable c)The “all-or-nothing” is one property. Others 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)

Real-Time & MultiMedia Lab Transaction Properties ACID Atomic – Others don’t see intermediate results, either Consistent System invariants not violated Ex: no money lost after operations) Isolated Operations can happen in parallel but as if were done serially Durability Once commits, move forward (Ch 7, won’t cover more)

Real-Time & MultiMedia Lab Classification of Transactions Flat Transactions Limited Example: what if want to keep first part of flight reservation? If abort and then restart, those might be gone. Example: what if want to move a Web page. All links pointing to it would need to be updated. It could lock resources for a long time Also Distributed and Nested Transactions

Real-Time & MultiMedia Lab Distributed Transactions a)A nested transaction b)A distributed transaction Nested transaction gives you a hierarchy –Can distribute (example: WP  JFK, JFK  Nairobi) –But may require multiple databases Distributed transaction is “flat” but across distributed data (example: JFK and Nairobi dbase

Real-Time & MultiMedia Lab Private Workspace (1) File system with transaction across multiple files Normally, updates seen + No way to undo Private Workspace  Copy files Only update Public Workspace once done If abort transaction, remove private copy. But copy can be expensive! How to fix?

Real-Time & MultiMedia Lab Private Workspace 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 c)Replace original file (new blocks plus descriptor) after commit

Real-Time & MultiMedia Lab Writeahead Log a) A transaction b) The log before each statement is executed If transaction commits, nothing to do If transaction is aborted, use log to rollback 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)

Real-Time & MultiMedia Lab Concurrency Control (1) General organization of managers for handling transactions.

Real-Time & MultiMedia Lab Concurrency Control (2) General organization of managers for handling distributed transactions.

Real-Time & MultiMedia Lab 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

Real-Time & MultiMedia Lab Serializability a) Three transactions T 1, T 2, and T 3. Answer could be 1, 2 or 3. All valid. –2 is serialized Concurrency controller needs to manage BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION (a) BEGIN_TRANSACTION x = 0; x = x + 2; END_TRANSACTION (b) BEGIN_TRANSACTION x = 0; x = x + 3; END_TRANSACTION (c) Schedule 1x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3Legal Schedule 2x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3;Legal Schedule 3x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3;Illegal (d)

Real-Time & MultiMedia Lab Two-Phase Locking (1) 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 Acquire locks (ex: in previous example). Perform update. Release. Can lead to deadlocks (use OS techniques to resolve) Can prove: if used by all transactions, then all schedules will be serializable

Real-Time & MultiMedia Lab Two-Phase Locking (2) 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

Real-Time & MultiMedia Lab Pessimistic Timestamp Ordering Concurrency control using timestamps.

Real-Time & MultiMedia Lab Timestamp Ordering Pessimistic Every read and write gets a timestamp (unique, using Lamport’s alg) If conflict, abort sub-operation and re-try Optimistic Allow all operations since conflict rate At end, if conflict, roll-back

Real-Time & MultiMedia Lab 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