Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

cp4 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

DBMS Concurrency Control:

What is Concurrency Control?

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.

Concurrency Control Protocols


Different concurrency control protocols offer different benefits
between the amount of concurrency they allow and the amount
of overhead that they impose. Following are the Concurrency
Control techniques in DBMS:

Lock-Based Protocols
Two Phase Locking Protocol
Timestamp-Based Protocols
Validation-Based Protocols

Lock-based Protocols
Lock Based Protocols in DBMS is a mechanism in which a
transaction cannot Read or Write the data until it acquires an
appropriate lock

A lock is a data variable which is associated with a data item.


This lock signifies that operations that can be performed on
the data item. Locks in DBMS help synchronize access to the
database items by concurrent transactions.
Binary Locks: A Binary lock on a data item can either locked or
unlocked states.
Shared/exclusive: This type of locking mechanism separates
the locks in DBMS based on their uses. If a lock is acquired on
a data item to perform a write operation, it is called an
exclusive lock.

1. Shared Lock (S):

A shared lock is also called a Read-only lock. With the shared


lock, the data item can be shared between transactions.

For example, consider a case where two transactions are


reading the account balance of a person. The database will let
them read by placing a shared lock. However, if another
transaction wants to update that account’s balance, shared
lock prevent it until the reading process is over.

2. Exclusive Lock (X):

With the Exclusive Lock, a data item can be read as well as


written. This is exclusive and can’t be held concurrently on the
same data item. X-lock is requested using lock-x instruction.
Transactions may unlock the data item after finishing the
‘write’ operation.

For example, when a transaction needs to update the account


balance of a person. You can allows this transaction by placing
X lock on it.

Starvation

Starvation is the situation when a transaction needs to wait for


an indefinite period to acquire a lock.

Following are the reasons for Starvation:


When waiting scheme for locked items is not properly
managed
In the case of resource leak
The same transaction is selected as a victim repeatedly

Two Phase Locking Protocol

This locking protocol divides the execution phase of a


transaction into three different parts.

In the first phase, when the transaction begins to execute,


it requires permission for the locks it needs.
The second part is where the transaction obtains all the
locks. When a transaction releases its first lock, the third
phase starts.
In this third phase, the transaction cannot demand any new
locks. Instead, it only releases the acquired locks.
The Two-Phase Locking protocol allows each transaction
to make a lock or unlock request in two steps:

Growing Phase: In this phase transaction may obtain locks


but may not release any locks.
Shrinking Phase: In this phase, a transaction may release
locks but not obtain any new lock
It is true that the 2PL protocol offers serializability.
However, it does not ensure that deadlocks do not happen.

Timestamp Based Protocol


It is the most commonly used concurrency protocol
Timestamp based protocol helps DBMS to identify
transactions and determines the serializability order

It has a unique identifier where each transaction is issued


with a timestamp when it is entered into the system

This protocol uses the system time or a logical counter as


a timestamp which starts working as soon as the
transaction is created

Read timestamp :
the largest value of timestamp of transaction
which has read the value of data variable
eg initial value of read (x)=0
now for this below example
T1 timestamp=10 T2 timestamp=20 T3 timestamp=30 T4 timestamp =40

r(x)

w(X)

w(X)

W(X)

R(X)
Now transaction 4 is doing the final read over
the data variable x
so read timestamp of x will became 40

Writetimestamp for X data variable will be 30 as


highest timestamp of transaction which is doing
the read operation is 30 that is T3

Two types of Timestamp:

1. W_Timestamp(X): This represents the largest


timestamp of any transaction that executes
write(X) successfully.

2. R_Timestamp(X): This represents the largest


timestamp of any transaction that executes
Read(X) successfully.

Timestamp ordering protocol

The timestamp ordering protocol ensures that


any conflicting read and write operation are
executed in timestamp order.
Following are the two cases which describe the
work of basic timestamp ordering protocol:

1. Suppose a transaction Ti read an item (X),


