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

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

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

Synchronization. Clock Synchronization

Portland State University ECE 588/688. Transactional Memory

Part III Transactions

Synchronization. Chapter 5

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

T ransaction Management 4/23/2018 1

Transactional Memory: Architectural Support for Lock-Free Data Structures Maurice Herlihy and J. Eliot B. Moss ISCA 93

Chapter 22. Transaction Management

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

Concurrency control CS 417. Distributed Systems CS 417

Transaction Processing: Concurrency Control. Announcements (April 26) Transactions. CPS 216 Advanced Database Systems

DB2 Lecture 10 Concurrency Control

Transactions. A Banking Example

Advances in Data Management Transaction Management A.Poulovassilis


Using Software Transactional Memory In Interrupt-Driven Systems

A transaction is a sequence of one or more processing steps. It refers to database objects such as tables, views, joins and so forth.

Database Systems CSE 414

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

Concurrency control 12/1/17

Chapter 7 (Cont.) Transaction Management and Concurrency Control

Database systems. Database: a collection of shared data objects (d1, d2, dn) that can be accessed by users

Transactional Memory. How to do multiple things at once. Benjamin Engel Transactional Memory 1 / 28

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

Transaction Management. Pearson Education Limited 1995, 2005

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

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

CSE 344 MARCH 5 TH TRANSACTIONS

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

Problems Caused by Failures

CS Reading Packet: "Transaction management, part 2"

Database Systems CSE 414

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

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

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

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 13 Managing Transactions and Concurrency

Implementing Isolation

CS 347 Parallel and Distributed Data Processing

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

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

Optimistic Concurrency Control. April 13, 2017

CSE 344 MARCH 9 TH TRANSACTIONS

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25

CSE 344 MARCH 25 TH ISOLATION

Distributed Systems. 12. Concurrency Control. Paul Krzyzanowski. Rutgers University. Fall 2017

Optimistic Concurrency Control. April 18, 2018

Concurrency Control - Two-Phase Locking

Chapter 13 : Concurrency Control

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

CS 347 Parallel and Distributed Data Processing

Transaction Management & Concurrency Control. CS 377: Database Systems

DATABASE DESIGN I - 1DL300

Concurrency Control! Snapshot isolation" q How to ensure serializability and recoverability? " q Lock-Based Protocols" q Other Protocols"

Transactions and Concurrency Control

TRANSACTION MEMORY. Presented by Hussain Sattuwala Ramya Somuri

Transactions: Definition. Concurrent transactions: Problems

Intro to Transactions

Transaction Processing Concurrency control

Concurrency Control Algorithms

Introduction to Data Management CSE 344

Transaction Management: Introduction (Chap. 16)

Concurrent & Distributed Systems Supervision Exercises

Concurrency control (1)

Concurrency. Consider two ATMs running in parallel. We need a concurrency manager. r1[x] x:=x-250 r2[x] x:=x-250 w[x] commit w[x] commit

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

Unit 10.5 Transaction Processing: Concurrency Zvi M. Kedem 1

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Graph-based protocols are an alternative to two-phase locking Impose a partial ordering on the set D = {d 1, d 2,..., d h } of all data items.

Chapter 15 : Concurrency Control

Isolation levels. Introduction to Database Design 2012, Lecture 14. Rasmus Ejlers Møgelberg. Questions class about one week before exam

h p:// Authors: Tomáš Skopal, Irena Holubová Lecturer: Mar n Svoboda, mar

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

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

Reminder from last time

Operating Systems. Operating Systems Sina Meraji U of T

Introduction to Transaction Processing Concepts and Theory

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

CS5412: TRANSACTIONS (I)

CSE 444: Database Internals. Lectures Transactions

Concurrency Control & Recovery

Advanced Databases. Lecture 9- Concurrency Control (continued) Masood Niazi Torshiz Islamic Azad University- Mashhad Branch

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

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 17-1

Transactions and Concurrency Control. Dr. Philip Cannata

Database Management System

Distributed Transaction Management

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Introduction to Data Management CSE 344

Control. CS432: Distributed Systems Spring 2017

Analysis of Transaction and Concurrency Mechanism in Two Way Waiting Algorithm for different Databases

Introduction to Data Management CSE 414

Review. Review. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Lecture #21: Concurrency Control (R&G ch.

Chapter 12 : Concurrency Control

Emmett Witchel The University of Texas At Austin

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

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

Transcription:

CPSC-4/6: Operang Systems Atomic Transactions The Transaction Model / Primitives Serializability Implementation Serialization Graphs 2-Phase Locking Optimistic Concurrency Control Transactional Memory Atomic Transactions Example: Online bank transaction: withdraw(amount, account) deposit(amount, account2) Q: What if network fails before deposit? Q2: What if sequence is interrupted by another sequence? Solution: Group operations in an atomic transaction. Primitives: BEGIN_TRANSACTION END_TRANSACTION ABORT_TRANSACTION READ WRITE

