Professional Documents
Culture Documents
GROUP ONE
Pessimistic Algorithms
• Is where you assume that all the users are trying to access the same record and it
literally locks the record exclusively for the first started transaction until it is
completed successfully or failed. Then the lock is released and the next transaction
on the record is handled in the same way.
• For example, an account is locked as soon as it is accessed in a transaction
therefore attempts to use other accounts in other transaction while it is locked will
either result in other processes being delayed until the account locked is released or
that process transaction will roll back.
•Example of Locking Mechanism
Optimistic Algorithms
• It is the process of restoring the data base to a correct state in the event of a failure
that is the process of restoring database to the most recent consistent state that
existed shortly before the time of system failure. The failure may be the result of a
system crush due to hardware or software errors in the application such as a logical
error in the programming that is accessing the database.
For example, if the system crushes before a fund transfer transaction completes its
execution, then either one or both accounts may have incorrect value thus, the
database must be restored to the state before transaction modified any of the accounts.
Database recovery techniques
Log based technique
• The log is an order of sequence of records, which sustains the operations record
accomplished by a transaction in the database
• In this, all events that have occurred in the database, like a record of every
single statement executed is backed up. It is the backup of transaction log
entries and contains all transaction that had happened to the database.
Through this, the database can be recovered to a specific point in time. For
example, it is even possible to perform a backup from a transaction log if the
data files are destroyed and not even a single committed transaction is lost.
• <TRX, Start>
• In the above syntax, we use TRX and start in which TRX means transaction and when a
transaction in the initial state that means we write start a log.
• <TRX, Name, 'First Name', 'Last Name' >
In this syntax where TRX means transaction and name is used to First Name and Last Name.
When we modify the name First Name to the Last Name then it writes a separate log file for
that.
<TRX, Commits>
• In the above syntax, we use two-variable transactions as TRX and commits,
when transaction execution is finished then it is written into another log file
that means the end of the transaction we called commits.
Shadow paging
• It is a recovery technique that is used to recover database. In this recovery
technique, database is considered as made up of fixed size of logical units of
storage which are referred as pages. pages are mapped into physical blocks
of storage, with help of the page table which allow one entry for each
logical page of database. This method uses two page tables named current
page table and shadow page table.
• The entries which are present in current page table are used to point to
most recent database pages on disk. Another table i.e., Shadow page table
is used when the transaction starts which is copying current page table.
After this, shadow page table gets saved on disk and current page table is
going to be used for transaction. Entries present in current page table may
be changed during execution but in shadow page table it never gets
changed. After transaction, both tables become identical.
Checkpoint
• The checkpoint is an established process where all the logs which are
previously used are clear out from the system and stored perpetually in a
storage disk. Checkpoint mention a point before which the DBMS was in a
compatible state, and all the transactions were perpetrated (carried out).
What is Data Recovery?
• It is the method of restoring the database to its correct state in the event of a
failure at the time of the transaction or after the end of a process.
What is the Need for Recovery of data?
• The storage of data usually includes four types of media with an increasing
amount of reliability: the main memory, the magnetic disk, the magnetic tape,
and the optical disk. Many different forms of failure can affect database
processing and/or transaction, and each of them has to be dealt with differently.
Some data failures can affect the main memory only, while others involve non-
volatile or secondary storage also. Among the sources of failure are:
• Due to hardware or software errors, the system crashes, which ultimately
resulting in loss of main memory.
• Failures of media, such as head crashes or unreadable media that results in the
loss of portions of secondary storage.
• There can be application software errors, such as logical errors that are
accessing the database that can cause one or more transactions to abort or fail.
• Natural physical disasters can also occur, such as fires, floods, earthquakes, or power
failures.
• Carelessness or unintentional destruction of data or directories by operators or users.
• Damage or intentional corruption or hampering of data (using malicious software or
files) hardware or software facilities.
Whatever the grounds of the failure are, there are two principal things that you have to
consider:
1.Failure of main memory, including that database buffers.
• To see where the problem has occurred, failure is generalized into various
categories, as follows –
Transaction failure:
There are two types of techniques, which can help a DBMS in recovering as
well as maintaining the atomicity of a transaction −
Maintaining the logs of each transaction, and writing them onto some stable
storage before actually modifying the database.
Log-based Recovery
a) undo(Ti) restores the value of all data items updated by Ti to their old values,
going backwards from the last log record for Ti
b) redo(Ti ) sets the value of all data items updated by Ti to the new values, going
forward from the first log record for Ti
Both operations must be idempotent i.e. even if the operation is executed multiple times, the effect is
the same as if it is executed once; this is needed since operations may get re-executed during recovery
Transaction Ti needs to be undone if the log contains the record <Ti start>, but does not contain the
record <Ti commit>.
Transaction Ti needs to be redone if the log contains both the record <Ti start> and the record <Ti
commit>.
Undo operations are performed first, then redo operations
Maintaining shadow paging
• This is the method where all the transactions are executed in the primary
memory or the shadow copy of database. Once all the transactions
completely executed, it will be updated to the database
Whenever any page is about to be written for the first time:
• Checkpoint is a mechanism where all the previous logs are removed from
the system and stored permanently in a storage disk.
• . Checkpoint declares a point before which the DBMS was in consistent
state, and all the transactions were committed
• The recovery system reads the logs backwards from the end to the last
checkpoint.
• It maintains two lists, an undo-list and a redo-list.
• If the recovery system sees a log with <T , Start> and <T , Commit> or just <T ,
n n n
Commit>, it puts the transaction in the redo-list.
• If the recovery system sees a log with <T , Start> but no commit or abort log
n
found, it puts the transaction in undo-list.
• All the transactions in the undo-list are then undone and their logs are
removed. All the transactions in the redo-list and their previous logs are
removed and then redone before saving their logs.