Indra Budi indra@cs.ui.ac.id Transaction Indra Budi indra@cs.ui.ac.id.

Slides:



Advertisements
Similar presentations
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Advertisements

Managing Multi-User Databases (1) IS 240 – Database Management Lecture #18 – Prof. M. E. Kabay, PhD, CISSP Norwich University
Concurrency control 1. 2 Introduction concurrency more than one transaction have access to data simultaneously part of transaction processing.
1 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transactions 3.
Concurrency Control Techniques
Lecture plan Transaction processing Concurrency control
Chapter 14: Transactions
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Chapter 12 Managing Multi-user Databases David M. Kroenke Database Processing © 2000 Prentice Hall.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
CSC271 Database Systems Lecture # 32.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
Fakultas Ilmu Komputer UI 1 Exercise A series of actions to be taken on the database such that either all actions are completed successfully, or none of.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Database Administration Chapter Six DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Transaction Management and Concurrency Control
10 1 Chapter 10 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
What is a Transaction? Logical unit of work
Transaction Management
1 Transaction Management Database recovery Concurrency control.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 18.
Chapter 9 Transaction Management and Concurrency Control
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management and Concurrency Control
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
1 IT420: Database Management and Organization Transactions 31 March 2006 Adina Crăiniceanu
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Databases Illuminated
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
1 IT420: Database Management and Organization Session Control Managing Multi-user Databases 24 March 2006 Adina Crăiniceanu
Concurrency Control in Database Operating Systems.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
© 2002 by Prentice Hall 1 Database Administration David M. Kroenke Database Concepts 1e Chapter 6 6.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Fundamentals, Design, and Implementation, 9/e Chapter 9 Managing Multi-User Databases.
1 IT420: Database Management and Organization Managing Multi-user Databases 29 March 2006 Adina Crăiniceanu
© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 8 Slide 1 IT 390 Business Database Administration Unit 8:
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
1 Database Systems ( 資料庫系統 ) December 27/28, 2006 Lecture 13 Merry Christmas & New Year.
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
Chapter 5 Managing Multi-user Databases 1. Multi-User Issues Database Administration Concurrency Control Database Security Database Recovery Page 307.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Transaction Management
Transaction Management and Concurrency Control
Managing Multi-user Databases
Chapter 9 Managing Multi-User Databases
Transaction Management Transparencies
Multi-User Databases Chapter 9.
Database Processing: David M. Kroenke’s Chapter Nine: Part One
Chapter 10 Transaction Management and Concurrency Control
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Presentation transcript:

Indra Budi indra@cs.ui.ac.id Transaction Indra Budi indra@cs.ui.ac.id

Exercise A series of actions to be taken on the database such that either all actions are completed successfully, or none of them can be completed, is known as a(n): a.) checkpoint. b.) log. c.) lock. d.) transaction. e.) concurrent. 2

Exercise When two transactions are being processed against the database at the same time, a.) they are called concurrent transactions. b.) they are usually interleaved. c.) they always result in a lost update problem. d.) one must be rolled back. e.) both a and b 3

Exercise …. means a transaction executes when all actions of the transaction are completed fully, or none are. This means there are no partial transactions (such as when half the actions complete and the other half do not). …. involves beginning a transaction with a ’consistent’ database, and finishing with a ’consistent’ database. For example, in a bank database, money should never be ”created” or ”deleted” without an appropriate deposit or withdrawal. Every transaction should see a consistent database. ….ensures that a transaction can run independently, without considering any side effects that other concurrently running transactions might have. ….define the persistence of committed data: once a transaction commits, the data should persist in the database even if the system crashes before the data is written to non-volatile storage. A …. is a series of (possibly overlapping) transactions. A …..occurs when a transaction reads a database object that has been modified by another not-yet-committed transaction. A ….over a set S of transactions is a schedule whose effect on any consistent database instance is identical to that of some complete serial schedule over the set of committed transactions in S. A …..is one in which a transaction can commit only after all other transactions whose changes it has read have committed. 4

Serializable schedule Schedule Atomicity Durability Isolation Recoverable schedule Serializable schedule Schedule Atomicity Durability Isolation Dirty Read Unrepeatable problem Consistency Cascading rollback 5

Exercise Do exercise 17.23 Elmasri pages 581 6

Schedule C is Serializable ? 25 25 125 250 250 250 T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B); B  B+100; Write(B); Read(B);B  B2; 7

Is Schedule D serializable ? 25 25 125 250 50 150 250 150 T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B);B  B2; Write(B); Read(B); B  B+100; 8

Database Administration All large and small databases need database administration Data administration refers to a function concerning all of an organization’s data assets Database administration (DBA) refers to a person or office specific to a single database and its applications 9

DBA Tasks Managing database structure Controlling concurrent processing Managing processing rights and responsibilities Developing database security Providing for database recovery Managing the DBMS Maintaining the data repository 10