CPSC-4/6: Operang Systems ACID Properties Atomic: Consistent: Isolated: Durable: transactions happen indivisibly no violation of system invariants no interference between concurrent transactions after transaction commits, changes are permanent Serializability Schedule is serial if the steps of each transaction occur consecutively. Schedule is serializable if its effect is equivalent to some serial schedule.. BEGIN TRANSACTION x := ; x := x + ; END TRANSACTION BEGIN TRANSACTION x := ; x := x + 2; END TRANSACTION BEGIN TRANSACTION x := ; x := x + 3; END TRANSACTION schedule x= x=x+ x= x=x+2 x= x=x+3 legal schedule 2 x= x= x=x+ x=x+2 x= x=x+3 legal schedule 3 x= x= x=x+ x= x=x+2 x=x+3 illegal 2

CPSC-4/6: Operang Systems Testing for Serializability the hard way: Serialization Graphs Input: Schedule S for set of transactions T, T 2,, T k. Output: Determination whether S is serializable. Method: Create serialization graph G: Nodes: correspond to transactions Arcs: G has an arc from T i to T j if there is a T i :UNLOCK(A m ) operation followed by a T j :LOCK(A m ) operation in the schedule. Perform topological sorting of the graph. If graph has cycles, then S is not serializable. If graph has no cycles, then topological order is a serial order for transactions. Theorem: This algorithm correctly determines if a schedule is serializable. Non-Serializable Schedule: Example [ref: J.D. Ullman: Principles of Database and Knowledge-Base Systems] Step T T2 T3 () LOCK A (2) (3) (4) (5) LOCK B LOCK B LOCK C UNLOCK B T (6) UNLOCK A T 2 (7) LOCK A (8) UNLOCK C (9) () UNLOCK A LOCK A T 3 () LOCK C (2) (3) UNLOCK B UNLOCK C (4) UNLOCK A 3

CPSC-4/6: Operang Systems Transactions: Implementation Issues. How to maintain information from not-yet committed transactions: Prepare for aborts private workspace write-ahead log / intention lists with rollback transactions commit data into database 2. Concurrency control: pessimistic -> lock-based: 2-Phase Locking optimistic -> Timestamp-Based with rollback 3. Commit protocol 2-Phase Commit Protocol. Serializability through Two-Phase Locking We allow for two types of locks: read locks (non-exclusive) write locks (require exclusive access) Enforce serializability through appropriate locking: release locks (and modify data) items only after lock point lock point acquire phase release phase All Two-Phase-Locking schedules are serializable. Problems: deadlock prone! allows only a subset of all serializable schedules. 4

CPSC-4/6: Operang Systems Two-Phase Locking (cont) Theorem: If S is any schedule of two-phase transactions, then S is serializable. Proof: Suppose not. Then the serialization graph G for S has a cycle, T i -> T i2 -> -> T ip -> T i Therefore, a lock by T i follows an unlock by T i, contradicting the assumption that T i is two-phase. What when Transactions fail: Transactions that Read Dirty Data () LOCK A (2) READ A (3) A:=A- (4) WRITE A (5) LOCK B (6) UNLOCK A (7) LOCK A (8) READ A (9) A:=A*2 () READ B () WRITE A (2) COMMIT (3) UNLOCK A (4) B:=B/A T T 2 Assume that T fails after (3).. T still holds lock on B. 2. Value read by T 2 at step (8) is wrong. T 2 must be rolled back and restarted. 3. Some transaction T 3 may have read value of A between steps (3) and (4) 5

CPSC-4/6: Operang Systems Solution: Strict Two-Phase Locking Strict two-phase locking: A transaction cannot write into the database until it has reached its commit point. A transaction cannot release any locks until it has finished writing into the database. Therefore, locks are not released until after the commit point. Pros: transaction read only values of committed transactions no cascaded aborts Cons: limited concurrency deadlocks Optimistic Concurrency Control Fundamental Principle: Forgiveness is easier to get than permission 6

CPSC-4/6: Operang Systems Optimistic Concurrency Control Basic idea: Process transaction without attention to serializability. Keep track of accessed data items. At commit point, check for conflicts with other transactions. Abort if conflicts occurred. Approach: Assign timestamp to each transaction. Make sure that schedule has the same effect of a serial schedule in order of assigned timestamps.?! Ensure Serializability: Scenario Transaction T 5pm W to A Item A Transaction T2 6pm R(A) = 7

CPSC-4/6: Operang Systems Ensure Serializability: Scenario 2 Transaction T 5pm W to A Item A Transaction T2 6pm R(A) = Ensure Serializability: Scenario 3 Transaction T 5pm Item A Transaction T2 6pm W to A R(A) = 8

CPSC-4/6: Operang Systems Ensure Serializability: Scenario 4 Transaction T 5pm Item A 2 2 2 2 Transaction T2 6pm W 2 to A Transaction T2 8pm 2 R(A) = 2 W to A 2 Timestamp-based Optimistic Concurrency Control Data items are tagged with read-time and write-time.. Transaction cannot read value of item if that value has not been written until after the transaction executed. Transaction with T.S. t cannot read item with write-time t 2 if t 2 > t. (abort and try with new timestamp) 2. Transaction cannot write item if item has value read at later time. Transaction with T.S. t cannot write item with read-time t 2 if t 2 > t. (abort and try with new timestamp) Other possible conflicts: Two transactions can read the same item at different times. What about transaction with T.S. t that wants to write to item with write-time t 2 and t 2 > t? 9

CPSC-4/6: Operang Systems Timestamp-Based Conc. Control (cont) Rules for preserving serial order using timestamps: a) Perform the operation X if X == READ and t >= t w or if X == WRITE and t >= t r and t >= t w. if X == READ : set t r = t if t > t r. if X == WRITE: set t w = t if t > t w. b) Do nothing if X == WRITE and t r <= t < t w. c) Abort transaction if X == READ and t < t w or X == WRITE and t < t r. Transactional Memory Transactional Memory borrows the concept of an atomic transaction from databases. Rather than locking resources, a code block is marked as atomic, and when it runs, the reads and writes are done against a transaction log instead of global memory. When the code is complete, the runtime re-checks all of the reads to make sure they are unchanged and then commits all of the changes to memory at once. If any of the reads are dirty, the transaction is rolled back and re-executed. This, when combined with additional tools for blocking and choice, allows program to remain simple, correct, and composable while scaling to many threads without the additional overhead that course-grained locking incurs. [Phil Windley, Technometria]

CPSC-4/6: Operang Systems Problems with Locking in OS s [C. J. Rossbach et al. : TxLinux: Using and Managing Hardware Transactional Memory in an Operating System, SOSP 27] In 2 study of Linux bugs, 346 of 25 bugs (34%) involved synchronization. 23 study of Linux 2.5 kernel found 4 confirmed and 8 unconfirmed deadlock bugs. Linux source file mm/filemap.c has a 5-line comment on the top of the file describing the lock ordering used in the file. The comment describes locks used at a calling depth of 4 from functions in the file. Locking is not modular; a component must know about the locks taken by another component in order to avoid deadlocks. Other known disadvantages: priority inversion, convoys, lack of composability, and failure to scale with problem size and complexity Transactional Memory: Primitives (conceptually) [M. Herlihy, J. Eliot, B. Mossin: Transactional memory: architectural support for lock-free data structures, Proceedings of the 2th Annual International Symposium on Computer Architecture (993)] Load-transactional (LT): reads the value of a shared memory location into a private register. Load-transactional-exclusive (LTX): reads the value of a shared memory location into a private register, hinting that the location is likely to be updated. Store-transactional (ST): tentatively writes a value from a private register to a shared memory location. This new value does not become visible to other processors until the transaction successfully commits.

CPSC-4/6: Operang Systems Transactional Memory: Primitives (conceptually) Commit (COMMIT): attempts to make the transaction s tentative changes permanent. It succeeds only if no other transaction has updated any location in the transaction s data set, and no other transaction has read any location in this transaction s write set. Successful: The transaction s changes to its write set become visible to other processes. Unsuccessful: All changes to the write set are discarded. Either way, COMMIT returns an indication of success or failure. Abort (ABORT): discards all updates to the write set. Validate (VALIDATE): tests the current transaction status. Successful: The current transaction has not aborted (although it may do so later). Unsuccessful: The current transaction has aborted, and VALIDATE discards the transaction s tentative updates. Transactional Memory in Practice: MetaTM Over 2 static occurrences of spinlocks in Linux! 2

CPSC-4/6: Operang Systems Transactional Memory in Practice In order to ensure isolation, TM systems must be able to roll back the effects of a transaction that has lost a conflict. TM can only roll back processor state and the contents of physical memory. e.g., the effects of I/O cannot be rolled back! Executing I/O operations as part of a transaction can break the atomicity and isolation. This is known as the output commit problem. Critical sections protected by locks will not restart and so may freely perform I/O. In practice, therefore, transactions have to run besides lock-based portions. This must be supported by the system. Simple SW Transactions: Sequence Locks Sequence locks (seqlocks) are a form of software transaction in the Linux kernel. Readers loop reading the seqlock counter at the start of the loop, performing any read of the data structure that they need, and then read the seqlock counter at the end of the loop. If the counter values match, the read loop exits. Writers lock each other out, and they increment the counter both before they start updating the data and after they end. Readers fail if they read an odd counter value as it means a writer was doing an update concurrent with their reading. 3