0% found this document useful (0 votes)
52 views

Unit4 Dbms

The document discusses a database management systems course, including its objectives, outcomes, mapping to programs and program educational objectives. It provides information on the course units, prerequisites, and evaluation scheme.

Uploaded by

Aman ANAND
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Unit4 Dbms

The document discusses a database management systems course, including its objectives, outcomes, mapping to programs and program educational objectives. It provides information on the course units, prerequisites, and evaluation scheme.

Uploaded by

Aman ANAND
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 209

Evaluation Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 1


Subject Syllabus

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 2


Subject Syllabus

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 3


Branch wise Application

DBMS can be used in :


• Finance
• Social Media Sites
• Human Resource Management
• Manufacturing
• Credit card transactions

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 4


Course Objective

• List and explain the fundamental concepts of a relational database


system
• Knowledge of DBMS, both in terms of use and
implementation/design.
• Experience with SQL and Manipulate a database using SQL
• Increased proficiency with the programming language C++.
• Experience working as part of team v Experience with analysis and
design of (DB) software
• Assess the quality and ease of use of data modeling and
diagramming tools
• Utilize a wide range of features available in a DBMS package.

Sana Anjum ACSAI-0402 and DBMS Unit-4


05/15/2024 5
Course Outcome
S. NO. Course Outcomes Blooms’
Taxonomy
K3
ACSAI040
Apply knowledge of database for real life applications.
2.1
K3, K4
ACSAI040 Apply query processing techniques to automate the
2.2 real time problems of databases.
K2, K3
ACSAI040 Identify and solve the redundancy problem in database
2.3 tables using normalization

Understand the concepts of transactions, their K2, K4


ACSAI040 processing so they will familiar with broad range of
2.4 database management issues including data integrity,
security and recovery.
ACSAI040 Design, develop and implement a small database K3, K6
2.5 project using database tools.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 6
Program Outcomes (POs)

Engineering Graduates will be able to:


1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 7


Program Outcomes (POs)

Contd..

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 8


Program Outcomes (POs)

Contd..

9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams,
and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent
and life-long learning in the broadest context of technological change.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 9


COs and POs Mapping

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

ACSAI0402.1
2 2 3 3 3 2 3 2 2 2 2 3

ACSAI0402.2
3 3 3 2 2 2 2 2 2 2 2 3

ACSAI0402.3
2 3 3 3 3 2 2 2 2 2 2 2

ACSAI0402.4
2 3 2 2 2 2 2 2 2 3 2 2

ACSAI0402.5
2 3 2 2 2 3 2 2 3 2 2 2

AVG
2.20 2.80 2.60 2.40 2.40 2.20 2.20 2.00 2.20 2.20 2.00 2.40

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 10


Program Specific Outcomes

On successful completion of graduation degree the Computer


Science & Engineering graduates will be able to:
Work as a software developer, database administrator, tester or networking
engineer for providing solutions to the real world and industrial problems. ​
PSO1:

Apply core subjects of information technology related to data structure and


algorithm, software engineering, web technology, operating system, database
and networking to solve complex IT problems. ​
PSO2:

Practice multi-disciplinary and modern computing techniques by lifelong learning


to establish innovative career.
PSO3:

Work in a team or individual to manage projects with ethical concern to be a


successful employee or employer in IT industry.
PSO4:

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 11


COs and PSOs Mapping

Program Specific Outcomes

PSO1 PSO2 PSO3 PSO4

ACSAI0402.1
3 1 3 1

ACSAI0402.2
3 1 3 1

ACSAI0402.3
3 1 3 1

ACSAI0402.4
3 1 3 1

ACSAI0402.5
3 1 3 1

AVG
3.00 1.00 3.00 1.00

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 12


Program Educational Objectives

PEO1: To have an excellent scientific and engineering breadth so as to


comprehend, analyze, design and provide sustainable solutions for
real-life problems using state-of-the-art technologies.
PEO2:To have a successful career in industries, to pursue higher
studies or to support entrepreneurial endeavors and to face global
challenges.
PEO3:To have an effective communication skills, professional attitude,
ethical values and a desire to learn specific knowledge in emerging
trends, technologies for research, innovation and product
development and contribution to society.
PEO4: To have life-long learning for up-skilling and re-skilling for
successful professional career as engineer, scientist, entrepreneur
and bureaucrat for betterment of society

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 13


Prerequisite and Recap

• There is No prerequisite for learning DBMS from scratch.


• Having knowledge of basic mathematics like - SUM,
DIFFERENCE, AVERAGE, MEAN, MEDIAN, MODE, etc will
definitely be a plus point.
• Having knowledge on Set Theory will help.
• The proper understanding of data structures (B and B+ trees)
will help you to understand the DBMS quickly.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 14


Result Analysis

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 15


Question Paper Template

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 16


Question Paper Template
SECTION – A CO

1. Attempt all parts- [10×1=10]

1-a. Question- (1)


1-b. Question- (1)
1-c. Question- (1)
1-d. Question- (1)
1-e. Question- (1)
1-f. Question- (1)
1-g. Question- (1)
1-h. Question- (1)
1-i. Question- (1)
1-j. Question- (1)

2. Attempt all parts- [5×2=10] CO

2-a. Question- (2)


2-b. Question- (2)
2-c. Question- (2)
2-d. Question- (2)
2-e. Question- (2)

SECTION – B CO

3. Answer any five of the following- [5×6=30]


3-a. Question- (6)
3-b. Question- (6)
3-c. Question- (6)
3-d. Question- (6)
3-e. Question- (6)
3-f. Question- (6)
3-g. Question- (6)
SECTION – C CO

4 Answer any one of the following- [5×10=50]

4-a. Question- (10)

4-b. Question- (10)


5. Answer any one of the following-
5-a. Question- (10)

5-b. Question- (10)


6. Answer any one of the following-
6-a. Question- (10)

6-b. Question- (10)


7. Answer any one of the following-
7-a. Question- (10)

7-b. Question- (10)

8. Answer any one of the following-


8-a. Question- (10)

8-b. Question- Sana Anjum ACSAI-0402 and DBMS (10)

Unit-4

05/15/2024 17
Brief Introduction about the Subject

1. A database management system (DBMS) refers to the


technology for creating and managing databases. DBMS is a
software tool to organize (create, retrieve, update, and manage)
data in a database.

2. The main aim of a DBMS is to supply a way to store up and


retrieve database information that is both convenient and
efficient. By data, we mean known facts that can be recorded
and that have embedded meaning.

3. Usually, people use software such as DBASE IV or V, Microsoft


ACCESS, or EXCEL to store data in the form of a database. A
datum is a unit of data. Meaningful data combined to form
information. Hence, information is interpreted data - data
provided with semantics. MS. ACCESS is one of the most
common examples of database management software.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 18
Branch wise Application

DBMS can be used in :


• Finance
• Social Media Sites
• Human Resource Management
• Manufacturing
• Credit card transactions

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 19


Content - Unit 4

Transaction Processing Concept: Transaction system, Testing of


serializability, serializability of schedules, conflict & view serializable
schedule, recoverability, Recovery from transaction failures, log based
recovery, checkpoints, deadlock handling.

Control Concurrency Techniques: Concurrency Control, Locking


Techniques for concurrency control, Time stamping protocols for
concurrency control, Validation-based protocol, Multiplegranularity, Multi
version schemes, Recovery with concurrent transaction, Case study of
Oracle.

Distributed Database: distributed data storage, concurrency


control, directory system.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 20


Topic Objective

1. 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.
2. Concurrency control is the activity of coordinating the
simultaneous execution of transactions in a multiprocessing
or multi-user database management system. The objective of
concurrency control is to ensure the serializability of
transactions in a multi-user database management system.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 21


Topic – Transaction and its Property
Objective

1. The DBMS is used to schedule the access of data


concurrently.

2. It means that the user can access multiple data from


the database without being interfered with each other.

3. Transactions are used to manage concurrency.

4. It is also used to satisfy ACID properties.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 22
Unit-4
Topic mapping with CO

Topic CO
Transaction system CO4

Testing of serializability, Serializability of schedules CO4


Conflict &View serializable schedule, CO1
Recoverability, Recovery from transaction failures CO1
Log based recovery, Checkpoints CO1
Deadlock handling CO1
Control Concurrency Techniques: Concurrency CO1
Control, Locking Techniques for concurrency control
Time stamping protocols for concurrency control CO1
Validation-based protocol CO1
Multiplegranularity CO1
Multi version schemes CO1
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 23
Topic mapping with CO

Topic CO
Recovery with concurrent transaction, Case study of Oracle CO1
Distributed Database: -Introduction Distributed Database CO1
Centralized and Distributed System Database System. CO1

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 24


Transaction

Goal :- Understand the basic properties of a transaction and


learn the concepts underlying transaction processing as well
as the concurrent executions of transactions.
A transaction is a unit of a program execution that accesses
and possibly modifies various data objects (tuples, relations).
Or
 Collections of operations that form a single logical unit of work are
called transactions.
 A database system must ensure proper execution of transactions
despite failures — either the entire transaction executes, or none of
it does.
Transaction Operations are :- Read (),Write ();

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 25


Example

E.g., transaction to transfer $50 from account A to account B:


1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Two main issues to deal with:
– Failures of various kinds, such as hardware failures and system
crashes
– Concurrent execution of multiple transactions

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 26


Required Properties of a Transaction

To preserve the integrity of data the database system must


ensure ACID Properties.

ACID Properties are :-


1. Atomicity
2. Durability
3. Consistency
4. Isolation

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 27


ACID Properties

1. Atomicity. Either all operations of the transaction are properly reflected


