Distributed Transaction Management

Similar documents
Control. CS432: Distributed Systems Spring 2017

Distributed Databases Systems

Chapter 9: Concurrency Control

Concurrency Control 9-1

Module 8 - Fault Tolerance

Distributed Database Management System UNIT-2. Concurrency Control. Transaction ACID rules. MCA 325, Distributed DBMS And Object Oriented Databases

Module 8 Fault Tolerance CS655! 8-1!

Problems Caused by Failures

Transaction Management. Pearson Education Limited 1995, 2005

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

Database Tuning and Physical Design: Execution of Transactions

Topics in Reliable Distributed Systems

Intro to Transaction Management

Transactions and Concurrency Control

Mobile and Heterogeneous databases Distributed Database System Transaction Management. A.R. Hurson Computer Science Missouri Science & Technology

Concurrency Control & Recovery

CS 347 Parallel and Distributed Data Processing

Chapter 22. Transaction Management

Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

COURSE 1. Database Management Systems

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Transaction Management Overview

CS 347 Parallel and Distributed Data Processing

Part III Transactions

Distributed Transaction Management. Distributed Database System

Implementing Isolation

Overview of Transaction Management

Multi-User-Synchronization

Some Examples of Conflicts. Transactional Concurrency Control. Serializable Schedules. Transactions: ACID Properties. Isolation and Serializability

Intro to Transactions

Overview. Introduction to Transaction Management ACID. Transactions

Transaction Management Overview. Transactions. Concurrency in a DBMS. Chapter 16

Chapter 15 : Concurrency Control

Example: Transfer Euro 50 from A to B

Transactions. Transaction. Execution of a user program in a DBMS.


Concurrency Control. R &G - Chapter 19

Concurrency Control & Recovery

Advances in Data Management Transaction Management A.Poulovassilis

T ransaction Management 4/23/2018 1

Comp 5311 Database Management Systems. 14. Timestamp-based Protocols

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Read Operations and Timestamps. Write Operations and Timestamps

Chapter 13 : Concurrency Control

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Database System Concepts

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

UNIT 4 TRANSACTIONS. Objective

Transaction Management: Concurrency Control

Optimistic Concurrency Control. April 18, 2018

Recovery System These slides are a modified version of the slides of the book Database System Concepts (Chapter 17), 5th Ed McGraw-Hill by

Chapter 12 : Concurrency Control

(Pessimistic) Timestamp Ordering

CSE 344 MARCH 9 TH TRANSACTIONS

Chapter 16: Recovery System. Chapter 16: Recovery System

Chapter 17: Recovery System

Goal of Concurrency Control. Concurrency Control. Example. Solution 1. Solution 2. Solution 3

230 Chapter 17. (c) Otherwise, T writes O and WTS(O) is set to TS(T).

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

XI. Transactions CS Computer App in Business: Databases. Lecture Topics

TRANSACTION MANAGEMENT

Final Review. May 9, 2017

Security Mechanisms I. Key Slide. Key Slide. Security Mechanisms III. Security Mechanisms II

Final Review. May 9, 2018 May 11, 2018

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview NOTICE: Faloutsos CMU SCS

Concurrency Control. Conflict Serializable Schedules. Example. Chapter 17

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

CS5412: TRANSACTIONS (I)

Pessimistic v.s. Optimistic. Outline. Timestamps. Timestamps. Timestamps. CSE 444: Database Internals. Main invariant:

DISTRIBUTED SYSTEMS [COMP9243] Lecture 5: Synchronisation and Coordination (Part 2) TRANSACTION EXAMPLES TRANSACTIONS.

Introduction to Data Management CSE 344

DISTRIBUTED SYSTEMS [COMP9243] Lecture 5: Synchronisation and Coordination (Part 2) TRANSACTION EXAMPLES TRANSACTIONS.

Distributed Systems (ICE 601) Transactions & Concurrency Control - Part1

Lecture 21. Lecture 21: Concurrency & Locking

Datenbanksysteme II: Synchronization of Concurrent Transactions. Ulf Leser

CSE 344 MARCH 25 TH ISOLATION

Synchronization Part II. CS403/534 Distributed Systems Erkay Savas Sabanci University

