Desirable characteristics of transaction processing captured by acronym ACID

Similar documents
TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION 4/3/2014

CSE 530A ACID. Washington University Fall 2013

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

UNIT-IV TRANSACTION PROCESSING CONCEPTS

T ransaction Management 4/23/2018 1

Lecture X: Transactions

TRANSACTION PROCESSING CONCEPTS

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25

Intro to Transactions

Consistency in Distributed Systems

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

Transactions. Transactions. Distributed Software Systems. A client s banking transaction. Bank Operations. Operations in Coordinator interface

CSCU9Q5. Topic Overview. Transaction Management. The Concept of a Transaction BACKUP & CONCURRENCY. CSCU9Q5: Database P&A 14 November 2017

Chapter 22. Transaction Management

EE324 INTRO. TO DISTRIBUTED SYSTEMS LECTURE 13 TRANSACTIONS

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

CS October 2017

Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428. Fall 2012

Introduction to Transaction Management

Transaction Management: Introduction (Chap. 16)

CSE 190D Database System Implementation

Problems Caused by Failures

Reminder from last time

0: BEGIN TRANSACTION 1: W = 1 2: X = W + 1 3: Y = X * 2 4: COMMIT TRANSACTION

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

Database Usage (and Construction)

TRANSACTION PROCESSING MONITOR OVERVIEW OF TPM FOR DISTRIBUTED TRANSACTION PROCESSING

COMP3151/9151 Foundations of Concurrency Lecture 8

Overview. Introduction to Transaction Management ACID. Transactions

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

Processor speed. Concurrency Structure and Interpretation of Computer Programs. Multiple processors. Processor speed. Mike Phillips <mpp>

Database Management System

Transaction Management. Pearson Education Limited 1995, 2005

Outline. Database Tuning. What is a Transaction? 1. ACID Properties. Concurrency Tuning. Nikolaus Augsten. Introduction to Transactions

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems

Databases - Transactions

Topics in Reliable Distributed Systems

D B M G D B M G 2. SQL language: other definitions. Transactions. Transactions. Introduction Transactions in SQL Properties of transactions

ATOMIC COMMITMENT Or: How to Implement Distributed Transactions in Sharded Databases

Introduction to Data Management. Lecture #24 (Transactions)

Transaction Management Exercises KEY

CSE 332: Locks and Deadlocks. Richard Anderson, Steve Seitz Winter 2014

Sebastian Obermeier, University of Paderborn Germany. mbusiness Deadlines pre-acp Blocking Bi-State-Termination

Information Systems (Informationssysteme)

Database Systems. Announcement

Introduction to Data Management CSE 344

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

Principles of Software Construction: Objects, Design, and Concurrency

Atomic Transac1ons. Atomic Transactions. Q1: What if network fails before deposit? Q2: What if sequence is interrupted by another sequence?

Transactions and Isolation

October/November 2009

Goal A Distributed Transaction

CPS352 Lecture - The Transaction Concept

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

For more Articles Go To: Whatisdbms.com CONCURRENCY CONTROL PROTOCOL

Synchronisation and Coordination (Part 2)

CS 5300 module6. Problem #1 (10 Points) a) Consider the three transactions T1, T2, and T3, and the schedules S1 and S2.

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

Problem: if one process cannot perform its operation, it cannot notify the. Thus in practise better schemes are needed.

Introduction to Data Management CSE 344

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

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

Defining properties of transactions

Advanced Databases Lecture 17- Distributed Databases (continued)

CSE 486/586 Distributed Systems

Distributed Databases

Concurrency Control & Recovery

Database Tuning and Physical Design: Execution of Transactions

Transactions and ACID

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

Transaction Management: Concurrency Control, part 2

Locking for B+ Trees. Transaction Management: Concurrency Control, part 2. Locking for B+ Trees (contd.) Locking vs. Latching

14.1 Answer: 14.2 Answer: 14.3 Answer: 14.4 Answer:

CS352 Lecture - The Transaction Concept

UNIT 4 TRANSACTIONS. Objective

Outline. Database Management and Tuning. Index Tuning Examples. Exercise 1 Query for Student by Name. Concurrency Tuning. Johann Gamper.

Safety and liveness for critical sections

Introduction to Data Management. Lecture #18 (Transactions)

Database Technology. Topic 8: Introduction to Transaction Processing

Database Management Systems CSEP 544. Lecture 9: Transactions and Recovery

Transactions: Definition. Concurrent transactions: Problems

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Last Class. Faloutsos/Pavlo CMU /615

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Overview of Transaction Management

Producer Consumer in Ada

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Distributed Transaction Management. Distributed Database System

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

Dealing with Issues for Interprocess Communication

Today s Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Formal Properties of Schedules. Conflicting Operations

Introducing Shared-Memory Concurrency

Plan. Department of Informatics. Advanced Software Engineering Prof. J. Pasquier-Rocha Cours de Master en Informatique - SH 2003/04

Introduction to Data Management CSE 344

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

CSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 14 Distributed Transactions

SQL: Transactions. Introduction to Databases CompSci 316 Fall 2017

Consistency. CS 475, Spring 2018 Concurrent & Distributed Systems

Transaction Processing: Basics - Transactions

Transaction Management: Concurrency Control

Transcription:

13-concurrency.txt Thu Oct 11 09:24:49 2012 1 Notes on Distributed Concurrency Management 15-440, Fall 2012 Carnegie Mellon University Randal E. Bryant Reading: Tannenbaum, Sect. 8.5 Part I: Single Server (Not covered very well in book) Database researchers laid the background for reasoning about how to process a number of concurrent events that update some shared global state. They invented the concept of a "transaction" in which a collection of reads and writes of a global state are bundled such that they appear to be single, indivisible operation. (They also defined standard models for reliable storage and for robust operation. We ll visit those later.) Desirable characteristics of transaction processing captured by acronym ACID Atomicity: Each transaction is either completed in its entirety, or ed. In the latter case, it should have no effect on the global state. Consistency: Each transaction preserves a set of invariants about the global state. The exact nature of these is system dependent. Isolation: Each transaction executes as if it were the only one with the ability to read and write the global state. Durability: Once a transaction has been completed, it cannot be "undone". (Note that the term "atomicity" or "atomic operations" are often synonomous with the combination of Atomicity+Isolation)

13-concurrency.txt Thu Oct 11 09:24:49 2012 2 A transaction example. Imagine we have a set of bank acounts, where balances are stored as an array Bal[i], giving the balance for account i. We could define a transaction to transfer money from one account to another: where we define operations withdraw & deposit as withdraw(i, v): b = Bal[i] if b >= v Bal[i] = b-v return true return false // Read // Test // Write : Bal[j] += v Imagine we have Bal[x] = 100, Bal[y] = Bal[z] = 0 and attempt two transactions: T1: xfer(x, y, 60) T2: xfer(x, z, 70) The ACID properties ensure that any implementation should make it appear as if the two transactions are executed in some serial order: T1 ; T2. Must have T1 succeed and T2 fail. End with Bal[x] = 40, Bal[y] = 60. T2 ; T1. Must have T2 succeed and T1 fail End with Bal[x] = 30, Bal[y] = 70. But, without taking special care, we can see that things could go very badly. Consider race condition in updating values of Bal[x]. If transactions interleave between respective Read & Write actions so that Bal[x] ends up as either 30 or 40, but both transactions take place. This could be viewed as a violation of isolation & durability. For consistency, consider following function: // Return sum of balances of accounts x & y sumbalance(i, j, k): return Bal[i] + Bal[j] + Bal[k] As a state invariant, we can say sumbalance(x, y, z) == 100 at all times. This got violated due to race, causing money to be artificially created.

13-concurrency.txt Thu Oct 11 09:24:49 2012 3 Implementing transaction with locks Easy to wrap lock around entire thing: // Transfer $v from account i to account j lock() unlock() But, this would be a serious sequential bottleneck. Prefer to uses finer grained locks, e.g., on a per-account basis: Attempt #1 // Transfer $v from account i to account j lock(i) unlock(i) lock(j) unlock(j) unlock(i) There are two problems with this code: 1. Releasing lock i early can give consistency violation. Some other transaction (e.g., sumbalance) could see decremented value of account i, but unincremented value of count j. Fix: Rule: Only release locks when all updating of state variables completed. lock(i); lock(j) unlock(i); unlock(j) unlock(i) 2. There s a deadlock. Consider Bal[x] = Bal[y] = 100 and then attempt transactions: xfer(x, y, 40) and xfer(y, x, 30) Can reach midpoint both have completed their respective withdrawals, but one holds lock on x while other holds lock on y. Fixing: Always acquire locks in a fixed order lock(min(i,j)); lock(max(i,j))