in the database or none are.
2. Consistency. Execution of a transaction in isolation preserves the
consistency of the database. The database must be consistent before and
after the transaction.
3. Isolation. Although multiple transactions may execute concurrently,
each transaction must be unaware of other concurrently executing
transactions. Multiple transactions occur independently without
interference.
That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj,
finished execution before Ti started, or Tj started execution after Ti finished.
4. Durability. After a transaction completes successfully, the changes it has
made to the database persist, even if there are system failures.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 28


Example of Fund Transfer

• Transaction to transfer $50 from account A to account B:


1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
• Atomicity requirement
– if the transaction fails after step 3 and before step 6, money will be “lost”
leading to an inconsistent database state
• Failure could be due to software or hardware
– the system should ensure that updates of a partially executed transaction are
not reflected in the database
• Durability requirement — once the user has been notified that the transaction has
completed (i.e., the transfer of the $50 has taken place), the updates to the
database by the transaction must persist even if there are software or hardware
failures.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 29
Example of Fund Transfer
• Transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Consistency requirement in above example:
– the sum of A and B is unchanged by the execution of the transaction
• In general, consistency requirements include
• Explicitly specified integrity constraints such as primary keys and foreign
keys
• Implicit integrity constraints
– e.g. sum of balances of all accounts, minus sum of loan amounts
must equal value of cash-in-hand
– A transaction must see a consistent database.
– During transaction execution the database may be temporarily inconsistent.
– When the transaction completes successfully the database must be
consistent
• Erroneous transaction logic can lead to inconsistency
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 30
Example of Fund Transfer

• Isolation requirement — if between steps 3 and 6, another transaction T2


is allowed to access the partially updated database, it will see an
inconsistent database (the sum A + B will be less than it should be).
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B)
• Isolation can be ensured trivially by running transactions serially
– that is, one after the other.
• However, executing multiple transactions concurrently has significant
benefits, as we will see later.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 31


Transaction State
 Active – the initial state; the transaction stays in this state while it is
executing
 Partially committed – after the final statement has been executed.
 Failed -- after the discovery that normal execution can no longer
proceed.
 Aborted – after the transaction has been rolled back and the
database restored to its state prior to the start of the transaction.
Two options after it has been aborted:
 Restart the transaction
o can be done only if no internal logical error
 Kill the transaction
 Committed – after successful completion.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 32


Transaction State Diagram

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 33


Concurrent Executions

Multiple transactions are allowed to run concurrently in the system.


Advantages are:-
– Increased processor and disk utilization, leading to better
transaction throughput
• E.g. one transaction can be using the CPU while another is
reading from or writing to the disk.

– Reduced average response time for transactions: short


transactions need not wait behind long ones.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 34


Concurrent Executions

Challenges:-
Concurrency Control: How do the DBMSs handle
concurrent transactions?
Crash Recovery: How do the DBMSs handle partial
transactions because of machine crashes or users abort the
transactions ?

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 35


Short Quiz

1. A transaction is delimited by statements (or function calls) of the form

a) Begin transaction and end transaction


b) Start transaction and stop transaction
c) Get transaction and post transaction
d) Read transaction and write transaction

2. Identify the characteristics of transactions


a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 36
Unit-4
Short Quiz

2. An operation is part of a transaction if it is ___ related.


1. Logically
2. Analytically
3. Reasonably
4. None

3. To access the contents of the database, ___ user performs


transactions.
5. Single
6. Two
7. Three
8. Multiple

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 37


Topic – Schedule Objective

1. When multiple transactions are running concurrently then


there needs to be a sequence in which the operations are
performed because at a time only one operation can be
performed on the database. This sequence of operations is
known as Schedule.

2. Note that the main objective of serializability is to find non-


serial schedules that allow transactions to execute
concurrently without interference and produce a database
state that could be produced by a serial execution.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 38


Schedule (CO4)

We know that transactions are set of instructions and


these instructions perform operations on database.

When multiple transactions are running concurrently then


there needs to be a sequence in which the operations are
performed because at a time only one operation can be
performed on the database. This sequence of operations is
known as Schedule.

Schedule – A sequences of instructions that specify the


chronological order in which instructions of concurrent
transactions are executed.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 39


Continue…..

A schedule is a collection of many transactions which is


implemented as a unit.
Depending upon how these transactions are arranged in
within a schedule, a schedule can be of two types:-
1. Serial: The transactions are executed one after another, in a
non-preemptive manner.
2. Concurrent: The transactions are executed in a preemptive,
time shared method.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 40


Types of Schedules in DBMS

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 41


Types of Schedules in DBMS
1. Serial Schedule:- In Serial schedule, a transaction is
executed completely before starting the execution of another
transaction. In other words, you can say that in serial
schedule, a transaction does not start execution until the
currently running transaction finished execution. This type of
execution of transaction is also known as non-
interleaved execution.
2. Non Serial Schedule :- In a non-serial Schedule, multiple
transactions execute concurrently/simultaneously. In the Non-
Serial Schedule, the other transaction proceeds without the
completion of the previous transaction. All the transaction
operations are interleaved
Note:- The transactions are executed in a non-serial manner,
keeping the end result correct and same as the serial
schedule.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 42
Schedule 1: serial schedule

• Let T1 transfer 50 from A to B, and T2 transfer 10% of the balance


from A to B.
• A serial schedule in which T1 is followed by T2 :-

• In this example, the transaction T2 does not start execution until


the transaction T1 is finished.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 43
Serial schedule

Schedule 1: serial schedule :-


T2 is a new transaction which deposits to account B 10% of
the amount in account A. If we prepare a serial schedule, then
either T1 will completely finish before T2 can begin, or T2
will completely finish before T1 can begin.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 44


Schedule 2: serial schedule

A serial schedule where T2 is followed by T1

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 45


Schedule 3: non serial schedule

 However, if we want to create a concurrent schedule, then


some Context Switching need to be made, so that some
portion of T1 will be executed, then some portion of T2 will
be executed and so on.

 Let T1 and T2 be the transactions defined previously. The


following schedule is not a serial schedule, but it is equivalent
to Schedule 1.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 46


Schedule 3: non serial schedule

In Schedules 1, 2 and 3, the sum A + B is preserved.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 47


Schedule 4: non serial schedule

The following concurrent schedule does not preserve the


value of (A + B ).

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 48


Short Quiz

1. I and J are _________ if they are operations by different transactions


on the same data item, and at least one of them is a write operation.
a) Conflicting
b) Overwriting
c) Isolated
d) Durable

2. A schedule is __________ if it is conflict equivalent to a serial


schedule.
a) Conflict serializable
b) Conflicting
c) Non serializable
d) None of the mentioned

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 49
Unit-4
Problems in Concurrent Transactions

• Dirty Read/ Un-commited Read/ Read After


Write (RAW)
• Unrepeatable Read
• Phantom Read
• Lost Update/ Write-Write Conflict
• Incorrect Summary

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 50


Short Quiz

3. The ___ schedule is a type of schedule where one transaction is


executed completely before starting another transaction.
1. Serial
2. Non-serial
3. Serializable
4. Non-serializable

4. A non-serial schedule would result if ___ is allowed.


5. Leaving
6. Inter-leaving
7. Intra-leaving
8. None of the above

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 51
Unit-4
Topic – Serializability Objective

1. The main objective of serializability is to find non-serial


schedules that allow transactions to execute concurrently
without interference and produce a database state that
could be produced by a serial execution.

2. Serializability helps preserve the consistency and


concurrency of a database. There are 2 methods widely
used to check serializability i.e. Conflict equivalent and
View equivalent.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 52
Unit-4
Serializability

• In the above example 4, we detected the error simple by examining


the schedule and applying common sense .But there must be some
well formed rules regarding how to arrange instructions of the
transactions to create error free concurrent schedules.
• When multiple transactions are running concurrently then there is a
possibility that the database may be left in an inconsistent state.

Serializability is a concept that helps us to check which schedules are


serializable. A serializable schedule is the one that always leaves the
database in consistent state.

• A serial schedule is always a serializable schedule because in serial


schedule, a transaction only starts when the other transaction
finished execution.
• However a non-serial schedule needs to be checked for Serializability.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 53
Serializability
A non-serial schedule of n number of transactions is said to be serializable
schedule, if it is equivalent to the serial schedule of those n transactions.
A serial schedule doesn’t allow concurrency, only one transaction
executes at a time and the other starts when the already running
transaction finished.
 Basic Assumption – Each transaction preserves database consistency.
 Thus serial execution of a set of transactions preserves database
consistency.
Note :- A schedule is serializable if it is equivalent to a serial schedule.
There are Two type of Serializability : -
1. conflict serializability: A non serial schedule is converted into serial
schedule by swapping non conflicting operations then it is known as
conflict serializable schedule.
2. view serializability:- If a schedule is view equivalent to its serial
schedule then the given schedule is said to be View Serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 54


Conflict Serializability
• A schedule is called conflict serializable if after swapping of non-
conflicting operations, it can transform into a serial schedule.
• The schedule will be a conflict serializable if it is conflict equivalent
to a serial schedule.
• Two instructions of two different transactions may want to access
the same data item in order to perform a read/write operation.
Conflict Serializability deals with detecting whether the instructions
are conflicting in any way, and specifying the order in which these
two instructions will be executed in case there is any conflict.
A conflict arises if at least one (or both) of the instructions is a
write operation.
i. TI R(x)= T2R(x)// non Conflict
ii. TI R(x)= T2W(x)//Conflict
iii. TI W(x)= T1R(x)//Conflict
iv. TI W(x)= T2W(x)//Conflict
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 55
Rules for Conflict Serializability

The following rules are important in Conflict Serializability:


1. If two instructions of the two concurrent transactions are
both for read operation, then they are not in conflict, and
can be allowed to take place in any order.
2. If one of the instructions wants to perform a read operation
and the other instruction wants to perform a write operation,
then they are in conflict, hence their ordering is important. If
the read instruction is performed first, then it reads the old
value of the data item and after the reading is over, the new
value of the data item is written. It the write instruction is
performed first, then updates the data item with the new
value and the read instruction reads the newly updated value.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 56


