Synchronization via Transactions

Similar documents
Condition Synchronization

Chapter 22. Transaction Management

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

Database Systems. Announcement

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

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

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

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

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Transaction Management: Introduction (Chap. 16)

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

DATABASE TRANSACTIONS. CS121: Relational Databases Fall 2017 Lecture 25

Semaphores and Monitors: High-level Synchronization Constructs

Intro to Transactions

Transaction Management. Pearson Education Limited 1995, 2005

TRANSACTION PROCESSING CONCEPTS

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

Chapter 6: Process Synchronization. Module 6: Process Synchronization

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

IV. Process Synchronisation

Introduction to Data Management CSE 344

CSE 530A ACID. Washington University Fall 2013

Transactions & Update Correctness. April 11, 2018

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

CSE 344 MARCH 5 TH TRANSACTIONS

Chapter 7 (Cont.) Transaction Management and Concurrency Control

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

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

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

Introduction to Data Management CSE 344

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

Locks and Condition Variables Recap. Introducing Monitors. Hoare Monitors: Semantics. Coke Machine Example. Locks. Condition variables

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

TRANSACTION PROPERTIES

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Concurrency Control - Formal Foundations

Producer Consumer in Ada

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

Process Synchronization

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Lock Granularity and Consistency Levels (Lecture 7, cs262a) Ali Ghodsi and Ion Stoica, UC Berkeley February 7, 2018

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Introduction to Data Management CSE 344

Introduction to Data Management CSE 344

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

Programmazione di sistemi multicore

Synchronization I. Jo, Heeseung

CSE 344 MARCH 21 ST TRANSACTIONS

Sharing Objects Ch. 3

Introduction to Data Management CSE 344

Module 6: Process Synchronization

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Information Systems (Informationssysteme)

Lecture 3: Synchronization & Deadlocks

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

CMPT 354: Database System I. Lecture 11. Transaction Management

Motivating Example. Motivating Example. Transaction ROLLBACK. Transactions. CSE 444: Database Internals

CS5460: Operating Systems

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

Concurrency control 12/1/17

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Transactions and Concurrency Control. Dr. Philip Cannata

Dealing with Issues for Interprocess Communication

A Causality-Based Runtime Check for (Rollback) Atomicity

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

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

COMP 346 WINTER Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION

Concurre Concurr nt n Systems 8L for Part IB Handout 3 Dr. Steven Hand 1

Announcements. Motivating Example. Transaction ROLLBACK. Motivating Example. CSE 444: Database Internals. Lab 2 extended until Monday

Today: Synchronization. Recap: Synchronization

CS 153 Design of Operating Systems Winter 2016

Introduction to Transaction Processing Concepts and Theory

Page 1. Goals of Today s Lecture. The ACID properties of Transactions. Transactions

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

CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion. Tyler Robison Summer 2010

6.830 Lecture Transactions October 23, 2017

Thread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens

Roadmap of This Lecture

Chapter 14: Transactions

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

Advanced Databases. Transactions. Nikolaus Augsten. FB Computerwissenschaften Universität Salzburg

Transactions. Juliana Freire. Some slides adapted from L. Delcambre, R. Ramakrishnan, G. Lindstrom, J. Ullman and Silberschatz, Korth and Sudarshan

Synchronization SPL/2010 SPL/20 1

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Transaction Management

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 4 Shared-Memory Concurrency & Mutual Exclusion


CHAPTER: TRANSACTIONS

CSC 261/461 Database Systems Lecture 24

SQL: Transactions. Introduction to Databases CompSci 316 Fall 2017

Databases - Transactions II. (GF Royle, N Spadaccini ) Databases - Transactions II 1 / 22

Reminder from last time

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Overview. Introduction to Transaction Management ACID. Transactions

CS 153 Design of Operating Systems Winter 2016

Introduction TRANSACTIONS & CONCURRENCY CONTROL. Transactions. Concurrency

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

What's wrong with Semaphores?

Transcription:

Synchronization via Transactions 1 Concurrency Quiz If two threads execute this program concurrently, how many different final values of X are there? Initially, X == 0. Thread 1 Thread 2 void increment() { void increment() { int temp = X; int temp = X; temp = temp + 1; temp = temp + 1; X = temp; X = temp; Answer: A. 0 B. 1 C. 2 D. More than 2 2

Schedules/Interleavings Model of concurrent execution Interleave statements from each thread into a single thread If any interleaving yields incorrect results, some synchronization is needed Thread 1 Thread 2 tmp1 = X; tmp1 = X; tmp2 = X; tmp2 = X; tmp1 = tmp1 + 1; tmp2 = tmp2 + 1; tmp2 = tmp2 + 1; X = tmp1; X = tmp2; tmp1 = tmp1 + 1; X = tmp1; X = tmp2; If X==0 initially, X == 1 at the end. WRONG result! 3 Locks fix this with Mutual Exclusion void increment() { lock.acquire(); int temp = X; temp = temp + 1; X = temp; lock.release(); Is mutual exclusion really what we want? Don t we just want the correct result? Some interleavings may give the correct result. Why can t we keep these? 4

Providing atomicity and isolation directly Critical regions need atomicity and isolation Definition: An atomic operation s effects either all happen or none happen. Money transfer either debits one acct and credits the other, or no money is transferred Definition: An isolated operation is not affected by concurrent operations. Partial results are not visible This allows isolated operations to be put in a single, global order 5 Providing atomicity and isolation directly Implementing atomicity and isolation Changes to memory are buffered (isolation) Other processors see old values (isolation) If something goes wrong (e.g., exception), system rolls back state to start of critical section (atomicity) When critical region ends, changes become visible all at once (atomicity) Hardware Processor support for buffering and committing values Software Runtime system buffers and commits values 6

Transactions Transaction begin (xbegin) Start of critical region Transaction end (xend) End of critical region xbegin/xend can be implicit with atomic{ Transaction restart (or abort) User decides to abort transaction In Java throwing an exception aborts the transaction accta -= 100; acctb += 100; Transaction to transfer $100 from accta to acctb. 7 Atomicity and Isolation AcctA starts with $150 Different blocks to update balance Overnight batch process to read/process/write accounts Debit $100 Telephone transaction to read/process/write quickly Debit $90 Isolation guarantees that phone update is not lost It is allowed by atomicity In fact, both transactions (in either order) should result in overdraft AcctA = -$40 8

Atomicity and Isolation AcctA starts with $150 Different blocks to update balance Overnight batch process to read/process/write accounts Debit $100 Telephone transaction to read/process/write quickly Debit $90 Isolation guarantees that phone update is not lost This is a lost update time atomic{ Read AcctA (150) Decrement AcctA by 100 Write AcctA (50) atomic{ AcctA -= 90 9 AcctA == 200 initially. After these two concurrent transactions AcctA==350. What property does that violate? A. No property is violated B. Atomicity C. Isolation D. Durability atomic{ AcctA += 150 atomic{ AcctA -= 90 10

Atomicity and Isolation Atomicity is hard because Programs make many small changes. Most operations are not atomic, like x++; System must be able to restore state at start of atomic operation What about actions like dispensing money or firing missles? Isolation is hard because More concurrency == more performance but system must disallow certain interleavings System usually does not allow visibility of isolated state (hence the term isolated) Data structures have multiple invariants that dictate constraints t on a consistent t update Mutual exclusion provides isolation Most popular parallel programming technique Parallel programming: how to provide isolation (and possibly atomicity) 11 Concrete Syntax for Transactions The concrete syntax of JDASTM. Transaction tx = new Transaction(id); boolean done = false; while(!done) { try { tx.begintransaction(); // party on my data structure! done = tx.committransaction(); catch(abortexception te ti e) { tx.aborttransaction(); done = false; 12

Transaction s System Bookkeeping Transaction A s read set is R A Set of objects (addresses) read by transaction A Transaction B s write set is W B Set of objects (addresses) written by transaction B Transaction A s address set is R A UNION W A Set of objects (addresses) read or written by transaction A accta -= 100; acctb = accta; Read: accta Write: accta, acctb 13 Transactional Safety Conflict serializability If one transaction writes data read or written by another transaction, then abort one transaction. Recoverability No transaction that has read data from an uncommitted transaction may commit. x++; load t0, [x] add t0, 1 store t0, [x] Safe if abort transaction A or B whenever W A (R B UNION W B ) EMPTYSET 14

Safety examples Transaction 0 Transaction 1 load t0, [x] add t0, 1 store t0, [x] load t0, [x] add t0, 1 Read: Write: x x Read: Write: x Conflict: Transaction 1 should restart 15 How Isolation Could Be Violated Dirty reads Non-repeatable reads Lost updates 16

Restarting + I/O = Confusion Transactions can restart! What kind of output should I expect? Transaction tx = new Transaction(id); boolean done = false; while(!done) { try { tx.begintransaction(); System.out.println( Deja vu all over again ); done = tx.committransaction(); catch(abortexception e) { tx.aborttransaction(); done = false; 17 Reading Uncommitted State What about transactional data read outside a transaction? Hardware support: strong isolation for all reads Software: Uncommitted state is visible In your lab, a lane can go from colored to white when a transaction rolls back The GUI updating thread reads uncommitted state outside of a transaction Why would we want to read data outside of a transaction? Performance 18

Transactional Communication Conflict serializability is good for keeping transactions out of each other s address sets Sometimes transactions must communicate One transaction produces a memory value Other transaction consumes the memory value Communication is easy to do with busy waiting Just read the variable that will change Transaction will restart when its written by other thread 19 Communicating Transactions Class CokeMachine{ int count = 0; CokeMachine::Deposit(){ CokeMachine::Remove(){ while (count == n) ; while (count == 0) ; Add coke to the machine; Remove coke from machine; count++; count--; Transactions busy-wait for each other. The variable count is in the read set, so any write to count will restart the transaction 20

Tx Communication Without Busy Waiting Retry: how to block with transactions Pause transaction deschedule this thread deschedule this thread Reschedule whenever another transaction conflicts with this transaction Transactional thread is suspended until another thread modifies data it read E.g., count variable 21 Retry: Communication Without Busy Wait Class CokeMachine{ int count = 0; CokeMachine::Deposit(){ CokeMachine::Remove(){ if(count == n) {retry; if(count == 0) { retry; Add coke to the machine; Remove coke from machine; count++; count--; Scheduler and runtime cooperate to monitor address sets of transactions that are descheduled 22

Comparing Transactions and Monitors CokeMachine::Deposit(){ if(count == n) {retry; Add coke to the machine; count++; CokeMachine::Remove(){ if(count == 0) {retry; Remove coke from machine; count--; Which is better? A. Transactions B. Monitors CokeMachine::Deposit(){ lock acquire(); while (count == n) { notfull.wait(&lock); Add coke to the machine; count++; notempty.notify(); lock release(); CokeMachine::Remove(){ lock acquire(); while (count == 0) { notempty.wait(&lock); Remove coke from to the machine; count--; notfull.notify(); lock release(); 23 Load linked/store Conditional Load linked/store conditional. Idea is to let user load a data item, compute, then store back and if no one else (i.e., another processor or an I/O device) has touched that memory location, then allow the store since the read-modify-write was atomic. tmp = r1 = [addr]; // Load linked into r1 do_whatever (some restrictions); // Store conditional from r2 if(tmp == [addr]) then [addr] = r2; r2 = 1; else r2 = 0; Restrictions on compute: no memory accesses, limited number of instructions, no interrupts or exceptions. Hardware queue locks 24

Load linked/store Conditional All of these events, if they happen between the load linked and the store conditional will cause the store conditional to fail. EXCEPT which? A. Breakpoint instruction B. Branch instruction C. External write to loaded memory address D. Return from exception instruction 25