1 / 16

Transactions and concurrency

Transactions and concurrency. INF08104: Database Systems Brian Davison , 2013/4. Agenda. Transactions Transaction control The transaction log Concurrency Locking Deadlocks Explicit locking. T ransactions. Logical unit of work May consist of several database operations

onslow
Télécharger la présentation

Transactions and concurrency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Transactions and concurrency INF08104: Database Systems Brian Davison, 2013/4

  2. Agenda • Transactions • Transaction control • The transaction log • Concurrency • Locking • Deadlocks • Explicit locking

  3. Transactions • Logical unit of work • May consist of several database operations • All operations must either succeed or fail

  4. E-commerce transaction example • Insert INVOICE record • Insert LINE for each different PRODUCT • Update each PRODUCT to reduce the prod_quantity • After LINES are inserted, update INVOICE to include tax

  5. Transaction control INSERT / UPDATE / DELETE … COMMIT

  6. ROLLBACK INSERT / UPDATE / DELETE … ROLLBACK

  7. Transaction isolation HR

  8. Transaction log INSERT / UPDATE / DELETE … COMMIT / ROLLBACK Transaction log

  9. Concurrency • Many simultaneous users • Problems • Inconsistent retrieval • Lost updates • Uncommitted data • To update stock value: • Read current product quantity • Calculate new product quantity • Store new value

  10. Lost updates • Customer1 orders 10 units of a product • Customer2 orders 50 units • Currently, 100 units available • 40 remaining • Step 5 is lost 

  11. Uncommitted data • Customer1 orders 10 units but is rolled back • Customer2 orders 50 units • Currently, 100 units available • 50 remaining • Uncommitted data 

  12. Locking (lost updates)

  13. Locking (uncommitted data)

  14. Deadlocks

  15. Explicit locks SELECT *FROM   countriesWHERE  country_id = 'ES'FOR UPDATE; LOCK TABLE COUNTRIES; SELECT… INSERT… UPDATE… COMMIT; Locks query results Locks released by COMMIT or ROLLBACK

  16. Transaction control LOCK TABLE invoice; LOCK TABLE product; INSERT INTO invoice … INSERT INTO invoice_line … UPDATE product SET prod_quantity = … INSERT INTO invoice_line … UPDATE product SET prod_quantity = … UPDATE invoice SET inv_total = … COMMIT;

More Related