Conflict Serializability

3. If both the transactions are for write operation, then they are
in conflict but can be allowed to take place in any order,
because the transaction do not read the value updated by
each other. However, the value that persists in the data item
after the schedule is over is the one written by the instruction
that performed the last write.
Finally we can say:-
Two instruction/operation are said to be in conflict Operation,
if they satisfy all the following three conditions:-
1. Two operation are set of conflicting when they should
belong to different transactions.
2. Both the instruction are working on same data item.
3. At least one of the instruction is a write instruction.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 57
Conflict Equivalent Schedules

• Two schedules are said to be conflict Equivalent if one


schedule can be converted into other schedule after swapping
non-conflicting operations.
Two schedules are said to be conflict equivalent if and only if:
• They contain the same set of the transaction.
• If each pair of conflict operations are ordered in the same
way.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 58


1. Conflict Serializability

Methods for conflict Serializability are :-

1. Swapping:- A schedule is called conflict serializable if we can


convert it into a serial schedule after swapping its non-
conflicting operations.

2. precedence Graph.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 59


Conflicting and non conflicting operations
Instructions li and lj of transactions Ti and Tj respectively,
conflict if and only if there exists some item Q accessed by
both li and lj, and at least one of these instructions wrote Q.

1. li = read(Q), lj = read(Q). li and lj don’t conflict.


2. li = read(Q), lj = write(Q). They conflict.
3. li = write(Q), lj = read(Q). They conflict
4. li = write(Q), lj = write(Q). They conflict

• It seem that , a conflict between li and lj forces a (logical)


temporal order between them.
– If li and lj are consecutive in a schedule and they do not
conflict, their results would remain the same even if they
05/15/2024 had been interchanged
Sana Anjum in the schedule.
ACSAI-0402 and DBMS Unit-4 60
1. Conflict Serializability (Cont.) by Swapping
Example :-
• Schedule S1 can be transformed into Schedule S2, a serial
schedule where T2 follows T1, by series of swaps of non-
conflicting instructions.
– Therefore Schedule S1 is conflict serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 61


Continue

In Non Serial Schedule S1


1. Two instruction are set of conflicting when they should
belong to different transactions. YES
2. Both the operations are working on same data item. NO
(Such case instruction are not conflict swap it)
3 . At least one of the operation is a write instruction.
(Don’t need to check because 2nd condition is
disqualified for conflict operation)
So Non Serial schedule (schedule S1) is Conflict Serializable
and also a serial schedule if this is a serial schedule maintain
the consistency of database.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 62


B. Precedence Graph

A precedence graph, also known as serialization graph or


conflict graph, is used for testing Conflict Serializability of a
schedule in the condition that forms the setting of
concurrency control in databases.
In a schedule of a precedence graph, The total number of
transactions will be similar to the total number of nodes.

Nodes: In the graph, for each transaction Tp the graph


contains a single node.
Edges: An edge is regulated connectivity between a set of two
distinct transactions Tq and Tr and it shows in the format Tq –
>Tr, where Tq is the beginning of the edge and Tr is the
ending.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 63
The Algorithm for testing Conflict Serializability of a
schedule

• Create a node T, for each transaction participating in schedule S in


the precedence graph.
• For every condition in schedule S create an edge Tp → Tq in
the precedence graph if a Transaction Tq implements a read_item
(Z) after Tp implements a write_item (Z). It's a Read-Write conflict.
• For every condition in schedule S create an edge Tp → Tq in the
precedence graph if a Transaction Tq implements a write_item
(Z) after Ti implements a read_item (Z). It's a Write-Read conflict.
• For every condition in schedule S create an edge Tp → Tq in the
precedence graph If a Transaction Tq implements a write_item
(Z) after Tp implements a write_item (Z). It's a Write-Write conflict.

• If and only if there is no cycle in the precedence graph, then the


schedule S is Serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 64


2. View Serializability

 This is another type of serializability that can be derived by


creating another schedule out of an existing schedule,
involving the same set of transactions.

 It is a type of serializability that can be used to check whether


the given schedule is view serializable or not.

 A schedule called as a view serializable if it is view equivalent


to a serial schedule.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 65


Why we need View Serializability?

We know that a serial schedule never leaves the database in


inconsistent state because there are no concurrent transactions
execution.
However a non-serial schedule can leave the database in
inconsistent state because there are multiple transactions running
concurrently. By checking that a given non-serial schedule is view
serializable, we make sure that it is a consistent schedule.

You may be wondering instead of checking that a non-serial


schedule is serializable or not, can’t we have serial schedule all the
time?
The answer is no, because concurrent execution of transactions
fully utilize the system resources and are considerably faster
compared to serial schedules.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 66
View Equivalent
Example:-

Serial Schedule of the above given schedule:

As we know that in Serial schedule a transaction only starts when the


current running transaction is finished.
If we can prove that the given schedule is View Equivalent to its serial
schedule then the given schedule is called view Serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 67


Condition of schedules to View-equivalent
Condition of schedules to View-equivalent
• Consider two schedules S1 and S2 each consisting of two transactions T1
and T2.
• Schedules S1 and S2 are called view equivalent if the following all three
conditions hold true for them-
Note:- Let us consider that the transactions T1 and T2 are being serialized
to create two different schedules S1 and S2 which we want to be View
Equivalent and both T1 and T2 wants to access the same data item.
1)Initial Read
For each data item A, if transaction Ti reads A from the database initially in
schedule S1, then in schedule S2 also, Ti must perform the initial read of A
from the database.(“Initial readers must be same for all the data items”.)

Transaction T1 is reading A from database.


05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 68
Cont…. (CO4)
2)Updated Read or intermediate read
If transaction Ti reads a data item that has been updated by the
transaction Tj in schedule S1, then in schedule S2 also, transaction Ti must
read the same data item that has been updated by the transaction Tj.

“Write-read sequence must be same.”.)


(

Above two schedule are not view-equivalent as in S1 :T3 is reading A


updated by T2, in S2 T3Sana
05/15/2024 is reading
Anjum A updated
ACSAI-0402 by T1. Unit-4
and DBMS 69
Conti……..

3)Final Write operation


For each data item A, if A has been updated at last by transaction Ti in
schedule S1, then in schedule S2 also, A must be updated at last by
transaction Ti.

“Final writers must be same for all the data items”.

Above two schedules are not view-equivalent as Final write operation in


S1 is done by T1 while in S2 done by T2.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 70


Example
Lets take an example.

Lets check the three conditions of view serializability.


1. Initial Read
• In schedule S1, transaction T1 first reads the data item X. In S2 also
transaction T1 first reads the data item X.
• Lets check for Y. In schedule S1, transaction T1 first reads the data item Y.
In S2 also the first read operation on Y is performed by T1.
• We checked for both data items X & Y and the initial read condition is
satisfied in S1 & S2.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 71


Conti….

2. Update Read
• In S1, transaction T2 reads the value of X, written by T1. In S2, the same
transaction T2 reads the X after it is written by T1.
• In S1, transaction T2 reads the value of Y, written by T1. In S2, the same
transaction T2 reads the value of Y after it is updated by T1.
• The update read condition is also satisfied for both the schedules.

3. Final Write
• In schedule S1, the final write operation on X is done by transaction T2. In
S2 also transaction T2 performs the final write on X.
• Lets check for Y. In schedule S1, the final write operation on Y is done by
transaction T2. In schedule S2, final write on Y is done by T2.
• We checked for both data items X & Y and the final write condition is
satisfied in S1 & S2.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 72


Continue…

Result:-

Since all the three conditions that checks whether the two schedules are
view equivalent are satisfied in this example, which means S1 and S2 are
view equivalent.
Also, as we know that the schedule S2 is the serial schedule of S1, thus we
can say that the schedule S1 is view serializable schedule.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 73


Checking Whether a Schedule is View Serializable Or Not-

Checking Whether a Schedule is View Serializable Or Not-


Method-01:-
Check whether the given schedule is conflict serializable or not.
 If the given schedule is conflict serializable, then it is surely view
serializable. Stop and report your answer.
 If the given schedule is not conflict serializable, then it may or may not be
view serializable. Go and check using other methods.

Note:-
1. All conflict serializable schedules are view serializable.
2. All view serializable schedules may or may not be conflict serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 74


Conti…

Method-02:
Check if there exists any blind write operation. (Writing without reading is
called as a blind write).
 If there does not exist any blind write, then the schedule is surely not view
serializable. Stop and report your answer.
 If there exists any blind write, then the schedule may or may not be view
serializable. Go and check using other methods.
Note:-
No blind write means not a view serializable schedule.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 75


Contin….

Method-03:
In this method, try finding a view equivalent serial schedule.

 Then, draw a graph using those dependencies.


 If there cycle exists in the graph, then the schedule is view serializable or
not check it.
 By using the above three conditions, write all the dependencies.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 76


Recoverability

Basic :-
• The order of execution of the transaction is called a schedule,
may it be a serial schedule or a concurrent schedule.

• Let’s say, there are 3 transactions running simultaneously


each having n, m, and k sub-operations. Then all the possible
serial schedules are 3! = 6. The number of concurrent
schedules possible = Total _ serial.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 77


Continue

Now due to this concurrency in schedules there can arise a lot of issues
such as inconsistent schedule.

Now if this inconsistency happens or there is a any crash in the system


