Topics in Distributed Databases Database System Implementation CSE 507 Some slides adapted from Navathe et. Al and Silberchatz et. Al.

Slides:



Advertisements
Similar presentations
Types of Distributed Database Systems
Advertisements

More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Distributed Systems Distributed Coordination. Introduction Concurrent processes in same system –Common memory and clock –Easy to see order of events Concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Lectures 25-26: Distributed Coordination (Ch 18)
Chapter 18: Distributed Coordination Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 18 Distributed Coordination Event Ordering.
(c) Oded Shmueli Distributed Recovery, Lecture 7 (BHG, Chap.7)
Distributed Databases John Ortiz. Lecture 24Distributed Databases2  Distributed Database (DDB) is a collection of interrelated databases interconnected.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Chapter 13 (Web): Distributed Databases
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 17 Distributed Coordination Event Ordering Mutual Exclusion Atomicity Concurrency.
Jan. 2014Dr. Yangjun Chen ACS Database recovery techniques (Ch. 21, 3 rd ed. – Ch. 19, 4 th and 5 th ed. – Ch. 23, 6 th ed.)
ICS 421 Spring 2010 Distributed Transactions Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 3/16/20101Lipyeow.
Database Replication techniques: a Three Parameter Classification Authors : Database Replication techniques: a Three Parameter Classification Authors :
Chapter 25 Distributed Databases and Client-Server Architectures Copyright © 2004 Pearson Education, Inc.
Transaction Management and Concurrency Control
CS 582 / CMPE 481 Distributed Systems
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Lecture-12 Concurrency Control in Distributed Databases
Manajemen Basis Data Pertemuan 10 Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
Chapter 18.2: Distributed Coordination Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 18 Distributed Coordination Chapter.
Chapter 18: Distributed Coordination (Chapter 18.1 – 18.5)
©Silberschatz, Korth and Sudarshan19.1Database System Concepts Distributed Transactions Transaction may access data at several sites. Each site has a local.
©Silberschatz, Korth and Sudarshan19.1Database System Concepts Lecture-10 Distributed Database System A distributed database system consists of loosely.
1 More on Distributed Coordination. 2 Who’s in charge? Let’s have an Election. Many algorithms require a coordinator. What happens when the coordinator.
1 ICS 214B: Transaction Processing and Distributed Data Management Distributed Database Systems.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
Distributed Databases
04/20/2005Yan Huang - CSCI5330 Database Implementation – Distributed Database Systems Distributed Database Systems.
Distributed Deadlocks and Transaction Recovery.
04/18/2005Yan Huang - CSCI5330 Database Implementation – Distributed Database Systems Distributed Database Systems.
DISTRIBUTED DATABASE SYSTEM.  A distributed database system consists of loosely coupled sites that share no physical component  Database systems that.
©Silberschatz, Korth and Sudarshan19.1Database System Concepts 1 Chapter 19: Distributed Databases Heterogeneous and Homogeneous Databases Distributed.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Lecture 16- Distributed Databases Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 12 Distributed Database Management Systems.
DISTRIBUTED COMPUTING
Operating Systems Distributed Coordination. Topics –Event Ordering –Mutual Exclusion –Atomicity –Concurrency Control Topics –Event Ordering –Mutual Exclusion.
A/18-849B/95-811A/19-729A Internet-Scale Sensor Systems: Design and Policy Lecture 7 Part 1. Distributed Databases Part 2. IrisNet Query Processing.
University of Tampere, CS Department Distributed Commit.
1 Distributed Databases (DDBs) Chap Distributed Databases Distributed Systems goal: –to offer local DB autonomy at geographically distributed locations.
ASMA AHMAD 28 TH APRIL, 2011 Database Systems Distributed Databases I.
Databases Illuminated
Distributed Database. Introduction A major motivation behind the development of database systems is the desire to integrate the operational data of an.
Distributed Transactions Chapter – Vidya Satyanarayanan.
Distributed Databases
Distributed Transaction Management. Outline Introduction Concurrency Control Protocols  Locking  Timestamping Deadlock Handling Replication.
Chapter 19 Distributed Databases. 2 Distributed Database System n A distributed DBS consists of loosely coupled sites that share no physical component.
Distributed Database: Part 2. Distributed DBMS Distributed database requires distributed DBMS Distributed database requires distributed DBMS Functions.
Introduction to Distributed Databases Yiwei Wu. Introduction A distributed database is a database in which portions of the database are stored on multiple.
Distributed DBMS, Query Processing and Optimization
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
©Silberschatz, Korth and Sudarshan18.1Database System Concepts 3 rd Edition 1 Chapter 18: Distributed Databases Distributed Data Storage Network Transparency.
CMS Advanced Database and Client-Server Applications Distributed Databases slides by Martin Beer and Paul Crowther Connolly and Begg Chapter 22.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 22: Distributed.
Silberschatz and Galvin  Operating System Concepts Module 18: Distributed Coordination Event Ordering Mutual Exclusion Atomicity Concurrency.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Distributed Databases and Client-Server Architectures
Chapter 18: Distributed Coordination
Lecture 17- Distributed Databases (continued)
Chapter 19: Distributed Databases
Database System Implementation CSE 507
Commit Protocols CS60002: Distributed Systems
Outline Announcements Fault Tolerance.
CSIS 7102 Spring 2004 Lecture 6: Distributed databases
Distributed Database Systems
DISTRIBUTED DATABASES
Distributed Databases Recovery
Module 18: Distributed Coordination
Presentation transcript:

