Rushdi Shams, Dept of CSE, KUET 1
› Action, or series of actions, carried out by
user or application, which reads or
updates contents of database.
› Transfo...
 Can have one of two outcomes:
› Success - transaction commits and database reaches a
new consistent state.
› Failure - t...
Rushdi Shams, Dept of CSE, KUET 4
 Process of managing simultaneous operations
on the database without having them interfere
with one another.
 Prevents i...
 Three examples of potential problems caused
by concurrency:
1. Lost update problem.
2. Uncommitted dependency problem.
3...
 Successfully completed update is overridden by
another user.
 T1 withdrawing £10 from an account with balx,
initially £...
Rushdi Shams, Dept of CSE, KUET 8
 Occurs when one transaction can see
intermediate results of another transaction
before it has committed.
 T4 updates ba...
Rushdi Shams, Dept of CSE, KUET 10
 Occurs when transaction reads several values but
second transaction updates some of them during
execution of first.
 So...
Rushdi Shams, Dept of CSE, KUET 12
 Objective of a concurrency control protocol is
to schedule transactions in such a way as to
avoid any interference.
 Co...
 Sequence of reads/writes by set of concurrent
transactions.
 There are 2 types of scheduling-
1. Serial scheduling
2. N...
› Schedule where operations of each transaction are
executed consecutively without any interleaved
operations from other t...
 Schedule where operations from set of
concurrent transactions are interleaved.
Rushdi Shams, Dept of CSE, KUET 16
 Objective of serializability is to find nonserial
schedules that allow transactions to execute
concurrently without inte...
 In serializability, ordering of read/writes is
important:
1. If two transactions only read a data item, they do
not conf...
Rushdi Shams, Dept of CSE, KUET 19
 Used to test for serializability
 Create
› node for each transaction;
› a directed edge Ti → Tj, if Tj reads the value ...
 T9 is transferring £100 from one account with
balance balx to another account with balance
baly.
 T10 is increasing bal...
Rushdi Shams, Dept of CSE, KUET 22
 Serializability identifies schedules that maintain
database consistency, assuming no transaction
fails.
 Could also exa...
 A schedule is recoverable if, for each pair of
transactions Ti and Tj, if Tj reads a data item
previously written by Ti,...
1. Optimistic method:
› Based on assumption that conflict does not happen
very often.
› So we better let the transaction r...
2. Timestamping:
› For any given database request, the system
compares the timestamp of the requesting
transaction with th...
3. Locking:
› When a transaction needs an assurance that
transaction will not be affected by others, it
requires a lock on...
 Exclusive Lock (XLock): If anybody is
having exclusive lock, the other users
will go into wait list until the exclusive
...
If A has XLock,
then if B wants XLock, B has to wait
then if B wants SLock, B has to wait
then if B wants NoLock, B can se...
 If transaction has shared lock on item, can read
but not update item.
 If transaction has exclusive lock on item, can
b...
 Problem is that transactions release locks too
soon, resulting in loss of total isolation and
atomicity.
 To guarantee ...
 Transaction follows 2PL protocol if all locking
operations precede first unlock operation in the
transaction.
 Two phas...
Rushdi Shams, Dept of CSE, KUET 33
Rushdi Shams, Dept of CSE, KUET 34
Rushdi Shams, Dept of CSE, KUET 35
Rushdi Shams, Dept of CSE, KUET 36
 Transactions conform to 2PL.
 T14 aborts.
 Since T15 is dependent on T14, T15 must also be
rolled back. Since T16 is d...
 An impasse that may result when two (or more)
transactions are each waiting for locks held by
the other to be released.
...
Rushdi Shams, Dept of CSE, KUET 39
 Deadlock should be transparent to user, so
DBMS should restart transaction(s).
 Three general techniques for handling
d...
 Transaction that requests lock will only wait for a
system-defined period of time.
 If lock has not been granted within...
 DBMS looks ahead to see if transaction would
cause deadlock and never allows deadlock to
occur.
 Wait-Die - only an old...
› Wound-Wait - only a younger transaction can wait
for an older one.
If older transaction requests lock held by younger
on...
 DBMS allows deadlock to occur but recognizes it
and breaks it.
 Usually handled by construction of wait-for graph
(WFG)...
Rushdi Shams, Dept of CSE, KUET 45
 Selecting a victim – minimize cost.
 Rollback – return to some safe state, restart
transaction for that state.
 Starva...
 Database Management Systems by R.
Ramakrishnan
 John Hall, Senior Lecturer, University of Bolton,
UK
 Operating System...
Upcoming SlideShare
Loading in...5
×

L11 l12 l13 transaction management

278

Published on

Published in: Technology, Real Estate
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
278
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

L11 l12 l13 transaction management

  1. 1. Rushdi Shams, Dept of CSE, KUET 1
  2. 2. › Action, or series of actions, carried out by user or application, which reads or updates contents of database. › Transforms database from one consistent state to another, although consistency may be violated during transaction. Rushdi Shams, Dept of CSE, KUET 2
  3. 3.  Can have one of two outcomes: › Success - transaction commits and database reaches a new consistent state. › Failure - transaction aborts, and database must be restored to consistent state before it started. Such a transaction is rolled back or undone.  Committed transaction cannot be aborted.  Aborted transaction that is rolled back can be restarted later. Rushdi Shams, Dept of CSE, KUET 3
  4. 4. Rushdi Shams, Dept of CSE, KUET 4
  5. 5.  Process of managing simultaneous operations on the database without having them interfere with one another.  Prevents interference when two or more users are accessing database simultaneously and at least one is updating data.  Although two transactions may be correct in themselves, interleaving of operations may produce an incorrect result. Rushdi Shams, Dept of CSE, KUET 5
  6. 6.  Three examples of potential problems caused by concurrency: 1. Lost update problem. 2. Uncommitted dependency problem. 3. Inconsistent analysis problem. Rushdi Shams, Dept of CSE, KUET 6
  7. 7.  Successfully completed update is overridden by another user.  T1 withdrawing £10 from an account with balx, initially £100.  T2 depositing £100 into same account.  Serially, final balance would be £190. Rushdi Shams, Dept of CSE, KUET 7
  8. 8. Rushdi Shams, Dept of CSE, KUET 8
  9. 9.  Occurs when one transaction can see intermediate results of another transaction before it has committed.  T4 updates balx to £200 but it aborts, so balx should be back at original value of £100.  T3 has read new value of balx (£200) and uses value as basis of £10 reduction, giving a new balance of £190, instead of £90. Rushdi Shams, Dept of CSE, KUET 9
  10. 10. Rushdi Shams, Dept of CSE, KUET 10
  11. 11.  Occurs when transaction reads several values but second transaction updates some of them during execution of first.  Sometimes referred to as dirty read or unrepeatable read.  T6 is totaling balances of account x (£100), account y (£50), and account z (£25).  Meantime, T5 has transferred £10 from balx to balz, so T6 now has wrong result (£10 too high). Rushdi Shams, Dept of CSE, KUET 11
  12. 12. Rushdi Shams, Dept of CSE, KUET 12
  13. 13.  Objective of a concurrency control protocol is to schedule transactions in such a way as to avoid any interference.  Could run transactions serially, but this limits degree of concurrency or parallelism in system.  Serializability identifies those executions of transactions guaranteed to ensure consistency. Rushdi Shams, Dept of CSE, KUET 13
  14. 14.  Sequence of reads/writes by set of concurrent transactions.  There are 2 types of scheduling- 1. Serial scheduling 2. Non serial scheduling Rushdi Shams, Dept of CSE, KUET 14
  15. 15. › Schedule where operations of each transaction are executed consecutively without any interleaved operations from other transactions. Rushdi Shams, Dept of CSE, KUET 15
  16. 16.  Schedule where operations from set of concurrent transactions are interleaved. Rushdi Shams, Dept of CSE, KUET 16
  17. 17.  Objective of serializability is to find nonserial schedules that allow transactions to execute concurrently without interfering with one another.  In other words, want to find nonserial schedules that are equivalent to some serial schedule. Such a schedule is called serializable. Rushdi Shams, Dept of CSE, KUET 17
  18. 18.  In serializability, ordering of read/writes is important: 1. If two transactions only read a data item, they do not conflict and order is not important. 2. If two transactions either read or write completely separate data items, they do not conflict and order is not important. 3. If one transaction writes a data item and another reads or writes same data item, order of execution is important. Rushdi Shams, Dept of CSE, KUET 18
  19. 19. Rushdi Shams, Dept of CSE, KUET 19
  20. 20.  Used to test for serializability  Create › 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.  If precedence graph contains cycle you are in trouble!! Rushdi Shams, Dept of CSE, KUET 20
  21. 21.  T9 is transferring £100 from one account with balance balx to another account with balance baly.  T10 is increasing balance of these two accounts by 10%.  Precedence graph has a cycle and so is not serializable. Rushdi Shams, Dept of CSE, KUET 21
  22. 22. Rushdi Shams, Dept of CSE, KUET 22
  23. 23.  Serializability identifies schedules that maintain database consistency, assuming no transaction fails.  Could also examine recoverability of transactions within schedule. Rushdi Shams, Dept of CSE, KUET 23
  24. 24.  A schedule is recoverable if, for each pair of transactions Ti and Tj, if Tj reads a data item previously written by Ti, then the commit operation of Ti precedes the commit operation of Tj. Rushdi Shams, Dept of CSE, KUET 24
  25. 25. 1. Optimistic method: › Based on assumption that conflict does not happen very often. › So we better let the transaction run to its completion and then check at commit time to see if there is a conflict. › If there is, the offending transaction simply starts again from the beginning. Rushdi Shams, Dept of CSE, KUET 25
  26. 26. 2. Timestamping: › For any given database request, the system compares the timestamp of the requesting transaction with the timestamp of the transaction that last retrieved or updated the requested record. › If there is a conflict, the requesting transaction can simply be restarted (with new timestamp). Rushdi Shams, Dept of CSE, KUET 26
  27. 27. 3. Locking: › When a transaction needs an assurance that transaction will not be affected by others, it requires a lock on that object. › Then the first transaction is able to carry out its processing without fear of others’ interference. Rushdi Shams, Dept of CSE, KUET 27
  28. 28.  Exclusive Lock (XLock): If anybody is having exclusive lock, the other users will go into wait list until the exclusive lock holder releases it.  Shared Lock (SLock): If anybody has shared lock, the other users with request shared lock can also have access to it. Rushdi Shams, Dept of CSE, KUET 28
  29. 29. If A has XLock, then if B wants XLock, B has to wait then if B wants SLock, B has to wait then if B wants NoLock, B can see it If A has SLock, then if B wants XLock, B has to wait then if B wants SLock, B gets permission then if B wants NoLock, B can see it If A has NoLock, then if B wants XLock, B will be granted then if B wants SLock, B will be granted then if B wants NoLock, B will be granted  Xlock= Exclusive Lock  SLock= Shared Lock Rushdi Shams, Dept of CSE, KUET 29
  30. 30.  If transaction has shared lock on item, can read but not update item.  If transaction has exclusive lock on item, can both read and update item.  Reads cannot conflict, so more than one transaction can hold shared locks simultaneously on same item. Rushdi Shams, Dept of CSE, KUET 30
  31. 31.  Problem is that transactions release locks too soon, resulting in loss of total isolation and atomicity.  To guarantee serializability, need an additional protocol concerning the positioning of lock and unlock operations in every transaction. Rushdi Shams, Dept of CSE, KUET 31
  32. 32.  Transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction.  Two phases for transaction: › Growing phase - acquires all locks but cannot release any locks. › Shrinking phase - releases locks but cannot acquire any new locks. Rushdi Shams, Dept of CSE, KUET 32
  33. 33. Rushdi Shams, Dept of CSE, KUET 33
  34. 34. Rushdi Shams, Dept of CSE, KUET 34
  35. 35. Rushdi Shams, Dept of CSE, KUET 35
  36. 36. Rushdi Shams, Dept of CSE, KUET 36
  37. 37.  Transactions conform to 2PL.  T14 aborts.  Since T15 is dependent on T14, T15 must also be rolled back. Since T16 is dependent on T15, it too must be rolled back.  This is called cascading rollback.  To prevent this with 2PL, leave release of all locks until end of transaction. Rushdi Shams, Dept of CSE, KUET 37
  38. 38.  An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released.  Deadlock is a situation in which two or more transactions are in a simultaneous wait state; each one waiting for one of the other to release a lock before it can proceed. Rushdi Shams, Dept of CSE, KUET 38
  39. 39. Rushdi Shams, Dept of CSE, KUET 39
  40. 40.  Deadlock should be transparent to user, so DBMS should restart transaction(s).  Three general techniques for handling deadlock: 1. Timeouts. 2. Deadlock prevention. 3. Deadlock detection and recovery. Rushdi Shams, Dept of CSE, KUET 40
  41. 41.  Transaction that requests lock will only wait for a system-defined period of time.  If lock has not been granted within this period, lock request times out.  In this case, DBMS assumes transaction may be deadlocked, even though it may not be, and it aborts and automatically restarts the transaction. Rushdi Shams, Dept of CSE, KUET 41
  42. 42.  DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur.  Wait-Die - only an older transaction can wait for younger one, otherwise If younger transaction requests lock held by older one, younger one is aborted (dies) and restarted with same timestamp. Rushdi Shams, Dept of CSE, KUET 42
  43. 43. › Wound-Wait - only a younger transaction can wait for an older one. If older transaction requests lock held by younger one, younger one is aborted (wounded). Rushdi Shams, Dept of CSE, KUET 43
  44. 44.  DBMS allows deadlock to occur but recognizes it and breaks it.  Usually handled by construction of wait-for graph (WFG) showing transaction dependencies: › Create a node for each transaction. › Create edge Ti -> Tj, if Ti waiting to lock item locked by Tj.  Deadlock exists if and only if WFG contains cycle. Rushdi Shams, Dept of CSE, KUET 44
  45. 45. Rushdi Shams, Dept of CSE, KUET 45
  46. 46.  Selecting a victim – minimize cost.  Rollback – return to some safe state, restart transaction for that state.  Starvation – same transaction may always be picked as victim, include number of rollback in cost factor. Rushdi Shams, Dept of CSE, KUET 46
  47. 47.  Database Management Systems by R. Ramakrishnan  John Hall, Senior Lecturer, University of Bolton, UK  Operating Systems Concept (6th Edition) by Silberschatz, Galvin and Gagne Rushdi Shams, Dept of CSE, KUET 47
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×