then our schedule should be able to revert back or rollback to the original
state. Thus the concept of recoverability comes into the picture.
What is a recoverable schedule?
• A Schedule in which transactions commit only after all transactions whose
changes they read , then commit are called recoverable schedules.
• In other words, if some transaction Tj is reading value updated or written
by some other transaction Ti, then the commit of Tj must occur after the
commit of Ti.
What is Irrecoverable schedule?
Irrecoverable schedule: The schedule will be irrecoverable if Tj reads the
updated value of Ti and Tj committed before Ti commit.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 78
Example

Let us understand this with a simple example: Let’s say you are coping an
examination paper from the person sitting in front of you. Then you
should not submit/commit your paper until and unless the person in front
of you submits first. Because he may later add some more points or
change some answers which you will missout.
Example

In the above figure, S1 is not recoverable because T2 is committing before


T1 although it is reading from T1. S2 is a recoverable schedule because T1
is committing after T2 as it has read from T2.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 79
Types of Recoverable Schedule

A recoverable schedule may be any one of these kinds-

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 80


1. Cascading Schedule

Cascading Schedule-
• If in a schedule, failure of one transaction causes several other dependent
transactions to rollback or abort, then such a schedule is called as
a Cascading Schedule or Cascading Rollback or Cascading Abort.
• It simply leads to the wastage of CPU time.
Example-

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 81


Conti…..
Here,
Transaction T2 depends on transaction T1.
Transaction T3 depends on transaction T2.
Transaction T4 depends on transaction T3.
In this schedule,
The failure of transaction T1 causes the transaction T2 to rollback.
The rollback of transaction T2 causes the transaction T3 to rollback.
The rollback of transaction T3 causes the transaction T4 to rollback.
Such a rollback is called as a Cascading Rollback.
There arises a problem of cascading rollbacks, which is a rollback of a single
transaction that will lead to a rollback of many other transactions, which will lead
to less throughput and high time-consuming. Now comes the concept of
cascadeless schedule/avoiding cascading abort.
NOTE-
• If the transactions T2, T3 and T4 would have committed before the failure
of transaction T1, then the schedule would have been irrecoverable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 82


2. Cascadeless Schedule

If in a schedule, a transaction is not allowed to read a data item until the


last transaction that has written it is committed or aborted, then such a
schedule is called as a Cascadeless Schedule.

In other words,
• Cascadeless schedule allows only committed read operations.
• Therefore, it avoids cascading roll back and thus saves CPU time.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 83


Example

Example
Here no uncommitted reads are allowed. That is no dirty reads are
allowed. That is no W-R problem. Disallowing a transaction from reading
uncommitted changes from another transaction. Cascadeless schedules
are also recoverable.

In the above figure, the schedule is cascadeless because we are reading


only after a committed write. But in a cascadeless schedule, there still can
be a problem of W-W, or lost update problem.
So, to avoid that strict schedule comes into the picture.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 84
Continue

NOTE-
• Cascadeless schedule allows only committed read operations.
• However, it allows uncommitted write operations.
Example-

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 85


3. Strict Schedule

If in a schedule, a transaction is neither allowed to read nor write a data


item until the last transaction that has written it is committed or aborted,
then such a schedule is called as a Strict Schedule.
In a strict schedule if T1 performs W(A) then T2 is not allowed to R(A) or
W(A) till T1 commits/rollback. Thus, avoiding the W-W(lost-update)
problem and W-R problem. Strict schedules are cascadeless as well as
recoverable.
In other words,
• Strict schedule allows only committed read and write operations.
• Clearly, strict schedule implements more restrictions than cascadeless
schedule.
Example :-

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 86


Example

In the above figure, this schedule is strict because T2 is doing R(X) only
after committing T1. R(Y) is before commit but that is okay because it is on
different data.
Remember-
• Strict schedules are more strict than cascadeless schedules.
• All strict schedules are cascadeless schedules.
• All cascadeless schedules are not strict schedules.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 87


In addition ,

serial schedule ⊆ strict schedule ⊆ cascadeless schedule ⊆ recoverable


schedule

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 88


Failure Classification
1. Transaction failure :The transaction failure occurs when it fails to
execute or when it reaches a point from where it can't go any further. If a
few transaction or process is hurt, then this is called as transaction failure.
• Reasons for a transaction failure could be –
– Logical errors: transaction cannot complete due to some internal error
condition
– System errors: the database system must terminate an active
transaction due to an error condition (e.g., deadlock).

2. System crash: a power failure or other hardware or software failure


causes the system to crash.
– Fail-stop assumption: non-volatile storage contents are assumed to
not be corrupted by system crash
• Database systems have numerous integrity checks to prevent
corruption of disk data

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 89


Failure Classification
3. Disk failure: a head crash or similar disk failure destroys all or
part of disk storage
-Disk failure occurs due to the formation of bad sectors, disk head
crash, and unreachability to the disk or any other failure, which
destroy all or part of disk storage.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 90


Short Quiz

1. If a schedule S can be transformed into a schedule S’ by a series of


swaps of non-conflicting instructions, then S and S’ are
a) Non conflict equivalent
b) Equal
c) Conflict equivalent
d) Isolation equivalent

2. A ___________of the transactions can be obtained by finding a linear


order consistent with the partial order of the precedence graph.
a) Serializability order
b) Direction graph
c) Precedence graph
d) Scheduling scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 91


Short Quiz
3. What is TRUE about Serializable Schedule?
a) In order to find non-serial schedules, the serializability of schedules
is checked to ensure the transactions can run concurrently without
being interfered with.
b) When the executions of the transactions have interleaving of their
operations, it indicates which schedules are correct.
c) If a non-serial schedule's result equals that of its serial transactions,
it will be serializable.
d) All of the above

4. Schedules are constructed using a graph known as a ___ graph.


a) Accordance c) Serializable
b) Precedence d) Non-Serializable

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 92
Unit-4
Topic – Recovery Objective

Recovery Time Objective (RTO) is the duration of time and a


service level within which a business process must be restored
after a disaster in order to avoid unacceptable consequences
associated with a break in continuity.

Transaction Recovery is an application recovery whereby the


effects of specific transactions during a specified timeframe are
removed from the database. ... User errors and application
failures are the most common causes of problems requiring
recovery, and therefore, the primary cause for system
unavailability.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 93


Recovery
The techniques used to recover the lost data due to system crash,
transaction errors, viruses, catastrophic failure, incorrect commands
execution etc. are database recovery techniques.

Example :-
Consider transaction Ti that transfers $50 from account A to account B
– Two updates: subtract 50 from A and add 50 to B
Transaction Ti requires updates to A and B to be output to the database.
– A failure may occur after one of these modifications have been made
but before both of them are made.
– Modifying the database without ensuring that the transaction will
commit may leave the database in an inconsistent state.
– Not modifying the database may result in lost updates if failure occurs
just after transaction commits.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 94
Data Access
Physical blocks are those blocks residing on the disk.
Buffer blocks are the blocks residing temporarily in main
memory.
Block movements between disk and main memory are
initiated through the following two operations:
– input(B) transfers the physical block B to main memory.
– output(B) transfers the buffer block B to the disk, and
replaces the appropriate physical block there.
We assume, for simplicity, that each data item fits in, and is
stored inside, a single block.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 95


Example of Data Access

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 96


Recovery and Atomicity
To ensure atomicity despite failures, we first output information describing
the modifications to stable storage without modifying the database itself.
Stable storage:
– To implement stable storage, we need to replicate the needed
information on several nonvolatile media with independent failure
modes and to update the information in a controlled manner to
ensure that failure during data transfer does not damage the needed
information.

shadow-copy

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 97


Types of Recovery (CO4)
There are two method of Recovery

1. Log-Based Recovery
2. Shadow Paging

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 98


1. Log-Based Recovery
 Recovery techniques are heavily dependent upon the existence of a
special file known as a system log.
 It contains information about the start and end of each transaction and
any updates which occur in the transaction. The log keeps track of all
transaction operations that affect the values of database items.

 The log is a sequence of records. Log of each transaction is maintained in


some stable storage so that if any failure occurs, then it can be recovered
from there.
 If any operation is performed on the database, then it will be recorded in
the log.But the process of storing the logs should be done before the
actual transaction is applied in the database.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 99


Continue
Procedure :-

• A log is kept on stable storage.


– The log is a sequence of log records, and maintains a record of update
activities on the database.
• When transaction Ti starts, it registers itself by writing a
<Ti start>log record
• Before Ti executes write(X), a log record
<Ti, X, V1, V2>
is written, where V1 is the value of X before the write (the old value), and
V2 is the value to be written to X (the new value).
• When Ti finishes it last statement, the log record <Ti commit> is written.

Two approaches using logs


– Immediate database modification
– Deferred database modification
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 100
A. Immediate Database Modification
The Immediate modification technique occurs if database modification
occurs while the transaction is still active.
In this technique, the database is modified immediately after every
operation. It follows an actual database modification.
Example :-
Let's assume there is a transaction to modify the City of a student. The
following logs are written for this transaction.
When the transaction is initiated, then it writes 'start' log.
• <Tn, Start>
When the transaction modifies the City from 'Noida' to 'Bangalore', then
another log is written to the file.
<Tn, City, 'Noida', 'Bangalore' >
When the transaction is finished, then it writes another log to indicate the
end of the transaction.
<Tn, Commit>

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 101


B. Deferred Database Modification
• The deferred modification technique occurs if the transaction does not
modify the database until it has committed.
• In this method, all the logs are created and stored in the stable storage,
and the database is updated when a transaction commits.
Or
• The deferred-modification scheme performs updates to buffer/disk only
at the time of transaction commit

– Simplifies some aspects of recovery


– But has overhead of storing local copy

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 102


Short Quiz

1. State true or false: If I = read(Q) and J = read(Q) then the order


of I and J does not matter.
a) True
b) False

2. State true or false: If I = read(Q) and J = write(Q) then the order


of I and J does not matter.
a) True
b) False

3. A ___________of the transactions can be obtained by finding a


