Dbms Unit 5 Final
Dbms Unit 5 Final
CONCEPTS
I) Transaction processing
II) Concurrency control Techniques
Transaction Processing
Introduction
Serializability of schedules
2. write_item(X):
• Read(A): Read operations Read(A) or R(A) reads the value of A from the database and stores it in
a buffer in main memory.
• Write (A): Write operation Write(A) or W(A) writes the value back to the database from buffer.
• 1. read_item(X):
• It reads a database item named X into a program variable. It works as follows,
• 1. The address of the disk block that contain item X is found.
• 2. The disk block is copied into a buffer in main memory.
• 3. The item X is copied from the buffer to the program variable named X.
• 2. write_item(X):
• It writes the value of the program variable X into the database item X. It works
as follows,
• 1. The address of the disk block that contains item X is found.
• 2. The disk block is copied into a buffer in main memory.
• 3. The item X is copied from the program variable named X into its correct
location in the buffer.
• 4. The updated block from the buffer is stored back to disk either immediately
or at sometime later.
INTRODUCTION
• The transaction is a set of logically related operation. It contains a
group of tasks.
• A transaction is an action or series of actions. It is performed by a
single user to perform operations for accessing the contents of the
database.
• Process:
• Single user
• Multi user
• Read/write
• Property of Transaction
• Atomicity
• Consistency
• Isolation
• Durability
States of Transaction
Schedule
• Ex:
• T1 executes but not complete the operation
• T2 starts to execute before T1 completes its operation.
3. Serializable schedule – non serial to serializable
• graph has a pair G = (V, E), where V consists a set of vertices, and E
consists a set of edges
• all edges Ti ->Tj , hold one of three conditions:
• Create a node Ti → Tj if Ti executes write (Q) before Tj executes read (Q).
• Create a node Ti → Tj if Ti executes read (Q) before Tj executes write (Q).
• Create a node Ti → Tj if Ti executes write (Q) before Tj executes write (Q).
Conflict Serializable Schedule
• e.g.; If a person has credited $500000 to his account, bank can’t say that
the update has been lost. To avoid this problem, multiple copies of
database are stored at different locations.
UNIT 5 – PART 2
Concurrency control techniques
• Concurrency Control is the management procedure that is required
for controlling concurrent execution of the operations that take place
on a database.
• Concurrency Control in Database Management System is a procedure
of managing simultaneous operations without conflicting with each
other.
• It ensures that Database transactions are performed concurrently
and accurately to produce correct results without violating data
integrity of the respective Database.
Problems with Concurrent Execution
• Write
• At time t2, transaction TX deducts $50 from account A that becomes $250 (only deducted and not updated/write).
• Alternately, at time t3, transaction TY reads the value of account A that will be $300 only because TX didn't update the value yet.
• At time t4, transaction TY adds $100 to account A that becomes $400 (only added but not updated/write).
• At time t6, transaction TX writes the value of account A that will be updated as $250 only, as TY didn't update the value yet.
• Similarly, at time t7, transaction TY writes the values of account A, so it will write as done at time t4 that will be $400. It means
• The dirty read problem occurs when one transaction updates an item
of the database, and somehow the transaction fails, and before the
data gets rollback, the updated database item is accessed by another
transaction. There comes the Read-Write Conflict between both
transactions.
• At time t1, transaction TX reads the value of account A, i.e., $300.
• At time t2, transaction TX adds $50 to account A that becomes $350.
• At time t3, transaction TX writes the updated value in account A, i.e., $350.
• Then at time t4, transaction TY reads account A that will be read as $350.
• Then at time t5, transaction TX rollbacks due to server problem, and the value changes back to
$300 (as initially).
• But the value for account A remains $350 for transaction TY as committed, which is the dirty read
and therefore known as the Dirty Read Problem.
Unrepeatable Read Problem (W-R Conflict)
• At time t2, transaction TY reads the value from account A, i.e., $300.
• At time t3, transaction TY updates the value of account A by adding $100 to the available balance, and then it becomes $400.
• After that, at time t5, transaction TX reads the available value of account A, and that will be read as $400.
• It means that within the same transaction T X, it reads two different values of account A, i.e., $ 300 initially, and after updation made
by transaction T , it reads $400. It is an unrepeatable read and is therefore known as the Unrepeatable read problem.
Potential problem
• Lost Updates occur when multiple transactions select the same row and update the row based on
the value selected
• Dirty read Uncommitted dependency issues occur when the second transaction selects a row
which is updated by another transaction
• Non-Repeatable Read occurs when a second transaction is trying to access the same row several
times and reads different data each time.
• Incorrect Summary issue occurs when one transaction takes summary over the value of all the
instances of a repeated data-item, and second transaction update few instances of that specific
data-item. In that situation, the resulting summary does not reflect a correct result.
Why use Concurrency method?
• The system needs to control the interaction among the concurrent transactions. This
control is achieved using concurrent-control schemes.
• Lock-Based Protocols
• Timestamp-Based Protocols
• A lock is a variable associated with a data item that describes the status of the item
with respect to the operations applied to it.
• 1.Binary Lock.
Binary Lock
• Binary lock values:
It can have only 2 states or values:
• Locked (1)
• Unlocked (0)
• If LOCK(x)=1,then x cannot be accessed by the database operation that requests the item.
• Unlock_ item
Shared/Exclusive Locks
Therefore LOCK(x) can have the above 3 possible states.
• Several transactions should be allowed to access
• The locking operations can be handled by maintaining lock table and
the item X if it is for reading purpose only. keeping track of the number of transactions holding a shared lock on
• 3. Number of reads.
• 4. Locking transactions.
• 1.read_ lock(x)
• The state of the LOCK is write locked or read locked .
• 2.write_lock(x)
• No interleaving is allowed unless the transaction started terminates
• 3.Unlock(x).
by giving the lock or the transaction is placed on a waiting queue for
the item.
Two Phase Locking
• Growing phase: In the growing phase, a new lock on the data item
may be acquired by the transaction, but none can be released.
• TS protocol ensures freedom from deadlock that means no transaction ever waits.
• But the schedule may not be recoverable and may not even be cascade- free.
Optimistic concurrency control techniques / Validation protocol
• Validation phase
• Write phase
• Read phase: In this phase, the transaction T is read and executed. It is used to read
the value of various data items and stores them in temporary local variables. It can
perform all the write operations on temporary variables without an update to the
actual database.
• Validation phase: In this phase, the temporary variable value will be validated
against the actual data to see if it violates the serializability.
• Write phase: If the validation of the transaction is validated, then the temporary
results are written to the database or system otherwise the transaction is rolled back.
Here each phase has the following different timestamps:
• Validation (Ti): It contains the time when Ti finishes its read phase and starts its
validation phase.