Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency Control in Distributed Database Systems Intelligent Information Systems Seminar 2 nd Sep 2015 Based on: Philip A. Bernstein and Nathan Goodman.

Similar presentations


Presentation on theme: "Concurrency Control in Distributed Database Systems Intelligent Information Systems Seminar 2 nd Sep 2015 Based on: Philip A. Bernstein and Nathan Goodman."— Presentation transcript:

1 Concurrency Control in Distributed Database Systems Intelligent Information Systems Seminar 2 nd Sep 2015 Based on: Philip A. Bernstein and Nathan Goodman. "Concurrency Control in Distributed Database Systems." ACM Computing Surveys (CSUR) 13.2 (1981): 185-221. Mahdi Jaberzadeh Ansari

2 Outline 1.Distributed Database Systems o Centralized DBS Vs. Distributed DBS o DDBMS 2.Transaction-Processing Models o Transaction Managers and Data Managers in DDBMS o Two-Phase Commit Algorithm 3.Concurrency Control in DDBMS o Concurrency Control Anomalies o Concurrency Control in DDBMS Vs. Mutual Exclusion in OSs 4.Distributed Synchronization Techniques o Tow-Phase Locking Algorithm o Wound-Wait Locking Algorithm 2IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn

3 Centralized Multi-User DBS IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn3 Distributed Database Systems DBMS DB

4 Distributed Multi-User DBS IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn4 Distributed Database Systems DBMS DB DBMS DB DBMS DB DDBS A distributed database system (DDBS) is a collection of multiple, logically interrelated databases distributed over a network.

5 Distributed Multi-User DBMS IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn5 Distributed Database Systems DBMS DB DBMS DB DBMS DB DDBMS A DDBMS is the software that manages the DDB and provides an access mechanism that makes this distribution transparent to the users.

6 A Simple Architecture of a DDBMS 6 Transaction Managers (TMs) supervise interactions between users and the DDBMS while Data Managers (DMs) manage the actual database. DB 1 DB 2 DB 3 DM1 DM3 DM2 TM1 TM3 TM2 T1 …. Tn T1 …. Tn T1 …. Tn Four operations are available at each TM interface: o READ(X) o WRITE(X, Val) o BEGIN o END Distributed Transaction-Processing Model IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Distributed Database Systems DDBMS DBMS 1 DBMS 2 DBMS 3

7 Centralized Transaction-Processing Model A centralized DBMS consists of one TM and one DM executing at one site. 7 DM TM T X T’s Private network dm-write(x) dm-read(x) BEGIN READ(X) WRITE(X, new-value) END TM initializes for T a private network. Sends dm-read(x) if not exists in private network, and returns its value. If X exists in private network rewrites it, otherwise create it with new value. The TM issues dm-write(x) for updated items. DB X X’ IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Transaction-Processing Models

8 Two-Phase Commit In composed transactions a DBMS can avoid partial results by having property of atomic commitment. Atomic commitment means all of a transaction’s dm-writes are processed or none are. 8 DM TM T X T’s Private network dm-write(X) X’ YY’ DB Y dm-write(Y) Secure Storage Y X END X’X Incorrect Data DB Recovery dm- write(Y) Failed during 2 nd phase dm-write(X) ✓ prewrite(X,Y) IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Transaction-Processing Models Secure Storage is part of the permanent memory which is used to save some partial data or some rows of DB temporally. First Phase Second Phase

9 Distributed Transaction-Processing Model (1) 9 DM TM T X T’s Private network X’ DB Secure Storage X BEGIN X’ X prewrite(X) dm-write(X) READ(X) dm-read(X) WRITE(X) END DM DB Secure Storage Xi’Xi’ X TM T’ Two-Phase Commit It has to be repeated for each copy of X in all sites. Now assume the commit failed on the second DM. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Transaction-Processing Models

10 dm- write(X) Distributed Transaction-Processing Model (2) 10 DM1 TM1 T X T’s Private network X’ DB Secure Storage X’ END DM2 DB Secure Storage Xi’Xi’ X TM2 T’ Slightly modify the prewrites to include all involved DMs. X, DM1 prewrite(X, DM1 ) dm-write(X) X IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Transaction-Processing Models Two-Phase Commit

11 Concurrency Control Definition Concurrency control is the activity of coordinating concurrent accesses for updates to a database in a multi-user DBMS or DDBMS. The goal is to prevent database updates performed by one user from interfering with database retrievals and updates performed by another one. An algorithm to perform such control in a multi-user DDBMS is called a synchronization technique. 11IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn http://www.cliparthut.com/clip-arts/127/policeman-clip-art-127884.gif Concurrency Control in DDBMS

12 Anomalies (1): Lost Update Anomaly 12 Execution of T1Execution of T2 $ 5,000 $ 1,000$ 2,000 $ 4,000 $3,000 Read balance. Sub $1,000.Sub $2,000. Write Result back to DB. Time Bank Lost $1,000. It must be $2,000. In this example 2 users try to update same row of 1 table simultaneously. Tom has an account with 2 ATM cards. Tom at ATM1 wants to withdraw $1,000 in Germany to buy a suit. In a very same time, Tom’s wife which has the second ATM card, wants to withdraw $2,000 in Australia to buy a pair of high heels. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