linear order consistent with the partial order of the precedence
graph.
a) Serializability order
b) Direction graph
c) Precedence graph
d) Scheduling scheme
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 103
Topic – Shadow Paging Objective

1. Shadow paging is one of the techniques that is used to


recover from failure. We all know that recovery means
to get back the information, which is lost. It helps to
maintain database consistency in case of failure.

2. The general idea in shadow paging is that existing data


is never overwritten, but instead modified pages are
always written to new locations on disk, and a mapping
is used to keep track of the current location of each
page.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 104


2. Shadow Paging
Shadow paging is an alternative to log-based recovery; this scheme is
useful if transactions execute serially
• Idea: maintain two page tables during the lifetime of a transaction –the
current page table, and the shadow page table
• Store the shadow page table in nonvolatile storage, such that state of the
database prior to transaction execution may be recovered.
– Shadow page table is never modified during execution
• To start with, both the page tables are identical. Only current page table is
used for data item accesses during execution of the transaction.
• Whenever any page is about to be written for the first time
– A copy of this page is made onto an unused page.
– The current page table is then made to point to the copy
– The update is performed on the copy

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 105


Sample Page Table

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 106


Shadow Paging advantage and Disadvantages

• Advantages of shadow-paging over log-based schemes


– no overhead of writing log records
– recovery is trivial
Disadvantages :
– Copying the entire page table is very expensive
• Can be reduced by using a page table structured like a B+-tree
– No need to copy entire tree, only need to copy paths in the
tree that lead to updated leaf nodes
– Commit overhead is high even with above extension
• Need to flush every updated page, and page table
– Data gets fragmented (related pages get separated on disk)
– After every transaction completion, the database pages containing old
versions of modified data need to be garbage collected
– Hard to extend algorithm to allow transactions to run concurrently
• Easier to extend log based schemes

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 107


Topic- Checkpoints Objective

1. Checkpoint is a mechanism where all the previous logs


are removed from the system and stored permanently
in a storage disk.

2. Checkpoint declares a point before which the DBMS


was in consistent state, and all the transactions were
committed.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 108


Checkpoint
 Problems in recovery procedure as discussed earlier :
1. searching the entire log is time-consuming
2. we might unnecessarily redo transactions which have already output
their updates to the database.
 The checkpoint is like a bookmark. While the execution of the transaction,
such checkpoints are marked, and the transaction is executed then using
the steps of the transaction, the log files will be created.

 When it reaches to the checkpoint, then the transaction will be updated


into the database, and till that point, the entire log file will be removed
from the file. Then the log file is updated with the new step of transaction
till next checkpoint and so on.

 The checkpoint is used to declare a point before which the DBMS was in
the consistent state, and all transactions were committed.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 109


Recovery using Checkpoint

In the following manner, a recovery system recovers the database from this
failure:-

Example :-

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 110


Why do we need Checkpoints ?

 Whenever transaction logs are created in a real-time environment,


it eats up lots of storage space. Also keeping track of every update and its
maintenance may increase the physical space of the system.

 Eventually, the transaction log file may not be handled as the size
keeps growing. This can be addressed with checkpoints.

 The methodology utilized for removing all previous transaction logs


and storing them in permanent storage is called a Checkpoint.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 111


Short Quiz

Which of the following scenarios may lead to an


irrecoverable error in a database system ?

A. A transaction writes a data item after it is read by an


uncommitted transaction
B. A transaction reads a data item after it is read by an
uncommitted transaction
C. A transaction reads a data item after it is written by a
committed transaction
D. A transaction reads a data item after it is written by
an uncommitted transaction

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 112


Short Quiz

• It is shown that the precedence graph has a pair G = (V, E), where
V and E are the ___, respectively.
1. Edges
2. Vertices
3. Edges and Vertices
4. Vertices and Edges

• All the transactions participating in the ___ are represented by the


set of vertices in the precedence graph.
1. Set
2. Schedule
3. System
4. Serial
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 113
Unit-4
Topics- Deadlock

1. In computer science, deadlock prevention algorithms are


used in concurrent programming when multiple processes
must acquire more than one shared resource.

2. A deadlock prevention algorithm organizes resource usage


by each process to ensure that at least one process is
always able to get all the resources it needs.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 114


Deadlock
What is Deadlock?
A system is in a deadlock state if there exists a set of transactions such
that every transaction in the set is waiting for another transaction in the
set.
None of the transaction can make progress in such a situation. The only
remedy to this undesirable condition is for system to invoke some drastic
action, such as rolling back some of the transactions involved in the
deadlock.

There are two methods for dealing with deadlock


1.Deadlock Prevention.
2.Deadlock detection & Recovery

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 115


Deadlock
What is Deadlock?
A system is in a deadlock state if there exists a set of transactions such
that every transaction in the set is waiting for another transaction in the
set.
None of the transaction can make progress in such a situation. The only
remedy to this undesirable condition is for system to invoke some drastic
action, such as rolling back some of the transactions involved in the
deadlock.
There are four condition simultaneously hold for deadlock
a. Mutual Exclusion
b. Hold and wait
c. No Preemption
d. Circular wait

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 116


1. Deadlock Prevention

Deadlock Prevention:- This protocol ensure that the system is not goes
deadlock state
There are two approaches to deadlock prevention.

1. One approach ensures that no cyclic waits can occur by ordering the requests
for locks.

2. Second Approach is the rollback of transaction. The simplest scheme under


the first approach requires that each transaction locks all its data before
execution. Moreover, either all are locked or none.

Another Approach for preventing deadlocks is to impose an ordering of all


data items, and to require that transaction lock data items in sequence.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 117


Preemption-Prevention to Deadlock

The second approach for prevention of deadlock is preemption and


transaction rollback.
In preemption, when a transaction T2 requests a lock that transaction T1
holds, the lock granted to T1 may be preempted by rolling back of T1 and
granting of lock to T2.

Two different deadlock prevention Technique using Timestamps

1.Wait-Die Scheme
2.Wound-Wait Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 118


Preemption-Prevention to Deadlock

Wait-Die scheme
• In this scheme, if a transaction requests for a resource which is already held
with a conflicting lock by another transaction then the DBMS simply checks
the timestamp of both transactions. It allows the older transaction to wait
until the resource is available for execution.

• Let's assume there are two transactions Ti and Tj and let TS(T) is a timestamp
of any transaction T. If T2 holds a lock by some other transaction and T1 is
requesting for resources held by T2 then the following actions are performed
by DBMS:-

• Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held some
resource, then Ti is allowed to wait until the data-item is available for
execution. That means if the older transaction is waiting for a resource which
is locked by the younger transaction, then the older transaction is allowed to
wait for resource until it is available.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 119
Preemption-Prevention to Deadlock

B. Wound wait scheme


• In wound wait scheme, if the older transaction requests for a resource which
is held by the younger transaction, then older transaction forces younger one
to kill the transaction and release the resource. After the minute delay, the
younger transaction is restarted but with the same timestamp.

• If the older transaction has held a resource which is requested by the


Younger transaction, then the younger transaction is asked to wait until older
releases it.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 120


Deadlock Detection

Deadlocks can be described precisely in terms of a directed Graph called


wait-for Graph.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 121


Recovery From Deadlock
When a detection algorithm determines that a dead lock exist, the system must
recover from the deadlock.

The most common solution is to rollback the transaction to break the


deadlock. The following three actions should be taken: -

1.Selection Of Victim:- Given a set of deadlocked transactions, we should


determine which transaction to rollback to break the deadlock. Following should
be kept in mind for determining the roll back of transaction

a)How many data items the transaction has used?


b)How many more data items the transaction needs for it to complete?
c)How many transactions will be involved in rollback?

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 122


Conti…..

b)Rollback :- Once we have decided that a particular transaction must be


rolled back, we must determine how far this transaction should be rolled back.
The simplest solution is total roll back. Abort the transaction and restart it.
However it is efficient to roll back the transaction to break the deadlock. The
deadlock detection mechanism should decide which locks the selected
transaction needs to release in order to break the deadlock.
c)Starvation:- In a system where the selection of victims is based primarily on
cost factors. It may happen that the same transaction is always picked as a
victim.
As a result, the transaction never completes its designated task,thus there is a
transaction. We must be ensure that a particular transaction is rolled back for
finite times.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 123


Remote Backup Systems

Remote backup systems provide high availability by allowing transaction


processing to continue even if the primary site is destroyed.

Figure:- Remote Backup Systems

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 124


Remote Backup Systems (Cont.)
• Detection of failure: Backup site must detect when primary site has failed
– to distinguish primary site failure from link failure maintain several
communication links between the primary and the remote backup.
– Heart-beat messages
• Transfer of control:
– To take over control backup site first perform recovery using its copy of
the database and all the long records it has received from the primary.
• Thus, completed transactions are redone and incomplete
transactions are rolled back.
– When the backup site takes over processing it becomes the new
primary
– To transfer control back to old primary when it recovers, old primary
must receive redo logs from the old backup and apply all updates
locally.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 125


Conti…..
Time to recover: To reduce delay in takeover, backup site periodically
processes the redo log records (in effect, performing recovery from
previous database state), performs a checkpoint, and can then delete
earlier parts of the log.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 126


Short Quiz
1. A system is in a ______ state if there exists a set of transactions such that
every transaction in the set is waiting for another transaction in the set.

A. Idle
B. Waiting
C. Deadlock
D. Ready

The deadlock state can be changed back to stable state by using _____________
statement.

A. Commit
B. Rollback
C. Savepoint
D. Deadlock

What are the ways of dealing with deadlock ?


A. Deadlock prevention
B. Deadlock recovery
C. Deadlock detection
D. All of the mentioned Sana Anjum ACSAI-0402 and DBMS
05/15/2024 127
Unit-4
Concurrency Control (CO5)

