SlideShare a Scribd company logo
1CONFIDENTIAL
Database Transaction
Isolation and Locking in
Java
Kanstantsin Slisenka, Senior Software Engineer
EPAM Systems
Aug 25, 2016
2CONFIDENTIAL
About me
EXPERIENCE
INTERESTED IN
• Java backend developer
• Oracle Certified Java 7 Programmer, OCEWCD, OCEJPAD
• Speaker at Java tech talks
• Java backend, SOA, databases, integration frameworks
• Solution architecture
• High load, fault-tolerant, distributed, scalable systems
kanstantsin_slisenka@epam.com
github.com/kslisenko
www.slisenko.net
Kanstantsin Slisenka
3CONFIDENTIAL
DID YOU USE TX ISOLATION OR
LOCKING AT YOUR PROJECTS?
4CONFIDENTIAL
•Transaction phenomena and isolation levels
•Pessimistic and optimistic approaches
•Transaction isolation in MySQL
•Database-level locks in MySQL
•JPA features for locking
Agenda
5CONFIDENTIAL
WHAT IS DATABASE TRANSACTION?
6CONFIDENTIAL
Database transactions and ACID
Atomicity1
Consistency2
Isolation3
Durability4
7CONFIDENTIAL
• Problem of concurrent updates made
by parallel transactions
• No problem if no concurrent updates
• Databases have protection
Transaction phenomena
PROBLEM PHENOMENA
• Dirty read
• Non-repeatable read
• Phantom insert
8CONFIDENTIAL
Transaction phenomena: dirty read
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
DATABASES ARE
PROTECTED AGAINST
THIS IN REAL LIFE
~ not committed data
• Transactions can read not committed
(dirty) data of each other
• Other transaction rollbacks, decision
was made based on never existed
data
PROBLEM
9CONFIDENTIAL
• Transactions can read not committed
(dirty) data of each other
• Other transaction rollbacks, decision
was made based on never existed
data
Transaction phenomena: dirty read
PROBLEM
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
balance = 1100
customer balance
tom ~1100~
~ not committed data
DATABASES ARE
PROTECTED AGAINST
THIS IN REAL LIFE
10CONFIDENTIAL
• Transactions can read not committed
(dirty) data of each other
• Other transaction rollbacks, decision
was made based on never existed
data
Transaction phenomena: dirty read
PROBLEM
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
balance = 1100
read not
committed
balance = 1100
customer balance
tom ~1100~
customer balance
tom ~1100~
~ not committed data
DATABASES ARE
PROTECTED AGAINST
THIS IN REAL LIFE
11CONFIDENTIAL
• Transactions can read not committed
(dirty) data of each other
• Other transaction rollbacks, decision
was made based on never existed
data
Transaction phenomena: dirty read
PROBLEM
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
balance = 1100
read not
committed
balance = 1100
rollback
customer balance
tom ~1100~
customer balance
tom 1000
customer balance
tom ~1100~
~ not committed data
DATABASES ARE
PROTECTED AGAINST
THIS IN REAL LIFE
12CONFIDENTIAL
• One transaction updates data
• Other transaction reads data several
times and get different results
Transaction phenomena: non-repeatable read
PROBLEM
Transaction 1 Transaction 2customer balance
tom 1000
begin begin
WHEN WE CAN LIVE WITH THIS
• We are fine with not the most
recent data
~ not committed data
time
13CONFIDENTIAL
Transaction phenomena: non-repeatable read
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
read
balance = 1000
customer balance
tom 1000
~ not committed data
• One transaction updates data
• Other transaction reads data several
times and get different results
PROBLEM
WHEN WE CAN LIVE WITH THIS
• We are fine with not the most
recent data
14CONFIDENTIAL
Transaction phenomena: non-repeatable read
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
balance = 900
commit
read
balance = 1000
customer balance
tom 900
customer balance
tom 1000
~ not committed data
• One transaction updates data
• Other transaction reads data several
times and get different results
PROBLEM
WHEN WE CAN LIVE WITH THIS
• We are fine with not the most
recent data
15CONFIDENTIAL
Transaction phenomena: non-repeatable read
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
read
balance = 1000
customer balance
tom 900
customer balance
tom 1000
~ not committed data
customer balance
tom 900
read
balance = 900
balance = 900
commit
• One transaction updates data
• Other transaction reads data several
times and get different results
PROBLEM
WHEN WE CAN LIVE WITH THIS
• We are fine with not the most
recent data
16CONFIDENTIAL
• One transaction inserts/deletes rows
• Other transaction reads several
times and get different number of
rows
Transaction phenomena: phantom
PROBLEM
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
WHEN WE CAN LIVE WITH THIS
• Read single rows, not ranges
• We are fine with not the most recent
data
~ not committed data
17CONFIDENTIAL
Transaction phenomena: phantom
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
get all customers
where balance < 2000
got 1 record
customer balance
tom 1000
~ not committed data
• One transaction inserts/deletes rows
• Other transaction reads several
times and get different number of
rows
PROBLEM
WHEN WE CAN LIVE WITH THIS
• Read single rows, not ranges
• We are fine with not the most recent
data
18CONFIDENTIAL
Transaction phenomena: phantom
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
get all customers
where balance < 2000
got 1 record
customer balance
tom 1000
jerry 500
customer balance
tom 1000
insert new customer
commit
~ not committed data
• One transaction inserts/deletes rows
• Other transaction reads several
times and get different number of
rows
PROBLEM
WHEN WE CAN LIVE WITH THIS
• Read single rows, not ranges
• We are fine with not the most recent
data
19CONFIDENTIAL
Transaction phenomena: phantom
Transaction 1 Transaction 2customer balance
tom 1000
time
begin begin
get all customers
where balance < 2000
got 1 record
customer balance
tom 1000
jerry 500
customer balance
tom 1000
insert new customer
commit
customer balance
tom 1000
jerry 500
get all customers
where balance < 2000
got 2 records
~ not committed data
• One transaction inserts/deletes rows
• Other transaction reads several
times and get different number of
rows
PROBLEM
WHEN WE CAN LIVE WITH THIS
• Read single rows, not ranges
• We are fine with not the most recent
data
20CONFIDENTIAL
HOW TO PROTECT?
21CONFIDENTIAL
Transaction isolation levels (standard)
• ISO/IEC 9075:1992
• Information technology --
Database languages -- SQL
http://www.contrib.andrew.cmu.edu/~shadow/s
ql/sql1992.txt
READ
UNCOMMITED
READ
COMMITED
REPEATABLE
READ
SERIALIZABLE
Dirty read YES NO NO NO
Non-
repeatable
read
YES YES NO NO
Phantom YES YES YES NO
• Defined in SQL92
• Trade-off between performance, scalability and data protection
• Same work performed with the same inputs may result in
different answers, depending on isolation level
• Implementation can be VERY DIFFERNT in different databases
22CONFIDENTIAL
HOW DOES IT WORK?
IN DIFFERENT DATABASES
23CONFIDENTIAL
• Locking rows or ranges
• Like ReadWriteLock/synchronized in Java
• Concurrent transactions wait until lock is released
Optimistic and pessimistic approaches
PESSIMISTIC OPTIMISTIC
• Multi version concurrency control (MVCC)
• Doesn’t lock anything
• Save all versions of data
• We work with data snapshots
• Like GIT/SVN
24CONFIDENTIAL
• Shared lock – read lock, many owners
• Exclusive lock – write lock, one owner
Pessimistic locking
BY OWNERSHIP
range lock row lock user balance
tom 1000
jerry 1500
EXCLUSIVE
T1
SHARED
EXCLUSIVE SHARED
EXCLUSIVE SHARED
• Row - specific rows by index (if index exists)
• Range – all records by condition
range lock row lock user balance
tom 1000
jerry 1500
EXCLUSIVE
T1
SHARED
EXCLUSIVE SHARED
EXCLUSIVE SHARED
range lock row lock user balance
tom 1000
jerry 1500
EXCLUSIVET1
SHARED
EXCLUSIVE SHARED
EXCLUSIVE SHARED
BY SCOPE
T2
T2
range lock row lock user balance
tom 1000
jerry 1500
EXCLUSIVE
T1
SHARED
EXCLUSIVE SHARED
EXCLUSIVE SHARED
T2T3
T2
T3
25CONFIDENTIAL
Optimistic multi version concurrency control (MVCC)
Updated user balance Deleted
0 tom 1000
1 tom 1000
1100
2
Transaction 1 (TS=0) READ
Transaction 2 (TS=1) WRITE
• Transactions see the rows with version less or equal to transaction start time
• On update: new version is added
• On remove: deleted column is set of new version number
HOW IT WORKS
Transaction 3 (TS=2)
DELETE
26CONFIDENTIAL
Optimistic MVCC vs pessimistic locks
MVCC (OPTIMISTIC) LOCKS (PESSIMISTIC)
Behavior
1. Each transaction works with
it’s own version
2. Concurrent transaction fails
1. Transaction which owns lock
works with data
2. Concurrent transactions wait
Locks NO YES
Performance and
scalability
GOOD BAD
Deadlocks NO POSSIBLE
Guarantee of recent data
version
NO YES
Extra disk space needed YES NO
Durability
better (because
of saved versions)
27CONFIDENTIAL
DB CONCEPT
READ
UNCOMMITED
READ COMMITED REPEATABLE READ SERIALIZABLE SPECIFICS
Oracle MVCC
NOT
SUPPORTED
DEFAULT
return new snapshot
each read
NOT SUPPORTED
returns
snapshot of
data at
beginning of
transaction
+ READ ONLY LEVEL
transaction only sees data at the moment
of start, writes not allowed
always returns snapshots, transaction fail
when concurrent update
MySQL
(InnoDB)
MVCC
return new snapshot
each time
DEFAULT
- save snapshot at first
read
- return it for next reads
- locks ranges
- transaction
lifetime
- Shared lock
on select
MSSQL LOCKS
+ Double read
phenomena:
able to read
same row twice
while it is
migrating to
another place
on disk
SNAPSHOT
(optimistic)
- locks rows
- transaction lifetime
- locks ranges
- transaction
lifetime
- selects:
shared range
lock
- updates:
exclusive lock
+ SNAPSHOT LEVEL
- save snapshot at first read
- return it for next reads
- transactions fail in case of optimistic
lock concurrent update
return new snapshot
each time
LOCK (pessimistic)
DEFAULT
- locks rows
- statements
lifetime
PostgreSQL MVCC
NOT
SUPPORTED
DEFAULT
return new snapshot
each read
- save snapshot at first
read
- return it for next reads
predicate
locking
(optimistic)
always returns snapshots, transaction fail
when concurrent update
Transaction isolation levels in different databases
28CONFIDENTIAL
LIVE DEMO
TRANSACTION ISOLATION IN MYSQL
29CONFIDENTIAL
LOCK SPECIFIC OBJECTS!
WANT TO OPTIMIZE?
30CONFIDENTIAL
• SELECT … LOCK IN SHARE MODE – shared (read) lock
• SELECT … FOR UPDATE – exclusive (write) lock
Pessimistic locking of specific rows/ranges (MySQL)
LOCKING SELECTS
IDEA
• Increase isolation level for specific rows/ranges
• Other rows/ranges can have lower isolation level
31CONFIDENTIAL
LIVE DEMO
MYSQL PESSIMISTIC LOCKING OF SPECIFIC OBJECTS
32CONFIDENTIAL
Database deadlocks
row locks user balance
tom 1000
jerry 1500
Transaction 1
EXCLUSIVE
SHAREDEXCLUSIVE
SHARED
Transaction 2
Database deadlocks happen because of bad application architecture design
• Take locks in same order in every transaction
• Use as small as possible transactions
HOW TO PREVENT DEADLOCKS
33CONFIDENTIAL
WHAT ABOUT JAVA?
34CONFIDENTIAL
hibernate.connection.isolation=level
Transaction isolation: configuration in Java
JDBC
Hibernate
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/testdb?user=test&password=pass");
c.setTransactionIsolation(level);
Connection.TRANSACTION_NONE 0
Connection.TRANSACTION_READ_UNCOMMITED 1
Connection.TRANSACTION_READ_COMMITED 2
Connection.TRANSACTION_REPEATABLE_READ 4
Connection.TRANSACTION_SERIALIZABLE 8
35CONFIDENTIAL
JPA features for locking
Enum LockModeType
PESSIMISTIC_READ Shared lock
PESSIMISTIC_WRITE Exclusive lock
EntityManager
lock(Object entity, LockModeType
lockMode)
Makes additional locking select query just to
lock entity
find(Class<T> entityClass, Object
primaryKey, LockModeType lockMode)
Makes locking select when reading entity
refresh(Object entity, LockModeType
lockMode)
Makes locking select when reloading entity
NamedQuery
@NamedQuery(name=“myQuery”, query=“…”,
lockMode=LockModeType.PESSIMISTIC_READ)
Allows to specify that we need locking select
to any query
• Complex to manually lock
entity relationships
• @NamedQuery is only way to
specify query lock
ADVANTAGES
• It is really simple
• Database specific things are
hidden from developer
• Supports parent-child entities
DRAWBACKS
36CONFIDENTIAL
Transaction isolation and locking with JPA
• Repeatable reads because of EntityManager’s cache
• Requests do not always go to database
Behavior = EntityManager + 2’nd lvl cache + database
Database
user balance
tom 1000
jerry 1500
2’nd level cache
user balance
tom 900
EntityManager
1’st level cache
user balance
tom ~1100~CLIENT
APPLICATION
37CONFIDENTIAL
Conclusion
• Do you have problems because of concurrent updates?
– Same as concurrent programming in Java
– Sometimes we can allow phenomena
• Transaction Isolation is trade-off between data protection and performance
• Two main approaches in databases implementation:
– Optimistic: no locks, data is versioned
– Pessimistic: range and low locks
• JPA
– Simplifies usage of pessimistic locking
– Adds own specific behavior because of caches
• For better performance:
– Prefer smaller transactions: they hold long time locks and can make deadlocks
– Be careful with declarative transaction management it can make heavy transactions
38CONFIDENTIAL
Oracle
Chapter 2-4
References
MySQL
Chapter 1
JPA
Chapter 12,
Locking
MSSQL
Chapter 13
PostgreSQL
Chapter 10
Examples
https://github.com/
kslisenko/tx-isolation
39CONFIDENTIAL
QUESTIONS?
THANK YOU!
kanstantsin_slisenka@epam.com
Ad

