Transaction Management

Similar documents
Chapter 7 (Cont.) Transaction Management and Concurrency Control

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

TRANSACTION PROPERTIES

Chapter 22. Transaction Management

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

Transaction Management. Pearson Education Limited 1995, 2005

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

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

Database Management Systems

Module 15: Managing Transactions and Locks

CS Reading Packet: "Transaction management, part 2"

T ransaction Management 4/23/2018 1

DATABASE DESIGN I - 1DL300

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe


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

Weak Levels of Consistency

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

Overview. Introduction to Transaction Management ACID. Transactions

Introduction to Transaction Processing Concepts and Theory

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

2 Copyright 2015 M. E. Kabay. All rights reserved. 4 Copyright 2015 M. E. Kabay. All rights reserved.

CMP-3440 Database Systems

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

Intro to Transactions

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Database Systems. Announcement

Transaction Processing Concepts and Theory. Truong Tuan Anh CSE-HCMUT

Transaction Management

CSE 530A ACID. Washington University Fall 2013

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

COURSE 1. Database Management Systems

Intro to Transaction Management

CSE 444: Database Internals. Lectures Transactions

Overview of Transaction Management

Transactions and Locking. Rose-Hulman Institute of Technology Curt Clifton

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

CSE 344 MARCH 5 TH TRANSACTIONS

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

CSE 344 MARCH 9 TH TRANSACTIONS

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Chapter 20 Introduction to Transaction Processing Concepts and Theory

Transaction Management & Concurrency Control. CS 377: Database Systems

Transaction Processing Concurrency control

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

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

Chapter 13. Concurrency Control. In This Chapter. c Concurrency Models c Transactions c Locking c Isolation Levels c Row Versioning

Introduction to Data Management CSE 344

Concurrency Control & Recovery

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

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

UNIT 4 TRANSACTIONS. Objective

BCA204T: DATA BASE MANAGEMENT SYSTEMS

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

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

Implementing Isolation

TRANSACTION MANAGEMENT

TRANSACTION PROCESSING CONCEPTS

Transaction Management: Introduction (Chap. 16)

Chapter 15 : Concurrency Control

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

Transaction Management: Concurrency Control

October/November 2009

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

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

Transaction Processing: Basics - Transactions

Database Systems CSE 414

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

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

Transaction Management Overview

Introduction to Data Management CSE 344

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

Concurrency Control Algorithms

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

Transaction Management and Concurrency Control. Chapter 16, 17

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

DB2 Lecture 10 Concurrency Control

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 13 : Concurrency Control

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

Problems Caused by Failures

Advances in Data Management Transaction Management A.Poulovassilis

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

Database System Concepts

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

CSE 344 MARCH 21 ST TRANSACTIONS

Introduction to Data Management CSE 414

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

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

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

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

Databases - Transactions

Concurrency control CS 417. Distributed Systems CS 417

Chapter 17: Recovery System

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

Database Systems CSE 414

Transactions. The Setting. Example: Bad Interaction. Serializability Isolation Levels Atomicity

Conflict Equivalent. Conflict Serializability. Example 1. Precedence Graph Test Every conflict serializable schedule is serializable

Database Management Systems 2010/11

Transcription:

Transaction Management Imran Khan FCS, IBA In this chapter, you will learn: What a database transaction is and what its properties are How database transactions are managed What concurrency control is and what role it plays in maintaining the database s integrity What locking methods are and how they work How database recovery management is used to maintain database integrity 2 1

What Is a Transaction? A transaction is a logical unit of work that must be either entirely completed or aborted; no intermediate states are acceptable. Most real-world database transactions are formed by two or more database requests. A database request is the equivalent of a single SQL statement in an application program or transaction. A transaction that changes the contents of the database must alter the database from one consistent database state to another. To ensure consistency of the database, every transaction must begin with the database in a known consistent state. 3 What is a Transaction? Logical unit of work Must be either entirely completed or aborted No intermediate states are acceptable Figure 9.1 4 2

Example Transaction Examine current account balance SELECT ACC_NUM, ACC_BALANCE FROM CHECKACC WHERE ACC_NUM = 0908110638 ; Consistent state after transaction No changes made to Database 5 Example Transaction Register credit sale of 100 units of product X to customer Y for $500 UPDATE PRODUCT SET PROD_QOH = PROD_QOH - 100 WHERE PROD_CODE = X ; UPDATE ACCT_RECEIVABLE SET ACCT_BALANCE = ACCT_BALANCE + 500 WHERE ACCT_NUM = Y ; Consistent state only if both database requests are fully completed DBMS doesn t guarantee transaction represents realworld event 6 3