13-concurrency.txt Thu Oct 11 09:24:49 2012 4 unlock(i); unlock(j) unlock(i); unlock(j) General rule: Always acquire locks according to some consistent global ordering. Why does this work? State of locks can be represented as directed graph. (the "Waits for" graph). Vertices represent transactions. Edge from vertex i to vertex j if transaction i is waiting for lock held by transaction j. Cycle in this graph indicates a deadlock. Label the edge with its lock ID. For any cycle, there must be some pair of edges (i, j), (j, k) labeled with values m & n such that m > n. That implies that transaction j is holding lock m and it wants lock n, where m > n. That implies that j is not acquiring its lock in proper order. This general scheme is known as two-phase locking. More precisely, as strong strict two-phase locking. General 2-phase locking Phase 1. Acquire or escalate locks (e.g., read lock to write lock) Phase 2. Release or deescalate locks Strict 2-phase locking During Phase 2. Release WRITE locks only at end of transactions Strong strict 2-phase locking During Phase 2. Release ALL locks only at end of transactions. This is the most common version. Required to provide ACID properties. Other ways to handle deadlock 1. Have lock manager build waits-for graph. When it finds a cycle, chose an offending transaction and force it to. 2. Use timeout. Transactions should be short. If hit time limit, chose some transaction that is waiting for a lock and force it to.

13-concurrency.txt Thu Oct 11 09:24:49 2012 5 Thinking about transactions. For reliability, typically split transaction into phases: 1. Preparation. Figure out what to do and how it will change state, without altering state. Generate L: Set of locks, and U: List of updates 2. Commit or. a. If everything OK, then update global state. b. If transaction cannot be completed, leave global state unchanged. In either case, release all locks Example: L = {i, j} U = [] // List of required updates begin(l) // Begin transaction. Acquire locks bi = Bal[i] bj = Bal[j] if bi >= v: Append(U, Bal[i] <- bi-v) Append(U, Bal[j] <- bj+v) commit(u, L) (L) commit(u, L): Perform all updates in U. Release all locks in L. (L): Release all locks in L.

13-concurrency.txt Thu Oct 11 09:24:49 2012 6 Part II Distributed Transactions Same general idea, but state spread across multiple servers. Want to enable single transaction to read and modify global state and maintain ACID properties. General idea: 1. Client initiates transaction. Makes use of "coordinator" (could be self). 2. All relevant servers operate as "participants". 4. The coordinator assigns a unique Transaction ID (TID) for the transaction. Two phase commit: Split each transaction into two phases: 1. Prepare & vote. Participants figure out all state changes Each determines if it will be able to complete transaction and communicates with coordinator 2. Commit. Coordinator broadcasts to participants whether to commit or If commit, then participants make their respective state changes Implemented by set of messages between coordinator & participants: 1.A: Coordinator sends "CanCommit?" query to participants B: Participants respond with "VoteCommit" or "VoteAbort" to coordinator 2.A: If any participant votes for, the entire transaction must be ed. Send "DoAbort" messages to participants. They release locks. B: Else, send "DoCommit" messages to participants. They complete transaction Example. Suppose bank account i managed by server A, and account j by server B: Then Server A would implement transaction: L = {i} begin(l) // Acquire lock U = [] b = Bal[i] if b >= v: Append(U, Bal[i] <- b-v) vote commit vote Server B would implement transaction L = {j} begin(l) // Acquire lock U = [] b = Bal[j] Append(U, Bal[j] <- b+v) vote commit Server B can assume that there will be a big enough balance in i s account. Entire transaction will otherwise.

13-concurrency.txt Thu Oct 11 09:24:49 2012 7 What about locking? Locks held by individual participants * Acquired at start of preparation process * Released as part of commit or. Distributed deadlock: * Possible to get cyclic dependency of locks by transactions across multiple servers * Manifested in 2PC by having one of the participants unable to respond to a voting request (because it is still waiting to lock its local resources). * Most often handle with timeout. Participant times out and then votes to. The transaction must then be retried. - Eliminates risk deadlock - Introduces danger of LIVELOCK: Keep retrying transaction but never succeed