0% found this document useful (0 votes)
2 views

Chapter 2 Transaction Management

Chapter 2 of 'Advanced Database Systems' discusses transaction processing concepts, defining a transaction as a logical unit of work that modifies a database. It emphasizes the importance of properties such as Atomicity, Consistency, Isolation, and Durability (ACID) in ensuring database integrity. The chapter also explores transaction processing systems, the distinction between business and online transactions, and the challenges of concurrent transaction processing, including issues like lost updates and inconsistent analysis.

Uploaded by

Zewdu Zemedu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 2 Transaction Management

Chapter 2 of 'Advanced Database Systems' discusses transaction processing concepts, defining a transaction as a logical unit of work that modifies a database. It emphasizes the importance of properties such as Atomicity, Consistency, Isolation, and Durability (ACID) in ensuring database integrity. The chapter also explores transaction processing systems, the distinction between business and online transactions, and the challenges of concurrent transaction processing, including issues like lost updates and inconsistent analysis.

Uploaded by

Zewdu Zemedu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Advanced Database Systems

Chapter 2
Transaction Processing Concepts

Sirage Z.
Department of Computer Science
Debre Berhan University
2022
What is a transaction?
 A Transaction is a mechanism for applying the desired
modifications/operations to a database.
 Action, or series of actions, carried out by a single user or
application program, which accesses or changes contents of
database. (i.e. Logical unit of work on the database.)
 A transaction could be a whole program, part/module of a
program or a single command.
 Changes made in real time to a database are called transactions.
 Examples include ATM transactions, credit card approvals, flight
reservations, hotel check-in, phone calls, supermarket canning,
academic registration and billing.
06/03/2025 Transactions processing and concurrency Management 2
…Con’t
 A transaction could be composed of one or more
database and non-database operations.
 Transforms database from one consistent state to
another, although consistency may be violated during
transaction.
 A database transaction is a unit of interaction with
database management system or similar system that
is treated in a coherent and reliable way independent
of other transactions.
06/03/2025 Transactions processing and concurrency Management 3
Transaction Processing System
 A system that manages transactions and controls their access to a DBMS
is called a TP monitor.
 A transaction processing system (TPS) generally consists of a TP monitor,
one or more DBMSs, and a set of application programs containing
transaction.
 In database field, a transaction is a group of logical operations that must
all succeed or fail as a group.
 Systems dedicated to supporting such operations are known as
transaction processing systems.

06/03/2025 Transactions processing and concurrency Management 4


…con’t
 Distinction between business transactions and online
transactions:
 A business transaction is an interaction in the real world, usually between
an enterprise and a person, where something is exchanged. Example :
market
 An online transaction is the execution of a program that performs an
administrative or real-time function, often by accessing shared data
sources, usually on behalf of an online user (although some transactions
are run offline in batch).

06/03/2025 Transactions processing and concurrency Management 5


…con’t
 Transactions can be started, attempted, then committed or aborted via data
manipulation commands of SQL.
 Can have one of the two outcomes for any transaction:
 Success - transaction commits and database reaches a new consistent
state
> Committed transaction cannot be aborted or rolled back.
 Failure - transaction aborts, and database must be restored to
consistent state before it started.
 Such a transaction is rolled back or undone.
 Aborted transaction that is rolled back can be restarted later.

06/03/2025 Transactions processing and concurrency Management 6


…con’t
 The DBMS has no inherent way of knowing the logical grouping of operations that
are supposed to be done together.
 Hence, it must provide the users a means to logically group their operations.
 Key words such as BEGIN TRANSACTION, COMMIT and ROLLBACK (or their
equivalents) are available in many data manipulation languages to delimit
transactions.
 A single transaction might require several queries, each reading and/or writing
information in the database.
 When this happens it is usually important to be sure that the database is not left
with only some of the queries carried out.
 For example, when doing a money transfer, if the money was debited from one
account, it is important that it also be credited to the depositing account.
 Also, transactions should not interfere with each other
06/03/2025 Transactions processing and concurrency Management 7
Properties of Transaction
 A transaction is expected to exhibit some basic features or properties to be
considered as a valid transaction.
 These features are:
> A: Atomicity
> C: Consistency
> I: Isolation
> D: Durability
 It is referred to as ACID property of a transaction.
 Without the ACID property, the integrity of the database cannot be
guaranteed.