Transaction Properties Atomicity All transaction operations must be completed Incomplete transactions are aborted Durability Permanence of consistent database state Serializability Conducts transactions in serial order Important in multi-user and distributed databases Isolation Transaction data cannot be reused until its execution is completed 7 Transaction Management with SQL Transaction support COMMIT ROLLBACK User initiated transaction sequence must continue until: COMMIT statement is reached ROLLBACK statement is reached End of a program reached Program reaches abnormal termination 8 4

Transaction Log Tracks all transactions that update database May be used by ROLLBACK command May be used to recover from system failure Log stores Record for beginning of transaction Each SQL statement Operation Names of objects Before and after values for updated fields Pointers to previous and next entries Commit Statement Example of Transaction Log (Table 9.1) 9 Concurrency Control Coordinates simultaneous transaction execution in multiprocessing database Ensure serializability of transactions in multiuser database environment Potential problems in multiuser environments Lost updates (Tables 9.2 and 9.3) Uncommitted data (Tables 9.4 and 9.5) Inconsistent retrievals (Tables 9.6 -- 9.8) 10 5

Concurrency Control Lost Updates Two concurrent transactions update PROD_QOH: TRANSACTION COMPUTATION T1: Purchase 100 units PROD_QOH = PROD_QOH + 100 T2: Sell 30 units PROD_QOH = PROD_QOH - 30 See Table 9.2 for the serial execution under normal circumstances. See Table 9.3 for the lost update problems resulting from the execution of the second transaction before the first transaction is committed. 11 Table 9.2 Normal Execution Of Two Transactions Table 9.3 Lost Updates 12 6

Concurrency Control Uncommitted Data Data are not committed when two transactions T1 and T2 are executed concurrently and the first transaction is rolled back after the second transaction has already accessed the uncommitted data -- thus violating the isolation property of the transaction. TRANSACTION COMPUTATION T1: Purchase 100 units PROD_QOH = PROD_QOH + 100 (Rolled back) T2: Sell 30 units PROD_QOH = PROD_QOH - 30 13 Table 9.4 Correct Execution Of Two Transactions Table 9.5 An Uncommitted Data Problem 14 7

Concurrency Control Inconsistent Retrievals Inconsistent retrievals occur when a transaction calculates some summary (aggregate) functions over a set of data while other transactions are updating the data. Example: T1 calculates the total quantity on hand of the products stored in the PRODUCT table. At the same time, T2 updates the quantity on hand (PROD_QOH) for two of the PRODUCT table s products. Table 9.6 Retrieval During Update Table 9.7 Transaction Results: Data Entry Correction Table 9.8 Inconsistent Retrievals 15 The Scheduler The scheduler establishes the order in which the operations within concurrent transactions are executed. The scheduler interleaves the execution of database operations to ensure serializability. To determine the appropriate order, the scheduler bases its actions on concurrency control algorithms, such as locking or time stamping methods. The scheduler also makes sure that the computer s CPU is used efficiently. 16 8

Read/Write Conflict Scenarios: Conflicting Database Operations Matrix Table 9.9 17 Concurrency Control with Locking Methods Lock guarantees current transaction exclusive use of data item Acquires lock prior to access Lock released when transaction is completed DBMS automatically initiates and enforces locking procedures Managed by lock manager Lock granularity indicates level of lock use 18 9

Concurrency Control with Locking Methods Lock Granularity Lock granularity indicates the level of lock use. Database level (See Figure 9.2) Table level (See Figure 9.3) Page level (See Figure 9.4) Row level (See Figure 9.5) Field level 19 Database-Level Locking Sequence Figure 9.2 20 10

Table-Level Lock Example Figure 9.3 21 Page-Level Lock Example Figure 9.4 22 11

Row-Level Lock Example Figure 9.5 23 Binary Locks A binary lock has only two states: locked (1) or unlocked (0). If an object is locked by a transaction, no other transaction can use that object. If an object is unlocked, any transaction can lock the object for its use. A transaction must unlock the object after its termination. Every transaction requires a lock and unlock operation for each data item that is accessed. Example of Binary Lock Table (Table 9.10) 24 12

