SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie 09 Transactions

Ähnlich wie 09 Transactions (20)

Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
 
Spring@transaction,isolation
Spring@transaction,isolationSpring@transaction,isolation
Spring@transaction,isolation
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
 
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
 
Osi Model
Osi Model Osi Model
Osi Model
 
Navigating Transactions: ACID Complexity in Modern Databases
Navigating Transactions: ACID Complexity in Modern DatabasesNavigating Transactions: ACID Complexity in Modern Databases
Navigating Transactions: ACID Complexity in Modern Databases
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
 
InfectNet Technical
InfectNet TechnicalInfectNet Technical
InfectNet Technical
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
 
Introduction to Cassandra & Data model
Introduction to Cassandra & Data modelIntroduction to Cassandra & Data model
Introduction to Cassandra & Data model
 

Mehr von Federico Russo

01 - Ereditarietà e polimorfismo
01 - Ereditarietà e polimorfismo01 - Ereditarietà e polimorfismo
01 - Ereditarietà e polimorfismo
Federico Russo
 

Mehr von Federico Russo (20)

23 Sicurezza in BBox
23 Sicurezza in BBox23 Sicurezza in BBox
23 Sicurezza in BBox
 
21 Buzzwords
21 Buzzwords21 Buzzwords
21 Buzzwords
 
18 - InfluxDB
18 - InfluxDB18 - InfluxDB
18 - InfluxDB
 
19 - The Highlander Project
19 - The Highlander Project19 - The Highlander Project
19 - The Highlander Project
 
22 - Better Coding
22 - Better Coding22 - Better Coding
22 - Better Coding
 
20 - Ottimizzare le query
20 - Ottimizzare le query20 - Ottimizzare le query
20 - Ottimizzare le query
 
17 - Web Application Threats
17 - Web Application Threats17 - Web Application Threats
17 - Web Application Threats
 
16 - Project Lombok
16 - Project Lombok16 - Project Lombok
16 - Project Lombok
 
15 - Java 8
15 - Java 815 - Java 8
15 - Java 8
 
14 - Atom
14 - Atom14 - Atom
14 - Atom
 
BBox e vaadin7
BBox e vaadin7BBox e vaadin7
BBox e vaadin7
 
Box Functionalities 0.20
Box Functionalities 0.20Box Functionalities 0.20
Box Functionalities 0.20
 
Tile server
Tile serverTile server
Tile server
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
12 java modifiers
12 java modifiers12 java modifiers
12 java modifiers
 
10 Data caching
10 Data caching10 Data caching
10 Data caching
 
04-JVM
04-JVM04-JVM
04-JVM
 
02 - Collezioni
02 - Collezioni02 - Collezioni
02 - Collezioni
 
01 - Ereditarietà e polimorfismo
01 - Ereditarietà e polimorfismo01 - Ereditarietà e polimorfismo
01 - Ereditarietà e polimorfismo
 
DataSnap
DataSnapDataSnap
DataSnap
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

09 Transactions