Your SlideShare is downloading. ×
  • Like
Databases: Concurrency Control
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Databases: Concurrency Control

  • 1,950 views
Published

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,950
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
68
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Concurrency Control
  • 2. Concurrency Control
    • Transaction
      • the basic unit of work in a DBMS
    • Properties of a transaction
      • ATOMICITY
      • CONSISTENCY
      • INDEPENDENCE
      • DURABILITY
  • 3. A.C.I.D properties (1)
    • Atomicity
      • the is the “all or nothing” property ; a transaction is an indivisible unit of work
  • 4. A.C.I.D properties (1)
    • Consistency
      • transactions transform the DB from one consistent state to another consistence state
  • 5. A.C.I.D properties (2)
    • Independence
      • 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
    • Funds transfer :
    • begin transaction T1
    • read balance1
    • balance1 = balance1 - 100
    • if balance1 < 0
      • then print “insufficient funds”
      • abort T1
    • end
    • write balance1
    • read balance2
    • balance2 = balance2 + 100
    • write balance2
    • commit T1
  • 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
      • Lost Update
      • Violation of Integrity Constraints
      • Inconsistent Retrieval
  • 10. Lost Update
    • Apparently successful updates can be overwritten be other transactions
    Begin transaction T1 read balance [ 100 ] balance = balance - 100 if 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
    • Begin transaction T3
    • 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”
    • commit T3
    • Begin transaction T4
    • read schedule where date = 4/4/01
    • read surgeon where surgeon.name = ‘Tom’
    • if not found then abort T4
    • surgeon.surgeon = ‘Tom’
    • commit 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 to read the partial results of incomplete transactions, they can obtain an inconsistent view of the DB ( dirty or unrepeatable reads )
  • 15. Inconsistent Retrieval ( Dirty Reads )
    • T1
    • begin transaction T1
    • read BalanceX
    • BalanceX = BalanceX - 100
    • if BalanceX < 0 then
    • begin
    • print ‘insufficient funds’
    • abort T1
    • end
    • write BalanceX
    • read BalanceY
    • BalanceY = BalanceY + 100
    • write BalanceY
    • commit T1
    • T2
    • begin transaction T2
    • read BalanceX
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • :
    • read BalanceY
    • commit T2
  • 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 do not conflict and order is not important.
    • If two transactions either read or write completely separate data items, they do not conflict 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 execution is important.
  • 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)]
    • Is this serialisable ?
  • 20. General Solution
    • Constrained Write Rule
    • 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)]
    • but
    • [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 a read-write conflict and the conflict between two writes is called a write-write conflict .
  • 25. Concurrency Control Techniques
    • There are three basic concurrency control techniques :
    • Locking Methods
    • Timestamp Methods
    • Optimistic Methods