Transaction and concurrency controll
description
Transcript of Transaction and concurrency controll
TRANSACTION AND CONCURRENCY CONTROLL
Chapter 13
“Distributed Systems: Concepts and Design”
Coulouris, Dollimore, KindbergHanna Björling,
Stina Fröjd & Liv Sundman
TRANSACTION A transaction is a point where there is
interaction with the database
A transaction is generally atomic
The state of the transaction being done is not visible. If it is not done completely, any changes it made will be undone. This is known as rollback
TRANSACTION It’s common to talk about transactions
in banking systems
Ex: A transfer between accounts. The money should be transferred as well as withdrawn
To make sure both things are done concurrency control is used
CONCURRENCY CONTROL Concurrency – multiple users want to
access the same data at the same time Concurrency control (CC) ensures that
correct results for parallel operations are generated
CC provides rules, methods, design methodologies and theories to maintain the consistency of components operating simultaneously while interacting with the same object
WHY CONCURRENCY CONTROL? Concurrency control is needed because
there are a lot of things that can go wrong
Each transaction itself can be okay, but the concurrency generates problems such as: The lost update problem The dirty read problem The incorrect summary problem
READ AND WRITE CONFLICTS
Figur 13.9
THREE METHODS There are many methods for
concurrency control
The main methods are:LocksOptimistic concurrency controlTimestamp ordering
LOCKS Locks are used to order transactions
that access the same objects according to the order of arrival of their operations at the objects
Mechanism for enforcing limits on access to the object
If the access to the object is locked other users have to wait until it’s unlocked
LOCK COMPABILITY
Figur 13.15
A PROBLEM WITH LOCK The use of locks can lead to deadlocks
Ex: Two transactions are waiting and each is dependent on the other to release a lock so it can resume
B
A
Waits for
Held by
Held by
T UU T
Waits for
Figur 13.20
OPTIMISTIC CONCURRENCY CONTROL Optimistic concurrency control (OCC) is
based on the assumption that two transactions won’t occur at the same time
OCC is generally used in environments with low data contention
OCC PHASES Begin Working phase Validation phase Update phase
OCC PHASES Begin: Record a timestamp marking the
transaction's beginning
Working phase: Read and write database values to a copy of the transaction which is not yet bound to the object. Several different transactions of this type may coexist
OCC PHASES Validate phase:
Controls if the transaction conflicts with another transaction on the same object
Update phase: Committed: If there is no conflict, make all
changes part of the official state of the database
Aborted: If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible
TIMESTAMP Whenever a transaction starts, it is
given a timestamp The timestamp tells in which order that
the transactions are supposed to be applied in
The transaction with the earliest timestamp is executed first
Every object in the database has a read timestamp and a write timestamp
MAJOR GOALS Serializability Recoverability Distribution
SERIALIZABILITY The goal with serializability is that the
result of the parallel transactions is the same as if though the transactions were preformed serially
RECOVERABILITY Recoverability means that committed
transactions do not read data written by aborted transactions
DISTRIBUTION Distributed serializability The serializability concept Commitment
Ordering allows to effectively achieve global serializability across multiple Database Systems, that may use different concurrency control mechanisms.
QUESTIONS?
THANK YOU,NU ÄR DET SLUT!