More Related Content

What's hot (20)

Survey of High Performance NoSQL Systems
Survey of High Performance NoSQL SystemsSurvey of High Performance NoSQL Systems
Survey of High Performance NoSQL Systems
ScyllaDB
 
MDF and LDF in SQL Server
MDF and LDF in SQL ServerMDF and LDF in SQL Server
MDF and LDF in SQL Server
Masum Reza
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
Chris Baglieri
 
Latency and Consistency Tradeoffs in Modern Distributed Databases
Latency and Consistency Tradeoffs in Modern Distributed DatabasesLatency and Consistency Tradeoffs in Modern Distributed Databases
Latency and Consistency Tradeoffs in Modern Distributed Databases
ScyllaDB
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
Jugal Shah
 
Kafka on Pulsar
Kafka on Pulsar Kafka on Pulsar
Kafka on Pulsar
StreamNative
 
Under the Hood of a Shard-per-Core Database Architecture
Under the Hood of a Shard-per-Core Database ArchitectureUnder the Hood of a Shard-per-Core Database Architecture
Under the Hood of a Shard-per-Core Database Architecture
ScyllaDB
 
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
Hideo Takagi
 
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
Edureka!
 
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 GamingAurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Amazon Web Services Korea
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Database
puja_dhar
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
Neeraj Singh
 