Topics in Distributed Databases Database System Implementation CSE 507 Some slides adapted from Navathe et. Al and Silberchatz et. Al.

Query Processing in Distributed Databases  Cost of transferring data (files and results) over the network.  This cost is usually high so some optimization is necessary.  Example: Employee at site 1 and Dept at Site 2  Employee at site 1. 10,000 rows. Row size = 100 bytes. Table size = 10 6 bytes.  Department at Site rows. Row size = 35 bytes. Table size = 3,500 bytes. FnameMinitLnameSSNBdateAddressSexSalarySuperssnDno DnameDnumberMgrssnMgrstartdate

Query Processing in Distributed Databases Q: For each employee, retrieve employee name and department name Where the employee works. Q:  Fname,Lname,Dname (Employee Dno = Dnumber Department)

Query Processing in Distributed Databases  Result  The result of this query will have 10,000 tuples, assuming that every employee is related to a department.  Suppose each result tuple is 40 bytes long. The query is submitted at site 3 and the result is sent to this site.  Problem: Employee and Department relations are not present at site 3.

Query Processing in Distributed Databases  Strategies: 1.Transfer Emp and Dept to site 3.  Total transfer = 1,000, = 1,003,500 bytes.

Query Processing in Distributed Databases  Strategies: 1.Transfer Emp and Dept to site 3.  Total transfer = 1,000, = 1,003,500 bytes. 2.Transfer Emp to site 2, execute join at site 2 and send the result to site 3.  Query result size = 40 * 10,000 = 400,000 bytes. Total transfer= 400, ,000,000 = 1,400,000 bytes.

Query Processing in Distributed Databases  Strategies: 1.Transfer Emp and Dept to site 3.  Total transfer = 1,000, = 1,003,500 bytes. 2.Transfer Emp to site 2, execute join at site 2 and send the result to site 3.  Query result size = 40 * 10,000 = 400,000 bytes. Total transfer= 400, ,000,000 = 1,400,000 bytes. 3.Transfer Dept to site 1, execute the join at site 1, and send the result to site 3.  Total bytes transferred = 400, = 403,500 bytes.  Optimization criteria: minimizing data transfer.

Query Processing in Distributed Databases Q’: For each department, retrieve the department name and the name of the department manager. Q:  Fname,Lname,Dname (Employee SSN = Mrgssn Department)

Query Processing in Distributed Databases  Result: 100 tuples, assuming that every department has a manager, the execution strategies are: 1.Transfer Emp. and Dept. to the result site 3  Total transfer = 1,000, = 1,003,500 bytes.

Query Processing in Distributed Databases  Result: 100 tuples, assuming that every department has a manager, the execution strategies are: 1.Transfer Emp and Dept to the result site 3  Total transfer = 1,000, = 1,003,500 bytes. 2.Transfer Emp to site 2, execute join at site 2 and send the result to site 3. Query result size = 40 * 100 = 4000 bytes.  Total transfer = ,000,000 = 1,004,000 bytes.

Query Processing in Distributed Databases  Result: 100 tuples, assuming that every department has a manager, the execution strategies are: 1.Transfer Emp and Dept to the result site 3  Total transfer = 1,000, = 1,003,500 bytes. 2.Transfer Emp to site 2, execute join at site 2 and send the result to site 3. Query result size = 40 * 100 = 4000 bytes.  Total transfer = ,000,000 = 1,004,000 bytes. 3.Transfer Dept to site 1, execute join at site 1 and send the result to site 3.  Total transfer size = = 7500 bytes.

Query Processing in Distributed Databases  Now suppose the result site is 2. Possible strategies : 1.Transfer Emp relation to site 2, execute the query and present the result to the user at site 2.  Total transfer size = 1,000,000 bytes for both queries Q and Q’. 2.Transfer Dept relation to site 1, execute join at site 1 and send the result back to site 2.  Total transfer size for Q = 400, = 403,500 bytes and for Q’ = = 7500 bytes.

