1 / 32

Trouble with transactions

Trouble with transactions. Evan Jones http:// evanjones.ca. A love story. A short love story. I fell in love …. A short love story. …with transactions. …with transactions.

fedora
Download Presentation

Trouble with transactions

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. Trouble with transactions Evan Jones http://evanjones.ca

  2. A love story

  3. A short love story

  4. I fell in love… A short love story

  5. …with transactions

  6. …with transactions 💖 💖 💖

  7. Transactions = correct programs

  8. A four year romance

  9. A four year romance Main memory transactions

  10. A four year romance Main memory transactions Automatic partitioning

  11. A four year romance Main memory transactions Consolidating workloads Automatic partitioning

  12. A four year romance Main memory transactions Consolidating workloads Automatic partitioning

  13. Applications,not databases

  14. Example: Read bank balance connection.begin_transaction() print connection.query_balance() # ... do some computation ... print connection.query_balance() connection.commit()

  15. Example: Read bank balance connection.begin_transaction() print connection.query_balance() # ... do some computation ... print connection.query_balance() connection.commit() = $1000

  16. Example: Read bank balance connection.begin_transaction() print connection.query_balance() # ... do some computation ... print connection.query_balance() connection.commit() = $1000 = $1500

  17. Example: Read bank balance connection.begin_transaction() print connection.query_balance() # ... do some computation ... print connection.query_balance() connection.commit() = $1000 💔 = $1500

  18. 💔#1: Weak defaults Transactions = Serializability Postgres: Read committed MySQL/InnoDB: “Repeatable read” (reality: something weird)

  19. 💔#1: Weak defaults Transactions = Serializability 💖 Postgres: Read committed MySQL/InnoDB: “Repeatable read” (reality: something weird)

  20. 💔#1: Weak defaults Transactions = Serializability 💖 Postgres: Read committed MySQL/InnoDB: “Repeatable read” (reality: something weird) Set SERIALIZABLE by default

  21. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance()

  22. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000

  23. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000 = okay!

  24. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000 = okay! Exception

  25. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000 = okay! Exception = $500

  26. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000 = okay! Exception = $500 💔

  27. Example 2: Withdrawal try: connection.begin_transaction() balance = connection.query_balance() connection.update_balance(balance – 500) some_function(connection) connection.commit() except e: connection.rollback() print connection.query_balance() = $1000 = okay! Exception = $500 💔

  28. 💔#2: Implicit begin some_function committed (my fault) DB automatically started new txn

  29. 💔#2: Implicit begin some_function committed (my fault) DB automatically started new txn If you begin, you commit Like memory in C/C++ Nested transactions can help Don’t implicitly start transactions

  30. Transactions: Use with care • Communication with external systems • Accidental long running transactions • Retry loops for concurrency errors

  31. Transactions: Use with care • Communication with external systems • Accidental long running transactions • Retry loops for concurrency errors Make it hard to use systems incorrectly http://evanjones.ca/

More Related