Managing Database Structure DBA’s tasks: Participate in database and application development Assist in requirements stage and data model creation Play an active role in database design and creation Facilitate changes to database structure Seek community-wide solutions Assess impact on all users Provide configuration control forum Be prepared for problems after changes are made Maintain documentation 11

Concurrency Control Concurrency control ensures that one user’s work does not inappropriately influence another user’s work No single concurrency control technique is ideal for all circumstances Trade-offs need to be made between level of protection and throughput 12

Atomic Transactions A transaction, or logical unit of work (LUW), is a series of actions taken against the database that occurs as an atomic unit Either all actions in a transaction occur or none of them do 13

Example: Atomic Transaction 14

Example: Atomic Transaction 15

Concurrent Transaction Concurrent transactions refer to two or more transactions that appear to users as they are being processed against a database at the same time In reality, CPU can execute only one instruction at a time Transactions are interleaved meaning that the operating system quickly switches CPU services among tasks so that some portion of each of them is carried out in a given interval Concurrency problems: lost update and inconsistent reads 16

Example: Concurrent Transactions 17

Example: Lost Update Problem 18

Concurrency Control and Locking We need a way to guarantee that our concurrent transactions can be serialized. Locking is one such means. Locking is done to data items in order to reserve them for future operations. A lock is a logical flag set by a transaction to alert other transactions the data item is in use. 19

Resource Locking Resource locking prevents multiple applications from obtaining copies of the same record when the record is about to be changed 20

Characteristics of Lock Locks may be applied to data items in two ways: Implicit Locks are applied by the DBMS Explicit Locks are applied by application programs. Locks may be applied to: a single data item (value) an entire row of a table a page (memory segment) (many rows worth) an entire table an entire database This is referred to as the Lock granularity Locks may be of type types depending on the requirements of the transaction: An Exclusive Lock prevents any other transaction from reading or modifying the locked item. A Shared Lock allows another transaction to read an item but prevents another transaction from writing the item. 21

Example: Explicit Locks 22

The Two-Phase Locking Protocol This is a protocol which ensures conflict-serializable schedules. Phase 1: Growing Phase transaction may obtain locks transaction may not release locks Phase 2: Shrinking Phase transaction may release locks transaction may not obtain locks The protocol assures serializability. It can be proved that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock). 23

2PL Examples User A places an exclusive lock on the balance User A reads the balance User A deducts $100 from the balance User B attempts to place a lock on the balance but fails because A already has an exclusive lock User B is placed into a wait state User A writes the new balance of $100 User A releases the exclusive lock on the balance User B places an exclusive lock on the balance User B reads the balance User B deducts $100 from the balance User B writes the new balance of $100 24

2PL Example User A places a shared lock on item raise_rate User A reads raise_rate User A places an exclusive lock on item Amy_salary User A reads Amy_salary User B places a shared lock on item raise_rate User B reads raise_rate User A calculates a new salary as Amy_salary * (1+raise_rate) User B places an exclusive lock on item Bill_salary User B reads Bill_salary User B calculates a new salary as Bill_salary * (1+raise_rate) User B writes Bill_salary User A writes Amy_salary User A releases exclusive lock on Amy_salary User B releases exclusive lock on Bill_Salary User B releases shared lock on raise_rate User A releases shared lock on raise_rate 25

Deadlock User A places an exclusive lock on item 1001 User B places an exclusive lock on item 2002 User A attempts to place an exclusive lock on item 2002 User A placed into a wait state User B attempts to place an exclusive lock on item 1001 User B placed into a wait state This is called a deadlock. One transaction has locked some of the resources and is waiting for locks so it can complete. A second transaction has locked those needed items but is awaiting the release of locks the first transaction is holding so it can continue. 26

Deadlock Deadlock, or the deadly embrace, occurs when two transactions are each waiting on a resource that the other transaction holds Preventing deadlock Allow users to issue all lock requests at one time Require all application programs to lock resources in the same order Breaking deadlock Almost every DBMS has algorithms for detecting deadlock When deadlock occurs, DBMS aborts one of the transactions and rollbacks partially completed work 27

Another Deadlock Example 28

Optimistic/Pessimistic Locking Optimistic locking assumes that no transaction conflict will occur DBMS processes a transaction; checks whether conflict occurred If not, the transaction is finished If so, the transaction is repeated until there is no conflict Pessimistic locking assumes that conflict will occur Locks are issued before transaction is processed, and then the locks are released Optimistic locking is preferred for the Internet and for many intranet applications 29

Example: Optimistic Locking 30

Example: Pessimistic Locking 31

Final Test Scheduled on Dec, 29th 2004, 09.00 – 11.00 WIB May open all notes written by hand, no copies, no print-out, close textbook Material from “Introduction to DB” to Concurrency Control 32

Next Wednesday (Dec 15th) Quiz Close Books & Close Notes Material SQL (Join, Aggregation, Grouping, Having, View) Transactions Processing & Concurrency Control 33