Query Processing in Distributed Databases  SemiJoin Operation  Reduce the number of tuples in a relation before transferring it to another site.  Example execution of Q or Q’:

Query Processing in Distributed Databases  Example execution of Q or Q’: 1. Project the join attributes of Dept at site 2, and transfer them to site 1. For Q, 4 (size of Dnumber) * 100 = 400 bytes are transferred and for Q’, 9 (size of Mgrssn) * 100 = 900 bytes are transferred.

Query Processing in Distributed Databases  Example execution of Q or Q’: 1. Project the join attributes of Dept at site 2, and transfer them to site Join the transferred file with the Emp at site 1, and transfer the required attributes from the resulting file to site 2. For Q, 34 (size of Lname, Fname, Dno) * 10,000 = 340,000 bytes are transferred and for Q’, 39 (size of Lname, Fname, Mgrssn) * 100 = 3900 bytes are transferred.

Query Processing in Distributed Databases  Example execution of Q or Q’: 1. Project the join attributes of Dept at site 2, and transfer them to site 1. 2.Join the transferred file with the Emp at site 1, and transfer the required attributes from the resulting file to site 2. 3.Execute the query by joining the transferred file with Depart and present the result to the user at site 2.

Recovery in Distributed Databases

Distributed Transactions  Transaction may access data at several sites.  Each site has a local transaction manager for :  Maintaining a log for recovery purposes  Participating in coordinating the concurrent execution of the transactions executing at that site.

Distributed Transactions  Each site has a transaction coordinator for:  Starting the execution of transactions that originate at the site.  Distributing subtransactions at appropriate sites for execution.  Coordinating the termination of each transaction that originates at the site, which may result in the transaction being committed at all sites or aborted at all sites.

Distributed Transactions

System Failure Modes  Failures unique to distributed systems:  Failure of a site.  Loss of massages  Handled by network transmission control protocols such as TCP-IP  Failure of a communication link  Handled by network protocols, by routing messages via alternative links  Network partition  split into two or more subsystems that lack any connection between them  Network partitioning and site failures are generally indistinguishable.

Commit Protocols  Commit protocols are used to ensure atomicity across sites  a transaction which executes at multiple sites must either be committed at all the sites, or aborted at all the sites.  not acceptable to have a transaction committed at one site and aborted at another  The two-phase commit (2PC) protocol is widely used  The three-phase commit (3PC) protocol is more complicated and more expensive, but avoids some drawbacks of 2PC. This protocol is not used in practice.

Commit Protocols  Assumes fail-stop model – failed sites simply stop working, and do not cause any other harm, such as sending incorrect messages to other sites.  Execution of the protocol is initiated by the coordinator after the last step of the transaction has been reached.  The protocol involves all the local sites at which the transaction executed.

2 Phase Commit Protocol --- Phase I  Let T be a transaction initiated at site S i, and let the transaction coordinator at S i be C i  Coordinator asks all participants to prepare to commit transaction T i.  C i adds the records to the log and forces log to stable storage  sends prepare T messages to all sites at which T executed.

2 Phase Commit Protocol – Phase I  Upon receiving message, transaction manager at site determines if it can commit the transaction  if not, add a record to the log and send abort T message to C i  if the transaction can be committed, then:  add the record to the log  force all records for T to stable storage  send ready T message to C i

2 Phase Commit Protocol – Phase II  T can be committed if C i received a ready T message from all the participating sites: otherwise T must be aborted.  Coordinator adds a decision record, or, to the log and forces record onto stable storage.  Coordinator sends a message to each participant informing it of the decision (commit or abort)  Participants take appropriate action locally.

2 Phase Commit – Handling Site Failures When site S i recovers, it examines its log to determine the fate of transactions active at the time of the failure.  Log contain record: txn had completed, nothing to be done  Log contains record: txn had completed, nothing to be done

2 Phase Commit – Handling Site Failures  Log contains record:  Site must consult C i to determine the fate of T.  If T committed, redo (T); write record  If T aborted, undo (T)

2 Phase Commit – Handling Site Failures  The log contains no log records concerning fate of T:  Implies that S k failed before responding to the prepare T message from C i  since the failure of S k precludes the sending of such a response, coordinator C 1 must abort T  S k must execute undo (T)

2 PC – Handling Coordinator Failures If coordinator fails while executing protocol for T the participating sites must decide on T’s fate: 1.If an active site contains a record in its log, then T must be committed. 2.If an active site contains an record in its log, then T must be aborted.

