Conflicts
How to we check if a schedule is serializable? We can look for orderings of actions that can interact. These illegal sequencing of actions are called conflicts.
Conflict ri(X); rj(Y) -- reads on different transactions A conflict occurs in a schedule if a pair of actions in a schedule such that, if their order is interchanged, then the behavior of at least one of the transactions involved can change. Simplified Notation For Schedules: ri(X) = a read operation in transaction "i" on database element "X" wj(Y) = a write operation in transaction "j" on database element "Y" Action Pairs: ri(X); rj(Y) -- reads on different transactions Never a conflict (even if X = Y) Reads can't change database state; no way to interact if swapped
Conflict More Action Pairs: ri(X); wj(Y) -- read/write on different objects and transactions Never a conflict. If the read in transaction "i" happens before the write in transaction "j", it has no effect on transaction "j". wi(X); wj(Y) -- write/write on different objects and transactions Never a conflict. Changing database element X has no bearing on changing Y
Conflict ri(X); wi(Y) -- read/write in same transaction More Action Pairs: ri(X); wi(Y) -- read/write in same transaction Conflict! Order of actions within a transaction are fixed and may not be changed. wi(X); wj(X) -- write/write on same object Conflict! Swapping the writes effects the final state of the object. Under the "no coincidences" assumption, we must assume that the two transactions are writing different values. ri(X); wj(X) -- read/write on same object Conflict! If the write changes the value of X before the read, the read will be different than if it had happened first.
Conflict-serializable Two actions, in different transactions, do not conflict (may be reordered without effect) unless: They involve the same database element, and At least one is a write. Two schedule are called conflict-equivalent if one can be transformed into the other by a sequence of non-conflicting swaps of adjacent actions. A schedule is called conflict-serializable if it is conflict-equivalent to a serializable schedule. To emphasize: All conflict-serializable schedules are serializable.
Is this schedule conflict-serializable? r1(A); w1(A); r2(A); w2(A); r1(B); w1(B); r2(B); w2(B) r1(A); w1(A); r2(A); r1(B); w2(A); w1(B); r2(B); w2(B) r1(A); w1(A); r1(B); r2(A); w2(A); w1(B); r2(B); w2(B) r1(A); w1(A); r1(B); r2(A); w1(B); w2(A); r2(B); w2(B) r1(A); w1(A); r1(B); w1(B); r2(A); w2(A); r2(B); w2(B) Yes, because we could make non-conflicting swaps until it was serialized.
How did I know what swaps to do? Magic Just Kidding If there is ever a pair of conflicting actions in a schedule, those transactions must appear in the same order in the serial schedule. We can't rearrange the order of a conflict, so it must be legal for the entire associated transactions to appear in the same order as the conflict. If we can't move the entire transaction there must be another contradictory conflict, thus it is not conflict-serializable. We can figure out the necessary order of the transactions by determining their precedence
Precedence Transaction 1 (T1) takes precedence over Transaction 2 (T2) in schedule S (written as T1 < T2), if there are actions A1 of T1 and A2 of T2, such that: A1 is ahead of A2 in S Both A1 and A2 involve the same database element, and At least one of A1 and A2 is a write action Notice that these are exactly the conditions under which we cannot swap the order of A1 and A2. Thus, A1 will appear before A2 in any schedule that is conflict-equivalent to S. As a result, a conflict- equivalent serial schedule must have T1 before T2.
d Precedence Graph The nodes of the precedence graph are the transactions of a schedule S. There is an arc from node Ti to node Tj if Ti < Tj. T1 < T2 T2 < T3 T1 < T3 T1 T3 T2
Determining Precedence S: r2(A); r1(B); w2(A); r3(A); w1(B); w3(A); r2(B); w2(B); Conflicts: r2(A); w3(A); -> T2 < T3 r1(B); w2(B); -> T1 < T2 w2(A); r3(A); -> T2 < T3 w2(A); w3(A); -> T2 < T3 w1(B); r2(B); -> T1 < T2 w1(B); w2(B); -> T1 < T2 T1 T3 T2
Precedence graphs and conflict-serializable All conflict-serializable schedules will have acyclic precedence graphs, meaning that there exists a topological order of the nodes that is a conflict-equivalent serial order. If there are cycles in the precedence graph, it means there isn't a legal order to serialize the transactions.
Is this precedence graph conflict-serializable? Yes No Depends on the order ??? T1 T3 T2 T4
Which serializations are conflict-equivalent to the precedence graph? T1; T2; T3; T4 T1; T2; T4; T3 T4; T1; T2; T3 ??? T1 T3 T2 T4