13 Anomalies (2) : Inconsistent Retrieval Anomaly 13 Execution of T1 Execution of T2 S $2,000 C $500 $ 2,000 $ 1,000 S $1,000 C $500 S $1,000 C $1,500 $ 500 $ 1,500 S $ 1,000 C $500 Ʃ = $1,500 Read saving balance - $1,000 Write result Read Saving and Checking balances Print Sum Read Checking balance + $1,000 Write result Time It must be $2,500 Temporal Result Tom at ATM1 wants to transfer $1,000 from Saving account to his Checking account. A little bit later, Tom’s wife which has the second ATM card, wants to print total amount of money that they have. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

14 Comparison with Mutual Exclusion in OSs (1) Concurrency control in DDBS and mutual exclusion in operating systems are similar in that, both are concerned with controlling concurrent access to shared resources. However, control schemes that work for one, do not necessarily work for the other. 14 http://csunplugged.org/routing-and-deadlock/ IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

15 Comparison with Mutual Exclusion in OSs (2) Suppose processes P1 and P2 require access to resources R1 and R2 at different points in their execution. 15 Time Execution of P1Execution of P2Resources P1 R1 R2 P2 P1 It is OK in OS concept. However in a database, this execution is not always acceptable. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

16 Comparison with Mutual Exclusion in OSs (3) Assume P1 wants to transfer $1000 from R1 to R2, while P2 wants to print balances and sum of balances must be true. 16 Execution of P1Execution of P2 $ 2,000 R1 $2,000 R2 $500 - $1,000 P1 R1 $1,000 P2 R1 $1,000 R2 $1,500 P1 $ 500 + $1,000 $500 $1,000 P2 reads wrong result for R2 balance. Time IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

17 Principal Issues in Concurrency Control There are 2 correctness criteria for each concurrency control algorithm: 1)It is expected that each transaction submitted to the system be executed eventually. 2)It is expected the computation performed by each transaction to be the same whether it executes alone in a dedicated system or in parallel with other transactions in a DDBS. 17 DB DM1 T3T2T1 DB DM2 T3T2T1 IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Concurrency Control in DDBMS

18 Serializability IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn18 Distributed Synchronization Techniques $5000 $2000 DB $5000 $3000 DB $5000 $2500 DB $5000 $2000 DB $5000 $1500 DB $5000 $6700 DB $5000 $4500 DB The order of concurrent transactions is serializable if the result of that be coincide with the result of the one of the possible sterilized orders. The art of finding such order in the partial transactions is called serializability. Serialized orders Concurrency

19 Two-Phase Locking (1) 19 The Two-Phase Locking (2PL) protocol forces each transaction to make a lock or unlock request in two steps: o Growing Phase: A transaction may obtain locks but may not release any locks. o Shrinking Phase: A transaction may release locks but not obtain any new lock. While the 2PL protocol guarantees serializability, it does not ensure that deadlocks do not happen. In this algorithm local and global deadlock detectors are looking for deadlocks periodically and solve them with restarting transactions to their initial states. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Distributed Synchronization Techniques

20 T1 was continuing updating X on DM2 without any knowledge of T2. Now it is time to release all locks. And awake the next queued transaction. Same as before, just form a private network for transaction. If LOCAL X is free then put a Read Lock on It. Keep the lock till END or change to WL. Main approach in 2PL is “Read Any, Write all”. Now just store new value of X in workspace. To update an item, write locks are required on all copies. Two-Phase Locking (2) 20 DM1 TM1 T1 X T’s Private network X’ DB Secure Storage X BEGIN X’ X prewrite(X) dm-write(X) READ(X) dm-read(X) WRITE(X) END DM2 DB Secure Storage Xi’Xi’ TM1 T2 prewrite(X, DM1) X, DM1 Now by having all locks, start to update all copies. dm-write(X) X’ X BEGIN READ(X) T2’s Private network Now in the middle of updating another transaction arisen. dm-write(X) But it must wait, because LOCAL X is lock. IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Distributed Synchronization Techniques

21 Wound-Wait Locking 21 Wound-Wait locking algorithm follows the same approach as the 2PL protocol. Except it does not have deadlock detector and uses timestamps to prevent deadlock. RequestsT1 isT1 is allowed to t(T1) > t(T2)  YoungerWait for T2(the older one) until it finishes. t(T1) < t(T2)  OlderAbort and rolled back and allowed T2 to be done. Time DB X TM1DM1 TM2 T1 T2 IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn Distributed Synchronization Techniques

22 Conclusion 1.Distributed Database Systems o Centralized and Distributed Multi-User DBS. o DDB, DDBS, DDBMS. 2.Transaction-Processing Models o Centralized and Distributed Transaction-Processing Models o Transaction Managers(TM) and Data Managers(DM) in DDBMS o 4 Main Operations in a TM Transaction in a DBMS and in a DDBMS: BEGIN, READ, WRITE, END o Modified Two-Phase Commit Algorithm in DDBMS 3.Concurrency Control in DDBMS o Concurrency Control Anomalies Lost Update Anomaly, Inconsistent Retrieval Anomaly o Concurrency Control in DDBMS versus Mutual Exclusion in OSs 4.Distributed Synchronization Techniques o Tow-Phase Locking Algorithm o Wound-Wait Locking Algorithm 22IIS Seminar: Concurrency Control In Distributed DBS Mahdi Jaberzadeh Ansari University of Bonn

23 23 The End. IIS Seminar: Concurrency Control In Distributed DBMS Mahdi Jaberzadeh Ansari University of Bonn


Download ppt "Concurrency Control in Distributed Database Systems Intelligent Information Systems Seminar 2 nd Sep 2015 Based on: Philip A. Bernstein and Nathan Goodman."

Similar presentations


Ads by Google