check the following condition:
here are conditions which we have to check
before the execution of read operation by any
transaction
If Timestamp(Ti) < W_Timestamp(X), then the
read operation is rejected and Ti is rolled back.
here we are checking that no transaction with
lower timestamp than read timestamp is
allowed to read the data

If Timestamp(Ti) > W_Timestamp(X), then the


operation is executed.
means new transaction having greater
timestamp that read timestamp of data can read
the data variable
2. Suppose a transaction Ti write an item (X),
check the following condition:

If Timestamp(Ti) < R_Timestamp(X) then the


operation is rejected.
this means once the higher timestamped
transaction has read the data then any
transaction with lower timestamp cannot
change the data
(bade transaction ne jo read kar lia hai chota
transaction change ni kar sakta)

If Timestamp(Ti) < W_Timestamp(X) then the


write operation is rejected and Ti transaction is
rolled back otherwise, other operations are
executed.

this means once the higher timestamped


transaction has write the data then any
transaction with lower timestamp cannot
change the data

TimeStamp 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.

Validation Based Protocol


Validation phase is also known as optimistic
concurrency control technique. In the validation
based protocol, the transaction is executed in
the following three phases:
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.

. Then, we must know about the following three


time-stamps that we assigned to transaction Ti,
to check its validity:

1. Start(Ti): It is the time when Ti started its


execution.

2. Validation(Ti): It is the time when Ti just


finished its read phase and begin its validation
phase.

3. Finish(Ti): the time when Ti end it’s all writing


operations in the database under write-phase.
Two more terms that we need to know are:

1. Write_set: of a transaction contains all the


write operations that Ti performs.

2. Read_set: of a transaction contains all the


read operations that Ti performs.

1. Finish(Tj)<Starts(Ti), since Tj finishes its


execution means completes its write-phase
before Ti started its execution(read-phase).
Then the serializability indeed maintained.

2. Ti begins its write phase after Tj completes


its write phase, and the read_set of Ti should be
disjoint with write_set of Tj.

3. Tj completes its read phase before Ti


completes its read phase and both read_set and
write_set of Ti are disjoint with the write_set of
Tj.

Recoverability in DBMS
Recoverability is a property of database
systems that ensures that, in the event of a
failure or error, the system can recover the
database to a consistent state

Recoverability guarantees that all committed


transactions are durable and that their effects
are permanently stored in the database, while
the effects of uncommitted transactions are
undone to maintain data consistency.

There are several levels of recoverability that


can be supported by a database system:

No-undo logging: This level of recoverability


only guarantees that committed transactions
are durable, but does not provide the ability
to undo the effects of uncommitted
transactions.

Undo logging: This level of recoverability


provides the ability to undo the effects of
uncommitted transactions but may result in
the loss of updates made by committed
transactions that occur after the failed
transaction.
Redo logging: This level of recoverability
provides the ability to redo the effects of
committed transactions, ensuring that all
committed updates are durable and can be
recovered in the event of failure.

Undo-redo logging: This level of


recoverability provides both undo and redo
capabilities, ensuring that the system can
recover to a consistent state regardless of
whether a transaction has been committed or
not.

chapter 6
File Organization and Trends in Databases : file organizations and its types, indexing, types of
indexing, hashing, hashing techniques, introduction to big data, nosql systems

File Organization : The File is a collection of


records.
File is group of information and how we store
information in database ?- in form of records and
how we determine every single record uniquely by
the help of primary keys
now we want to store the table let us say in
harddisk so how we are going to store that table
and how we are going to access that in faster way
this we are going to learn in this chapter

File organization is used to describe the way in


which the records are stored in terms of blocks,
and the blocks are placed on the storage medium.

Objective of file organization


1> It contains an optimal selection of records, i.e.,
records can be selected as fast as possible.
2> To perform insert, delete or update transaction
on the records should be quick and easy.
3> The duplicate records cannot be induced as a
result of insert, update or delete.
4> For the minimal cost of storage, records should
be stored efficiently.

Types of file organization:


1. Sequential file organization
2. Heap file organization
3. Hash file organization
4. B+ file organization
5. Indexed sequential access method (ISAM)
6. Cluster file organization

You might also like