Tải bản đầy đủ (.pdf) (92 trang)

Dbms chapter 5 transaction processing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.51 MB, 92 trang )

Ho Chi Minh City University of Technology
Faculty of Computer Science and Engineering

Chapter 5: Introduction to
Transaction Processing Concepts
and Theory
Database Management Systems
(CO3021)
Computer Science Program
Dr. Võ Thị Ngọc Châu
()
Semester 1 – 2020-2021


Course outline


Chapter 1. Overall Introduction to Database
Management Systems



Chapter 2. Disk Storage and Basic File Structures



Chapter 3. Indexing Structures for Files



Chapter 4. Query Processing and Optimization





Chapter 5. Introduction to Transaction
Processing Concepts and Theory



Chapter 6. Concurrency Control Techniques



Chapter 7. Database Recovery Techniques
2


References


[1] R. Elmasri, S. R. Navathe, Fundamentals of Database
Systems- 6th Edition, Pearson- Addison Wesley, 2011.


R. Elmasri, S. R. Navathe, Fundamentals of Database Systems- 7th
Edition, Pearson, 2016.



[2] H. G. Molina, J. D. Ullman, J. Widom, Database System


Implementation, Prentice-Hall, 2000.


[3] H. G. Molina, J. D. Ullman, J. Widom, Database Systems:
The Complete Book, Prentice-Hall, 2002



[4] A. Silberschatz, H. F. Korth, S. Sudarshan, Database

System Concepts –3rd Edition, McGraw-Hill, 1999.


[Internet] …
3


Content


5.1. Introduction to Transaction Processing



5.2. Transaction and System Concepts



5.3. Desirable Properties of Transactions




5.4. Characterizing Schedules based on
Recoverability



5.5. Characterizing Schedules based on
Serializability



5.6. Transaction Support in SQL
4


5.1. Introduction to
Transaction Processing


Transaction processing systems are
systems with large databases and hundreds
of concurrent users executing database
transactions.





High availability and fast response time for

hundreds of concurrent users
Examples: airline reservations, banking, credit
card processing, online retail purchasing, stock
markets, supermarket checkouts, etc.

the concept of a transaction, which is used
to represent a logical unit of database
processing that must be completed in its
entirety to ensure correctness

5


5.1. Introduction to
Transaction Processing




Single-user vs. multi-user database systems


Concurrent execution of transactions in a multiuser system



Recovery from transaction failures when
transactions fail while executing

The number of users who can use the system

concurrently-that is, at the same time


Single-user if at most one user at a time can use
the system



Multiuser if many users can use the system - and
hence access the database - concurrently

6


5.1. Introduction to
Transaction Processing
Interleaved processing versus parallel processing of concurrent transactions
Figure 20.1, [1], pp. 747

Concurrent execution of processes is actually
interleaved. Interleaving keeps the CPU busy
when a process requires an input or output
(I/O) operation, such as reading a block from
disk. The CPU is switched to execute another
process rather than remaining idle during I/O
time. Interleaving also prevents a long
process from delaying other processes.

If the computer system has
multiple hardware processors

(CPUs), parallel processing of
multiple processes is possible.
7


5.1. Introduction to
Transaction Processing


A Transaction: logical unit of database processing
that includes one or more database access
operations (read – retrieval, write – insert, update,
delete).


Typically implemented by a computer program that
includes database commands



The database operations that form a transaction can
either be embedded within an application program or they
can be specified interactively via a high-level query
language such as SQL.



Transaction boundaries: Begin and End
transaction statements.




An application program may contain several
transactions separated by the transaction
boundaries.

8


5.1. Introduction to
Transaction Processing
SIMPLE MODEL OF A DATABASE (for purposes
of discussing transactions):


A database - collection of named data items



Granularity of data - a field, a record , or a
whole disk block (Concepts are independent of
granularity)



Basic operations are read and write


read_item(X): Reads a database item named X into
a program variable. To simplify our notation, we

assume that the program variable is also named X.



write_item(X): Writes the value of program
variable X into the database item named X.

9


5.1. Introduction to
Transaction Processing
READ AND WRITE OPERATIONS:


Basic unit of data transfer from the disk to the computer main
memory is one block. In general, a data item (what is read or
written) will be the field of some record in the database,
although it may be a larger unit such as a record or even a
whole block.



read_item(X) command includes the following steps:
1.

Find the address of the disk block that contains item X.

2.


Copy that disk block into a buffer in main memory (if that disk block is
not already in some main memory buffer).

3.

Copy item X from the buffer to the program variable named X.
10


5.1. Introduction to
Transaction Processing
READ AND WRITE OPERATIONS:
write_item(X) command includes the following steps:


1.

Find the address of the disk block that contains item X.

2.

Copy that disk block into a buffer in main memory (if that disk block
is not already in some main memory buffer).

3.

Copy item X from the program variable named X into its correct
location in the buffer.

4.


Store the updated block from the buffer back to disk (either

immediately or at some later point in time).
11


5.1. Introduction to
Transaction Processing

Two sample transactions.
(a) Transaction T1.
(b) Transaction T2.

Figure 20.2, [1], pp. 750.

12


5.1. Introduction to
Transaction Processing


Why concurrency control is needed



The problems encountered with the
transactions running concurrently if
uncontrolled



The lost update problem



The temporary update (or dirty read) problem



The incorrect summary problem



The unrepeatable problem



The phantom problem

13


5.1. Introduction to
Transaction Processing


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.


5.1. Introduction to
Transaction Processing


The temporary update (or dirty read) problem


This problem occurs when one transaction updates a database item
and then the transaction fails for some reason. The updated item is
accessed by another transaction before it is changed.




The incorrect summary problem


If one transaction is calculating an aggregate summary function on a
number of records while other transactions are updating some of these
records, the aggregate function may calculate some values before they are
16
updated and others after they are updated.


5.1. Introduction to

Transaction Processing


The unrepeatable (nonrepeatable) problem


A transaction T reads an item twice and the
item is changed by another transaction T'
between the two reads. Hence, T receives

different values for its two reads of the same
item.

17


5.1. Introduction to
Transaction Processing


The phantom problem


A transaction T1 may read a set of rows from a
table, perhaps based on some condition
specified in the SQL WHERE-clause. Now
suppose that a transaction T2 inserts a new row
that also satisfies the WHERE-clause condition

used in T1, into the table used by T1. If T1 is

repeated, then T1 will see a phantom, a row
that previously did not exist.
18


5.1. Introduction to
Transaction Processing


Why recovery is needed


Whenever a transaction is submitted to a DBMS for execution,
the system is responsible for making sure:






either (1) all the operations in the transaction are completed
successfully and their effect is recorded permanently in the
database,
or (2) the transaction has no effect whatsoever on the database
or on any other transactions.

The DBMS must not permit some operations of a transaction
T to be applied to the database while other operations of T
are not.




This may happen if a transaction fails after executing some of
its operations but before executing all of them.

19


5.1. Introduction to
Transaction Processing


Several possible reasons for a transaction to
fail in the middle of execution:


1. A computer failure (system crash)



2. A transaction or system error



3. Local errors or exception conditions detected
by the transaction



4. Concurrency control enforcement




5. Disk failure



6. Physical problems and catastrophes

 Recovery and backup

20


5.1. Introduction to
Transaction Processing
Why recovery is needed:
(What causes a Transaction to fail)
1. A computer failure (system crash): A hardware or software error

occurs in the computer system during transaction execution. If the
hardware crashes, the contents of the computer’s internal memory
may be lost.
2. A transaction or system error : Some operation in the transaction

may cause it to fail, such as integer overflow or division by zero.
Transaction failure may also occur because of erroneous parameter
values or because of a logical programming error. In addition, the user
may interrupt the transaction during its execution.


21


5.1. Introduction to
Transaction Processing
Why recovery is needed:
3. Local errors or exception conditions detected by the transaction:
- certain conditions necessitate cancellation of the transaction. For
example, data for the transaction may not be found. A condition,
such as insufficient account balance in a banking database, may
cause a transaction, such as a fund withdrawal from that account, to
be canceled.

- a programmed abort in the transaction causes it to fail.
5.

Concurrency control enforcement: The concurrency control
method may decide to abort the transaction, to be restarted later,
because it violates serializability or because several transactions are
in a state of deadlock.
22


5.1. Introduction to
Transaction Processing
Why recovery is needed:
5.

Disk failure: Some disk blocks may lose their data because of a
read or write malfunction or because of a disk read/write head

crash. This may happen during a read or a write operation of the
transaction.

6.

Physical problems and catastrophes: This refers to an endless list
of problems that includes power or air-conditioning failure, fire,
theft, sabotage, overwriting disks or tapes by mistake, and
mounting of a wrong tape by the operator.

23


5.2. Transaction and System Concepts
A transaction is an atomic (logical) unit of work that is
either completed in its entirety or not done at all.
Transaction states:


Active state



Partially committed state



Committed state




Failed state



Terminated State
24


5.2. Transaction and System Concepts

State transition diagram illustrating the states for
transaction execution.
Figure 20.4, [1], pp. 754.
25


×