2 PC – Handling Coordinator Failures 3. If some active participating site does not contain a record in its log,  then the failed coordinator C i cannot have decided to commit T.  Can therefore abort T; however, such a site must reject any subsequent message from C i

2 PC – Handling Coordinator Failures 4. If none of the above cases holds,  then all active sites must have a, but no additional control records (such as of ).  In this case active sites must wait for C i to recover, to find decision.  Blocking problem : active sites may have to wait for failed coordinator to recover.

2 PC – Handling Network Partition  If the coordinator and all its participants remain in one partition, the failure has no effect on the commit protocol.

2 PC – Handling Network Partition  If the coordinator and its participants belong to several partitions:  Sites that are not in the partition containing the coordinator think the coordinator has failed, and execute the protocol to deal with failure of the coordinator.  No harm results, but sites may still have to wait for decision from coordinator.

2 PC – Handling Network Partition  The coordinator and the sites are in the same partition as the coordinator think that the sites in the other partition have failed, and follow the usual commit protocol.  Again, no harm results.

Locking in Distributed Databases

Single Lock Manager Approach  System maintains a single lock manager that resides in a single chosen site, say S i  When a transaction needs to lock a data item:  it sends a lock request to S i and lock manager determines whether the lock can be granted immediately.  If yes, lock manager sends back OK  If no, request is delayed until it can be granted.

Single Lock Manager Approach  The transaction can read the data item from any one of its replicas.  Writes must be performed on all replicas of a data item  Advantages of scheme:  Simple implementation  Simple deadlock handling  Disadvantages of scheme are:  Bottleneck: lock manager site becomes a bottleneck  Vulnerability: system is vulnerable to lock manager site failure.

Distributed Lock Manager  In this approach, functionality of locking is implemented by lock managers at each site  Lock managers control access to local data items  But special protocols may be used for replicas  Advantage: work is distributed and can be made robust to failures  Disadvantage: deadlock detection is more complicated  Lock managers cooperate for deadlock detection

Distributed Lock Manager  Several variants of this approach  Primary copy  Majority protocol  Biased protocol  Quorum consensus

Distributed Lock Manager – Primary Copy  Choose one replica of data item to be the primary copy.  Site containing that is called the primary site for that data item  Different data items can have different primary sites  When a transaction needs to lock a data item Q, it requests a lock at the primary site of Q.  Implicitly gets lock on all replicas of the data item

Distributed Lock Manager – Primary Copy  Benefit  Concurrency control for replicated data handled similarly to unreplicated data - simple implementation.  Drawback  If the primary site of Q fails, Q is inaccessible even though other sites containing a replica may be accessible.

Distributed Lock Manager – Majority Protocol  Local lock manager at each site administers lock and unlock requests for data items stored at that site.  When a transaction wishes to lock an unreplicated data item Q residing at site S i,  A message is sent to S i s lock manager.  If Q is locked in an incompatible mode, then wait

Distributed Lock Manager – Majority Protocol  In case of replicated data  If Q is replicated at n sites, then a lock request message must be sent to more than half of the n sites in which Q is stored.  The transaction does not operate on Q until it has obtained a lock on a majority of the replicas of Q.  When writing the data item, transaction performs writes on all replicas.

Distributed Lock Manager – Majority Protocol  Benefit  Can be used even when some sites are unavailable  Of course need to consider site failures  Drawback  Requires 2(n/2 + 1) messages for handling lock requests, and (n/2 + 1) messages for handling unlock requests.  Potential for deadlock even with single item - e.g., each of 3 transactions may have locks on 1/3rd of the replicas of a data.

Distributed Lock Manager – Biased Protocol  Slight variation of majority protocol.  Shared locks. When a transaction needs to lock data item Q, it simply requests a lock on Q from the lock manager at one site containing a replica of Q.  Exclusive locks. When transaction needs to lock data item Q, it requests a lock on Q from the lock manager at all sites containing a replica of Q.

Distributed Lock Manager – Biased Protocol  Advantage –  imposes less overhead on read operations.  Disadvantage –  additional overhead on writes

Distributed Locks– Quorum Consensus Protocol  A generalization of both majority and biased protocols  Each site is assigned a weight. Let S be the total of all site weights  Choose two values read quorum Q r and write quorum Q w  Such that Q r + Q w > S and 2 * Q w > S  Quorums can be chosen (and S computed) separately for each item

Distributed Locks– Quorum Consensus Protocol  Each read must lock enough replicas that the sum of the site weights is >= Q r  Each write must lock enough replicas that the sum of the site weights is >= Q w  For simplicity assume all replicas are written  Of course we need to consider site failures.