Defining properties of transactions

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

Transactions. CS6450: Distributed Systems Lecture 16. Ryan Stutsman

CONCURRENCY CONTROL, TRANSACTIONS, LOCKING, AND RECOVERY

Concurrency Control II and Distributed Transactions

Lock-based concurrency control. Q: What if access patterns rarely, if ever, conflict? Serializability. Concurrency Control II (OCC, MVCC)

Multi-version concurrency control

Transaction Management & Concurrency Control. CS 377: Database Systems

Database Management Systems

Concurrency control 12/1/17

Introduction to Transaction Management

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Database Management Systems 2010/11

Introduction to Data Management CSE 344

CSE 344 MARCH 5 TH TRANSACTIONS

5/17/17. Announcements. Review: Transactions. Outline. Review: TXNs in SQL. Review: ACID. Database Systems CSE 414.

Transactions. Chapter 15. New Chapter. CS 2550 / Spring 2006 Principles of Database Systems. Roadmap. Concept of Transaction.

Multi-version concurrency control

Introduction to Data Management CSE 344

Database Systems CSE 414

Problems Caused by Failures

Introduction to Data Management CSE 344

Introduction to Data Management CSE 344

Database Recovery. Dr. Bassam Hammo

Introduction to Data Management CSE 344

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

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

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

Intro to Transactions

Transaction Management. Pearson Education Limited 1995, 2005

T ransaction Management 4/23/2018 1

CSE 344 MARCH 9 TH TRANSACTIONS

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

CS122 Lecture 15 Winter Term,

CSE 344 MARCH 21 ST TRANSACTIONS

Chapter 22. Transaction Management

CSE 344 MARCH 25 TH ISOLATION

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

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

Database Systems CSE 414

DATABASE DESIGN I - 1DL300

Database System Concepts

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

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

CSE 444: Database Internals. Lectures Transactions

Chapter 13: Transactions

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

Topics in Reliable Distributed Systems

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Database Systems CSE 414

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

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

Concurrency Control & Recovery

Introduction to Data Management CSE 414

Introduction to Transaction Management

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences. Dr. Anis Koubaa. Spring 2014

Chapter 15: Transactions

Transactions and Recovery Study Question Solutions

TRANSACTION PROCESSING CONCEPTS

CSE 444: Database Internals. Lectures 13 Transaction Schedules

UNIT 4 TRANSACTIONS. Objective

Database System Concepts

Transactions and Concurrency Control

Concurrency Control. Concurrency Control Ensures interleaving of operations amongst concurrent transactions result in serializable schedules

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

DB2 Lecture 10 Concurrency Control

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

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

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

Causal Consistency and Two-Phase Commit

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

Chapter 15: Transactions

Transaction Concept. Two main issues to deal with:

Roadmap of This Lecture

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

CS352 Lecture - Concurrency

Transactions and Concurrency Control. Dr. Philip Cannata

CSIT5300: Advanced Database Systems

Database System Concepts

BİL 354 Veritabanı Sistemleri. Transaction (Hareket)

CS352 Lecture - Concurrency

CHAPTER: TRANSACTIONS

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

Concurrency control CS 417. Distributed Systems CS 417

Concurrency Control & Recovery

Lecture 20 Transactions

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

Transactions. Prepared By: Neeraj Mangla

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

CS 5614: Transaction Processing 121. Transaction = Unit of Work Recall ACID Properties (from Module 1)

Chapter 6 Distributed Concurrency Control

CS322: Database Systems Transactions

Example: Transfer Euro 50 from A to B

CS5412: TRANSACTIONS (I)

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

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

UNIT IV TRANSACTION MANAGEMENT

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

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

Transcription:

Transactions: ACID, Concurrency control (2P, OCC) Intro to distributed txns The transaction Definition: A unit of work: May consist of multiple data accesses or updates Must commit or abort as a single atomic unit COS 418: Advanced Computer Systems ecture 5 Michael Freedman Transactions can either commit, or abort hen commit, all updates performed on database are made permanent, visible to other transactions hen abort, database restored to a state such that the aborting transaction never executed 2 Defining properties of transactions Atomicity: Either all constituent operations of the transaction complete successfully, or none do Consistency: Each transaction in isolation preserves a set of integrity constraints on the data Goal #1: Handle failures Atomicity and Durability Isolation: Transactions behavior not impacted by presence of other concurrent transactions Durability: The transaction s effects survive failure of volatile (memory) or non-volatile (disk) storage 3 4 1

Account transfer transaction Transfers $10 from account A to account B Txn transfer(a, B): begin_tx a ß read(a) if a < 10 then abort_tx else write(a, a 10) b ß read(b) write(b, b+10) commit_tx 5 Problem Suppose $100 in A, $100 in B commit_tx starts commit protocol: write(a, $90) to disk write(b, $110) to disk hat happens if system crash after first write, but before second write? After recovery: Partial writes, money is lost Txn transfer(a, B): begin_tx a ß read(a) if a < 10 then abort_tx else write(a, a 10) b ß read(b) write(b, b+10) commit_tx ack atomicity in the presence of failures 6 How to ensure atomicity? og: A sequential file that stores information about transactions and system state esides in separate, non-volatile storage One entry in the log for each update, commit, abort operation: called a log record og record contains: Monotonic-increasing log sequence number (SN) Old value (before image) of the item for undo New value (after image) of the item for redo rite-ahead ogging (A) Ensures atomicity in the event of system crashes under no-force/steal buffer management 1. Force all log records pertaining to an updated page into the (non-volatile) log before any writes to page itself 2. A transaction is not considered committed until all log records (including commit record) are forced into log 7 8 2

A example force_log_entry(a, old=$100, new=$90) force_log_entry(b, old=$100, new=$110) write(a, $90) write(b, $110) force_log_entry(commit) Does not have to flush to disk Goal #2: Concurrency control Transaction Isolation hat if the commit log record size > the page size? How to ensure each log record is written atomically? rite a checksum of entire log entry 9 10 Two concurrent transactions Isolation between transactions transaction sum(a, B): begin_tx a ß read(a) b ß read(b) print a + b commit_tx transaction transfer(a, B): begin_tx a ß read(a) if a < 10 then abort_tx else write(a, a 10) b ß read(b) write(b, b+10) commit_tx Isolation: sum appears to happen either completely before or completely after transfer Schedule for transactions is an ordering of the operations performed by those transactions 11 12 3

Problem for concurrent execution: Inconsistent retrieval Serial execution of transactions transfer then sum: transfer: r A w A r B w B sum: debit credit r A r B Concurrent execution resulting in inconsistent retrieval, result differing from any serial execution: transfer: r A w A r B w B sum: debit r A r B credit Time à = commit 13 Equivalence of schedules Two operations from different transactions are conflicting if: 1. They read and write to the same data item 2. The write and write to the same data item Two schedules are equivalent if: 1. They contain the same transactions and operations 2. They order all conflicting operations of nonaborting transactions in the same way 14 Serializability A schedule is conflict serializable if it is equivalent to some serial schedule i.e., non-conflicting operations can be reordered to get a serial schedule How to ensure a serializable schedule? ocking-based approaches Strawman 1: Big Global ock Acquire the lock when transaction starts elease the lock when transaction ends esults in a serial transaction schedule at the cost of performance 15 16 4