06/03/2025 Transactions processing and concurrency Management 8


Atomicity
 Is All or None property
 Every transaction should be considered as an atomic process which
cannot be sub divided into small tasks.
 Due to this property, just like an atom which exists or does not
exist, a transaction has only two states.
> Done or Never Started.
> Done - a transaction must complete successfully and its effect
should be visible in the database.
> Never Started - If a transaction fails during execution then all its
modifications must be undone to bring back the database to the
last consistent state, i.e., remove the effect of failed transaction.
 No state between Done and Never Started
06/03/2025 Transactions processing and concurrency Management 9
Consistency
 If the transaction code is correct then a transaction, at the end of its
execution, must leave the database consistent.
 A transaction should transform a database from one previous consistent
state to another consistent state.
Isolation
 A transaction must execute without interference from other concurrent
transactions and its intermediate or partial modifications to data must not
be visible to other transactions.

06/03/2025 Transactions processing and concurrency Management 10


Durability
 The effect of a completed transaction must persist in the
database,
i.e., its updates must be available to other transaction
immediately after the end of its execution, and is should
not be affected due to failures after the completion of
the transaction.
 In practice, these properties are often relaxed somewhat
to provide better performance.

06/03/2025 Transactions processing and concurrency Management 11


Transaction Support
 No explicit Begin Transaction statement
 Transaction initiation is done implicitly when particular SQL statements are encountered.
 Every transaction must have an explicit end statement
 COMMIT
 ROLLBACK
 Every transaction has certain characteristics attributed to it.
 These characteristics are specified by a SET TRANSACTION statement in SQL.
 The characteristics are
 the access mode
 the diagnostic area size
 the isolation level.
 Access mode is READ ONLY or READ WRITE
 Diagnostic area size option
 Integer value indicating number of conditions held simultaneously in the diagnostic area
06/03/2025 Transactions processing and concurrency Management 12
Transaction Support …con’t
 Isolation level option
 Dirty read
 Nonrepeatable read
 Phantoms
 Dirty read A transaction T1 may read the update of a transaction T2, which has
not yet committed. If T2 fails and is aborted, then T1 would have read a value that
does not exist and is incorrect.
 Nonrepeatable read transaction T1 may read a given value from a table. If another
transaction T2 later updates that value and T1 reads that value again, T1 will see a
different value.
 Phantoms 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.
06/03/2025 Transactions processing and concurrency Management 13
…con’t
 The transaction sub system of a DBMS is depicted in the following.

of the DBMS
Fig. the transaction sub system

06/03/2025 Transactions processing and concurrency Management 14


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)

06/03/2025 Transactions processing and concurrency Management 15


Transaction and System Concepts (cont’d.)

Figure 2.4 State transition diagram illustrating


the states for transaction execution

06/03/2025 Transactions processing and concurrency Management 16


State of a Transaction
 A transaction is an atomic operation from the users’ perspective.
But it has a collection of operations and it can have a number of
states during its execution.
 A transaction can end in three possible ways.
1. Successful Termination: when a transaction completes the execution of all
operations in it and reaches the COMMIT command.
2. Suicidal Termination: when the transaction detects an error during its
processing and decide to quick itself before the end of the transaction and
perform a ROLL BACK
3. Murderous Termination: When the DBMS or the system force the
execution to abort for any reason. And hence, rolled back.

06/03/2025 Transactions processing and concurrency Management 17


Ways of Transaction Execution
 There are two ways of executing a set of transactions:
 (a) Serially: Serial Execution: In a serial execution transactions are executed strictly serially.
> Thus, Transaction Ti completes and writes its results to the database then only
the next transaction Tj is scheduled for execution.
> This means at one time there is only one transaction is being executed in the
system.
> The data is not shared between transactions at one specific time.

06/03/2025 Transactions processing and concurrency Management 18


...con’t
 In Serial transaction execution, one transaction being executed
does not interfere the execution of any other transaction.
 Good things about serial execution
 Correct execution, i.e., if the input is correct then output will be correct.
 Fast execution, since all the resources are available to the active.
 The worst thing about serial execution is very inefficient resource utilization. i.e. reduced parallelism.

 Notations:
> Read(x) read data item x from database
> Write(x) write data item x into the database

06/03/2025 Transactions processing and concurrency Management 19


