>_
EngineeringNotes
Back to DBMS Topics

Atomicity and Durability Implementation

1Recovery Mechanism Component

The Recovery Mechanism Component of a DBMS supports atomicity and durability. It ensures that the database stays consistent despite system failures.

2Shadow-Copy Scheme

This scheme is based on making copies of the database (also known as shadow copies).

Learning Mode

Recommended for first-time reading

Shadow-Copy Step-by-Step

Initial State

Logic Sequence: 1 / 6
Volatile RAM

New Copy Workspace

Empty

Non-Volatile Disk
db-pointer: [Sector 0]
Address_A

Old Copy (Current)

Points to address_a

Address_B

Empty Location

Ready

1

The db-pointer is pointing to the current 'Old DB Copy' on the disk.

Steps and Core Logic:

  • Assumption: Only one Transaction (T) is active at a time.
  • A pointer called db-pointer is maintained on the disk; which at any instant points to the current copy of DB.
  • A transaction (T) that wants to update the DB first creates a complete copy of the DB. (Main Cause of Inefficiency)
  • All further updates are done on the new DB copy, leaving the original copy (shadow copy) untouched.
  • If at any point the T has to be aborted, the system deletes the new copy. The old copy is not affected.
  • If T success, it is committed as:
    • 1. OS makes sure all the pages of the new copy of DB are written on the disk.
    • 2. DB system updates the db-pointer to point to the new copy of DB.
    • 3. New copy is now the current copy of DB.
    • 4. The old copy is deleted.
    • 5. The T is said to have been COMMITTED at the point where the updated db-pointer is written to disk.
Atomicity
  • If T fails before pointer update, old content is not affected.
  • T abort is done by just deleting the new copy.
  • Hence, either all updates are reflected or none.
Durability
  • Suppose system fails before updated db-pointer is written to disk. On restart, it reads db-pointer and sees original content.
  • T is successful only when pointer is updated.
  • If system fails after pointer update, all pages were already written to disk. On restart, it reads new copy.

"The implementation is dependent on write to the db-pointer being atomic. Luckily, disk system provide atomic updates to entire block or at least a disk sector. So, we make sure db-pointer lies entirely in a single sector by storing it at the beginning of a block."

Inefficient, as entire DB is copied for every Transaction.

3Log-Based Recovery Methods

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

Stable storage: A classification of computer data storage technology that guarantees atomicity for any given write operation and allows software to be written that is robust against some hardware and power failures.

Deferred DB Modifications

  • Ensuring atomicity by recording all DB modifications in the log but deferring execution until final action of T.
  • Log information is used to execute deferred writes when T is completed.
  • If system crashed before T completes, or T is aborted, the information in the logs are ignored.
  • If T completes, the records associated to it in log file are used in executing the deferred writes.
  • If failure occur while this updating is taking place, we perform REDO.
Logs (Stable Storage)Deferred

<T₀ start>

<T₀, A, 950>

// Only New Value

<T₀, B, 2050>

<T₀ commit>

Immediate DB Modifications

  • DB modifications to be output to the DB while the T is still in active state.
  • These are called uncommitted modifications.
  • In event of crash or T failure, system uses old value field to restore modified values.
  • Update takes place only after log records are in stable storage.
  • Failure Handling:
    • Before T completes/aborts: Old value field used to UNDO.
    • T completes and system crashes: New value field used to REDO T having commit logs.
Logs (Stable Storage)Immediate

<T₀ start>

<T₀, A,1000,950>
↑ Old Value↑ New Value

<T₀, B, 2000, 2050>

<T₀ commit>