You are on page 1of 10

Precedence Graph

 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

Database System Concepts - 6th Edition 14.14 ©Silberschatz, Korth and Sudarshan
Testing for Conflict Serializability
 A schedule is conflict serializable if and only if its
precedence graph is acyclic.
 To test for conflict serializability, we need to
construct the precedence graph and to invoke a
cycle-detection algorithm
 Cycle-detection algorithms exist which take order
n2 time, where n is the number of vertices in the
graph.
 (Better algorithms take order n + e where e is
the number of edges.)
 If precedence graph is acyclic, the serializability
order can be obtained by a topological sorting of
the graph.
 That is, a linear order consistent with the
partial order of the graph.
 For example, a serializability order for the
schedule (a) would be one of either (b) or (c)

 A serializability order of the transactions can be


obtained by finding a linear order consistent with the
partial order of the precedence graph. This process is
Database System Concepts - 6th Edition 14.15 ©Silberschatz, Korth and Sudarshan
Precedence graph of Schedule 1 and 2

Database System Concepts - 6th Edition 14.16 ©Silberschatz, Korth and Sudarshan
Example (Serializability)
We now present a simple and efficient method for determining conflict serializability
of a schedule. Consider a schedule S. We construct a directed graph,
called a precedence graph, fromS. This graph consists of a pair G = (V, E),
where V is a set of vertices and E is a set of edges. The set of vertices consists of
all the transactions participating in the schedule.

The set of edges consists of all edges


Ti →Tj for which one of three conditions holds:
1. Ti executes write(Q) before Tj executes read(Q).
2. Ti executes read(Q) before Tj executes write(Q).
3. Ti executes write(Q) before Tj executes write(Q).

Database System Concepts - 6th Edition 14.17 ©Silberschatz, Korth and Sudarshan
Cycle-detection Algorithms
 To test for conflict serializability, we need to construct the precedence
graph and to invoke a cycle-detection algorithm.
 Cycle-detection algorithms, such as those based on depth-first search,
require on the order of n2 operations, where n is the number of
vertices in the graph (that is, the number of transactions).

Database System Concepts - 6th Edition 14.18 ©Silberschatz, Korth and Sudarshan
Example
 consider transaction T5, which transfers $10 from account B to account A. Let schedule 8
be as defined in below figure, We claim that schedule 8 is not conflict equivalent to the
serial schedule <T1,T5>, since, in schedule 8, the write(B) instruction of T5 conflicts with
the read(B) instruction of T1. This creates an edge T5 → T1 in the precedence graph.
Similarly, we see that the write(A) instruction of T1 conflicts with the read instruction of T5
creating an edge T1 → T5. This shows that the precedence graph has a cycle and
that schedule 8 is not serializable.

Figure: schedule 8 

Database System Concepts - 6th Edition 14.19 ©Silberschatz, Korth and Sudarshan
 Example

Database System Concepts - 6th Edition 14.20 ©Silberschatz, Korth and Sudarshan
Recoverable Schedules

 Recoverable schedule — if a transaction Tj reads a data item


previously written by a transaction Ti , then the commit operation of Ti
must appear before the commit operation of Tj.
 The following schedule is not recoverable if T9 commits immediately
after the read(A) operation.

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

Database System Concepts - 6th Edition 14.21 ©Silberschatz, Korth and Sudarshan
Cascading Rollbacks
 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

Database System Concepts - 6th Edition 14.22 ©Silberschatz, Korth and Sudarshan
Cascadeless Schedules

 Cascadeless schedules — 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
 It is desirable to restrict the schedules to those that are
cascadeless
 Example of a schedule that is NOT cascadeless

Database System Concepts - 6th Edition 14.23 ©Silberschatz, Korth and Sudarshan

You might also like