…con’t
 Example of a serial execution
 Suppose data items X = 10, Y = 6, and N =1 and T 1 and T2 are transactions.
Time T1 T2
T1 T2 read (X) {X =
read (X) read (X) 10}
X := X+N {X =
X := X+N X := X+N
11}
write (X) write (X) write (X) {X =
read (Y) 11}
Y := Y+N read (Y) {Y =
write (Y) 6}
Y := Y+N {Y =
7}
write (Y) {Y =
7}
read (X) {X =
11}
X := X+N {X =
 Final values of X, Y at the end of T1 and T2: 12}
 X = 12 and Y = 7. write (X)

 Thus in serial execution of transaction, if we have two transactions T i and Ti+1, then Ti+1 will only be executed
after the completion of Ti.
06/03/2025 Transactions processing and concurrency Management 20
…con’t
 (b) Concurrently: is the reverse of serially executable transactions,
 In this scheme the individual operations of transactions, i.e., reads and writes are interleaved in some
order.
Time T1 T2
read (X) {X = 10}
read (X) {X = 10}
X := X+N {X = 11}
X := X+N {X = 11}
write (X) {X = 11}
write (X) (X=11)
read (Y) {Y = 6}
Y := Y+N {Y = 7}
write (Y) {Y = 7}

 Final values at the end of T1 and T2: X = 11, and Y = 7.


 This improves resource utilization, unfortunately gives incorrect result.
 The correct value of X is 12 but in concurrent execution X =11, which is incorrect.
 The reason for this error is incorrect sharing of X by T1 and T2.
06/03/2025 Transactions processing and concurrency Management 21
…con’t
 In serial execution
 T2 read the value of X written by T1 (i.e., 11)
 In concurrent execution
 T2 read the same value of X (i.e., 10) as T1 did and the update made by T1 was
overwritten by T2’s update.
 This is the reason the final value of X is one less than what is produced by serial
execution.
 But, why concurrent execution? Reasons:
 Many systems have an independent component to handle I/O like DMA (Direct
Memory Access) module.
 CPU may process other transactions while one is in I/O operation
 Improves resource utilization
 Increases the throughput of the system.
06/03/2025 Transactions processing and concurrency Management 22
Problems Associated with Concurrent Transaction
Processing
 Two transactions may be correct when inserting of operations may produce an incorrect result
which needs control over access.
 Having a concurrent transaction processing, one can enhance the throughput of the system.
 As reading and writing is performed from and on secondary storage, the system will not be idle
during these operations if there is a concurrent processing.
 Every transaction is correct when executed alone.
 The three potential problems caused by concurrency are:
> Lost Update Problem
> Uncommitted Dependency Problem
> Inconsistent Analysis Problem.

06/03/2025 Transactions processing and concurrency Management 23


Lost Update Problem
 Successfully completed update on a data set by one transaction is
overridden by another transaction/user.
 E.g. Account with balance A=100.
> T1 reads the account A
> T1 withdraws 10 from A
> T1 makes the update in the Database
> T2 reads the account A
> T2 adds 100 on A
> T2 makes the update in the Database
 In the above case, if done one after the other (serially) then we have no problem.
 If the execution is T1 followed by T2 then A=190
 If the execution is T2 followed by T1 then A=190
06/03/2025 Transactions processing and concurrency Management 24
…con’t
 But if they start at the same time in the following sequence:
 T1 reads the account A=100
 T1 withdraws 10 making the balance A=90
 T2 reads the account A=100
 T2 adds 100 making A=200
 T1 makes the update in the Database A=90
 T2 makes the update in the Database A=200
 After the successful completion of the operation in this schedule,
the final value of A will be 200 which override the update made by
the first transaction that changed the value from 100 to 90.

06/03/2025 Transactions processing and concurrency Management 25


Uncommitted Dependency Problem
 Occurs when one transaction can see intermediate results of
another transaction before it is committed.
 E.g.
 T2 increases 100 making it 200 but then aborts the transaction before it
is committed.
 T1 gets 200, subtracts 10 and make it 190. But the actual balance should
be 90

06/03/2025 Transactions processing and concurrency Management 26


Inconsistent Analysis Problem
 Occurs when transaction reads several values but second transaction updates some of
them during execution and before the completion of the first.

 As discussed above, the objective of Concurrency Control Protocol is to schedule


transactions in such a way as to avoid any interference between them.
 This demands a new principle in transaction processing, which is serializability of the
