09 Transactions
Upcoming SlideShare
Loading in...5
×
 

09 Transactions

on

  • 299 views

 

Statistics

Views

Total Views
299
Views on SlideShare
299
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

09 Transactions 09 Transactions Presentation Transcript

  • TRANSACTIONS Talk 9
  • TRANSACTIONS: WHAT FOR? • Allow many operations to be canceled at once. • Maintain • Handle consistency of data. concurrent requests in a deterministic way. • Guarantee the persistence of data.
  • TRANSACTIONS: WHAT FOR? • RDBMS • Any Content Management System • Versioning • Filesystems Systems (Git, SVN) (NTFS, HFS, ext3, ext4, BTRfs)
  • TRANSACTIONS: WHAT FOR? •A unit of work. •SQL is inherently transactional.
  • TRANSACTIONS: WHAT FOR? •Atomicity. •Consistency. •Isolation. •Durability.
  • TRANSACTIONS: WHAT FOR? •Atomicity: every SQL command is transactional. •Consistency: not only relational but also logical. •Isolation: not necessarily serialized. •Durability: resist to system failures. http://en.wikipedia.org/wiki/ACID
  • ATOMICITY • The • All transaction is one or nothing. its modifications are applied, or none. • Transactionless means: each statement has its own transaction (= autocommit).
  • CONSISTENCY • Transactions leave the database in a consistent state: all its internal rules are always enforced. • The DBMS handles relational consistency, the developer handles logical consistency.
  • DURABILITY • Your data is safe. • Eg: non persisted data is logged.
  • ISOLATION • How the DBMS handles concurrent accesses to data? • Many levels of isolation. isolation causes read phenomena (reading nonexistent data, writing ephemeral data). • Wrong
  • READ PHENOMENA users id name age 1 Joe 20 2 Jill 25 http://en.wikipedia.org/wiki/Isolation_(database_systems)
  • id 1 2 users name Joe Jill age 20 25 Transaction 1 DIRTY READS Transaction 2 SELECT age FROM users WHERE id = 1;! /* will read 20 */ UPDATE users SET age = 21 WHERE id = 1;! /* No commit here */ SELECT age FROM users WHERE id = 1;! /* will read 21 */ ROLLBACK; /* lock-based DIRTY READ */
  • id 1 2 users name Joe Jill age 20 25 NON-REPEATABLE READS Transaction 1 Transaction 2 SELECT * FROM users WHERE id = 1; UPDATE users SET age = 21 WHERE id = 1;! COMMIT; SELECT * FROM users WHERE id = 1;! COMMIT; /* lock-based REPEATABLE READ */
  • id 1 2 users name Joe Jill age 20 25 Transaction 1 PHANTOM READS Transaction 2 SELECT * FROM users! WHERE age BETWEEN 10 AND 30; INSERT INTO users VALUES ( 3, 'Bob', 27 );! COMMIT; SELECT * FROM users! WHERE age BETWEEN 10 AND 30;! // Will see Bob.
  • ISOLATION LEVELS AND READ PHENOMENA Isolation level Read Uncommitted Read Committed Repeatable Read Serializable Dirty reads may occur Non-repeatable Phantom reads reads may occur may occur may occur may occur may occur
  • DBMS AND ISOLATION LEVELS Isolation level Oracle Firebird Apache Derby MS SQL MySQL Read Uncommitted NO NO OK OK OK Read Committed Default Default Default Default OK Repeatable Read Not exactly OK OK OK Default Serializable OK OK OK OK OK Note: no-one defaults to Serializable!!
  • THE DELPHI WAY ...! Connection1.StartTransaction;! try! ...! Query1.ExecSQL;! ...! Connection1.Commit;! except! Connection1.Rollback;! raise;! end;! ... http://docwiki.embarcadero.com/RADStudio/XE5/en/Managing_Transactions_(FireDAC)
  • THE BBOX WAY Windows Client Controllers BOs Server DAOs Database
  • THE BBOX WAY Windows Controllers @Transactional BOs DAOs Database
  • THE SPRING WAY @Transactional! public void doATransactionalThing() {! ...
  • THE SPRING WAY @Transactional(! isolation = Isolation.SERIALIZABLE,! rollbackFor = {KaBoomException.class},! propagation = Propagation.REQUIRED,! readOnly = true)! public void doATransactionalThing()! throws KaBoomException {! ...
  • Next Talk: Data Caching