©silberschatz, Korth and Sudarshan 1.1 Database System Concepts
©silberschatz, Korth and Sudarshan 1.1 Database System Concepts
Transaction Concept Transaction State Implementation of Atomicity and Durability Concurrent Executions
Serializability
Recoverability Implementation of Isolation Transaction Definition in SQL Testing for Serializability.
1.1
Transaction Concept
A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction must see a consistent database. During transaction execution the database may be inconsistent. When the transaction is committed, the database must be consistent. Two main issues to deal with:
Failures of various kinds, such as hardware failures and system crashes Concurrent execution of multiple transactions
1.2
ACID Properties
To preserve integrity of data, the database system must ensure: Atomicity. Either all operations of the transaction are properly reflected in the database or none are. Consistency. Execution of a transaction in isolation preserves the consistency of the database. Isolation. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions.
That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj, finished execution before Ti started, or Tj started execution after Ti finished.
Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.
1.3
4. read(B)
5. B := B + 50 6. write(B)
Consistency requirement the sum of A and B is unchanged by the execution of the transaction.
Atomicity requirement if the transaction fails after step 3 and before step 6, the system should ensure that its updates are not reflected in the database, else an inconsistency will result.
1.4
1.5
Transaction State
Active, the initial state; the transaction stays in this state while it is executing Partially committed, after the final statement has been executed. Failed, after the discovery that normal execution can no longer proceed. Aborted, after the transaction has been rolled back and the database restored to its state prior to the start of the transaction. Two options after it has been aborted:
restart the transaction only if no internal logical error
1.6
1.7
1.8
Useful for text editors, but extremely inefficient for large databases: executing a single transaction requires copying the entire database. Will see better schemes in Chapter 17.
Database System Concepts 1.9 Silberschatz, Korth and Sudarshan
Concurrent Executions
Multiple transactions are allowed to run concurrently in the system. Advantages are:
increased processor and disk utilization, leading to better transaction throughput: one transaction can be using the CPU while another is reading from or writing to the disk
Disk-bound vs. CPU-bound systems
reduced average response time for transactions: short transactions need not wait behind long ones.
Concurrency control schemes mechanisms to achieve isolation, i.e., to control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the database
Will study in Chapter 14, after studying notion of correctness of concurrent executions.
1.10
Schedules
Schedules sequences that indicate the chronological order in which instructions of concurrent transactions are executed
a schedule for a set of transactions must consist of all instructions of those transactions must preserve the order in which the instructions appear in each individual transaction.
1.11
Example Schedules
Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. The following is a serial schedule (Schedule 1 in the text), in which T1 is followed by T2.
1.12
1.14
Serializability
Basic Assumption Each transaction must preserve database consistency. Thus serial execution of a set of transactions preserves database consistency. A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of schedule equivalence give rise to the notions of:
1. conflict serializability 2. view serializability
We ignore operations other than read and write instructions, and we assume that transactions may perform arbitrary computations on data in local buffers in between reads and writes. Our simplified schedules consist of only read and write instructions.
1.15
Conflict Serializability
Instructions li and lj of transactions Ti and Tj respectively, conflict if there exists some item Q accessed by both li and lj, and at least one of these instructions writes Q. 1. li = read(Q), lj = read(Q). li and lj do not conflict. 2. li = read(Q), lj = write(Q). They conflict. 3. li = write(Q), lj = read(Q). They conflict. 4. li = write(Q), lj = write(Q). They conflict. Intuitively, a conflict between li and lj forces a (logical) temporal order between them: If li and lj are consecutive in a schedule and they do not conflict, their results would remain the same if they are interchanged in the schedule.
1.16
write(Q)
We are unable to swap instructions in the above schedule to obtain either an equivalent serial schedule < T3, T4 >, or an equivalent serial schedule < T4, T3 >.
1.17
1.18
View Serializability
Let S and S be two schedules with the same set of transactions. S and S are view equivalent if the following three conditions are met:
1. For each data item Q, if transaction Ti reads the initial value of Q in schedule S, then transaction Ti must in schedule S, also read the initial value of Q. 2. For each data item Q, if transaction Ti performs read(Q) in schedule S, where Q was written by some transaction Tj , then transaction Ti must in schedule S also perform read(Q) on the result of same write(Q) in transaction Tj .
3. For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule S must perform the final write(Q) operation in schedule S.
As can be seen, view equivalence is also based purely on reads and writes alone.
1.19
Every view serializable schedule that is not conflict serializable has so-called blind writes.
1.20
Determining such equivalence requires analysis of operations other than read and write.
Database System Concepts 1.21 Silberschatz, Korth and Sudarshan
Recoverability
Need to address the effect of transaction failures on concurrently running transactions. Recoverable schedule if a transaction Tj reads a data item previously written by a transaction Ti , the commit operation of Ti appears before the commit operation of Tj. The following schedule (Schedule 11) is not recoverable if T9 commits immediately after the read
If T8 should abort or rollback, T9 would have read (and possibly shown/committed to the user) an incorrect database state. Hence database must ensure that schedules are recoverable.
Database System Concepts 1.22 Silberschatz, Korth and Sudarshan
Recoverability (Cont.d)
Cascading rollback a single transaction failure leads to a series of transaction rollbacks. Consider the following schedule where none of the transactions has yet committed (so the schedule is recoverable)
If T10 fails, T11 and T12 must also be rolled back. Can lead to the undoing of a significant amount of work
1.23
Recoverability (Cont.d)
Cascadeless schedules cascading rollbacks cannot occur; for each pair of transactions Ti and Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the read operation of Tj. Every cascadeless schedule is also recoverable (why?) It is desirable to restrict schedules to those that are cascadeless
1.24
Implementation of Isolation
Schedules must be conflict or view serializable, and recoverable, for the sake of database consistency, and preferably cascadeless.
A policy in which only one transaction can execute at a time generates serial schedules, but provides a poor degree of concurrency.. Concurrency-control schemes tradeoff between the amount of concurrency they allow and the amount of overhead that they incur.
Some schemes allow only conflict-serializable schedules to be generated, while others allow view-serializable schedules that are not conflict-serializable.
1.25
1.26
y
Database System Concepts 1.27 Silberschatz, Korth and Sudarshan
write(Z)
read(U) read(Y) write(Y) read(Z) write(Z) read(U) write(U)
1.28