schedule of execution of multiple transactions.
 Related with the inconsistent analysis problem we have the phantom read and the
fuzzy(unclear) read problems

06/03/2025 Transactions processing and concurrency Management 27


Serializability
 In any transaction processing system, if concurrent processing is
implemented, there will be concept called schedule having or
determining the execution sequence of operations in different
transactions.
 Schedule: time-ordered sequence of the important actions taken
by one or more transitions.
 Schedule represents the order in which instructions are executed in the system in
chronological ordering.
 The scheduler component of a DBMS must ensure that the individual steps of
different transactions preserve consistency.

06/03/2025 Transactions processing and concurrency Management 28


…con’t
 1) Serial Schedule: a schedule where the operations of each transaction are
executed consecutively without any interleaved operations from other transactions.
 2) Non-serial Schedule: Schedule where operations from a set of concurrent
transactions are interleaved.
> The objective of serializability is to find non-serial schedules that
allow transactions to execute concurrently without interfering with
one another.
 If a non serial schedule can come up with a result equivalent to some serial schedule,
we call the schedule Serializable.
 Sequence of the execution of the operations will result in a value identical with serially
executed transaction, which always is correct.
 Serializability identifies those concurrent executions of transactions guaranteed to
ensure consistency.

06/03/2025 Transactions processing and concurrency Management 29


Serialization
 Objective of serialization is to find schedules that allow
transactions to execute concurrently without interfering with one
another.
 If two transactions only read data, order is not important.
 If two transactions either read or write completely separate data
items, they do not conflict and order is not important.
 If one transaction writes a data item and another reads or writes
the same data item, order of execution is important
 Possible solution: Run all transactions serially.
 This is often too restrictive as it limits degree of concurrency or
parallelism in system.
06/03/2025 Transactions processing and concurrency Management 30
Test for Serializability
 Constrained write rule: transaction updates data item based on its old
value, which is first read by the transaction.
 Under the constrained write rule we can use precedence graph to test for
serializability.
 A non serial schedule can be tasted for serializability by using a method called
precedence graph.
 A precedence graph is composed of:
 Nodes to represent the transactions, and
 Arc(directed edge) to connect nodes indicating the order of execution for
the transactions
 So that the directed edge TiTj implies, in an equivalent serial execution Ti
must be executed before Tj.
06/03/2025 Transactions processing and concurrency Management 31
The rules of precedence graph:
 Represent each transaction in the schedule with a node.
 Then draw a directed arc from Ti to Tj (that is Ti to Tj ) if:
1. Tj Reads an item that is already Written by Ti
> Ti Write(x) Then Tj Read(x)
2. Tj Writes an item that already has been Read by Ti, or
> Ti Read(x) Then Tj Write(x)
3. Tj Writes an item that already has been Written by Ti
> Ti Write(x) Then Tj Write(x)
 After drawing the precedence graph, if there is any cycle in the graph, the
schedule is said to be Non Serializable.
 Otherwise, if there is no cycle in the graph, the schedule is equivalent with
some serial schedule and is serializable
06/03/2025 Transactions processing and concurrency Management 32
Figure 2.5 Examples of serial and nonserial schedules involving transactions T1 and
T2 (a) Serial schedule A: T1 followed by T2 (b) Serial schedule B: T2 followed by T1
(c) Two nonserial schedules C and D with interleaving of operations
06/03/2025 Transactions processing and concurrency Management 33
Characterizing Schedules Based on
Serializability
 Testing for serializability of a schedule

Algorithm 2.1 Testing conflict serializability of a schedule S


Characterizing Schedules Based on
Serializability (cont’d.)

Figure 2.7 Constructing the precedence graphs for schedules A to D from Figure 20.5 to
test for conflict serializability (a) Precedence graph for serial schedule A (b) Precedence
graph for serial schedule B (c) Precedence graph for schedule C (not serializable) (d)
Precedence graph for schedule D (serializable, equivalent to schedule A)
Exercise
Ex1:
R1(x) W2(x) W1(x)
Check: T1T2 and T2T1
Ex2:
R1(x)W2(x)W1(x)W3(x)
Check: T1T2, T2T1, T2T3, T3T2, T1T3, and T3T1

06/03/2025 Transactions processing and concurrency Management 36


06/03/2025 Transactions processing and concurrency Management 37

You might also like