Spark sql
Spark sqlSpark sql
Spark sql
Zahra Eskandari
 
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking VN
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
rahulrathore725
 
Redis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech TalkRedis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech Talk
Red Hat Developers
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Edureka!
 
The Mechanics of Testing Large Data Pipelines (QCon London 2016)
The Mechanics of Testing Large Data Pipelines (QCon London 2016)The Mechanics of Testing Large Data Pipelines (QCon London 2016)
The Mechanics of Testing Large Data Pipelines (QCon London 2016)
Mathieu Bastian
 
Apache Cassandra at the Geek2Geek Berlin
Apache Cassandra at the Geek2Geek BerlinApache Cassandra at the Geek2Geek Berlin
Apache Cassandra at the Geek2Geek Berlin
Christian Johannsen
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
Marin Dimitrov
 
Survey of High Performance NoSQL Systems
Survey of High Performance NoSQL SystemsSurvey of High Performance NoSQL Systems
Survey of High Performance NoSQL Systems
ScyllaDB
 
MDF and LDF in SQL Server
MDF and LDF in SQL ServerMDF and LDF in SQL Server
MDF and LDF in SQL Server
Masum Reza
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
Chris Baglieri
 
Latency and Consistency Tradeoffs in Modern Distributed Databases
Latency and Consistency Tradeoffs in Modern Distributed DatabasesLatency and Consistency Tradeoffs in Modern Distributed Databases
Latency and Consistency Tradeoffs in Modern Distributed Databases
ScyllaDB
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
Jugal Shah
 
