Set-B: - A Single Unit of Work

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

1}Define transaction.

Explain transaction and system concepts

2}Explain various phases in ARIES with an example.

a) 3) Explain lock management conversions 5M b) Explain multi version techniques in detail


10M
b) 4) a) Explain caching of disk blocks 5M b)Explain checkpoints in the system Explain recovery
outline and categorization of recovery algorithms. 10M

set-b
Explain in detail the role of immediate update in Recovery.
Explain with neat diagram the concept of Shadow paging Recovery algorithm

Identify and explain the deadlock detection methods in concurrency control 5m Illustrate
locking protocol detailing Strict Two-Phase Locking protocol. 10m
Detail the importance of timestamping in concurrency control 5m Demonstrate the role of
binary locks and shared locks in two phase locking 10m

Set c
Detail the importance of timestamping in concurrency control. Explain one algorithm using
this method.
What is a serial schedule? What is a serializable schedule? Illustrate Why is a serial schedule
considered correct .Illustrate Why is a serializable schedule considered correct
Explain Write-Ahead Logging, Steal/No-Steal, and Force/No-Force 10m Distinguish between
serial and interleave schedule with an example. 5m

Explain atomicity, durability, isolation 5m Explain with neat diagram the concept of
Shadow paging Recovery algorithm 10m

1`}

• A transaction is a single unit of work that can be completed on the whole or which is not
done at all.
• It is important to maintain the information about when a transaction starts, commits or
aborts.
• States of a transaction:
– Active state
– Partially committed state
– Committed state
– Failed state
– Terminated State
• A recovery manager maintains the following operations:
begin_transaction, read or write and end_transaction.
• Recovery techniques use the following operators:
Redo and Undo
State Transition Diagram that depicts the states for executing a transaction.
• It maintains the operations of all the transactions.
• By using a unique transaction id, we can identify a transaction.
• Types of log record----
[start_transaction,T]
[write_item,T,X,old_value,new_value]
[read_item,T,X]
[commit,T]
[abort,T]
• A transaction may enter into commit point when all its operations are executed successfully
and the effect of these operations on the database was recorded in the system log.
• Roll Back of transactions:
This is needed for all the transactions that has a [start_transaction,T] entry into the system log but no
entry [commit,T] of commit into the log.
• Redoing
• Force writing a transaction
• Atomicity − This property states that a transaction must be treated as an atomic unit, that is,
either all of its operations are executed or none. There must be no state in a database where
a transaction is left partially completed. States should be defined either before the execution
of the transaction or after the execution/abortion/failure of the transaction. (all or Nothing)
• Consistency − The database must remain in a consistent state after any transaction. No
transaction should have any adverse effect on the data residing in the database. If the
database was in a consistent state before the execution of a transaction, it must remain
consistent after the execution of the transaction as well. (remain same before and after)
• Durability − The database should be durable enough to hold all its latest updates even if the
system fails or restarts. If a transaction updates a chunk of data in a database and commits,
then the database will hold the modified data. If a transaction commits but the system fails
before the data could be written on to the disk, then that data will be updated once the
system springs back into action. (withstand)
• Isolation − In a database system where more than one transaction are being executed
simultaneously and in parallel, the property of isolation states that all the transactions will be
carried out and executed as if it is the only transaction in the system. No transaction will
affect the existence of any other transaction.

2}

Algorithms for Recovery and Isolation Exploiting Semantics, or ARIES is a


recovery algorithm designed to work with a no-force, steal database approach.
ARIES uses a steal/no-force approach for writing, and it is based on three concepts:
1. Write-ahead logging
2. Repeating history during redo
ARIES will retrace all actions of the database system prior to the crash to
reconstruct the database state when the crash occurred. Transactions that were
uncommitted at the time of the crash (active transactions) are undone.
3. Logging changes during undo It will prevent ARIES from repeating the
completed undo operations if a failure occurs during recovery, which causes a
restart of the recovery process.
Before describing this topic we need to elaborate some concepts:
1. Log sequence number
It refers to a pointer used to identify the log records.
2. Dirty page table
It refers to pages with their updated version placed in main memory and disk
version of it is not updated.
A table is maintained which is useful in reducing unnecessary redo operation.
3. Fuzzy checkpoints.
A new type checkpoints i.e. fuzzy checkpoints has been derived that allowed to
process new transactions alter the log has been updated without having to
update the database.
The ARIES recovery procedure consists of three main steps:
1. Analysis
The analysis step identifies the dirty (updated) pages in the buffer (Note 6), and
the set of transactions active at the time of the crash. The appropriate point in
the log where the REDO operation should start is also determined
2. REDO
The REDO phase actually reapplies updates from the log to the database.
Generally, the REDO operation is applied to only committed transactions.
However, in ARIES, this is not the case. Certain information in the ARIES log
will provide the start point for REDO, from which REDO operations are applied
until the end of the log is reached. In addition, information stored by ARIES and
in the data pages will allow ARIES to determine whether the operation to be
redone has actually been applied to the database and hence need not be
reapplied. Thus only the necessary REDO operations are applied during
recovery.
3. UNDO
During the UNDO phase, the log is scanned backwards and the operations of
transactions that were active at the time of the crash are undone in reverse
order. The information needed for ARIES to accomplish its recovery procedure
includes the log, the Transaction Table, and the Dirty Page Table. In addition,
check pointing is used. These two tables are maintained by the transaction
manager and written to the log during check pointing.

Lock-based Protocols
Lock Based Protocols in DBMS is a mechanism in which a transaction cannot Read or Write
the data until it acquires an appropriate lock. Lock based protocols help to eliminate the
concurrency problem in DBMS for simultaneous transactions by locking or isolating a
particular transaction to a single user.
A lock is a data variable which is associated with a data item. This lock signifies that operations
that can be performed on the data item. Locks in DBMS help synchronize access to the database
items by concurrent transactions.

All lock requests are made to the concurrency-control manager. Transactions proceed only once
the lock request is granted.

Binary Locks: A Binary lock on a data item can either locked or unlocked states.
Shared/exclusive: This type of locking mechanism separates the locks in DBMS based on their
uses. If a lock is acquired on a data item to perform a write operation, it is called an exclusive
lock.

1. Shared Lock (S):

A shared lock is also called a Read-only lock. With the shared lock, the data item can be shared
between transactions. This is because you will never have permission to update data on the data
item.

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

2. Exclusive Lock (X):

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

For example, when a transaction needs to update the account balance of a person. You can
allows this transaction by placing X lock on it. Therefore, when the second transaction wants to
read or write, exclusive lock prevent this operation.

3. Simplistic Lock Protocol

This type of lock-based protocols allows transactions to obtain a lock on every object before
beginning operation. Transactions may unlock the data item after finishing the ‘write’ operation.

4. Pre-claiming Locking

Pre-claiming lock protocol helps to evaluate operations and create a list of required data items
which are needed to initiate an execution process. In the situation when all locks are granted, the
transaction executes. After that, all locks release when all of its operations are over.

Starvation

Starvation is the situation when a transaction needs to wait for an indefinite period to acquire a
lock.
Following are the reasons for Starvation:

 When waiting scheme for locked items is not properly managed


 In the case of resource leak
 The same transaction is selected as a victim repeatedly

Deadlock

Deadlock refers to a specific situation where two or more processes are waiting for each other to
release a resource or more than two processes are waiting for the resource in a circular chain.

Two Phase Locking Protocol


Two Phase Locking Protocol also known as 2PL protocol is a method of concurrency control
in DBMS that ensures serializability by applying a lock to the transaction data which blocks
other transactions to access the same data simultaneously. Two Phase Locking protocol helps to
eliminate the concurrency problem in DBMS.
This locking protocol divides the execution phase of a transaction into three different parts.

 In the first phase, when the transaction begins to execute, it requires permission for the
locks it needs.
 The second part is where the transaction obtains all the locks. When a transaction
releases its first lock, the third phase starts.
 In this third phase, the transaction cannot demand any new locks. Instead, it only
releases the acquired locks.

The Two-Phase Locking protocol allows each transaction to make a lock or unlock request in
two steps:

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

In the above-given diagram, you can see that local and global deadlock detectors are searching
for deadlocks and solve them with resuming transactions to their initial states.

Strict Two-Phase Locking Method


Strict-Two phase locking system is almost similar to 2PL. The only difference is that Strict-2PL
never releases a lock after using it. It holds all the locks until the commit point and releases all
the locks at one go when the process is over.

Centralized 2PL
In Centralized 2 PL, a single site is responsible for lock management process. It has only one
lock manager for the entire DBMS.

Primary copy 2PL


Primary copy 2PL mechanism, many lock managers are distributed to different sites. After that,
a particular lock manager is responsible for managing the lock for a set of data items. When the
primary copy has been updated, the change is propagated to the slaves.

Distributed 2PL
In this kind of two-phase locking mechanism, Lock managers are distributed to all sites. They
are responsible for managing locks for data at that site. If no data is replicated, it is equivalent to
primary copy 2PL. Communication costs of Distributed 2PL are quite higher than primary copy
2PL

Timestamp-based Protocols
Timestamp based Protocol in DBMS is an algorithm which uses the System Time or Logical
Counter as a timestamp to serialize the execution of concurrent transactions. The Timestamp-
based protocol ensures that every conflicting read and write operations are executed in a
timestamp order.
The older transaction is always given priority in this method. It uses system time to determine
the time stamp of the transaction. This is the most commonly used concurrency protocol.

Lock-based protocols help you to manage the order between the conflicting transactions when
they will execute. Timestamp-based protocols manage conflicts as soon as an operation is
created.

Example:

Suppose there are there transactions T1, T2, and T3.


T1 has entered the system at time 0010
T2 has entered the system at 0020
T3 has entered the system at 0030
Priority will be given to transaction T1, then transaction T2 and lastly Transaction T3.
Advantages:

 Schedules are serializable just like 2PL protocols


 No waiting for the transaction, which eliminates the possibility of deadlocks!

Disadvantages:

Starvation is possible if the same transaction is restarted and continually aborted

Validation Based Protocol


Validation based Protocol in DBMS also known as Optimistic Concurrency Control
Technique is a method to avoid concurrency in transactions. In this protocol, the local copies of
the transaction data are updated rather than the data itself, which results in less interference
while execution of the transaction.
The Validation based Protocol is performed in the following three phases:

1. Read Phase
2. Validation Phase
3. Write Phase

Read Phase
In the Read Phase, the data values from the database can be read by a transaction but the write
operation or updates are only applied to the local data copies, not the actual database.

Validation Phase
In Validation Phase, the data is checked to ensure that there is no violation of serializability
while applying the transaction updates to the database.

Write Phase
In the Write Phase, the updates are applied to the database if the validation is successful, else;
the updates are not applied, and the transaction is rolled back.

Characteristics of Good Concurrency Protocol


An ideal concurrency control DBMS mechanism has the following objectives:

 Must be resilient to site and communication failures.


 It allows the parallel execution of transactions to achieve maximum concurrency.
 Its storage mechanisms and computational methods should be modest to minimize
overhead.
 It must enforce some constraints on the structure of atomic actions of transactions.

Recovery or shadow page recovery algorithm:

• Shadow paging is a technique for providing atomicity and durability in database systems.
• Shadow paging is a copy-on-write technique for avoiding in-place updates of pages. Instead,
when a page is to be modified, a shadow page is allocated.
• Since the shadow page has no references (from other pages on disk), it can be modified
liberally, without concern for consistency constraints, etc. When the page is ready to become
durable, all pages that referred to the original are updated to refer to the new replacement page
instead. Because the page is "activated" only when it is ready, it is atomic.
• This increases performance significantly by avoiding many writes on hotspots high up in the
referential hierarchy (e.g.: a file system superblock) at the cost of high commit latency.
Shadow paging considers:
1. The database is partitioned into fixed-length blocks referred to as PAGES.
2. Page table has n entries – one for each database page.
3. Each contain pointer to a page on disk (1 to 1st page on database and so on…).
The idea is to maintain 2 pages tables during the life of transaction.
1. The current page table
2. The shadow page table
When transaction starts, both page tables are identical
1. The shadow page table is never changed over the duration of the transaction
2. The current page table may be changed when a transaction performs a write operation.
3. All input and output operations use the current page table to locate database pages on
disk.

Advantages:
• No Overhead for writing log records.
• No Undo / No Redo algorithm.
• Recovery is faster.
Disadvantages:
• Data gets fragmented or scattered.
• After every transaction completion database pages containing old version of modified data
need to be garbage collected.
• Hard to extend algorithm to allow transaction to run concurrently.

Schedule, as the name suggests, is a process of lining the transactions and


executing them one by one. When there are multiple transactions that are
running in a concurrent manner and the order of operation is needed to be set
so that the operations do not overlap each other, Scheduling is brought into
play and the transactions are timed accordingly. The basics of Transactions
and Schedules is discussed in Concurrency Control (Introduction) ,
and Transaction Isolation Levels in DBMS  articles. Here we will discuss
various types of schedules.
Attention reader! Don’t stop learning now.  Practice GATE exam well before
the actual exam with the subject-wise and overall quizzes available in GATE
Test Series Course.
Learn all GATE CS concepts with Free Live Classes  on our youtube
channel.
1. Serial Schedules:
Schedules in which the transactions are executed non-interleaved,
i.e., a serial schedule is one in which no transaction starts until a
running transaction has ended are called serial schedules.

Example: Consider the following schedule involving two transactions


T1 and T2.
T1 T2

R(A)

W(A)

R(B)

W(B)

R(A)

R(B)

where R(A) denotes that a read operation is performed on some data


item ‘A’
This is a serial schedule since the transactions perform serially in the
order T1 —> T2
2. Non-Serial Schedule:
This is a type of Scheduling where the operations of multiple
transactions are interleaved. This might lead to a rise in the
concurrency problem. The transactions are executed in a non-serial
manner, keeping the end result correct and same as the serial
schedule. Unlike the serial schedule where one transaction must wait
for another to complete all its operation, in the non-serial schedule,
the other transaction proceeds without waiting for the previous
transaction to complete. This sort of schedule does not provide any
benefit of the concurrent transaction. It can be of two types namely,
Serializable and Non-Serializable Schedule.
The Non-Serial Schedule can be divided further into Serializable and
Non-Serializable.
a. Serializable:
This is used to maintain the consistency of the database. It
is mainly used in the Non-Serial scheduling to verify whether
the scheduling will lead to any inconsistency or not. On the
other hand, a serial schedule does not need the
serializability because it follows a transaction only when the
previous transaction is complete. The non-serial schedule is
said to be in a serializable schedule only when it is
equivalent to the serial schedules, for an n number of
transactions. Since concurrency is allowed in this case thus,
multiple transactions can execute concurrently. A
serializable schedule helps in improving both resource
utilization and CPU throughput. These are of two types:
1. Conflict Serializable:
A schedule is called conflict serializable if it can be
transformed into a serial schedule by swapping
non-conflicting operations. Two operations are said
to be conflicting if all conditions satisfy:
 They belong to different transactions
 They operate on the same data item
 At Least one of them is a write operation
2. View Serializable:
A Schedule is called view serializable if it is view
equal to a serial schedule (no overlapping
transactions). A conflict schedule is a view
serializable but if the serializability contains blind
writes, then the view serializable does not conflict
serializable.
b. Non-Serializable:
The non-serializable schedule is divided into two types,
Recoverable and Non-recoverable Schedule.
1. Recoverable Schedule:
Schedules in which transactions commit only after
all transactions whose changes they read commit
are called recoverable schedules. In other words, if
some transaction Tj is reading value updated or
written by some other transaction T i, then the
commit of Tj must occur after the commit of T i.
Example – Consider the following schedule
involving two transactions T1 and T2.

Define trigger. Explain it with an example


define cursor. Explain it with an example
) Define user defined function. Explain it with an example 5M b) Define Normalization. Explain various forms in
Normalization
a) Define procedure. Explain user defined procedure with an example 5M b) Explain algorithms
for algorithm sorting 10M

Give a set. of FDs for the relation schema R(A,B,C,Dj with prilnary key AB under which R is in 1NF but not in
2NF

Explain insertion and deletion anomaly

Consider a table of hospital management and show the difference between 2NF and 3NF 10m Define all the
rules followed in 3NF 5m

Create a table with library management details and show the difference between 4NF and 5NF 10m Describe
all the rules followed in 5NF 5

iscuss the main heuristics that are applied during query optimization.

Describe different indexing types with example

hat is the difference between conflict equivalence and view equivalence 5m Normalize the following
schema, with given constraints, to 4NF. books(accessionno, isbn, title, author, publisher) users(userid,
name, deptid, deptname) accessionno→isbn isbn→title isbn→publisher isbn→→author userid→name
userid→deptid deptid→deptname 10m

Illustrate Hash function with example 10m What is the difference between a primary index and a secondary
index 5m

Cursor is a Temporary Memory or Temporary Work Station. It is Allocated by


Database Server at the Time of Performing DML(Data Manipulation Language)
operations on Table by User. Cursors are used to store Database Tables.
There are 2 types of Cursors: Implicit Cursors, and Explicit Cursors. These are
explained as following below.
1. Implicit Cursors:
Implicit Cursors are also known as Default Cursors of SQL SERVER.
These Cursors are allocated by SQL SERVER when the user
performs DML operations.
2. Explicit Cursors :
Explicit Cursors are Created by Users whenever the user requires
them. Explicit Cursors are used for Fetching data from Table in Row-
By-Row Manner.
How to create Explicit Cursor:
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL
Course  by GeeksforGeeks.
1. Declare Cursor Object.
Syntax : DECLARE cursor_name CURSOR FOR SELECT * FROM
table_name
DECLARE s1 CURSOR FOR SELECT * FROM studDetails
2. Open Cursor Connection.
Syntax : OPEN cursor_connection

OPEN s1
3. Fetch Data from cursor.
There are total 6 methods to access data from cursor. They are as
follows :
FIRST is used to fetch only the first row from cursor table.
LAST is used to fetch only last row from cursor table.
NEXT is used to fetch data in forward direction from cursor table.
PRIOR is used to fetch data in backward direction from cursor table.
ABSOLUTE n is used to fetch the exact nth row from cursor table.
RELATIVE n is used to fetch the data in incremental way as well as
decremental way.
Syntax : FETCH NEXT/FIRST/LAST/PRIOR/ABSOLUTE
n/RELATIVE n FROM cursor_name
4. FETCH FIRST FROM s1
5. FETCH LAST FROM s1
6. FETCH NEXT FROM s1
7. FETCH PRIOR FROM s1
8. FETCH ABSOLUTE 7 FROM s1
9. FETCH RELATIVE -2 FROM s1
10. Close cursor connection.
Syntax : CLOSE cursor_name
CLOSE s1
11. Deallocate cursor memory.
Syntax : DEALLOCATE cursor_name
DEALLOCATE s1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy