Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 20

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

CE 301T

CHAPTER 20
Introduction to Transaction Processi
Concepts and Theory
Dr. Najma Ismat
nismat@ssuet.edu.pk

Computer Engineering Depar


Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe
Introduction
◼ Transaction
◼ Describes local unit of database processing
◼ Transaction processing systems
◼ Systems with large databases and hundreds of
concurrent users
◼ Require high availability and fast response time

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 2


20.1 Introduction to Transaction
Processing
◼ Single-user DBMS
◼ At most one user at a time can use the system

◼ Example: home computer

◼ Multiuser DBMS
◼ Many users can access the system (database)

concurrently
◼ Example: airline reservations system

◼ Multiprogramming
◼ Allows the operating system to execute multiple processes
concurrently
◼ Executes commands from one process, then suspends that process
and executes commands from another process, etc.
◼ Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 3
Introduction to Transaction
Processing (cont’d.)
◼ Interleaved processing
◼ When multiple transactions are being processed simultaneously,
their operations can become interleaved, meaning that the
operations of one transaction can be interspersed with the
operations of another.
◼ Parallel processing
◼ Processes C and D in figure below

Figure 20.1 Interleaved processing versus parallel processing of concurrent


transactions
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20-4
Transactions
◼ Transaction: an executing program
◼ Forms logical unit of database processing

◼ Begin and end transaction statements


◼ Specify transaction boundaries

◼ Read-only transaction
◼ If the database operations in a transaction do not

update the database but only retrieve data


◼ Read-write transaction
◼ If the database operations in a transaction can update and
retrieve data the transaction is read-write transaction

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 5


Database Items
◼ Database represented as a collection of named data items
◼ The size of a data item called its granularity
◼ Measure of level of details of the data structure.

◼ Data item
◼ Record Granularity of
◼ Disk block data
◼ Attribute value of a record

◼ Transaction processing concepts independent of item granularity


◼ if the data item granularity is one disk block, then the disk block address can
be used as the data item name.
◼ If the item granularity is a single record, then the record id can be the item
name. Using

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 6


Read and Write Operations
◼ read_item(X)
◼ Reads a database item named X into a program variable named X

◼ Process includes finding the address of the disk block, and copying

to and from a memory buffer


◼ write_item(X)
◼ Writes the value of program variable X into the database item

named X
◼ Process includes finding the address of the disk block, copying to

and from a memory buffer, and storing the updated disk block back
to disk

The DBMS maintains a database cache and a number of buffers in main


memory to store data contents if immediate update/write cannot be done

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 7


Read and Write Operations (cont’d.)
◼ Read set of a transaction
◼ Set of all items read

◼ Write set of a transaction


◼ Set of all items written

Figure 20.2 Two sample transactions (a) Transaction T1 (b) Transaction T2

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 8


DBMS Buffers
◼ DBMS will maintain several main memory data buffers in
the database cache
◼ When buffers are occupied, a buffer replacement policy is
used to choose which buffer will be replaced
◼ Example policy: least recently used

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 9


Concurrency Control
◼ Transactions submitted by various users may execute concurrently
◼ Access and update the same database items
◼ Some form of concurrency control is needed
◼ The lost update problem
◼ Occurs when two transactions that access the same database items
have operations interleaved
◼ Results in incorrect value of some database items
If the concurrent execution is uncontrolled, it may lead to problems, such as an
inconsistent database.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 10


Concurrent Execution Example
Example 1: Airline reservations database in which a record is stored for each airline
flight. Each record includes the number of reserved seats on two flights named as X
and Y

Example 2: Assume a banking system where with one transaction doing a transfer
of funds from account X to account Y and the other transaction doing a deposit to
account X

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20-11


The Lost Update Problem
This problem occurs when two transactions that access the same database items
have their operations interleaved in a way that makes the value of some database
items incorrect.

Figure 20.3
Some problems that occur when concurrent execution is uncontrolled.
(a) The lost update problem.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20-12


The Temporary Update Problem
This problem occurs when one transaction updates a database item and then
the transaction fails for some reason

Figure 20.3 (b) The temporary update problem

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20-13


The Incorrect Summary Problem
If one transaction is calculating an aggregate summary function on several database
items while other transactions are updating some of these items, the aggregate
function may calculate some values before they are updated and others after they
are updated.

Figure 20.3 (c) The incorrect summary problem


Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20-14
The Unrepeatable Read Problem
◼ Transaction T reads the same item twice
◼ Value is changed by another transaction T′ between the two reads
◼ T receives different values for the two reads of the same item
◼ Example: for example, if during an airline reservation transaction, a
customer inquires about seat availability on several flights.
◼ When the customer decides on a particular flight, the transaction then reads
the number of seats on that flight a second time before completing the
reservation, and it may end up reading a different value for the item.

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 15


Why Recovery is Needed
◼ Committed transaction
◼ Effect recorded permanently in the database

◼ Aborted transaction
◼ Does not affect the database

◼ Types of transaction failures


◼ Computer failure (system crash)

◼ Transaction or system error

◼ Local errors or exception conditions detected by the transaction

◼ Concurrency control enforcement

◼ Disk failure

◼ Physical problems or catastrophes

◼ System must keep sufficient information to recover quickly from the


failure
◼ Disk failure or other catastrophes have long recovery times
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 16
20.2 Transaction and System
Concepts
◼ System must keep track of when each transaction starts, terminates,
commits, and/or aborts
◼ BEGIN_TRANSACTION
◼ READ or WRITE
◼ END_TRANSACTION
◼ COMMIT_TRANSACTION
◼ ROLLBACK (or ABORT)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 17


The System Log
◼ System log keeps track of transaction operations
◼ Sequential, append-only file
◼ Not affected by failure (except disk or catastrophic failure)
◼ Log buffer →holds the last part of the log file, so that log entries are first
added to the
◼ Main memory buffer

◼ When full, appended to the end of the log file on disk

◼ Log file is backed up periodically


◼ Undo and redo operations based on the log possible because the log
keeps track of all the write operations

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 18


Commit Point of a Transaction
◼ Occurs when all operations that access the database have completed
successfully
◼ And the effect of operations recorded in the log

◼ Transaction writes a commit record into the log


◼ If system failure occurs, can search for transactions with recorded

start_transaction but no commit record


◼ Force-writing the log buffer to disk
◼ Writing log buffer to disk before the transaction reaches the

commit point

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 19


DBMS-Specific Buffer Replacement Policies
◼ Page replacement policy
◼ Select the particular buffers to be replaced when all are full
◼ Domain separation (DS) method
◼ DBMS cache is divided into separate domains (sets of buffers).
◼ Each domain handles one type of disk page and uses
LRU/GRU page replacement policy
◼ Index pages
◼ Data file pages
◼ Log file pages
◼ Number of available buffers for each domain is predetermined

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 20


DBMS-Specific Buffer Replacement
Policies (cont’d.)
◼ Hot set method
◼ Useful in queries that scan a set of pages repeatedly

◼ The hot set method determines for each database processing

algorithm the set of disk pages that will be accessed repeatedly


◼ Does not replace the set in the buffers until processing is

completed
◼ The DBMIN method
◼ Predetermines the pattern of page references for each algorithm

for a particular type of database operation


◼ Calculates locality set using query locality set model (QLSM)

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 21


20.3 Desirable Properties of
Transactions
◼ Transactions should possess several properties, often called
the ACID properties; they should be enforced by the
concurrency control and recovery methods of the DBMS.
◼ ACID properties
◼ Atomicity

◼ A transaction is an atomic unit of processing and should be


performed in its entirety or not at all
◼ Consistency preservation
◼ A transaction should be consistency preserving, that if it is
completely executed from beginning to end without interference
from other transactions.
◼ Takes database from one consistent state to another

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 22


20.3 Desirable Properties of
Transactions (cont’d)
◼ Isolation
◼ transaction should appear as though it is being executed in
isolation from other transactions, even though many transactions
are executing concurrently.
◼ Not interfered with by other transactions
◼ Durability or permanency
◼ The changes applied to the database by a committed transaction
must persist in the database. T
◼ These changes must not be lost because of any failure amd must
persist in the database

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 23


Desirable Properties of Transactions
(cont’d.)
◼ Levels of isolation
◼ Level 0 isolation does not overwrite the dirty reads of

higher-level transactions
◼ Dirty read occurs when a transaction reads the data that has been
updated by another transaction that is still uncommitted.
◼ Level 1 isolation has no lost updates
◼ Level 2 isolation has no lost updates and no dirty reads
◼ Level 3 (true) isolation has repeatable reads
◼ In addition to level 2 properties
◼ Snapshot isolation

Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Slide 20- 24

You might also like