Chapter 9 Transactions Management and Concurrency Control
Chapter 9 Transactions Management and Concurrency Control
Chapter 9 Transactions Management and Concurrency Control
Transaction
Management and
Concurrency Control
LEARNING OBJECTIVES
BEGIN TRANSACTION;
DELETE FROM HumanResources.JobCandidate
WHERE JobCandidateID = 13;
COMMIT;
EXAMPLE OF TRANS ACTION –
SQL STATEMENT
Consistency
• A transaction is consistently processing if its complete
execution, take database from one consistent state to
another.
Isolation
• Data used during transaction cannot be used by second
transaction until the first is completed
Durability / Permanency
• Ensures that once transactions are committed, they cannot
be undone or lost. This is achieved by saving data related
to transaction in more than one places along with
database.
13
WHAT IS CONCURRENCY
CONTROL?
Lost update
• Occurs in two concurrent transactions when:
• Same data element is updated
• One of the updates is lost
Uncommitted data
• Occurs when:
• Two transactions are executed concurrently
• First transaction is rolled back after the second
transaction has already accessed uncommitted data
Inconsistent retrievals
• Occurs when a transaction accesses data before and
after one or more other transactions finish working
21
with such data
METHODS USE TO ENSURE
CONCURRENCY CONTROL
28
PROBLEM IN LOCKING METHOD
30
EXAMPLE OF DEADLOCKS
• Deadlock Prevention
• A transaction requesting a new lock is aborted if there is a
possibility that a deadlock may occur. If the transaction is aborted,
all the changes made by this transaction are rolled back and all locks
are released. The transaction is then re-scheduled for execution.
Deadlock prevention works because it avoids the conditions that
lead to deadlocking.
• Deadlock Detection
• The DBMS periodically tests the database for deadlocks. If a
deadlock is found, one of the transactions (the "victim") is aborted
(rolled back and rescheduled) and the other transaction continues.
• Deadlock Avoidance
• The transaction must obtain all the locks it needs before it can be
executed. This technique avoids rollback of conflicting transactions
by requiring that locks be obtained in succession. However, the
serial lock assignment required in deadlock avoidance increases the
TIME-STAMP BASED PROTOCOL
• Disadvantages
• Each value stored in the database
requires two additional stamp fields
• Increases memory needs
• Increases the database’s
processing overhead
• Demands a lot of system resources
34
TIMESTAMP ORDERING
PROTOCOL