Under the Hood of a Shard-per-Core Database Architecture
Under the Hood of a Shard-per-Core Database ArchitectureUnder the Hood of a Shard-per-Core Database Architecture
Under the Hood of a Shard-per-Core Database Architecture
ScyllaDB
 
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
【ウェブ セミナー】AI 時代のクラウド データ ウェアハウス Azure SQL Data Warehouse [実践編]
Hideo Takagi
 
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
What is Hadoop | Introduction to Hadoop | Hadoop Tutorial | Hadoop Training |...
Edureka!
 
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 GamingAurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Aurora는 어떻게 다른가 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
Amazon Web Services Korea
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Database
puja_dhar
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
Neeraj Singh
 
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking VN
 
Redis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech TalkRedis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech Talk
Red Hat Developers
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Edureka!
 
The Mechanics of Testing Large Data Pipelines (QCon London 2016)
The Mechanics of Testing Large Data Pipelines (QCon London 2016)The Mechanics of Testing Large Data Pipelines (QCon London 2016)
The Mechanics of Testing Large Data Pipelines (QCon London 2016)
Mathieu Bastian
 
Apache Cassandra at the Geek2Geek Berlin
Apache Cassandra at the Geek2Geek BerlinApache Cassandra at the Geek2Geek Berlin
Apache Cassandra at the Geek2Geek Berlin
Christian Johannsen
 

Similar to Database transaction isolation and locking in Java (20)

Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Lec08
Lec08Lec08
Lec08
saryu2011
 
DBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasdddddddddddddddddddddDBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasddddddddddddddddddddd
Bishnuramghimire1
 
DBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasdddddddddddddddddddddDBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasddddddddddddddddddddd
Bishnuramghimire1
 
Transaction
TransactionTransaction
Transaction
Sanjoy Kumar Roy
 
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
Shivji Kumar Jha
 
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...
Mydbops
 
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDSYUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
AhmadSajjad34
 
UNIT-4-Transactionstates and processing ppt.pptx
UNIT-4-Transactionstates and  processing ppt.pptxUNIT-4-Transactionstates and  processing ppt.pptx
UNIT-4-Transactionstates and processing ppt.pptx
Uma Kakarlapudi
 
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingGeek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
IDERA Software
 
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Rajesh Kannan S
 
Transaction concurrency control
Transaction concurrency controlTransaction concurrency control
Transaction concurrency control
Anand Grewal
 
SQL vs No SQL vs NewSQL for online transactional processing.pptx
SQL vs No SQL vs NewSQL for online transactional processing.pptxSQL vs No SQL vs NewSQL for online transactional processing.pptx
SQL vs No SQL vs NewSQL for online transactional processing.pptx
mahdiaghaei19
 
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!
Boris Hristov
 
Transactions in database systems and functions
Transactions in database systems and functionsTransactions in database systems and functions
Transactions in database systems and functions
janakiraman123
 
Rails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdfRails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdf
GowthamvelPalanivel
 
Unit 5 dbms
Unit 5 dbmsUnit 5 dbms
Unit 5 dbms
Sweta Singh
 
Transactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Transactions-in-Oracle-Evgenya-Kotzeva (2).pptTransactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Transactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Noorien3
 
J-Fall2013- Lucas Jellema: Integrity in Java apps handouts
J-Fall2013- Lucas Jellema: Integrity in Java apps handoutsJ-Fall2013- Lucas Jellema: Integrity in Java apps handouts
J-Fall2013- Lucas Jellema: Integrity in Java apps handouts
Getting value from IoT, Integration and Data Analytics
 
Data Integrity in Java Applications (JFall 2013)
Data Integrity in Java Applications (JFall 2013)Data Integrity in Java Applications (JFall 2013)
Data Integrity in Java Applications (JFall 2013)
Lucas Jellema
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
DBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasdddddddddddddddddddddDBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasddddddddddddddddddddd
Bishnuramghimire1
 
DBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasdddddddddddddddddddddDBMS CIIT Ch8.pptasddddddddddddddddddddd
DBMS CIIT Ch8.pptasddddddddddddddddddddd
Bishnuramghimire1
 
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
Shivji Kumar Jha
 
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...
Mydbops
 
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDSYUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
YUMNST.pptWDWWFFEFEWFFFCSCSDCSDSDSDDFSDSDS
AhmadSajjad34
 
UNIT-4-Transactionstates and processing ppt.pptx
UNIT-4-Transactionstates and  processing ppt.pptxUNIT-4-Transactionstates and  processing ppt.pptx
UNIT-4-Transactionstates and processing ppt.pptx
Uma Kakarlapudi
 
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and LockingGeek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
Geek Sync | How to Detect, Analyze, and Minimize SQL Server Blocking and Locking
IDERA Software
 
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Slashn Talk OLTP in Supply Chain - Handling Super-scale and Change Propagatio...
Rajesh Kannan S
 
Transaction concurrency control
Transaction concurrency controlTransaction concurrency control
Transaction concurrency control
Anand Grewal
 
SQL vs No SQL vs NewSQL for online transactional processing.pptx
SQL vs No SQL vs NewSQL for online transactional processing.pptxSQL vs No SQL vs NewSQL for online transactional processing.pptx
SQL vs No SQL vs NewSQL for online transactional processing.pptx
mahdiaghaei19
 
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!
Boris Hristov
 
Transactions in database systems and functions
Transactions in database systems and functionsTransactions in database systems and functions
Transactions in database systems and functions
janakiraman123
 
Transactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Transactions-in-Oracle-Evgenya-Kotzeva (2).pptTransactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Transactions-in-Oracle-Evgenya-Kotzeva (2).ppt
Noorien3
 
Data Integrity in Java Applications (JFall 2013)
Data Integrity in Java Applications (JFall 2013)Data Integrity in Java Applications (JFall 2013)
Data Integrity in Java Applications (JFall 2013)
Lucas Jellema
 
Ad

More from Constantine Slisenka (11)

Unlocking the secrets of successful architects: what skills and traits do you...
Unlocking the secrets of successful architects: what skills and traits do you...Unlocking the secrets of successful architects: what skills and traits do you...
Unlocking the secrets of successful architects: what skills and traits do you...
Constantine Slisenka
 
Lyft talks #4 Orchestrating big data and ML pipelines at Lyft
Lyft talks #4 Orchestrating big data and ML pipelines at LyftLyft talks #4 Orchestrating big data and ML pipelines at Lyft
Lyft talks #4 Orchestrating big data and ML pipelines at Lyft
Constantine Slisenka
 
What does it take to be architect (for Cjicago JUG)
What does it take to be architect (for Cjicago JUG)What does it take to be architect (for Cjicago JUG)
What does it take to be architect (for Cjicago JUG)
Constantine Slisenka
 
What does it take to be an architect
What does it take to be an architectWhat does it take to be an architect
What does it take to be an architect
Constantine Slisenka
 
VoxxedDays Minsk - Building scalable WebSocket backend
VoxxedDays Minsk - Building scalable WebSocket backendVoxxedDays Minsk - Building scalable WebSocket backend
VoxxedDays Minsk - Building scalable WebSocket backend
Constantine Slisenka
 
Building scalable web socket backend
Building scalable web socket backendBuilding scalable web socket backend
Building scalable web socket backend
Constantine Slisenka
 
Latency tracing in distributed Java applications
Latency tracing in distributed Java applicationsLatency tracing in distributed Java applications
Latency tracing in distributed Java applications
Constantine Slisenka
 
Distributed transactions in SOA and Microservices
Distributed transactions in SOA and MicroservicesDistributed transactions in SOA and Microservices
Distributed transactions in SOA and Microservices
Constantine Slisenka
 
Best practices of building data streaming API
Best practices of building data streaming APIBest practices of building data streaming API
Best practices of building data streaming API
Constantine Slisenka
 
Networking in Java with NIO and Netty
Networking in Java with NIO and NettyNetworking in Java with NIO and Netty
Networking in Java with NIO and Netty
Constantine Slisenka
 
Profiling distributed Java applications
Profiling distributed Java applicationsProfiling distributed Java applications
Profiling distributed Java applications
Constantine Slisenka
 
Unlocking the secrets of successful architects: what skills and traits do you...
Unlocking the secrets of successful architects: what skills and traits do you...Unlocking the secrets of successful architects: what skills and traits do you...
Unlocking the secrets of successful architects: what skills and traits do you...
Constantine Slisenka
 
Lyft talks #4 Orchestrating big data and ML pipelines at Lyft
Lyft talks #4 Orchestrating big data and ML pipelines at LyftLyft talks #4 Orchestrating big data and ML pipelines at Lyft
Lyft talks #4 Orchestrating big data and ML pipelines at Lyft
Constantine Slisenka
 
What does it take to be architect (for Cjicago JUG)
What does it take to be architect (for Cjicago JUG)What does it take to be architect (for Cjicago JUG)
What does it take to be architect (for Cjicago JUG)
Constantine Slisenka
 
What does it take to be an architect
What does it take to be an architectWhat does it take to be an architect
What does it take to be an architect
Constantine Slisenka
 
VoxxedDays Minsk - Building scalable WebSocket backend
VoxxedDays Minsk - Building scalable WebSocket backendVoxxedDays Minsk - Building scalable WebSocket backend
VoxxedDays Minsk - Building scalable WebSocket backend
Constantine Slisenka
 
Building scalable web socket backend
Building scalable web socket backendBuilding scalable web socket backend
Building scalable web socket backend
Constantine Slisenka
 
Latency tracing in distributed Java applications
Latency tracing in distributed Java applicationsLatency tracing in distributed Java applications
Latency tracing in distributed Java applications
Constantine Slisenka
 
Distributed transactions in SOA and Microservices
Distributed transactions in SOA and MicroservicesDistributed transactions in SOA and Microservices
Distributed transactions in SOA and Microservices
Constantine Slisenka
 
Best practices of building data streaming API
Best practices of building data streaming APIBest practices of building data streaming API
Best practices of building data streaming API
Constantine Slisenka
 
Networking in Java with NIO and Netty
Networking in Java with NIO and NettyNetworking in Java with NIO and Netty
Networking in Java with NIO and Netty
Constantine Slisenka
 
Profiling distributed Java applications
Profiling distributed Java applicationsProfiling distributed Java applications
Profiling distributed Java applications
Constantine Slisenka
 
Ad

Recently uploaded (20)

Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Best Accounting Practice Management Software Guide for 2025
Best Accounting Practice Management Software Guide for 2025Best Accounting Practice Management Software Guide for 2025
Best Accounting Practice Management Software Guide for 2025
Tidyflow
 
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Message Blink
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Building Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App DevelopmentBuilding Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App Development
Net-Craft.com
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Best Accounting Practice Management Software Guide for 2025
Best Accounting Practice Management Software Guide for 2025Best Accounting Practice Management Software Guide for 2025
Best Accounting Practice Management Software Guide for 2025
Tidyflow
 
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Effortless SMS Blasts from Salesforce with Message Blink — No Tab Switching!
Message Blink
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Building Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App DevelopmentBuilding Apps for Good The Ethics of App Development
Building Apps for Good The Ethics of App Development
Net-Craft.com
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 