ocking ocks maintained by transaction manager Transaction requests lock for a data item Transaction manager grants or denies lock ock types Shared: Need to have before read object Exclusive: Need to have before write object Shared (S) Exclusive (X) Shared (S) Yes No Exclusive (X) No No How to ensure a serializable schedule? Strawman 2: Grab locks independently, for each data item (e.g., bank accounts A and B transfer: A r A w A A B r B w B B sum: A r A A B r B B Permits this non-serializable interleaving Time à = commit / = exclusive- / Shared-lock; / = X- / S-unlock 17 18 Two-phase locking (2P) 2P rule: Once a transaction has released a lock it is not allowed to obtain any other locks A growing phase when transaction acquires locks A shrinking phase when transaction releases locks In practice: Growing phase is the entire transaction Shrinking phase is during commit 19 2P allows only serializable schedules 2P rule: Once a transaction has released a lock it is not allowed to obtain any other locks transfer: A r A w A A B r B w B B sum: A r A A B r B B 2P precludes this non-serializable interleaving Time à = commit / = X- / S-lock; / = X- / S-unlock 20 5

2P and transaction concurrency Serializability versus linearizability 2P rule: Once a transaction has released a lock it is not allowed to obtain any other locks transfer: A r A A w A B r B B w B sum: A r A B r B 2P permits this serializable, interleaved schedule Time à = commit / = X- / S-lock; / = X- / S-unlock = release all locks 21 inearizability is a guarantee about single operations on single objects Once write completes, all later reads (by wall clock) should reflect that write Serializability is a guarantee about transactions over one or more objects Doesn t impose real-time constraints inearizability + serializability = strict serializability Transaction behavior equivalent to some serial execution And that serial execution agrees with real-time 22 ecall: lock-based concurrency control Big Global ock: esults in a serial transaction schedule at the cost of performance Two-phase locking with finer-grain locks: Growing phase when txn acquires locks Shrinking phase when txn releases locks (typically commit) Allows txn to execute concurrently, improvoing performance Q: hat if access patterns rarely, if ever, conflict? 23 24 6

Be optimistic! OCC: Three-phase approach Goal: ow overhead for non-conflicting txns Begin: ecord timestamp marking the transaction s beginning Assume success! Modify phase: Process transaction as if would succeed Check for serializability only at commit time Txn can read values of committed data items pdates only to local copies (versions) of items (in db cache) If fails, abort transaction Validate phase Optimistic Concurrency Control (OCC) Commit phase Higher performance when few conflicts vs. locking ower performance when many conflicts vs. locking 25 If validates, transaction s updates applied to DB Otherwise, transaction restarted Care must be taken to avoid TOCTTO issues 26 OCC: hy validation is necessary OCC: Validate Phase txn coord O New txn creates shadow copies of P and Q P and Q s copies at inconsistent state Transaction is about to commit. System must ensure: Initial consistency: Versions of accessed objects at start consistent hen commits txn updates, create new versions at some timestamp t P Q txn coord No conflicting concurrency: No other txn has committed an operation at object that conflicts with one of this txn s invocations 27 28 7

OCC: Validate Phase 2P & OCC = strict serialization Validation needed by transaction T to commit: For all other txns O either committed or in validation phase, one of following holds: A. O completes commit before T starts modify Provides semantics as if only one transaction was running on DB at time, in serial order + eal-time guarantees B. T starts commit after O completes commit, and eadset T and riteset O are disjoint C. Both eadset T and riteset T are disjoint from riteset O, and O completes modify phase. hen validating T, first check (A), then (B), then (C). If all fail, validation fails and T aborted 29 2P: Pessimistically get all the locks first OCC: Optimistically create copies, but then recheck all read + written items before commit 30 Consider partitioned data over servers Distributed Transactions O P Q hy not just use 2P? Grab locks over entire read and write set Perform writes elease locks (at commit time) 31 32 8

Consider partitioned data over servers Strawman: Consensus per txn group? O O P P Q Q How do you get serializability? On single machine, single COMMIT op in the A S In distributed setting, assign global timestamp to txn (at sometime after lock acquisition and before commit) Centralized txn manager Distributed consensus on timestamp (not all ops) 33 Single amport clock, consensus per group? inearizability composes! But doesn t solve concurrent, non-overlapping txn problem 34 ednesday Google Spanner Distributed Transactions: Calvin, ococo 35 9