Transactions and Concurrency Control. Dr. Philip Cannata

Transaction Processing: Concurrency Control ACID. Transaction in SQL. CPS 216 Advanced Database Systems. (Implicit beginning of transaction)

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

transaction - (another def) - the execution of a program that accesses or changes the contents of the database

Concurrency Control. [R&G] Chapter 17 CS432 1

! A lock is a mechanism to control concurrent access to a data item! Data items can be locked in two modes :

Transaction Processing: Basics - Transactions

Chapter 6 Distributed Concurrency Control

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #19: Logging and Recovery 1

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Transaction Management

A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes:

Foundation of Database Transaction Processing. Copyright 2012 Pearson Education, Inc.

Concurrency Control. P.J. M c.brien. Imperial College London. P.J. M c.brien (Imperial College London) Concurrency Control 1 / 1

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall

CSE 190D Database System Implementation

Transaction Management & Concurrency Control. CS 377: Database Systems

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

Introduction to Database Systems CSE 444

Transactions. 1. Transactions. Goals for this lecture. Today s Lecture

DB2 Lecture 10 Concurrency Control

Concurrency Control. Chapter 17. Comp 521 Files and Databases Spring

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Transactions. Lecture 8. Transactions. ACID Properties. Transaction Concept. Example of Fund Transfer. Example of Fund Transfer (Cont.

Transcription:

Distributed Transaction Management Material from: Principles of Distributed Database Systems Özsu, M. Tamer, Valduriez, Patrick, 3rd ed. 2011 + Presented by C. Roncancio Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/1

Transaction A transaction is a collection of actions that make consistent transformations of system states while preserving system consistency. concurrency transparency failure transparency Database in a consistent state Database may be temporarily in an inconsistent state during execution Database in a consistent state Begin Transaction Execution of Transaction End Transaction Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/2

Characterization Read set (RS) The set of data items that are read by a transaction Write set (WS) The set of data items whose values are changed by this transaction Base set (BS) RS WS Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/3

Principles of Transactions ATOMICITY all or nothing CONSISTENCY no violation of integrity constraints ISOLATION concurrent changes invisible serializable DURABILITY committed updates persist Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/4

Atomicity Either all or none of the transaction's operations are performed. Atomicity requires that if a transaction is interrupted by a failure, its partial results must be undone. The activity of preserving the transaction's atomicity in presence of transaction aborts due to input errors, system overloads, or deadlocks is called transaction recovery. The activity of ensuring atomicity in the presence of system crashes is called crash recovery. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/5

Consistency Internal consistency A transaction which executes alone against a consistent database leaves it in a consistent state. Transactions do not violate database integrity constraints. Transactions are correct programs Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/6

Isolation Serializability If several transactions are executed concurrently, the results must be the same as if they were executed serially in some order. Incomplete results An incomplete transaction cannot reveal its results to other transactions before its commitment. Necessary to avoid cascading aborts. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/7

SQL-92 Isolation Levels Phenomena: Dirty read T 1 modifies x which is then read by T 2 before T 1 terminates; T 1 aborts T 2 has read value which never exists in the database. Non-repeatable (fuzzy) read T 1 reads x; T 2 then modifies or deletes x and commits. T 1 tries to read x again but reads a different value or can t find it. Phantom T 1 searches the database according to a predicate while T 2 inserts new tuples that satisfy the predicate. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/9

SQL-92 Isolation Levels (cont d) Read Uncommitted For transactions operating at this level, all three phenomena are possible. Read Committed Fuzzy reads and phantoms are possible, but dirty reads are not. Repeatable Read Only phantoms possible. Anomaly Serializable None of the phenomena are possible. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/10

Durability Once a transaction commits, the system must guarantee that the results of its operations will never be lost, in spite of subsequent failures. Database recovery Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/11

Characterization of Transactions Based on Application areas Non-distributed vs. distributed Compensating transactions Heterogeneous transactions Timing On-line (short-life) vs batch (long-life) Structure Flat (or simple) transactions Nested transactions Workflows Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/12

Transactions Provide Atomic and reliable execution in the presence of failures Correct execution in the presence of multiple user accesses Correct management of replicas (if they support it) Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/17

Transaction Processing Issues Transaction structure (usually called transaction model) Flat (simple), nested Internal database consistency Semantic data control (integrity enforcement) algorithms Reliability protocols Atomicity & Durability Local recovery protocols Global commit protocols Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/18

Transaction Processing Issues Concurrency control algorithms How to synchronize concurrent transaction executions (correctness criterion) Intra-transaction consistency, Isolation Replica control protocols How to control the mutual consistency of replicated data One copy equivalence and ROWA Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/19

Architecture Revisited Begin_transaction, Read, Write, Commit, Abort Results With other TMs Transaction Manager (TM) Scheduling/ Descheduling Requests Scheduler (SC) Distributed Execution Monitor With other SCs To data processor Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/20

Centralized Transaction Execution User Application Begin_Transaction, Read, Write, Abort, EOT Read, Write, Abort, EOT Scheduled Operations Transaction Manager (TM) Scheduler (SC) Recovery Manager (RM) Results Results User Application Results & User Notifications Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/21

Distributed Transaction Execution User application Begin_transaction, Read, Write, EOT, Abort Read, Write, EOT, Abort TM Results & User notifications TM Distributed Transaction Execution Model Replica Control Protocol SC SC Distributed Concurrency Control Protocol RM RM Local Recovery Protocol Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/22

Concurrency Control The problem of synchronizing concurrent transactions such that the consistency of the database is maintained while, at the same time, maximum degree of concurrency is achieved. Anomalies: Lost updates The effects of some transactions are not reflected on the database. Inconsistent retrievals A transaction, if it reads the same data item more than once, should always read the same value. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/23

Serializability in Distributed DBMS Somewhat more involved. Two histories have to be considered: local histories global history For global transactions (i.e., global history) to be serializable, two conditions are necessary: Each local history should be serializable. Two conflicting operations should be in the same relative order in all of the local histories where they appear together. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/24

Global Non-serializability T 1 : Read(x) T 2 : Read(x) x x-100 Read(y) Write(x) Commit Read(y) y y+100 Write(y) Commit x stored at Site 1, y stored at Site 2 LH 1, LH 2 are individually serializable (in fact serial), but the two transactions are not globally serializable. LH 1 ={R 1 (x),w 1 (x), R 2 (x)} LH 2 ={R 2 (y), R 1 (y),w 1 (y)} Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/25

Concurrency Control Algorithms Pessimistic Two-Phase Locking-based (2PL) Centralized (primary site) 2PL Primary copy 2PL Distributed 2PL Timestamp Ordering (TO) Basic TO Multiversion TO Conservative TO Hybrid Optimistic Locking-based Timestamp ordering-based Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/26

Timestamp Ordering! Transaction (T i ) is assigned a globally unique timestamp ts(t i ). " Transaction manager attaches the timestamp to all operations issued by the transaction. # Each data item is assigned a write timestamp (wts) and a read timestamp (rts): rts(x) = largest timestamp of any read on x wts(x) = largest timestamp of any write on x $ Conflicting operations are resolved by timestamp order. Basic T/O: for R i (x) for W i (x) if ts(t i ) < wts(x) if ts(t i ) < rts(x) or ts(t i ) < wts(x) then reject R i (x) then reject W i (x) else {accept R i (x), else { accept W i (x), rts(x) ts(t i )} wts(x) ts(t i ) } Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/27

Multiversion Timestamp Ordering Do not modify the values in the database, create new values. A R i (x) is translated into a read on one version of x. Find a version of x (say x v ) such that ts(x v ) is the largest timestamp less than ts(t i ). A W i (x) is translated into W i (x w ) and accepted if the scheduler has not yet processed any R j (x r ) such that ts(t i ) < ts(x r ) < ts(t j ) Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/28

Locking-Based Algorithms Transactions indicate their intentions by requesting locks from the scheduler (called lock manager). Locks are either read lock (rl) [also called shared lock] or write lock (wl) [also called exclusive lock] Read locks and write locks conflict (because Read and Write operations are incompatible rl wl rl yes no wl no no Locking works nicely to allow concurrent processing of transactions. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/29

Two-Phase Locking (2PL)! A Transaction locks an object before using it. " When an object is locked by another transaction, the requesting transaction must wait. # When a transaction releases a lock, it may not request another lock. Lock point Obtain lock No. of locks Release lock Phase 1 Phase 2 BEGIN END Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/30

Strict 2PL Hold locks until the end. No. of locks Obtain lock Release lock BEGIN period of data item use END Transaction duration Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/31

Centralized 2PL There is only one 2PL scheduler in the distributed system. Lock requests are issued to the central scheduler. Data Processors at participating sites Coordinating TM Lock Request Central Site LM Operation Lock Granted End of Operation Release Locks Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/32

Distributed 2PL 2PL schedulers are placed at each site. Each scheduler handles lock requests for data at that site. A transaction may read any of the replicated copies of item x, by obtaining a read lock on one of the copies of x. Writing into x requires obtaining write locks for all copies of x. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/33

Distributed 2PL Execution Coordinating TM Participating LMs Participating DPs Lock Request Operation End of Operation Release Locks Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/34

Deadlock A transaction is deadlocked if it is blocked and will remain blocked until there is intervention. Locking-based CC algorithms may cause deadlocks. TO-based algorithms that involve waiting may cause deadlocks. Wait-for graph If transaction T i waits for another transaction T j to release a lock on an entity, then T i T j in WFG. T i T j Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/35

Local versus Global WFG Assume T 1 and T 2 run at site 1, T 3 and T 4 run at site 2. Also assume T 3 waits for a lock held by T 4 which waits for a lock held by T 1 which waits for a lock held by T 2 which, in turn, waits for a lock held by T 3. Local WFG T 1 Site 1 Site 2 T 4 Global WFG T 2 T 3 T 1 T 4 T 2 T 3 Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/36

Deadlock Management Ignore Let the application programmer deal with it, or restart the system Prevention Guaranteeing that deadlocks can never occur in the first place. Check transaction when it is initiated. Requires no run time support. Avoidance Detecting potential deadlocks in advance and taking action to insure that deadlock will not occur. Requires run time support. Detection and Recovery Allowing deadlocks to form and then finding and breaking them. As in the avoidance scheme, this requires run time support. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/37

Deadlock Detection Transactions are allowed to wait freely. Wait-for graphs and cycles. Topologies for deadlock detection algorithms Centralized Distributed Hierarchical Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/38

Centralized Deadlock Detection One site is designated as the deadlock detector for the system. Each scheduler periodically sends its local WFG to the central site which merges them to a global WFG to determine cycles. How often to transmit? Too often higher communication cost but lower delays due to undetected deadlocks Too late higher delays due to deadlocks, but lower communication cost Would be a reasonable choice if the concurrency control algorithm is also centralized. Proposed for Distributed INGRES Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/39

Hierarchical Deadlock Detection Build a hierarchy of detectors DD 0x DD 11 DD 14 Site 1 Site 2 Site 3 Site 4 DD 21 DD 22 DD 23 DD 24 Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/40

Distributed Deadlock Detection Sites cooperate in detection of deadlocks. One example: The local WFGs are formed at each site and passed on to other sites. Each local WFG is modified as follows:! Since each site receives the potential deadlock cycles from other sites, these edges are added to the local WFGs " The edges in the local WFG which show that local transactions are waiting for transactions at other sites are joined with edges in the local WFGs which show that remote transactions are waiting for local ones. Each local deadlock detector: looks for a cycle that does not involve the external edge. If it exists, there is a local deadlock which can be handled locally. looks for a cycle involving the external edge. If it exists, it indicates a potential global deadlock. Pass on the information to the next site. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/41

Relaxed Concurrency Control Non-serializable histories E.g., ordered shared locks Semantics of transactions can be used Look at semantic compatibility of operations rather than simply looking at reads and writes Nested distributed transactions Closed nested transactions Open nested transactions Multilevel transactions Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/42

Reliability Problem: How to maintain atomicity durability properties of transactions Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/43

Update Strategies In-place update Each update causes a change in one or more data values on pages in the database buffers Out-of-place update Each update causes the new value(s) of data item(s) to be stored separate from the old value(s) Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/44

In-Place Update Recovery Information Database Log Every action of a transaction must not only perform the action, but must also write a log record to an append-only file. Old stable database state Update Operation New stable database state Database Log Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/45

Logging The log contains information used by the recovery process to restore the consistency of a system. This information may include transaction identifier type of operation (action) items accessed by the transaction to perform the action old value (state) of item (before image) new value (state) of item (after image) Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/46

Why Logging? Upon recovery: all of T 1 's effects should be reflected in the database (REDO if necessary due to a failure) none of T 2 's effects should be reflected in the database (UNDO if necessary) Begin T 1 End system crash Begin T 2 0 t time Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/47

Out-of-Place Update Recovery Information Shadowing When an update occurs, don't change the old page, but create a shadow page with the new values and write it into the stable database. Update the access paths so that subsequent accesses are to the new shadow page. The old page retained for recovery. Differential files For each file F maintain a read only part FR a differential file consisting of insertions part DF + and deletions part DF - Thus, F = (FR DF + ) DF - Updates treated as delete old value, insert new value Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/48

Distributed Reliability Protocols Commit protocols How to execute commit command for distributed transactions. Issue: how to ensure atomicity and durability? Termination protocols If a failure occurs, how can the remaining operational sites deal with it. Non-blocking : the occurrence of failures should not force the sites to wait until the failure is repaired to terminate the transaction. Recovery protocols When a failure occurs, how do the sites where the failure occurred deal with it. Independent : a failed site can determine the outcome of a transaction without having to obtain remote information. Independent recovery non-blocking termination Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/49

Two-Phase Commit (2PC) Phase 1 : The coordinator gets the participants ready to write the results into the database Phase 2 : Everybody writes the results into the database Coordinator :The process at the site where the transaction originates and which controls the execution Participant :The process at the other sites that participate in executing the transaction Global Commit Rule:! The coordinator aborts a transaction if and only if at least one participant votes to abort it. " The coordinator commits a transaction if and only if all of the participants vote to commit it. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/50

Centralized 2PC P P P P C C C P P P P ready? yes/no commit/abort? commited/aborted Phase 1 Phase 2 Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/51

2PC Protocol Actions Coordinator Participant INITIAL PREPARE INITIAL write begin_commit in log VOTE-ABORT write abort in log No Ready to Commit? Yes WAIT VOTE-COMMIT write ready in log Any No? Yes write abort in log GLOBAL-ABORT READY No write commit in log COMMIT ABORT VOTE-COMMIT ACK ACK Unilateral abort Abort write abort in log Type of msg Commit write commit in log write end_of_transaction in log ABORT COMMIT Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/52

Linear 2PC Prepare VC/VA GC/GA Phase 1 VC/VA VC/VA VC/VA 1 2 3 4 5 N Phase 2 VC: Vote-Commit, VA: Vote-Abort, GC: Global-commit, GA: Global-abort GC/GA GC/GA GC/GA GC/GA Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/53

Distributed 2PC Coordinator Participants Participants prepare vote-abort/ vote-commit global-commit/ global-abort decision made independently Phase 1 Phase 2 Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/54

Problem With 2PC Blocking Ready implies that the participant waits for the coordinator If coordinator fails, site is blocked until recovery Blocking reduces availability Independent recovery is not possible However, it is known that: Independent recovery protocols exist only for single site failures; no independent recovery protocol exists which is resilient to multiple-site failures. So we search for these protocols 3PC Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/55

Network Partitioning Simple partitioning Only two partitions Multiple partitioning More than two partitions Formal bounds: There exists no non-blocking protocol that is resilient to a network partition if messages are lost when partition occurs. There exist non-blocking protocols which are resilient to a single network partition if all undeliverable messages are returned to sender. There exists no non-blocking protocol which is resilient to a multiple partition. Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/59

Independent Recovery Protocols for Network Partitioning No general solution possible allow one group to terminate while the other is blocked improve availability How to determine which group to proceed? The group with a majority How does a group know if it has majority? Centralized Whichever partitions contains the central site should terminate the transaction Voting-based (quorum) Distributed DBMS M. T. Özsu & P. Valduriez Ch.10/60