2. Concurrency Control
-
- the basic unit of work in a DBMS
- Properties of a transaction
3. A.C.I.D properties (1)
-
- the is the all or nothing property ; a transaction is an
indivisible unit of work
4. A.C.I.D properties (1)
-
- transactions transform the DB from one consistent state to
another consistence state
5. A.C.I.D properties (2)
-
- transactions execute independently of one another i.e. the
partial effect of one transaction is not visible to other
transactions.
6. A.C.I.D properties (2)
- Durability (aka Persistence)
-
- the effect of a successfully completed (i.e. committed)
transaction are permanently recorded in the DB and cannot be
undone.
7. Example Transaction
- balance1 = balance1 - 100
-
- then print insufficient funds
- balance2 = balance2 + 100
8. Discussing the Example
- Effect of the abort is to rollback the transaction and undo
changes it has made on the DB
- in this example, transaction was not written to the DB prior to
abort and so no undo is necessary
9. Problems with Concurrency
- Concurrent transaction can cause three kinds of database
problems
-
- Violation of Integrity Constraints
10. Lost Update
- Apparently successful updates can be overwritten be other
transactions
Begin transaction T1 read balance [ 100 ] balance = balance -
100if balance < 0 print insufficient funds abort T1 end write
balance [ 0 ] Initial Balance= 100 Begin transaction T2 read
balance [ 100 ] balance = balance + 100 write balance [ 200 ]
commit T2 11. Violation of Integrity Constraints 12. Violation of
Integrity Constraints
- read schedule where date = 4/4/01
- read surgeon where surgeon.name = schedule.surgeon and
surgeon.operation = Appendectomy
- if not found then abort T3
- schedule.operation = Appendectomy
- read schedule where date = 4/4/01
- read surgeon where surgeon.name = Tom
- if not found then abort T4
13. Violation of Integrity Constraints 14. Inconsistent
Retrieval ( Dirty Reads )
- Most concurrency control systems focus on the transaction which
update the DB since they are the only ones which can corrupt the
DB
- If transaction are allowed toreadthe partial results of
incomplete transactions, they can obtain an inconsistent view of
the DB ( dirtyorunrepeatable reads )
15. Inconsistent Retrieval ( Dirty Reads )
- BalanceX = BalanceX - 100
- BalanceY = BalanceY + 100
16. Concurrency Control
- Schedules and Serialisation
- Order in a schedule is VERY important
- S = [R1(x), R2(x), W1(x), W2(x)]
- so, is it O.K. to do reads before or after writes, e.g. Lost
Update Problem
17. Conflicting Operations
- If two transactions only read a data item, they donotconflict
and order is not important.
- If two transactions either read or write completely separate
data items, they donotconflict and order is not important.
- If one transactions writes a data item and another transaction
reads or writes the same data item, the order of
executionisimportant.
18. Serial Schedule
- What is a serial schedule ?
- S = [R1(X), W1(X), R2(X), W2(X), R3(X)]
19. Serialisable Schedule
- What is a serialisable schedule ?
- S = [R1(x), R2(x),W1(x), R3(x), W2(x)]
20. General Solution
- Transaction should always Read before they Write
21. Rules for Equivalence of Schedules
- Each read operation must read the same values in both
schedules; this effectively means that those values must have been
produced by the same write operation the both schedules
- The final state of the database must be the same in both
schedules; thus the final write operation on each data item is the
same in both schedules
22. Try these...
- [R1(x), W1(x), R2(x), W2(x)]
- [R1(x), R2(x), W1(x), W2(x)]
- [R1(x), R3(y), R2(x), W2(z), W2(y), W1(x), R2(y), W1(z)]
23. Conflicting Operations
- Read operations cannot conflict with one and other, thus the
order of read operations does not matter.
- i.e.[R1(x), R2(x)] = [R2(x), R1(x)]
- [R1(x),W1(x),R2(x)] != [R1(x), R2(x), W1(x)]
24. Conflicting Operations
- In terms of schedule equivalence, it is the ordering of
CONFLICTING operators which must be the same in both schedules
- The conflict between read and write operations is called
aread-write conflictand the conflict between two writes is called
awrite-write conflict .
25. Concurrency Control Techniques
- There are three basic concurrency control techniques :