• A database must provide a mechanism that will ensure that


all possible schedules are
– either conflict or view serializable, and
– are recoverable and preferably cascadeless
• A policy in which only one transaction can execute at a time
generates serial schedules, but provides a poor degree of
concurrency
– Are serial schedules recoverable/cascadeless?
• Testing a schedule for serializability after it has executed is a
little too late!
• Goal – to develop concurrency control protocols that will
assure serializability.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 128


Concurrency Control Techniques (CO5)

• Concurrency Control
it is process of managing simultaneous execution of
transaction in a shared database to ensure the serializability of
transaction.

• Purpose of Concurrency Control


– To enforce Isolation
– To preserve database consistency
– To resolve the read write or write – write conflicts.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 129


Concurrency Control Techniques (CO5)

Concurrency Control Techniques

• Time Stamping Protocol


• Lock Based Protocol
– 2PL (2Phase Locking)
– Graph Based Approach
• Validation Based Protocol

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 130


Timestamp-Based Protocols

• Each transaction is issued a timestamp when it enters the


system. If an old transaction Ti has time-stamp TS(Ti), a new
transaction Tj is assigned time-stamp TS(Tj) such that TS(Ti)
<TS(Tj).
• The protocol manages concurrent execution such that the
time-stamps determine the serializability order.
• In order to assure such behavior, the protocol maintains for
each data Q two timestamp values:
– W-timestamp(Q) is the largest time-stamp of any transaction that
executed write(Q) successfully.
– R-timestamp(Q) is the largest time-stamp of any transaction that
executed read(Q) successfully.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 131
Timestamp-Based Protocols (Cont.)
• The timestamp ordering protocol ensures that any
conflicting read and write operations are executed in
timestamp order.
• Suppose a transaction Ti issues a read(Q)
1. If TS(Ti) < W-timestamp(Q), then Ti needs to read a value of
Q that was already overwritten. (swapping of conflicting
pairs)
 Hence, the read operation is rejected, and Ti is rolled back.

2. If TS(Ti)  W-timestamp(Q), then the read operation is


executed, and R-timestamp(Q) is set to max(R-
timestamp(Q), TS(Ti)).

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 132


Timestamp-Based Protocols (Cont.)
• Suppose that transaction Ti issues write(Q).
1. If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is
producing was needed previously, and the system assumed
that that value would never be produced. (swapping of
conflicting pairs)
 Hence, the write operation is rejected, and Ti is rolled back.

2. If TS(Ti)  W-timestamp(Q), then Ti is attempting to write


an obsolete value of Q. (swapping of conflicting pairs)
 Hence, this write operation is rejected, and Ti is rolled back.
3. Otherwise, the write operation is executed, and W-
timestamp(Q) is set to TS(Ti).

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 133


Timestamp-Based Protocols (Cont.)
• A partial schedule for several data items for transactions with
• timestamps 1, 2, 3, 4, 5

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 134


Thomas’ Write Rule
• Modified version of the timestamp-ordering protocol in
which obsolete write operations may be ignored under
certain circumstances.
• When Ti attempts to write data item Q, if TS(Ti) < W-
timestamp(Q), then Ti is attempting to write an obsolete
value of {Q}.
– Rather than rolling back Ti as the timestamp ordering protocol
would have done, this {write} operation can be ignored.
• Otherwise this protocol is the same as the timestamp
ordering protocol.
• Thomas' Write Rule allows greater potential concurrency.
– Allows some view-serializable schedules that are not conflict-
serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 135


Lock-Based Protocols (CO5)

• A lock is a mechanism to control concurrent access to a


data item
– To access data item lock is acquired
– After completion of transaction lock must be released
• Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as well
as write. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is

requested using lock-S instruction.


• Lock requests are made to concurrency-control manager.
Transaction can proceed only after request is granted.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 136


Lock-Based Protocols (CO5) contd

• A locking protocol is a set of rules followed by all


transactions while requesting and releasing locks. Locking
protocols restrict the set of possible schedules.
• Lock-compatibility matrix

• A transaction may be granted a lock on an item if the


requested lock is compatible with locks already held on the
item by other transactions
• Any number of transactions can hold shared locks on an
item,
– but if any transaction holds an exclusive on the item no other
transaction may hold any lock on the item.
• If a lock cannot be granted, the requesting transaction is
made to wait till all incompatible locks held by other
05/15/2024 transactions have
Sana been
Anjum released. The lock
ACSAI-0402 and DBMS is then granted.
Unit-4 137
Lock-Based Protocols (CO5)

• Example of a transaction performing locking:


T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)

• Locking as above is not sufficient to guarantee serializability


 if A and B get updated in-between the read of A and B, the
displayed sum would be wrong.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 138


The Two-Phase Locking Protocol
• This is a protocol which ensures conflict-serializable
schedules.
• Phase 1: Growing Phase
– transaction may obtain locks
– transaction may not release locks
• Phase 2: Shrinking Phase
– transaction may release locks
– transaction may not obtain locks
• The protocol assures serializability. It can be proved that
the transactions can be serialized in the order of their lock
points (i.e. the point where a transaction acquired its final
lock).

Sana Anjum ACSAI-0402 and DBMS Unit-4


05/15/2024 139
The Two-Phase Locking Protocol (Cont.)

• Two-phase locking does not ensure freedom from


deadlocks
• Cascading roll-back is possible under two-phase locking.
To avoid this, follow a modified protocol called strict
two-phase locking. Here a transaction must hold all its
exclusive locks till it commits/aborts.
• Rigorous two-phase locking is even stricter: here all
locks are held till commit/abort. In this protocol
transactions can be serialized in the order in which they
commit.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 140


The Two-Phase Locking Protocol (Cont.)

• There can be conflict serializable schedules that cannot


be obtained if two-phase locking is used.
• However, in the absence of extra information (e.g.,
ordering of access to data), two-phase locking is needed
for conflict serializability in the following sense:

Given a transaction Ti that does not follow two-phase


locking, we can find a transaction Tj that uses two-phase
locking, and a schedule for Ti and Tj that is not conflict
serializable.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 141


Lock Conversions (CO5)

• Two-phase locking with lock conversions:


– First Phase:
– can acquire a lock-S on item
– can acquire a lock-X on item
– can convert a lock-S to a lock-X (upgrade)
– Second Phase:
– can release a lock-S
– can release a lock-X
– can convert a lock-X to a lock-S (downgrade)
• This protocol assures serializability. But still relies on
the programmer to insert the various locking
instructions.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 142
Unit-4
Pitfalls of Lock-Based Protocols
• Consider the partial schedule

Neither T3 nor T4 can make progress — executing lock-S(B) causes


T4 to wait for T3 to release its lock on B, while executing lock-
X(A) causes T3 to wait for T4 to release its lock on A.
• Such a situation is called a deadlock.
– To handle a deadlock one of T3 or T4 must be rolled back and
05/15/2024
its locks released.
Sana Anjum ACSAI-0402 and DBMS
143
Unit-4
Pitfalls of Lock-Based Protocols

• The potential for deadlock exists in most locking protocols.


Deadlocks are a necessary evil.
• Starvation is also possible if concurrency control manager is
badly designed. For example:
– A transaction may be waiting for an X-lock on an item, while
a sequence of other transactions request and are granted
an S-lock on the same item.
– The same transaction is repeatedly rolled back due to
deadlocks.
• Concurrency control manager can be designed to prevent
starvation.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 144
Unit-4
The Two-Phase Locking Protocol (Cont.)

• Problems with 2-PL,


– Cascading Aborts and Deadlocks.

• There are three categories:


– Strict 2-PL
– Rigorous 2-PL
– Conservative 2-PL

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 145
Unit-4
The Two-Phase Locking Protocol (Cont.)

Conservative 2-PL –
• Static 2-PL, this protocol requires the transaction to
lock all the items it access before the Transaction
begins execution by pre-declaring its read-set and
write-set.
 If any of the predeclared items needed cannot be locked, the
transaction does not lock any of the items, instead it waits until
all the items are available for locking.
 Conflict serializable, view serializable.
 Possibility of irrecoverable schedules, cascading rollbacks

Conservative 2-PL is Deadlock free and but it does not ensure


Strict schedule

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 146
Unit-4
The Two-Phase Locking Protocol (Cont.)

Strict-2PL
 The first phase of Strict-2PL is same as 2PL.
 After acquiring all the locks in the first phase, the
transaction continues to execute normally. But in contrast
to 2PL, Strict-2PL does not release a lock after using
it(write operation).
 Partial shrinking Phase.
 Strict-2PL holds all the locks until the commit point and
releases all the locks at a time.
 Strict-2PL does not have cascading abort as 2PL does.
• Following Strict 2-PL ensures that our schedule is:
– Recoverable
– Cascadeless
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 147
Unit-4
The Two-Phase Locking Protocol (Cont.)

Rigorous 2-PL –
 It is an improvement over 2PL protocol.
 This requires that in addition to the lock being 2-
Phase all Exclusive(X) and Shared(S) Locks held by the
transaction be released until after the Transaction
Commits.
 No shrinking phase is there in the life of transaction.
 Following Rigorous 2-PL ensures that our schedule is:
– Recoverable
– Cascadeless
– Serializability
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 148
Unit-4
Graph Based Protocol
• A lock based technique that guarantees serializability that is
not based on 2PL.
• Additional information is required, how the transactions will
use the data.
• We need an idea about the order the data items are to be
accessed.
• Partial ordering is imposed on the data items.
• Only Exclusive Locks are allowed.
• The first lock by Ti may be on any data item.
• Subsequently, a data Q can be locked by Ti only if the
parent of Q is currently locked by Ti.
• Data items can be unlocked at any time.
• Data item locked and unlocked by a transaction Ti can not
be subsequently relocked by the same transaction.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 149
Unit-4
Graph Based Protocol

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 150
Unit-4
Validation Based Protocol
Validation Based Protocol is also called Optimistic Concurrency
Control Technique. This protocol is used in DBMS (Database
Management System) for avoiding concurrency in transactions. It
is called optimistic because of the assumption it makes, i.e. very
less interference occurs, therefore, there is no need for checking
while the transaction is executed.

In this technique, no checking is done while the transaction is


been executed. Until the transaction end is reached updates in
the transaction are not applied directly to the database. All
updates are applied to local copies of data items kept for the
transaction. At the end of transaction execution, while execution of
the transaction, a validation phase checks whether any of
transaction updates violate serializability. If there is no violation of
serializability the transaction is committed and the database is
updated; or else, the transaction is updated and then restarted.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 151
Validation Based Protocol

Optimistic Concurrency Control is a three-phase protocol. The


three phases for validation based protocol:

Read Phase:
Values of committed data items from the database can be read
by a transaction. Updates are only applied to local data
versions.
Validation Phase:
Checking is performed to make sure that there is no violation of
serializability when the transaction updates are applied to the
database.
Write Phase:
On the success of the validation phase, the transaction updates
are applied to the database, otherwise, the updates are
discarded and the transaction is slowed down.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 152
Multiple Granularity Locking Scheme
• Transaction Ti can lock a node Q, using the following rules:
1. The lock compatibility matrix must be observed.
2. The root of the tree must be locked first, and may be
locked in any mode.
3. A node Q can be locked by Ti in S or IS mode only if the
parent of Q is currently locked by Ti in either IX or IS mode.
4. A node Q can be locked by Ti in X, SIX, or IX mode only if
the parent of Q is currently locked by Ti in either IX or SIX
mode.
5. Ti can lock a node only if it has not previously unlocked any
node (that is, Ti is two-phase).
6. Ti can unlock a node Q only if none of the children of Q are
currently locked by Ti.
• Observe that locks are acquired in root-to-leaf order, whereas
they are released in leaf-to-root order.
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 153
Multiple Granularity (CO4)
• Allow data items to be of various sizes and define a hierarchy of
data granularities, where the small granularities are nested within
larger ones.
• Can be represented graphically as a tree.
• When a transaction locks a node in the tree explicitly, it implicitly
locks all the node's descendents in the same mode.
• Granularity of locking (level in tree where locking is done):
– fine granularity (lower in tree): high concurrency, high locking
overhead
– coarse granularity (higher in tree): low locking overhead, low
concurrency
Reference Book :- DATABASE SYSTEM Concepts (6th Edition) Abraham
Silberschatz, Henry F. Korth, S. Sudarshan. Page No. -679-682.
For video link:-
http://www.infocobuild.com/education/audio-video-courses/computer-scienc
e/FundamentalsOfDatabaseSystems-IIT-Kanpur/lecture-42.html
https://www.youtube.com/watch?v=jm1NUBMpyVo

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 154


Example of Granularity Hierarchy

The levels, starting from the (top) level are


– database
– area
– file
– record

Figure :- Granularity hierarchy

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 155


Intention Lock Modes

• In addition to S and X lock modes, there are three additional lock


modes with multiple granularity:
– intention-shared (IS): indicates explicit locking at a lower level of
the tree but only with shared locks.
– intention-exclusive (IX): indicates explicit locking at a lower level
with exclusive or shared locks
– shared and intention-exclusive (SIX): the subtree rooted by that
node is locked explicitly in shared mode and explicit locking is
being done at a lower level with exclusive-mode locks.
• intention locks allow a higher level node to be locked in S or X mode
without having to check all descendent nodes.

For video lecture:-


https://www.youtube.com/watch?v=yIqBwxokm40&list=PLyvBGMF
YV3auVdxQ1-88ivNFpmUEy-U3M&index=35
05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 156
Multi version Concurrency Control
Technique

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 157


Multi version Concurrency Control
Technique
• Multiversion schemes keep old versions of data item to increase
concurrency.
– Multiversion Timestamp Ordering
– Multiversion Two-Phase Locking
– Snapshot isolation
• Each successful write results in the creation of a new version of the
data item written.
• Use timestamps to label versions.
• When a read(Q) operation is issued, select an appropriate version of
Q based on the timestamp of the transaction, and return the value
of the selected version.
• reads never have to wait as an appropriate version is returned
immediately.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 158


Multi version Concurrency Control
Technique
MVCC: Implementation Issues
• Creation of multiple versions increases storage
overhead
– Extra tuples
– Extra space in each tuple for storing version
information
• Versions can, however, be garbage collected
– E.g. if Q has two versions Q5 and Q9, and the
oldest active transaction has timestamp > 9,
than Q5 will never be required again

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 159


Multi version Concurrency Control
Technique

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 160


Multi version Concurrency Control Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 161


Multi version Concurrency Control Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 162


Multi version Concurrency Control Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 163


Multi version Concurrency Control Scheme

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 164


Multi version Concurrency Control Scheme

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 165
Unit-4
Short quiz

• When using this type of protocol, each transaction must obtain a


___ on the data before it can read or write it.
1. Lock
2. Protocol
3. Base
4. Transaction
• How many types of locks are there in this protocol?
1. 2
2. 3
3. 4
4. 5

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 166
Unit-4
Short quiz

• Which of the following is a type of lock?


1. Shared lock
2. Exclusive lock
3. Both A and B
4. None of the above

• What is a shared lock also known as?


1. Share-only lock
2. Read-only lock
3. Write-only lock
4. Fetch-only lock

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 167
Unit-4
Topic-Distributed Database Objective

1. The basic function of DDBMS is basically to decide which


copy of a replicated data item to access and to maintain
the consistency of copies of replicated data items.

2. The ability to recover from the individual site crashes and


from new types of failures such as failure of
communication links.

3. The main objectives of query processing in a distributed


environment is to form a high level query on a distributed
database, which is seen as a single database by the
users, into an efficient execution strategy expressed in a
low level language in local databases.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 168


What is Distributed Database?
A distributed database (DDB) is a collection of multiple, logically
interrelated databases distributed over a computer network.
A distributed database management system (DDBMS) is the software that
manages the DDB and provides an access mechanism that makes this
distribution transparent to the users.

Distributed database (DDB)

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 169


Types of Distributed Database
A DDBMS mainly classified into two types: -

1. Homogeneous Distributed database management systems:-


In a homogeneous distributed database all sites have identical software
and are aware of each other and agree to cooperate in processing user
requests. The homogeneous system is much easier to design and manage
The operating system used, at each location must be same or compatible.
The database application (or DBMS) used at each location must be same
or compatible.
2. Heterogeneous Distributed database management systems:-
In a heterogeneous distributed database different sites may use different
schema and software. In heterogeneous systems, different nodes may
have different hardware & software and data structures at various nodes
or locations are also incompatible. Different computers and operating
systems, database applications or data models may be used at each of the
locations.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 170


Conti…..
Characteristics Distributed database (DDB) are

 All sites are interconnected.


 Fragments can be replicated.
 Logically related shared data can be collected.
 Data at each and every site is controlled by the DBMS.
 Each Distributed Database Management System takes part in at
least one global application.

Functionality Distributed database (DDB) are


 Security
 Keeping track of data
 Replicated data management
 System catalog management
 Distributed transaction management
 Distributed database recovery

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 171


Advantages & Disadvantages
Advantages of Distributed database (DDB) are :-

 Less danger of a single-point failure. When one of the computers fails, the
workload is picked up by other workstations.
 Data are also distributed at multiple sites.
 The end user is able to access any available copy of the data, and an end
user's request is processed by any processor at the data location.
 Improved communications. Because local sites are smaller and located
closer to customers.
 Reduced operating costs. It is more cost effective to add workstations to a
network than to update a mainframe system.
 Faster data access, faster data processing.
 A distributed database system spreads out the systems workload by
processing data at several sites.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 172


Cont….
Disadvantages Distributed database (DDB) are

 Complexity of management and control.


 Applications must recognize data location, and they must be able to stitch
together data from various sites.
 Security.
 Increased storage and infrastructure requirements.
 Multiple copies of data has to be at different sites, thus an additional disk
storage space will be required.
 The probability of security lapses increases when data are located at
multiple sites

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 173


System Failure Modes

• Failures unique to distributed systems:


– Failure of a site.
– Loss of messages
• Handled by network transmission control protocols such as TCP-IP
– Failure of a communication link
• Handled by network protocols, by routing messages via alternative links
– Network partition
• A network is said to be partitioned when it has been split into two or
more subsystems that lack any connection between them
– Note: a subsystem may consist of a single node

• Network partitioning and site failures are generally


indistinguishable.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 174
Unit-4
Commit Protocols

• Commit protocols are used to ensure atomicity across


sites
– a transaction which executes at multiple sites must either be
committed at all the sites, or aborted at all the sites.
– not acceptable to have a transaction committed at one site
and aborted at another
• The two-phase commit (2PC) protocol is widely used
• The three-phase commit (3PC) protocol is more
complicated and more expensive, but avoids some
drawbacks of two-phase commit protocol. This
protocol is not used in practice.

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 175
Unit-4
Two Phase Commit Protocol (2PC)
• Assumes fail-stop model – failed sites simply
stop working, and do not cause any other harm,
such as sending incorrect messages to other
sites.
• Execution of the protocol is initiated by the
coordinator after the last step of the transaction
has been reached.
• The protocol involves all the local sites at which
the transaction executed
• Let T be a transaction initiated at site Si, and let
the transaction coordinator at Si be Ci
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 176
Unit-4
Phase 1: Obtaining a Decision (Voting Phase)

• Coordinator asks all participants to prepare to commit


