Your SlideShare is downloading. ×
0
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
0321210255 Ch20 Transaction C
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

0321210255 Ch20 Transaction C

968

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
968
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
1
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. Granularity of Data Items <ul><li>Size of data items chosen as unit of protection by concurrency control protocol. </li></ul><ul><li>Ranging from coarse to fine: </li></ul><ul><ul><li>The entire database. </li></ul></ul><ul><ul><li>A file. </li></ul></ul><ul><ul><li>A page (or area or database spaced). </li></ul></ul><ul><ul><li>A record. </li></ul></ul><ul><ul><li>A field value of a record. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 2. Granularity of Data Items <ul><li>Tradeoff: </li></ul><ul><ul><li>coarser, the lower the degree of concurrency; </li></ul></ul><ul><ul><li>finer, more locking information that is needed to be stored. </li></ul></ul><ul><li>Best item size depends on the types of transactions. </li></ul>© Pearson Education Limited 1995, 2005
  • 3. Hierarchy of Granularity <ul><li>Could represent granularity of locks in a hierarchical structure. </li></ul><ul><li>Root node represents entire database, level 1s represent files, etc. </li></ul><ul><li>When node is locked, all its descendants are also locked. </li></ul><ul><li>DBMS should check hierarchical path before granting lock. </li></ul>© Pearson Education Limited 1995, 2005
  • 4. Hierarchy of Granularity <ul><li>Intention lock could be used to lock all ancestors of a locked node. </li></ul><ul><li>Intention locks can be read or write. Applied top-down, released bottom-up. </li></ul>© Pearson Education Limited 1995, 2005
  • 5. Levels of Locking © Pearson Education Limited 1995, 2005
  • 6. Database Recovery <ul><li>Process of restoring database to a correct state in the event of a failure. </li></ul><ul><li>Need for Recovery Control </li></ul><ul><ul><li>Two types of storage: volatile (main memory) and nonvolatile. </li></ul></ul><ul><ul><li>Volatile storage does not survive system crashes. </li></ul></ul><ul><ul><li>Stable storage represents information that has been replicated in several nonvolatile storage media with independent failure modes. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 7. Types of Failures <ul><li>System crashes, resulting in loss of main memory. </li></ul><ul><li>Media failures, resulting in loss of parts of secondary storage. </li></ul><ul><li>Application software errors. </li></ul><ul><li>Natural physical disasters. </li></ul><ul><li>Carelessness or unintentional destruction of data or facilities. </li></ul><ul><li>Sabotage. </li></ul>© Pearson Education Limited 1995, 2005
  • 8. Transactions and Recovery <ul><li>Transactions represent basic unit of recovery. </li></ul><ul><li>Recovery manager responsible for atomicity and durability. </li></ul><ul><li>If failure occurs between commit and database buffers being flushed to secondary storage then, to ensure durability, recovery manager has to redo ( rollforward ) transaction’s updates. </li></ul>© Pearson Education Limited 1995, 2005
  • 9. Transactions and Recovery <ul><li>If transaction had not committed at failure time, recovery manager has to undo ( rollback ) any effects of that transaction for atomicity. </li></ul><ul><li>Partial undo - only one transaction has to be undone. </li></ul><ul><li>Global undo - all transactions have to be undone. </li></ul>© Pearson Education Limited 1995, 2005
  • 10. Example <ul><li>DBMS starts at time t 0 , but fails at time t f . Assume data for transactions T 2 and T 3 have been written to secondary storage. </li></ul><ul><li>T 1 and T 6 have to be undone. In absence of any other information, recovery manager has to redo T 2 , T 3 , T 4 , and T 5 . </li></ul>© Pearson Education Limited 1995, 2005
  • 11. Recovery Facilities <ul><li>DBMS should provide following facilities to assist with recovery: </li></ul><ul><ul><li>Backup mechanism, which makes periodic backup copies of database. </li></ul></ul><ul><ul><li>Logging facilities, which keep track of current state of transactions and database changes. </li></ul></ul><ul><ul><li>Checkpoint facility, which enables updates to database in progress to be made permanent. </li></ul></ul><ul><ul><li>Recovery manager, which allows DBMS to restore database to consistent state following a failure. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 12. Log File <ul><li>Contains information about all updates to database: </li></ul><ul><ul><li>Transaction records. </li></ul></ul><ul><ul><li>Checkpoint records. </li></ul></ul><ul><li>Often used for other purposes (for example, auditing). </li></ul>© Pearson Education Limited 1995, 2005
  • 13. Log File <ul><li>Transaction records contain: </li></ul><ul><ul><li>Transaction identifier. </li></ul></ul><ul><ul><li>Type of log record, (transaction start, insert, update, delete, abort, commit). </li></ul></ul><ul><ul><li>Identifier of data item affected by database action (insert, delete, and update operations). </li></ul></ul><ul><ul><li>Before-image of data item. </li></ul></ul><ul><ul><li>After-image of data item. </li></ul></ul><ul><ul><li>Log management information. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 14. Sample Log File © Pearson Education Limited 1995, 2005
  • 15. Log File <ul><li>Log file may be duplexed or triplexed. </li></ul><ul><li>Log file sometimes split into two separate random-access files. </li></ul><ul><li>Potential bottleneck; critical in determining overall performance. </li></ul>© Pearson Education Limited 1995, 2005
  • 16. Checkpointing <ul><ul><li>Checkpoint </li></ul></ul><ul><ul><li>Point of synchronization between database and log file. All buffers are force-written to secondary storage. </li></ul></ul><ul><li>Checkpoint record is created containing identifiers of all active transactions. </li></ul><ul><li>When failure occurs, redo all transactions that committed since the checkpoint and undo all transactions active at time of crash. </li></ul>© Pearson Education Limited 1995, 2005
  • 17. Checkpointing <ul><li>In previous example, with checkpoint at time t c , changes made by T 2 and T 3 have been written to secondary storage. </li></ul><ul><li>Thus: </li></ul><ul><ul><li>only redo T 4 and T 5 , </li></ul></ul><ul><ul><li>undo transactions T 1 and T6. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 18. Recovery Techniques <ul><li>If database has been damaged: </li></ul><ul><ul><li>Need to restore last backup copy of database and reapply updates of committed transactions using log file. </li></ul></ul><ul><li>If database is only inconsistent: </li></ul><ul><ul><li>Need to undo changes that caused inconsistency. May also need to redo some transactions to ensure updates reach secondary storage. </li></ul></ul><ul><ul><li>Do not need backup, but can restore database using before- and after-images in the log file. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 19. Main Recovery Techniques <ul><li>Three main recovery techniques: </li></ul><ul><ul><li>Deferred Update </li></ul></ul><ul><ul><li>Immediate Update </li></ul></ul><ul><ul><li>Shadow Paging </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 20. Deferred Update <ul><li>Updates are not written to the database until after a transaction has reached its commit point. </li></ul><ul><li>If transaction fails before commit, it will not have modified database and so no undoing of changes required. </li></ul><ul><li>May be necessary to redo updates of committed transactions as their effect may not have reached database. </li></ul>© Pearson Education Limited 1995, 2005
  • 21. Immediate Update <ul><li>Updates are applied to database as they occur. </li></ul><ul><li>Need to redo updates of committed transactions following a failure. </li></ul><ul><li>May need to undo effects of transactions that had not committed at time of failure. </li></ul><ul><li>Essential that log records are written before write to database. Write-ahead log protocol . </li></ul>© Pearson Education Limited 1995, 2005
  • 22. Immediate Update <ul><li>If no “ transaction commit ” record in log, then that transaction was active at failure and must be undone. </li></ul><ul><li>Undo operations are performed in reverse order in which they were written to log . </li></ul>© Pearson Education Limited 1995, 2005
  • 23. Shadow Paging <ul><li>Maintain two page tables during life of a transaction: current page and shadow page table. </li></ul><ul><li>When transaction starts, two pages are the same. </li></ul><ul><li>Shadow page table is never changed thereafter and is used to restore database in event of failure. </li></ul><ul><li>During transaction, current page table records all updates to database. </li></ul><ul><li>When transaction completes, current page table becomes shadow page table. </li></ul>© Pearson Education Limited 1995, 2005
  • 24. Advanced Transaction Models <ul><li>Protocols considered so far are suitable for types of transactions that arise in traditional business applications, characterized by: </li></ul><ul><ul><li>Data has many types, each with small number of instances. </li></ul></ul><ul><ul><li>Designs may be very large. </li></ul></ul><ul><ul><li>Design is not static but evolves through time. </li></ul></ul><ul><ul><li>Updates are far-reaching. </li></ul></ul><ul><ul><li>Cooperative engineering. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 25. Advanced Transaction Models <ul><li>May result in transactions of long duration, giving rise to following problems: </li></ul><ul><ul><li>More susceptible to failure - need to minimize amount of work lost. </li></ul></ul><ul><ul><li>May access large number of data items - concurrency limited if data inaccessible for long periods. </li></ul></ul><ul><ul><li>Deadlock more likely. </li></ul></ul><ul><ul><li>Cooperation through use of shared data items restricted by traditional concurrency protocols. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 26. Advanced Transaction Models <ul><li>Look at five advanced transaction models: </li></ul><ul><ul><li>Nested Transaction Model </li></ul></ul><ul><ul><li>Sagas </li></ul></ul><ul><ul><li>Multi-level Transaction Model </li></ul></ul><ul><ul><li>Dynamic Restructuring </li></ul></ul><ul><ul><li>Workflow Models </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 27. Nested Transaction Model <ul><li>Transaction viewed as hierarchy of subtransactions. </li></ul><ul><li>Top-level transaction can have number of child transactions. </li></ul><ul><li>Each child can also have nested transactions. </li></ul><ul><li>In Moss’s proposal, only leaf-level subtransactions allowed to perform database operations. </li></ul><ul><li>Transactions have to commit from bottom upwards. </li></ul><ul><li>However, transaction abort at one level does not have to affect transaction in progress at higher level. </li></ul>© Pearson Education Limited 1995, 2005
  • 28. Nested Transaction Model <ul><li>Parent allowed to perform its own recovery: </li></ul><ul><ul><li>Retry subtransaction. </li></ul></ul><ul><ul><li>Ignore failure, in which case subtransaction non-vital. </li></ul></ul><ul><ul><li>Run contingency subtransaction. </li></ul></ul><ul><ul><li>Abort. </li></ul></ul><ul><li>Updates of committed subtransactions at intermediate levels are visible only within scope of their immediate parents. </li></ul>© Pearson Education Limited 1995, 2005
  • 29. Nested Transaction Model <ul><li>Further, commit of subtransaction is conditionally subject to commit or abort of its superiors. </li></ul><ul><li>Using this model, top-level transactions conform to traditional ACID properties of flat transaction. </li></ul>© Pearson Education Limited 1995, 2005
  • 30. Example of Nested Transactions © Pearson Education Limited 1995, 2005
  • 31. Nested Transaction Model - Advantages <ul><li>Modularity - transaction can be decomposed into number of subtransactions for purposes of concurrency and recovery. </li></ul><ul><li>Finer level of granularity for concurrency control and recovery. </li></ul><ul><li>Intra-transaction parallelism. </li></ul><ul><li>Intra-transaction recovery control. </li></ul>© Pearson Education Limited 1995, 2005
  • 32. Emulating Nested Transactions using Savepoints <ul><li>An identifiable point in flat transaction representing some partially consistent state. </li></ul><ul><li>Can be used as restart point for transaction if subsequent problem detected. </li></ul><ul><li>During execution of transaction, user can establish savepoint, which user can use to roll transaction back to. </li></ul><ul><li>Unlike nested transactions, savepoints do not support any form of intra-transaction parallelism. </li></ul>© Pearson Education Limited 1995, 2005
  • 33. Sagas <ul><li>“ A sequence of (flat) transactions that can be interleaved with other transactions”. </li></ul><ul><li>DBMS guarantees that either all transactions in saga are successfully completed or compensating transactions are run to undo partial execution. </li></ul><ul><li>Saga has only one level of nesting. </li></ul><ul><li>For every subtransaction defined, there is corresponding compensating transaction that will semantically undo subtransaction’s effect. </li></ul>© Pearson Education Limited 1995, 2005
  • 34. Sagas <ul><li>Relax property of isolation by allowing saga to reveal its partial results to other concurrently executing transactions before it completes. </li></ul><ul><li>Useful when subtransactions are relatively independent and compensating transactions can be produced. </li></ul><ul><li>May be difficult sometimes to define compensating transaction in advance, and DBMS may need to interact with user to determine compensation. </li></ul>© Pearson Education Limited 1995, 2005
  • 35. Multi-level Transaction Model <ul><li>Closed nested transaction - atomicity enforced at the top-level. </li></ul><ul><li>Open nested transactions - allow partial results of subtransactions to be seen outside transaction. </li></ul><ul><li>Saga model is example of open nested transaction. </li></ul><ul><li>So is multi-level transaction model where tree of subtransactions is balanced. </li></ul><ul><li>Nodes at same depth of tree correspond to operations of same level of abstraction in DBMS. </li></ul>© Pearson Education Limited 1995, 2005
  • 36. Multi-level Transaction Model <ul><li>Edges represent implementation of an operation by sequence of operations at next lower level. </li></ul><ul><li>Traditional flat transaction ensures no conflicts at lowest level (L0). </li></ul><ul><li>In multi-level model two operations at level L i may not conflict even though their implementations at next lower level L i-1 do. </li></ul>© Pearson Education Limited 1995, 2005
  • 37. Example - Multi-level Transaction Model © Pearson Education Limited 1995, 2005
  • 38. Example - Multi-level Transaction Model <ul><ul><li>T 7 : T 71 , which increases bal x by 5 </li></ul></ul><ul><ul><li>T 72 , which subtracts 5 from bal y </li></ul></ul><ul><ul><li>T 8 : T 81 , which increases bal y by 10 </li></ul></ul><ul><ul><li>T 82 , which subtracts 2 from bal x </li></ul></ul><ul><li>As addition and subtraction commute, can execute these subtransactions in any order, and correct result will always be generated. </li></ul>© Pearson Education Limited 1995, 2005
  • 39. Dynamic Restructuring <ul><li>To address constraints imposed by ACID properties of flat transactions, two new operations proposed: split_transaction and join_transaction. </li></ul><ul><li>split-transaction - splits transaction into two serializable transactions and divides its actions and resources (for example, locked data items) between new transactions. </li></ul><ul><li>Resulting transactions proceed independently. </li></ul>© Pearson Education Limited 1995, 2005
  • 40. Dynamic Restructuring <ul><li>Allows partial results of transaction to be shared, while still preserving its semantics. </li></ul><ul><li>Can be applied only when it is possible to generate two transactions that are serializable with each other and with all other concurrently executing transactions. </li></ul>© Pearson Education Limited 1995, 2005
  • 41. Dynamic Restructuring <ul><li>Conditions that permit transaction to be split into A and B are: </li></ul><ul><ul><li>. AWriteSet  BWriteSet  BWriteLast. </li></ul></ul><ul><ul><li>If both A and B write to same object, B’s write operations must follow A’s write operations. </li></ul></ul><ul><ul><li>. AReadSet  BWriteSet =  . </li></ul></ul><ul><ul><li>A cannot see any results from B. </li></ul></ul><ul><ul><li>. BReadSet  AWriteSet = ShareSet. </li></ul></ul><ul><ul><li>B may see results of A. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 42. Dynamic Restructuring <ul><li>These guarantee that A is serialized before B. </li></ul><ul><li>However, if A aborts, B must also abort. </li></ul><ul><li>If both BWriteLast and ShareSet are empty, then A and B can be serialized in any order and both can be committed independently. </li></ul>© Pearson Education Limited 1995, 2005
  • 43. Dynamic Restructuring <ul><li>join-transaction - performs reverse operation, merging ongoing work of two or more independent transactions, as though they had always been single transaction. </li></ul>© Pearson Education Limited 1995, 2005
  • 44. Dynamic Restructuring <ul><li>Main advantages of dynamic restructuring are: </li></ul><ul><ul><li>Adaptive recovery. </li></ul></ul><ul><ul><li>Reducing isolation. </li></ul></ul>© Pearson Education Limited 1995, 2005
  • 45. Workflow Models <ul><li>Has been argued that above models are still not powerful to model some business activities. </li></ul><ul><li>More complex models have been proposed that are combinations of open and nested transactions. </li></ul><ul><li>However, as they hardly conform to any of ACID properties, called workflow model used instead. </li></ul><ul><li>Workflow is activity involving coordinated execution of multiple tasks performed by different processing entities (people or software systems). </li></ul>© Pearson Education Limited 1995, 2005
  • 46. Workflow Models <ul><li>Two general problems involved in workflow systems: </li></ul><ul><ul><li>specification of the workflow, </li></ul></ul><ul><ul><li>execution of the workflow. </li></ul></ul><ul><li>Both problems complicated by fact that many organizations use multiple, independently managed systems to automate different parts of the process. </li></ul>© Pearson Education Limited 1995, 2005

×