Transactions
Transactions
Transaction
A transaction can be defined as a group of tasks. A single task is the
minimum processing unit of work, which cannot be divided further..
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.
ACID Properties
To ensure integrity of data, the database system must maintain:
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.
That is, for every pair of transactions T and T , it appears to T that
i j i
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.
Demonstrating ACID
Crash:
Active transactions must be identified and aborted
when system recovers
Commit and Abort Records identify completed
transactions. If, during a backward log scan, the first
record encountered for T is an update record, then T
was active at time of crash and must be rolled back
Continue
Checkpoints
of those transactions
must preserve the order in which the instructions appear in each
individual transaction.
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.
Cont.
Let T1 and T2 be the transactions defined previously. The following
schedule is not a serial schedule, but it is equivalent to Schedule 1.
Cont.
The following concurrent schedule does not preserve the value of the
the sum A + B.
Some definitions
Schedule: Time ordered sequence of the actions
taken by one or more transactions
Serial schedule: A schedule that considers all the
actions of a transaction T1, followed by all the
actions of another transaction T2 and so on.
Serializable schedule: A schedule whose effect on the
state of the Database is the same as the effect of
some serial schedule. All serial schedules are
serialisable but not all serializable schedules are
serial!
Conflict: A pair of consecutive database actions
(reads, writes) is in conflict if changing their order
would change the result of at least one of the
transactions.
Conflict equivalence: Two schedules are conflict-
equivalent if they can be turned into one another by
a sequence of non conflicting swaps of adjacent
actions
Conflict serializability: A schedule is conflict
serializable if it is conflict equivalent to a serial
schedule
Serializability
Basic Assumption – Each transaction preserves 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
Conflict Serializability
Instructions li and lj of transactions Ti and Tj respectively,
conflict if and only if there exists some item Q accessed
by both li and lj, and at least one of these instructions wrote
Q.
1. li = read(Q), lj = read(Q). li and lj don’t 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
Conflict Serializability (Cont.)
If a schedule S can be transformed into a schedule S´ by a series of
swaps of non-conflicting instructions, we say that S and S´ are conflict
equivalent.
We say that a schedule S is conflict serializable if it is conflict
equivalent to a serial schedule
Example of a schedule that is not conflict serializable:
T3 T4
read(Q)
write(Q)
write(Q)
s
Recoverable Schedules
Need to address the effect of transaction failures on concurrently
running transactions.
Recoverable schedule — if a transaction Tj reads a data items
previously written by a transaction Ti , the commit operation of Ti
appears before the commit operation of Tj.
The following schedule is not recoverable if T9 commits immediately
after the read.
If T8 should abort, T9 would have read (and possibly shown to the
user) an inconsistent database state. Hence database must ensure that
schedules are recoverable
Cascading Schedule
Every cascadeless schedule is also recoverable
It is desirable to restrict the schedules to those that are
cascadeless
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.
Cascadeless Schedules (Cont.)
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)
Repeatable read
Read committed
Read uncommitted
Testing for Serializability
Consider some schedule of a set of transactions T1, T2, ...,
Tn
Precedence graph — a direct graph where the vertices are
the transactions (names).
We draw an arc from Ti to Tj if the two transaction
conflict, and Ti accessed the data item on which the
conflict arose earlier.
We may label the arc by the item that was accessed.
Example 1