transaction Ti.
– Ci adds the records <prepare T> to the log and forces log to
stable storage
– sends prepare T messages to all sites at which T executed
• Upon receiving message, transaction manager at site
determines if it can commit the transaction
– if not, add a record <no T> to the log and send abort T
message to Ci
– if the transaction can be committed, then:
– add the record <ready T> to the log
– force all records for T to stable storage
– send ready T message to Ci
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 177
Unit-4
Phase 2: Recording the Decision

• T can be committed of Ci received a ready T


message from all the participating sites:
otherwise T must be aborted.
• Coordinator adds a decision record, <commit T>
or <abort T>, to the log and forces record onto
stable storage. Once the record stable storage it
is irrevocable (even if failures occur)
• Coordinator sends a message to each participant
informing it of the decision (commit or abort)
• Participants take appropriate action locally.
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 178
Unit-4
Handling of Failures - Site Failure

When site Si recovers, it examines its log to determine the fate of


transactions active at the time of the failure.
• Log contain <commit T> record: txn had completed, nothing to be
done
• Log contains <abort T> record: txn had completed, nothing to be
done
• Log contains <ready T> record: site must consult Ci to determine the
fate of T.
– If T committed, redo (T); write <commit T> record
– If T aborted, undo (T)
• The log contains no log records concerning T:
– Implies that Sk failed before responding to the prepare T message from Ci
– since the failure of Sk precludes the sending of such a response,
coordinator C1 must abort T
– Sk must execute undo (T) Handling of Failures - Site Failure

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 179
Unit-4
Handling of Failures- Coordinator Failure
• If coordinator fails while the commit protocol for T is executing then
participating sites must decide on T’s fate:
1. If an active site contains a <commit T> record in its log, then T must
be committed.
2. If an active site contains an <abort T> record in its log, then T must
be aborted.
3. If some active participating site does not contain a <ready T> record
in its log, then the failed coordinator Ci cannot have decided to
commit T.
 Can therefore abort T; however, such a site must reject any
subsequent <prepare T> message from Ci
4. If none of the above cases holds, then all active sites must have a
<ready T> record in their logs, but no additional control records
(such as <abort T> of <commit T>).
 In this case active sites must wait for Ci to recover, to find
decision.
• Blocking problem: active sites may have to wait for failed coordinator to
05/15/2024
recover. Sana Anjum ACSAI-0402 and DBMS
180
Unit-4
Handling of Failures- Network Partition

• If the coordinator and all its participants remain in one partition,


the failure has no effect on the commit protocol.
• If the coordinator and its participants belong to several partitions:
– Sites that are not in the partition containing the coordinator
think the coordinator has failed, and execute the protocol to
deal with failure of the coordinator.
• No harm results, but sites may still have to wait for decision
from coordinator.
• The coordinator and the sites are in the same partition as the
coordinator think that the sites in the other partition have failed,
and follow the usual commit protocol.
• Again, no harm results

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 181
Unit-4
Daily Quiz

• What is serializability?
• What are the types of serializable schedules?
• Define recoverability.
• What do you understand by log based recovery?
• Explain concurrency control.
• What do you mean by directory system.
• What is distributed data storage?
• How do you test serializability?

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 182


Weekly Assignment

• Explain ACID properties to preserve the integrity of database. CO4


• Differentiate between conflict and view serializable schedule. CO4
• What do you mean by transaction processing? CO4
• What do you understand by distributed databases? Give the various
advantages and disadvantages of distributed database management
system. CO4
• What is a deadlock? How can a deadlock occur? Explain. CO4
• What is Log? How is it maintained? CO4
• Discuss the salient features of deferred database modification and
immediate database modification strategies in brief CO4

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 183


Faculty Video Links, Youtube & NPTEL Video Links and Online
Courses Details

• Self Made Video Link:


Youtube/other Video Links
1. https://www.youtube.com/watch?v=5ammL5KU4mo
2. https://www.youtube.com/watch?v=HAAhn--tZV8
3. https://www.youtube.com/watch?v=q6ISl9YNxoQ
4. https://www.youtube.com/watch?v=XCLA0cjk0o8&t=17s
5. https://www.youtube.com/watch?v=Yu4rIeQZOjo
6. https://www.youtube.com/watch?v=HhLhIEnsBR0
7. https://www.youtube.com/watch?v=u3-ciC_TC_k
8. https://www.youtube.com/watch?v=qH2iYtuJEwQ&t=330s
9. https://www.youtube.com/watch?v=Jw3jDTAXuAk&list=PL-zLo58JCM3BkfC_
wlAosP5VTLV9ObiW1&index=37
10. https://www.youtube.com/watch?v=IYaxn0qkzUI&t=12s
11. https://www.youtube.com/watch?v=xCxdBkFX_ww
12. https://www.youtube.com/watch?v=-r734q6sSa0

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 184


MCQ s

• In which state, the transaction will wait for the final statement has
been executed?
a) Active
b) Failed
c) Aborted
d) partially committed

• A Transaction ends
a) only when it is Committed.
b) only when it is Rolled-back
c) when it is Committed or Rolled-back
d) only when it is initialized

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 185


MCQ s

• Identify the characteristics of transactions


a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

• Consider money is transferred from (1)account-A to account-B and


(2) account-B to account-A. Which of the following form a
transaction?
a) Only 1
b) Only 2
c) Both 1 and 2 individually
d) Either 1 or 2

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 186


MCQ s

• A distributed database has which of the following advantages over a


centralized database?
a) Software cost
b) Software complexity
c) Slow Response
d) Modular growth

• An operation is part of a transaction if it is ___ related.


1. Logically
2. Analytically
3. Reasonably
4. None

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 187


MCQ s

• To access the contents of the database, ___ user performs


transactions.
1. Single
2. Two
3. Three
4. Multiple

• Which of the following is an operation of transactions?


1. Read
2. Write
3. Commit
4. All of the above

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 188
Unit-4
MCQ s

• X is read from a database and stored in a buffer in main memory


with the ___ operation.
1. Read
2. Write
3. Commit
4. Rollback

• Writing the data from the buffer back to the database is


accomplished by using the _____ operation.
1. Read
2. Write
3. Commit
4. Rollback
Sana Anjum ACSAI-0402 and DBMS
05/15/2024 189
Unit-4
Glossary Questions
1. Attempt all the parts. Pick the correct option from glossary. [CO1]
i) Atomicity ii) Consistency iii) Transactions iv) Schedules v) Concurrency control scheme
1. Collections of operations that form a single logical unit of work are called __________
2. The “all-or-none” property is commonly referred to as _________
3. Execution of translation in isolation preserves the _________ of a database
4. The execution sequences in concurrency control are termed as ________
5. The scheme that controls the interaction between executing transactions is called as
_____

2. Attempt all the parts. Pick the correct option from glossary. [CO1]
i) Consistency ii)Isolation iii) Durability iv)Timestamp v)tuple
a) The __________ data type stores date as well as time
b) _____________ ensures that the database properly changes states upon a successfully
committed transaction.
c) ________ enables transactions to operate independently of and transparent to each
other.
d) _________ ensures that the result or effect of a committed transaction persists in case
of a system failure.
e) Record is also called as a _______

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 190


Old Question Papers

• http://www.aktuonline.com/papers/btech-cs-5-sem-data-base-man
agement-system-KCS501-2020.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-KCS-501-2018-19.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-ncs-502-2017-18.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-ncs-502-2016-17.pdf

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 191


Sessional 1

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 192


Sessional 1

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 193


Conti… 2
Sessional

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 194


Sessional 2

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 195


Conti..

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 196


Conti… 3
Sessional

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 197


Old University Question Papers

05/15/2024 198
Sana Anjum ACSAI-0402 and DBMS Unit-4
University Question Papers

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 199


University Question Papers

Sana Anjum ACSAI-0402 and DBMS


05/15/2024 200
Unit-4
University Question Papers

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 201


University Question Papers

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 202


University Question Papers

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 203


University Question Papers

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 204


Expected Questions for University Exam

• What is Relational Algebra?


• Describe Integrity constraints with its types.
• Discuss the following terms (i) DDL Command (ii) DML
command.
• Write difference between Cross Join, Natural Join, left outer
join and right outer join with suitable example.
• Define constraint and its types in DBMS.
• What is relational calculus? Differentiate relational algebra
and relational calculus.
• List the data types that are allowed for SQL Attributes.
• What do you mean by Cursors in SQL?
• Define Union and Intersection using SQL.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 205


Expected Questions for University Exam
• Give the following queries in the relational algebra using the
relational schema:
student(id, name)
enrolled(id, code)
subject(code, lecturer)
– i). What are the names of students enrolled in cs3020?
– ii). Which subjects is Hector taking?
– iii). Who teaches cs1500?
– iv). Who teaches cs1500 or cs3020?
– v). Who teaches at least two different subjects?
– vi). What are the names of students in cs1500 or cs307?
– vii). What are the names of students in both cs1500 and
cs1200?

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 206


References

• Korth, Silbertz, Sudarshan,” Database Concepts”, McGraw Hill


• Date C J, “An Introduction to Database Systems”, Addision Wesley
• Elmasri, Navathe, “ Fundamentals of Database Systems”, Addision
Wesley
• O’Neil, Databases, Elsevier Pub.
• RAMAKRISHNAN"Database Management Systems",McGraw Hill
• Leon &Leon,”Database Management Systems”, Vikas Publishing
House
• Bipin C. Desai, “ An Introduction to Database Systems”, Galgotia
Publications
• Majumdar& Bhattacharya, “Database Management System”, TMH
• R.P. Mahapatra, Database Management System, Khanna
Publishing House

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 207


Recap of Unit

• Knowledge of transaction processing concept.

• Knowledge of how to recover from transaction failures.

• Knowledge of distributed database.

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 208


Thank You

05/15/2024 Sana Anjum ACSAI-0402 and DBMS Unit-4 209

You might also like