Serializability

Conflict serializable schedule orders any conflicting operations in same way as some serial execution. Constrained write rule: transaction updates data item based on its old value, which is first read. Under the constrained write rule we can use precedence graph to test for serializability.

Practical session 1 Thu 3/11/05

COMP 302

V. Tamma

COMP 302

22 V. Tamma

Serializability - some important rules
In serializability, ordering of read/writes is important: (a) If two transactions only read a data item, they do not conflict and order is not important. (b) If two transactions either read or write completely separate data items, they do not conflict and order is not important. (c) If one transaction writes a data item and another reads or writes same data item, order of execution is important.
COMP 302
20 V. Tamma

Precedence Graph
Given a schedule S, a precedence graph is a directed graph G= (N,E) where
• N = set of nodes • E = set of directed edges

Created as follows:
• create a node for each transaction; • a directed edge Ti → Tj, if Tj reads the value of an item written by Ti; • a directed edge Ti → Tj, if Tj writes a value into an item after it has been read by Ti.
COMP 302
23 V. Tamma

Ti must appear before T j If the precedence graph contains cycle schedule is not conflict serializable. Example . Two schedules S1 and S2 are view equivalent if: • For each data item x. testing whether schedule is serializable is NP-complete. if Ti reads initial value of x in S1. Tamma View Serializability Offers less stringent definition of schedule equivalence than conflict serializability. • For each data item x. same transaction must perform final write on x in S2.Non-conflict serializable schedule COMP 302 V. Tamma COMP 302 24 V. if last write on x performed by Ti in S1. then in any serial schedule S’ equivalent to S. Ti must also read initial value of x in S2. Tamma COMP 302 V. if value read by x is written by Tj. • In general. Ti must also read value of x produced by Tj in S2. View Serializability • Schedule is view serializable if it is view equivalent to a serial schedule. although converse is not true.Precedence Graph and serializability If an edge Ti → Tj exists in the precedence graph for S. Tamma . COMP 302 V. • For each read on x by Ti in S1. • It can be shown that any view serializable schedule that is not conflict serializable contains one or more blind writes. • Every conflict serializable schedule is view serializable.

If transaction fails. COMP 302 29 V.Exercise settings • For this exercise you will work in groups of 3 or 4 people • You will have 10 minutes to work out the solution to the problem with your colleagues • After that. Could also examine recoverability of transactions within schedule. Tamma Solution ex 1 The precedence graph looks like Recoverability Serializability identifies schedules that maintain database consistency. Tamma • There is a cycle in the graph. Durability states that once transaction commits. therefore the schedule is NOT view serialisable COMP 302 V. Tamma . Tamma COMP 302 V. you will have 5 minutes to compare your solution with the one of your neighbours Exercise 1 Consider the following schedule Time t1 t2 t3 t4 t5 T1 T2 T3 begin_transaction read (balx) begin_transaction write (balx) write(balx) begin_transaction commit commit read(balx) commit Determine whether the schedule is conflict serialisable and/or view serialisable COMP 302 V. therefore the schedule is NOT conflict serialisable • T2 has a blind write. compensating. transaction). assuming no transaction fails. its changes cannot be undone (without running another. atomicity requires effects of transaction to be undone.

Tamma Solution ex 2 The precedence graph looks like Locking methods: problems Deadlock: An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released. does not avoid cascading abort if T3 had aborted. Determine if the schedule is: • conflict serialisable • view serialisable • recoverable • avoids abort cascading COMP 302 30 V. (however. Tamma COMP 302 V. T2 would also have to abort as it has read the value of an aborted transaction). then the commit operation of Ti precedes the commit operation of Tj. • • • The graph does not have a cycle thus the schedule is conflict serialisable Since the schedule is conflict serialisable.Recoverable Schedule Time t1 t2 t3 t4 t5 Exercise 2 Consider the following schedule T1 T2 T3 begin_transaction read (balx) begin_transaction read (baly) read(baly ) begin_transaction commit read(balx) write(balx) commit A schedule where. if Tj reads a data item previously written by Ti. then it is view serialisable Recoverable. Tamma . COMP 302 V. Tamma COMP 302 45 V. for each pair of transactions Ti and Tj.

If older transaction requests lock held by younger one. WFG is created at regular intervals. Two general techniques for handling deadlock: • • Deadlock prevention. Tamma Deadlock Prevention DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur. Deadlock exists if and only if WFG contains cycle. Tamma COMP 302 49 V.possible solutions? Only one way to break deadlock: abort one or more of the transactions. Could order transactions using transaction timestamps: • Wait-Die . younger one is aborted (wounded). • Wound-Wait . Deadlock should be transparent to user. otherwise transaction is aborted (dies) and restarted with same timestamp. if Ti waiting to lock item locked by Tj. COMP 302 47 V. so DBMS should restart transaction(s).an example Deadlock . Create edge Ti -> Tj . Deadlock detection and recovery.only an older transaction can wait for younger one. Deadlock Detection and Recovery DBMS allows deadlock to occur but recognizes it and breaks it. Tamma .only a younger transaction can wait for an older one. COMP 302 45 V. Usually handled by construction of wait-for graph (WFG) showing transaction dependencies: • • Create a node for each transaction.Deadlock . Tamma COMP 302 46 V.

• avoiding starvation. Exercise 3 • The locking information for several transactions is shown below. Tamma . Tamma Solution ex 3 The WFG looks like • The graph shows that there is a deadlock COMP 302 V.Recovery from Deadlock Detection Several issues: • choice of deadlock victim. Tamma COMP 302 V. Produce a wait-for-graph (WFG) for the transactions and determine whether deadlock exist COMP 302 V. • how far to roll a transaction back.

Sign up to vote on this title
UsefulNot useful