Professional Documents
Culture Documents
Lect 15 - Transaction and Concurrency Control
Lect 15 - Transaction and Concurrency Control
Lect 15 - Transaction and Concurrency Control
Presented By:
Tsitsi Mandizvidza
Reg number c14122839t
1.0
What is A Transaction
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
1.1
Properties of transactions : ACID
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
1.2
Atomic Transactions
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
1.3
Atomic Transactions
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
ISOLATION TRANSACTION
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Nested transaction
A nested transaction is a
database transaction that is started by an
instruction within the scope of an already
started transaction.
Nested transactions are implemented differently in
different databases.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Nested transactions
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
THE RULES FOR COMMITTING OF NESTED TRANSACTIONS
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Example
USEFULNESS OF NESTED TRANSACTION
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Concurrency control
Example
A and B, might both read the same row and
calculate new values for one of the columns based
on the data that these applications read. If A
updates the row and then B also updates the row,
A's update lost.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
continuation
Figur 13.9
Three methods
Binary Locks
Have only two states: locked (1) or unlocked (0).
Shared/Exclusive Locks
exists when access is reserved specifically for the
transaction that locked the object .
A shared lock exists when concurrent transactions
are granted read access on the basis of common lock
shared lock produces no conflict as long as all the
concurrent transactions are read only
LOCK TYPES
DEADLOCKS
A deadlock occurs when two transactions wait
indefinitely for each other to unlock data.
Deadlock detection. The DBMS periodically tests the
database for deadlocks. if a deadlock is found one of
the transactions is aborted (rolled back and restarted)
and the other transaction are continues.
A problem with lock
Waits for B
Held by
Drawbacks of locks
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Optimistic concurrency control
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
Serializability
Recoverability
Distribution
Serializability
Distributed serializability
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
continuation
OPTIMISTIC • based on the • Only suitable for • This technique is very • Conflicts are
assumption that environments efficient when conflicts expensive to
two transactions where there are are rare. The deal with, since
won’t occur at few conflicts and occasional conflicts the conflicting
the same time no long result in the transaction transaction must
transactions. roll back. be rolled back.
• Acceptable for • Longer
mostly Read or • The rollback involves transactions are
Query database only the local copy of more likely to
systems that data, the database is have conflicts
require very few not involved and thus and may be
update there will not be any repeatedly
transactions cascading rollbacks. rolled
• For document back because of
sharing over the conflicts with
internet short
transactions.
continuation
TIMESTAMP ODERING • Each operation • Used in file • The timestamp • The timestamp
in a transaction servers. ordering based protocol
is validated • Database protocol ensures may produce
when it is system conflict schedule which
carried out serializability. is not
This is because recoverable.
conflicting
operations are
processed in
timestamp order.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
References
Questions
ANSWER TO QUESTION 1
ANSWER TO QUESTION 2
ANSWER TO QUESTION 3
Although locks prevent serious data inconsistencies, their use may lead to two major
problems:
1.The transaction schedule dictated by the locking requirements may not be
serializable, thus causing data integrity and consistency problems.
2.The schedule may create deadlocks.
Deadlocks are the equivalent of a traffic gridlock in a big city and are caused by two
transactions INDEFINITELY waiting for each other to unlock data.
In the following table (Next Slide), we can illustrate the scenario that
leads to a deadlock.)
Illustration of a deadlock
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Three basic techniques exist to control deadlocks:
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000