Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same.

Similar presentations


Presentation on theme: "1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same."— Presentation transcript:

1 1 Chapter 3. Synchronization

2 STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same clock Shared data for synchronization Semaphore for mutual exclusion Synchronization in distributed system Difficult to handle it No same physical clock No shared data for synchronization Machine 1Machine 2 Semaphore Remote Access : Delay and Error

3 STEMPusan National University STEM-PNU 3 Clock In distributed systems Multiple Physical Clocks : No Centralized Clock Logical Clock rather than a Global Physical Clock

4 STEMPusan National University STEM-PNU 4 Global Clock and Logical Clock Global Clock TAI (Temps Atomique International) at Paris Time Server Broadcasting from Satellite Granularity Logical Clock Not absolute time but for ordering Lamport Algorithm Correction of Clock T(A, tx) < T(B, rx)

5 STEMPusan National University STEM-PNU 5 Logical Clock Not absolute time but for ordering Lamport Algorithm Correction of Clock C(A, tx) < C(B, rx) 1 2 3 4 5 5 6 7 8 9 10 11 12 13 14 6 7 8 15 16 17 10 11 12 9 10 13 14 18 19 1 2 3 4 5 5 6 7 8 9 10 11 12 13 14 6 7 8 15 16 17 10 16 17 18 19 18 19 18 19

6 STEMPusan National University STEM-PNU 6 Global Clock and Time Server Global Clock TAI (Temps Atomique International) at Paris Time Server Broadcasting from Satellite Granularity Global Clock Server Adjust local clock Cristian’s Algorithm Berkeley Algorithm Time never runs backward

7 STEMPusan National University STEM-PNU 7 Global State States of each local system Messages in transit Very important to determine the status of distributed system Example : Deadlock Detection Distributed Snapshot : State of distributed systems in a given time

8 STEMPusan National University STEM-PNU 8 Mutual Exclusion : Monitor (Coordinator) In a single system : Easy to implement by semaphore In distributed systems : No shared data for semaphore A Centralized Algorithm Simple But single point of failure

9 STEMPusan National University STEM-PNU 9 Mutual Exclusion : Distributed Algorithm No central coordinator Rule : When a system receive a request Not in CS or Not to enter : OK to requester In CS : No reply To enter : compare Timestamp and one with lower TS wins

10 STEMPusan National University STEM-PNU 10 Mutual Exclusion : Token Ring One with token can enter CS If a system wants to enter CS : wait Token and process it Otherwise, pass token to the next Token Wait until it gets the token

11 STEMPusan National University STEM-PNU 11 Mutual Exclusion : Comparison # of messages per request delay per request Problem Monitor32Crash of monitor Distributed Algorithm 2(n-1) n points of Crash Token Ring0 to n-1 Token lost

12 STEMPusan National University STEM-PNU 12 Election : Bully Algorithm When it is found that a coordinator is required

13 STEMPusan National University STEM-PNU 13 Election : Ring Algorithm When it is found that the coordinator has crashed, Circulate message with priority

14 STEMPusan National University STEM-PNU 14 Distributed Transaction Transaction Example : Flight Reservation Consistent State Consistent State Set of operations 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)

15 STEMPusan National University STEM-PNU 15 ACID Properties : Atomicity and Consistency Atomicity. All or Nothing Not Partially Done Example : Failure in Flight Reservation Consistency. Execution of a transaction preserves the consistency of the database. State 1 State 2 All Nothing State 2’ Partially Done Consistent

16 STEMPusan National University STEM-PNU 16 Transaction States Active Partially Committed FailedAborted Committed the initial state; the transaction stays in this state while it is executing after the discovery that normal execution can no longer proceed. after the transaction has been rolled back and the database restored to its state prior to the start of the transaction. - restart the transaction or - kill the transaction ALL NOTHING

17 STEMPusan National University STEM-PNU 17 ACID Properties : Isolation and Durability Isolation. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions. Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. DB Transaction 1 Transaction 2 No Effect

18 STEMPusan National University STEM-PNU 18 Example Transaction : Transfer $50 from account A to account B: 1.read(A) 2.A := A – 50 3.write(A) 4.read(B) 5.B := B + 50 6.write(B) Consistency requirement the sum of A and B is unchanged after the transaction. Atomicity requirement Durability Isolation

19 STEMPusan National University STEM-PNU 19 Example : Concurrent Execution Two Transactions T 1 : transfer $50 from A to B, T 2 transfer 10% of the balance from A to B Serial ScheduleConcurrent Schedule

20 STEMPusan National University STEM-PNU 20 Serializability What happens after these transactions ? Serial Schedule : Always Correct T1  T2 and T2  T1 Concurrent Schedule Serializable if Result (T1||T2) = Result(T1  T2) or Result(T2  T1)

21 STEMPusan National University STEM-PNU 21 Transaction : Atomicity Failure during transaction Abort the partial execution How to discard incomplete transaction Deferred updates Immediate updates Safe transaction Decrease failure probability Rollback Recovery Return to initial state Without minimum cost

22 STEMPusan National University STEM-PNU 22 Safe Transaction Decrease the possibility of failure Two Phase Commit Wedding Ceremony Protocol 1 st Phase : send ready message 2 nd Phase : execute only when OK messages are received from all

23 STEMPusan National University STEM-PNU 23 Log History of operations Used for rollback (Transaction#, Pre-state, Post-state) (Trans#, DataItem, OldValue, NewValue) Transaction operation1 operation3 operation2 System log

24 STEMPusan National University STEM-PNU 24 Deferred Updates Reflect Logs after Commit Shadowing If the transaction fails, then discard logs Transaction operation1 operationn... System Begin Commit Write or update operations log

25 STEMPusan National University STEM-PNU 25 (T1, begin) (T1, A, 20, 30) (T2, begin) (T1, B, 30, 40) (T2, B, 40, 50) (T1, commit) (T3, begin) (T2, C, 100, 50) (T2, commit) (T3, D, 10, 20) Delete them OK Deferred Updates : Recovery Log File Fail Here 1. Transaction with commit: OK 2. Transaction with begin but without commit : Delete log records

26 STEMPusan National University STEM-PNU 26 Transaction Begin Commit Immediate Updates Execute operation immediately If the transaction fails, undo operations operation1 operation3 operation2 System log

27 STEMPusan National University STEM-PNU 27 Which one is better ?

28 STEMPusan National University STEM-PNU 28 Transaction : Serializability Serialization Exchange non-conflict operation Conflict operation : Result(T1.Op,T2.Op) ≠ Result(T2.Op,T1.Op) Time-stamping Two Phase Locking r(a)w(a)r(b)w(b) r(a)w(a)r(b)w(b) Trans 1 Trans 2 Time

29 STEMPusan National University STEM-PNU 29 Time Stamping If conflict occurs, then abort For read(T,x), ts(T) < ts WR (x), then abort T For write(T,x), ts(T) < ts WR (x) or ts(T) < ts RD (x), then abort T

30 STEMPusan National University STEM-PNU 30 Two Phase Locking 2PL Strict 2PL

31 STEMPusan National University STEM-PNU 31 Implementation of Concurrency Control in Distributed Systems Three Managers TM (Transaction Manager) : Ensure the Atomicity Scheduler : Main Responsibility for Concurrency Control DM (Data Manager) : Simple Read/Write In a single machine In distributed systems


Download ppt "1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same."

Similar presentations


Ads by Google