Database transaction isolation and locking in Java

  • 1. 1CONFIDENTIAL Database Transaction Isolation and Locking in Java Kanstantsin Slisenka, Senior Software Engineer EPAM Systems Aug 25, 2016
  • 2. 2CONFIDENTIAL About me EXPERIENCE INTERESTED IN • Java backend developer • Oracle Certified Java 7 Programmer, OCEWCD, OCEJPAD • Speaker at Java tech talks • Java backend, SOA, databases, integration frameworks • Solution architecture • High load, fault-tolerant, distributed, scalable systems [email protected] github.com/kslisenko www.slisenko.net Kanstantsin Slisenka
  • 3. 3CONFIDENTIAL DID YOU USE TX ISOLATION OR LOCKING AT YOUR PROJECTS?
  • 4. 4CONFIDENTIAL •Transaction phenomena and isolation levels •Pessimistic and optimistic approaches •Transaction isolation in MySQL •Database-level locks in MySQL •JPA features for locking Agenda
  • 6. 6CONFIDENTIAL Database transactions and ACID Atomicity1 Consistency2 Isolation3 Durability4
  • 7. 7CONFIDENTIAL • Problem of concurrent updates made by parallel transactions • No problem if no concurrent updates • Databases have protection Transaction phenomena PROBLEM PHENOMENA • Dirty read • Non-repeatable read • Phantom insert
  • 8. 8CONFIDENTIAL Transaction phenomena: dirty read Transaction 1 Transaction 2customer balance tom 1000 time begin begin DATABASES ARE PROTECTED AGAINST THIS IN REAL LIFE ~ not committed data • Transactions can read not committed (dirty) data of each other • Other transaction rollbacks, decision was made based on never existed data PROBLEM
  • 9. 9CONFIDENTIAL • Transactions can read not committed (dirty) data of each other • Other transaction rollbacks, decision was made based on never existed data Transaction phenomena: dirty read PROBLEM Transaction 1 Transaction 2customer balance tom 1000 time begin begin balance = 1100 customer balance tom ~1100~ ~ not committed data DATABASES ARE PROTECTED AGAINST THIS IN REAL LIFE
  • 10. 10CONFIDENTIAL • Transactions can read not committed (dirty) data of each other • Other transaction rollbacks, decision was made based on never existed data Transaction phenomena: dirty read PROBLEM Transaction 1 Transaction 2customer balance tom 1000 time begin begin balance = 1100 read not committed balance = 1100 customer balance tom ~1100~ customer balance tom ~1100~ ~ not committed data DATABASES ARE PROTECTED AGAINST THIS IN REAL LIFE
  • 11. 11CONFIDENTIAL • Transactions can read not committed (dirty) data of each other • Other transaction rollbacks, decision was made based on never existed data Transaction phenomena: dirty read PROBLEM Transaction 1 Transaction 2customer balance tom 1000 time begin begin balance = 1100 read not committed balance = 1100 rollback customer balance tom ~1100~ customer balance tom 1000 customer balance tom ~1100~ ~ not committed data DATABASES ARE PROTECTED AGAINST THIS IN REAL LIFE
  • 12. 12CONFIDENTIAL • One transaction updates data • Other transaction reads data several times and get different results Transaction phenomena: non-repeatable read PROBLEM Transaction 1 Transaction 2customer balance tom 1000 begin begin WHEN WE CAN LIVE WITH THIS • We are fine with not the most recent data ~ not committed data time
  • 13. 13CONFIDENTIAL Transaction phenomena: non-repeatable read Transaction 1 Transaction 2customer balance tom 1000 time begin begin read balance = 1000 customer balance tom 1000 ~ not committed data • One transaction updates data • Other transaction reads data several times and get different results PROBLEM WHEN WE CAN LIVE WITH THIS • We are fine with not the most recent data
  • 14. 14CONFIDENTIAL Transaction phenomena: non-repeatable read Transaction 1 Transaction 2customer balance tom 1000 time begin begin balance = 900 commit read balance = 1000 customer balance tom 900 customer balance tom 1000 ~ not committed data • One transaction updates data • Other transaction reads data several times and get different results PROBLEM WHEN WE CAN LIVE WITH THIS • We are fine with not the most recent data
  • 15. 15CONFIDENTIAL Transaction phenomena: non-repeatable read Transaction 1 Transaction 2customer balance tom 1000 time begin begin read balance = 1000 customer balance tom 900 customer balance tom 1000 ~ not committed data customer balance tom 900 read balance = 900 balance = 900 commit • One transaction updates data • Other transaction reads data several times and get different results PROBLEM WHEN WE CAN LIVE WITH THIS • We are fine with not the most recent data
  • 16. 16CONFIDENTIAL • One transaction inserts/deletes rows • Other transaction reads several times and get different number of rows Transaction phenomena: phantom PROBLEM Transaction 1 Transaction 2customer balance tom 1000 time begin begin WHEN WE CAN LIVE WITH THIS • Read single rows, not ranges • We are fine with not the most recent data ~ not committed data
  • 17. 17CONFIDENTIAL Transaction phenomena: phantom Transaction 1 Transaction 2customer balance tom 1000 time begin begin get all customers where balance < 2000 got 1 record customer balance tom 1000 ~ not committed data • One transaction inserts/deletes rows • Other transaction reads several times and get different number of rows PROBLEM WHEN WE CAN LIVE WITH THIS • Read single rows, not ranges • We are fine with not the most recent data
  • 18. 18CONFIDENTIAL Transaction phenomena: phantom Transaction 1 Transaction 2customer balance tom 1000 time begin begin get all customers where balance < 2000 got 1 record customer balance tom 1000 jerry 500 customer balance tom 1000 insert new customer commit ~ not committed data • One transaction inserts/deletes rows • Other transaction reads several times and get different number of rows PROBLEM WHEN WE CAN LIVE WITH THIS • Read single rows, not ranges • We are fine with not the most recent data
  • 19. 19CONFIDENTIAL Transaction phenomena: phantom Transaction 1 Transaction 2customer balance tom 1000 time begin begin get all customers where balance < 2000 got 1 record customer balance tom 1000 jerry 500 customer balance tom 1000 insert new customer commit customer balance tom 1000 jerry 500 get all customers where balance < 2000 got 2 records ~ not committed data • One transaction inserts/deletes rows • Other transaction reads several times and get different number of rows PROBLEM WHEN WE CAN LIVE WITH THIS • Read single rows, not ranges • We are fine with not the most recent data
  • 21. 21CONFIDENTIAL Transaction isolation levels (standard) • ISO/IEC 9075:1992 • Information technology -- Database languages -- SQL http://www.contrib.andrew.cmu.edu/~shadow/s ql/sql1992.txt READ UNCOMMITED READ COMMITED REPEATABLE READ SERIALIZABLE Dirty read YES NO NO NO Non- repeatable read YES YES NO NO Phantom YES YES YES NO • Defined in SQL92 • Trade-off between performance, scalability and data protection • Same work performed with the same inputs may result in different answers, depending on isolation level • Implementation can be VERY DIFFERNT in different databases
  • 22. 22CONFIDENTIAL HOW DOES IT WORK? IN DIFFERENT DATABASES
  • 23. 23CONFIDENTIAL • Locking rows or ranges • Like ReadWriteLock/synchronized in Java • Concurrent transactions wait until lock is released Optimistic and pessimistic approaches PESSIMISTIC OPTIMISTIC • Multi version concurrency control (MVCC) • Doesn’t lock anything • Save all versions of data • We work with data snapshots • Like GIT/SVN
  • 24. 24CONFIDENTIAL • Shared lock – read lock, many owners • Exclusive lock – write lock, one owner Pessimistic locking BY OWNERSHIP range lock row lock user balance tom 1000 jerry 1500 EXCLUSIVE T1 SHARED EXCLUSIVE SHARED EXCLUSIVE SHARED • Row - specific rows by index (if index exists) • Range – all records by condition range lock row lock user balance tom 1000 jerry 1500 EXCLUSIVE T1 SHARED EXCLUSIVE SHARED EXCLUSIVE SHARED range lock row lock user balance tom 1000 jerry 1500 EXCLUSIVET1 SHARED EXCLUSIVE SHARED EXCLUSIVE SHARED BY SCOPE T2 T2 range lock row lock user balance tom 1000 jerry 1500 EXCLUSIVE T1 SHARED EXCLUSIVE SHARED EXCLUSIVE SHARED T2T3 T2 T3
  • 25. 25CONFIDENTIAL Optimistic multi version concurrency control (MVCC) Updated user balance Deleted 0 tom 1000 1 tom 1000 1100 2 Transaction 1 (TS=0) READ Transaction 2 (TS=1) WRITE • Transactions see the rows with version less or equal to transaction start time • On update: new version is added • On remove: deleted column is set of new version number HOW IT WORKS Transaction 3 (TS=2) DELETE
  • 26. 26CONFIDENTIAL Optimistic MVCC vs pessimistic locks MVCC (OPTIMISTIC) LOCKS (PESSIMISTIC) Behavior 1. Each transaction works with it’s own version 2. Concurrent transaction fails 1. Transaction which owns lock works with data 2. Concurrent transactions wait Locks NO YES Performance and scalability GOOD BAD Deadlocks NO POSSIBLE Guarantee of recent data version NO YES Extra disk space needed YES NO Durability better (because of saved versions)
  • 27. 27CONFIDENTIAL DB CONCEPT READ UNCOMMITED READ COMMITED REPEATABLE READ SERIALIZABLE SPECIFICS Oracle MVCC NOT SUPPORTED DEFAULT return new snapshot each read NOT SUPPORTED returns snapshot of data at beginning of transaction + READ ONLY LEVEL transaction only sees data at the moment of start, writes not allowed always returns snapshots, transaction fail when concurrent update MySQL (InnoDB) MVCC return new snapshot each time DEFAULT - save snapshot at first read - return it for next reads - locks ranges - transaction lifetime - Shared lock on select MSSQL LOCKS + Double read phenomena: able to read same row twice while it is migrating to another place on disk SNAPSHOT (optimistic) - locks rows - transaction lifetime - locks ranges - transaction lifetime - selects: shared range lock - updates: exclusive lock + SNAPSHOT LEVEL - save snapshot at first read - return it for next reads - transactions fail in case of optimistic lock concurrent update return new snapshot each time LOCK (pessimistic) DEFAULT - locks rows - statements lifetime PostgreSQL MVCC NOT SUPPORTED DEFAULT return new snapshot each read - save snapshot at first read - return it for next reads predicate locking (optimistic) always returns snapshots, transaction fail when concurrent update Transaction isolation levels in different databases
  • 30. 30CONFIDENTIAL • SELECT … LOCK IN SHARE MODE – shared (read) lock • SELECT … FOR UPDATE – exclusive (write) lock Pessimistic locking of specific rows/ranges (MySQL) LOCKING SELECTS IDEA • Increase isolation level for specific rows/ranges • Other rows/ranges can have lower isolation level
  • 31. 31CONFIDENTIAL LIVE DEMO MYSQL PESSIMISTIC LOCKING OF SPECIFIC OBJECTS
  • 32. 32CONFIDENTIAL Database deadlocks row locks user balance tom 1000 jerry 1500 Transaction 1 EXCLUSIVE SHAREDEXCLUSIVE SHARED Transaction 2 Database deadlocks happen because of bad application architecture design • Take locks in same order in every transaction • Use as small as possible transactions HOW TO PREVENT DEADLOCKS
  • 34. 34CONFIDENTIAL hibernate.connection.isolation=level Transaction isolation: configuration in Java JDBC Hibernate Connection c = DriverManager.getConnection("jdbc:mysql://localhost/testdb?user=test&password=pass"); c.setTransactionIsolation(level); Connection.TRANSACTION_NONE 0 Connection.TRANSACTION_READ_UNCOMMITED 1 Connection.TRANSACTION_READ_COMMITED 2 Connection.TRANSACTION_REPEATABLE_READ 4 Connection.TRANSACTION_SERIALIZABLE 8
  • 35. 35CONFIDENTIAL JPA features for locking Enum LockModeType PESSIMISTIC_READ Shared lock PESSIMISTIC_WRITE Exclusive lock EntityManager lock(Object entity, LockModeType lockMode) Makes additional locking select query just to lock entity find(Class<T> entityClass, Object primaryKey, LockModeType lockMode) Makes locking select when reading entity refresh(Object entity, LockModeType lockMode) Makes locking select when reloading entity NamedQuery @NamedQuery(name=“myQuery”, query=“…”, lockMode=LockModeType.PESSIMISTIC_READ) Allows to specify that we need locking select to any query • Complex to manually lock entity relationships • @NamedQuery is only way to specify query lock ADVANTAGES • It is really simple • Database specific things are hidden from developer • Supports parent-child entities DRAWBACKS
  • 36. 36CONFIDENTIAL Transaction isolation and locking with JPA • Repeatable reads because of EntityManager’s cache • Requests do not always go to database Behavior = EntityManager + 2’nd lvl cache + database Database user balance tom 1000 jerry 1500 2’nd level cache user balance tom 900 EntityManager 1’st level cache user balance tom ~1100~CLIENT APPLICATION
  • 37. 37CONFIDENTIAL Conclusion • Do you have problems because of concurrent updates? – Same as concurrent programming in Java – Sometimes we can allow phenomena • Transaction Isolation is trade-off between data protection and performance • Two main approaches in databases implementation: – Optimistic: no locks, data is versioned – Pessimistic: range and low locks • JPA – Simplifies usage of pessimistic locking – Adds own specific behavior because of caches • For better performance: – Prefer smaller transactions: they hold long time locks and can make deadlocks – Be careful with declarative transaction management it can make heavy transactions
  • 38. 38CONFIDENTIAL Oracle Chapter 2-4 References MySQL Chapter 1 JPA Chapter 12, Locking MSSQL Chapter 13 PostgreSQL Chapter 10 Examples https://github.com/ kslisenko/tx-isolation