Table 9.10 An Example Of A Binary Lock 25 Exclusive/ Shared Locks Exclusive Locks An exclusive lock exists when access is specially reserved for the transaction that locked the object. The exclusive lock must be used when the potential for conflict exists. An exclusive lock is issued when a transaction wants to write (update) a data item and no locks are currently held on that data item. 26 Shared Locks A shared lock exists when concurrent transactions are granted READ access on the basis of a common lock. A shared lock produces no conflict as long as the concurrent transactions are read only. A shared lock is issued when a transaction wants to read data from the database and no exclusive lock is held on that data item. 13

Problems with Locking Transaction schedule may not be serializable Managed through two-phase locking Schedule may create deadlocks Managed by using deadlock detection and prevention techniques 27 Two-Phase Locking Two-Phase Locking The two-phase locking protocol defines how transactions acquire and relinquish locks. It guarantees serializability, but it does not prevent deadlocks. In a growing phase, a transaction acquires all the required locks without unlocking any data. Once all locks have been acquired, the transaction is in its locked point. In a shrinking phase, a transaction releases all locks and cannot obtain any new locks. Governing rules Two transactions cannot have conflicting locks No unlock operation can precede a lock operation in the same transaction No data are affected until all locks are obtained 28 14

Two-Phase Locking Protocol Figure 9.6 29 Concurrency Control with Locking Methods Deadlocks (Deadly Embrace) Deadlocks exist when two transactions T1 and T2 exist in the following mode: T1 = access data items X and Y T2 = access data items Y and X If T1 has not unlocked data item Y, T2 cannot begin; and, if T2 has not unlocked data item X, T1 cannot continue. (See Table 9.11) 30 15

Concurrency Control with Locking Methods Three Techniques to Control Deadlocks: Deadlock Prevention A transaction requesting a new lock is aborted if there is a possibility that a deadlock can occur. Deadlock Detection The DBMS periodically tests the database for deadlocks. If a deadlock is found, one of the transactions ( victim ) is aborted, and the other transaction continues. Deadlock Avoidance The transaction must obtain all the locks it needs before it can be executed. 31 How Deadlock Conditions Created 32 Table 9.11 16

Concurrency Control with Time Stamping Methods The time stamping approach assigns a global unique time stamp to each transaction to schedule concurrent transactions. The time stamp value produces an explicit order in which transactions are submitted to the DBMS. Time stamps must have two properties: Uniqueness assures that no equal time stamp values can exist. Monotonicity assures that time stamp values always increase. The DBMS executes conflicting operations in time stamp order to ensure the serializability. 33 Concurrency Control with Optimistic Methods It is based on the assumption that the majority of the database operations do not conflict. A transaction is executed without restrictions until it is committed. Each transaction moves through two or three phases: Read Phase: The transaction reads the database, executes the needed computations, and makes the updates to a private copy of the database values. Validation Phase: The transaction is validated to assure that the changes made will not affect the integrity and consistency of the database. Write Phase: The changes are permanently applied to the database. 34 17

Database Recovery Management Recovery restores a database from a given state, usually inconsistent, to a previously consistent state. Recovery techniques are based on the atomic transaction property: All portions of the transaction must be applied and completed to produce a consistent database. If, for some reason, any transaction operation cannot be completed, the transaction must be aborted, and any changes to the database must be rolled back. Levels of Backup Full backup of the database: It backs up or dumps the whole database. Differential backup of the database: Only the last modifications done to the database are copied. Backup of the transaction log only: It backs up all the transaction log operations that are not reflected in a previous backup copy of the database. 35 Causes of Database Failure Software Operating system, DBMS, application programs, viruses Hardware Memory chip errors, disk crashes, bad disk sectors, disk full errors Programming Exemption Application programs, end users Transaction Deadlocks External Fire, earthquake, flood 36 18

Transaction Recovery Procedures Deferred-write and Deferred-update Transaction operations do not immediately update the database. Instead, all changes are written to the transaction log. The database is updated only after the transaction reaches its commit point. Write-through The database is immediately updated by transaction operations during the transaction s execution, even before the transaction reaches its commit point. The transaction log is also updated. If a transaction fails, the database uses the log information to roll back the database. 37 19