Transaction Management Concurrency Control and Backup
Transaction Management Concurrency Control and Backup
Concurrency Control
Technique, Backup and
Recovery
Kuribachew Gizaw(PhD)
Dec2023
Introduction
Transaction processing systems are systems with large
databases and hundreds of concurrent users executing database transactions.
Examples of such systems include airline reservations, banking, credit card processing,
online retail purchasing, stock markets, supermarket checkouts, and many other
applications.
A transaction is an executing program that forms a logical unit of database
processing.
A transaction includes one or more database access operations—these can
include insertion, deletion, modification, or retrieval operations.
One way of specifying the transaction boundaries is by specifying explicit begin
transaction and end transaction statements in an application program.
Read-Write transaction
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.
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.
Concurrency Control
Concurrency control and recovery mechanisms are mainly concerned with the
database commands in a transaction.
Transactions submitted by the various users may execute concurrently and
may access and update the same database items. If this concurrent execution
is uncontrolled, it may lead to problems, such as an inconsistent database.
Why concurrency control is needed?
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. Then changes the updated
value resulting from one of the transaction is lost.
Why concurrency control is
needed?...
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. Meanwhile, the updated item is accessed (read) by another transaction
before it is changed back to its original value.
The Incorrect Summary Problem: If one transaction is calculating an
aggregate summary function on a number of 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.
The Unrepeatable Read Problem: Another problem that may occur is called
unrepeatable read, where a transaction T reads the same item twice and the
item is changed by another transaction T between the two reads.
Transaction States
A transaction is an atomic unit of work that should either be completed in its entirety or
not done at all. For recovery purposes, the system needs to keep track of when each
transaction starts, terminates, and commits or aborts.
BEGIN_TRANSACTION. This marks the beginning of transaction execution.
READ or WRITE. These specify read or write operations on the database items that are executed
as part of a transaction.
END_TRANSACTION. This specifies that READ and WRITE transaction operations have ended and
marks the end of transaction execution.
However, at this point it may be necessary to check whether the changes introduced by
the transaction can be permanently applied to the database (committed) or whether the
transaction has to be aborted because it violates serializability or for some other reason.
COMMIT_TRANSACTION. This signals a successful end of the transaction so that any changes
(updates) executed by the transaction can be safely committed to the database and will not be
undone.
ROLLBACK (or ABORT). This signals that the transaction has ended unsuccessfully, so that any
changes or effects that the transaction may have applied to the database must be undone.
Transaction States
The System Log
In these entries, T refers to a unique transaction-id that is generated automatically
by the system for each transaction and that is used to identify each transaction:
1. [start_transaction,T]. Indicates that transaction T has started execution.
2. [write_item, T, X, old_value, new_value]. Indicates that transaction T has
changed the value of database item X from old_value to new_value.
3. [read_item,T,X].Indicates that transaction T has read the value of database item
X.
4. [commit, T]. Indicates that transaction T has completed successfully, and affirms
that its effect can be committed (recorded permanently) to the database.
5. [abort,T].Indicates that transaction T has been aborted.
A transaction T reaches its commit point when all its operations that access the
database have been executed successfully and the effect of all the transaction
operations on the database have been recorded in the log. Beyond the commit
point, the transaction is said to be committed, and its effect must be permanently
recorded in the database.
Desirable properties of Transaction
Transactions should possess several properties, often called the ACID
properties; they should be enforced by the concurrency control and recovery
methods of the DBMS. The following are the ACID properties:
Atomicity. A transaction is an atomic unit of processing; it should either be
performed in its entirety or not performed at all.
Consistency preservation. 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.
Isolation. A transaction should appear as though it is being executed in isolation
from other transactions, even though many transactions are executing.
Durability or permanency. The changes applied to the database by a
committed transaction must persist in the database. These changes must not be lost
because of any failure.
Schedules
A schedule (or history) S of n transactions T1,T2,...,Tn is an ordering of the
operations of the transactions.
Two operations in a schedule are said to be conflict if they satisfy all three of the
following conditions:
(1) they belong to different transactions;
(2) they access the same item X; and
(3) at least one of the operations is a write_item(X).
2. Redo logs: are set of files that records all changes made to the
database during transaction. In case of loss these files can replay
transaction.
Implemented by Oracle DB