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

DBMS CH-3

Transaction processing systems allow multiple users to concurrently access large databases to execute transactions. A transaction represents a logical unit of work that can commit successfully and apply changes to the database or abort and rollback without applying changes. Transaction processing systems must ensure the atomicity, consistency, isolation, and durability (ACID) properties despite hundreds of users executing transactions simultaneously.
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)
47 views

DBMS CH-3

Transaction processing systems allow multiple users to concurrently access large databases to execute transactions. A transaction represents a logical unit of work that can commit successfully and apply changes to the database or abort and rollback without applying changes. Transaction processing systems must ensure the atomicity, consistency, isolation, and durability (ACID) properties despite hundreds of users executing transactions simultaneously.
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/ 45

Advanced Database Management system

CHAPTER THREE

Transaction Processing Concept

02/24/2023
1
Transaction


A transaction is typically implemented by a computer program, which
includes database commands such as retrievals, insertions, deletions, and
updates.

Transaction is a mechanism for applying the desired modifications /
operations to a database
Any changes made in real time to a database are called transactions.

In database field, a transaction is a group of logical operations that must
all succeed or fail as a group.
02/24/2023 2
Systems dedicated for supporting transaction such operations are
known a transaction processing systems(TPS).

TPS- are systems with large databases and hundreds of concurrent


users that are executing database transactions.

 The concept of transaction provides a mechanism for describing


logical units of database processing.

02/24/2023 3
Transaction processing systems are systems with large databases
and hundreds of concurrent users executing database transactions.
Examples of such systems include airline reservations, banking
system, credit card processing, stock markets, supermarket checkouts,
and many other applications.

These systems require high availability and fast response time for
hundreds of concurrent users.

02/24/2023 4
Transaction: Logical unit of database processing that includes one or more
access operations (read -retrieval, write - insert or update-delete)

This transaction contains the steps involved in the business operation

Transactions can be started, attempted, then committed or aborted via


data manipulation commands/ Transaction Control Languages of SQL

02/24/2023 5
We can have one of the following 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.

02/24/2023 6
States of Transactions

A transaction in a database can be in one of the following states:

1. Active state

2. Partially Committed state

3. Failed state

4. Aborted state:

5. Committed state

02/24/2023 7
1. Active state: In this state, the transaction is being executed. This is the initial
state of every database transaction.

2. Partially Committed state: When a transaction executes its final operation, it


is said to be in a partially committed state.

3. Failed state: A transaction is said to be in a failed state if any of the checks


made by the database recovery system fails. A failed transaction can no longer
proceed further.

02/24/2023 8
4. Aborted state: If any of the checks fails and the transaction has
reached a failed state, then the recovery manager rolls back all its write
operations on the database to bring the database back to its original
state where it was prior to the execution of the transaction.
Transactions in this state are called aborted.

The database recovery module can select one of the two operations
after a transaction aborts:
A. Re-start the transaction
B. Kill the transaction
02/24/2023 9
5. Committed state: If a transaction executes all its operations

successfully, it is said to be committed. All its effects are now


permanently published on the database system.

02/24/2023 10
The following diagram representing different states in database transaction:

02/24/2023 11
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 COMMITED state.

2. Suicidal Termination: when the transaction detects an error during its


processing and decide to abrupt itself before the end of the transaction and
perform a ROLL BACK operation(Restart transaction).

3. Murderous Termination: When the DBMS or the system force the


execution to abort for any reason. And hence, rolled back(Kill transaction)
02/24/2023 12
Single-User vs. Multiuser Systems
One criterion for classifying a database system is according to the number of user who can use the

system concurrently—that is, at the same time.

DBMS Classifies system in to two based on number of users who are accessing the system concurrently

1. Single user system :- if at most one user using the system at a time.

2. Multi-user system: - if many users can use the system—and hence access the database concurrently.

Most of today’s DBMSs are multiuser. For example, an airline reservations system I used by hundreds

of travel agents and reservation clerks concurrently.

02/24/2023 13
Single-User vs. Multiuser Systems

In a multiuser DBMS, the stored data items are the primary
resources that may be accessed concurrently by interactive users or
application programs, which are constantly retrieving information
from and modifying the database.

Multiple users can access databases and use computer systems


simultaneously because of the concept of multiprogramming, which
allows the operating system of the computer to execute multiple
programs
02/24/2023
or processes at the same time.
14
A single central processing unit (CPU) can only execute at most one
process at a time. However, multiprogramming operating systems
execute some commands from one process, then suspend that process
and execute some commands from the next process, and so on.

 A process is resumed at the point where it was suspended whenever


it gets its turn to use the CPU again. Hence, concurrent execution of
processes is actually interleaved,

02/24/2023 15
• As illustrated in Figure below, which shows two processes, A and B,
executing concurrently in an interleaved fashion. Interleaving keeps
the CPU busy when a process requires an input or output (I/O)
operation, such as reading 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
02/24/2023
of multiple processes is possible, as illustrated by processes C16and D
Interleaved processing versus parallel processing of concurrent transactions

02/24/2023 17
 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

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 Transactions should not interfere with each other which leads to
inconsistent results.
02/24/2023 18
Transactions, Database Items, Read and Write Operations
A transaction includes one or more database access operations—these
include insertion, deletion, modification, or retrieval operations. 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

02/24/2023 19
If the database operations in a transaction do not update the database but only

retrieve data, the transaction is called a read-only transaction; otherwise it

is known as a read-write transaction.

A database is basically represented as a collection of named data items. The

size of a data item is called its granularity.

Basic operations done on the database during transactions are read and write

02/24/2023 20
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.

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

02/24/2023 21
Executing a 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.

02/24/2023 22
Executing a 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).
02/24/2023 23
Ways of Executing Transaction

In a database system many transactions are executed. Basically there are two
ways of executing a set of transactions:

1. Serial Execution

2. Concurrent execution

1. 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.

02/24/2023 24
Serial 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

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 for the active transaction.

02/24/2023 25
02/24/2023 26
02/24/2023 27
2. Concurrent execution

Concurrent execution: 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.

02/24/2023 28
02/24/2023 29
Concurrent execution………
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.

In serial execution T2 read the value of X written by T1 (i.e., 11) but 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.

02/24/2023 30
Problem associated with concurrent transaction

1. The Lost Update Problem

This occurs when two transactions that access the same database items have their
operations interleaved in a way that makes the value of some database item incorrect

2. The Temporary Update (or Dirty Read) Problem


 This 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 back to its original value.

02/24/2023 31
Problem associated with concurrent transaction……

3. 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 updated and others after they are updated.

02/24/2023 32
Desirable Properties of Transactions

Transactions should possess several properties, often called the ACID


properties. The following are the transaction properties:

1. Atomicity.

2. Consistency /preservation behaving similarly

3. Isolation

4. Durability / permanency

02/24/2023 33
1. Atomicity.


A transaction is an atomic unit of processing; it should either be performed in its entirety or not
performed at all.

Every transaction should be considered as an atomic process which can not 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.

02/24/2023 34
2. Consistency/ behaving similarly:

• The preservation of consistency is generally considered to be the


responsibility of the programmers who write the database programs or of
the DBMS module that enforces integrity constraints

• A transaction should be consistency preserving, meaning that if it is


completely executed from beginning to end without interference from
other transactions, it should take the database from one consistent state to
another.
02/24/2023 35
3. Isolation

Isolation: In a database system where more than one transaction are


being executed simultaneously and in parallel, the property of
isolation states that all the transactions will be carried out and
executed as if it is the only transaction in the system. No transaction
will affect the existence of any other transaction.
• Isolation is enforced by the concurrency control subsystem of the DBMS. If every
transaction does not make its updates visible to other transactions until it is committed, one
form of isolation is enforced that solves the temporary update problem.
02/24/2023 36
4. Durability or permanency

Durability: the durability property of the transaction states that 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.

02/24/2023 37
What causes a Transaction to fail?


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.

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.
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
02/24/2023 38
What causes a Transaction to fail?
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.
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.
 Physical problems and catastrophes: This refers to an endless list
of problems that includes power or air-conditioning failure, fire, theft
and etc.

02/24/2023 39
Schedules based on recoverability
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.
02/24/2023 40
Schedules classified on the base recoverability as follows

1. Recoverable schedule:

 One where no transaction needs to be rolled back.

 A schedule S is recoverable if no transaction T in S commits until all transactions T’


that have written an item that T reads have committed.

2. Cascadeless schedule:
One where every transaction reads only the items that are written by committed
transactions.
3. Strict Schedules:

A schedule in which a transaction can neither read nor write an item X until the last
transaction
02/24/2023 that wrote X has committed. 41
The schedules based on serializability can be of two types:-
1. Serial Schedule
2. Non serial schedules
Serial Schedule: a schedule where the operations of each transaction
are executed consecutively without any interleaved operations from
other transactions
Non-serial Schedule: Schedule where operations from a set of
concurrent transactions are interleaved.
02/24/2023 42
The objective of serializability is to find non-serial schedules that
allow to execute transactions concurrently without interfering with
one another.

In other words, if we find that non-serial schedules that are equivalent


to some serial schedule. Such a schedule is called serializable.

If a non-serial schedule can come up with a result equivalent to some


serial schedule, we call the schedule Serializable

02/24/2023 43
02/24/2023 44
THE END OF CHAPTER THREE

02/24/2023 45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy