Prev: multi-version-concurrency-control Next: crash-recovery-algorithms
Recovery algorithms ensure consistency, atomicity, and durability.
Every recovery algorithm has two parts:
The two key primitives are UNDO
and
REDO
.
Steal Policy: Whether the DBMS allows an uncommitted transaction to overwrite the most recently committed value of an object on disk. - STEAL: allowed - NO-STEAL: not allowed Force Policy: Whether the DBMS ensures that all updates made by a transaction are reflected on non-volatile storage before the transaction is allowed to commit. - FORCE: enforced - NO-FORCE: not enforced
Force makes it easier to recover but results in poorer runtime performance.
The DBMS maintains two separate copies of the database (master, shadow). Updates are only made in the shadow copy. When a transaction commits, atomically switch the shadow to become the new master.
This is a NO-STEAL
+ FORCE
system.
Implementation:
UNDO: Remove the shadow pages. Leave the master and DB root pointer alone. REDO: Not needed.
The DBMS records all changes made to the database in a log file on non-volatile storage before the change is made to disk. The log contains instructions required to undo and redo after a crash.
This is a STEAL
+ NO-FORCE
system.
This has the fastest runtime performance, but recovery time is slower than shadow paging because it has to replay the log.
Implementation: - All log records are written to
non-volatile storage before the page is written to non-volatile storage.
- A transaction is not considered committed until all its log
recordshave been written to disk. - When the transaction starts, write a
BEGIN
record to the log. - When it finishes, write a
COMMIT
to make sure all log records are flushed before it
returns an acknowledgement to the application. - Each log entry contains
the following information: - Transaction ID - Object ID - Before Value
(for UNDOing) - After Value (for REDOing) - Log entries to disk after
transaction commits. Group commits can be used to batch multiple log
flushes together to amoritize overhead.
Write-Ahead Logging has a problem in that the log file grows infinitely. After a crash, the DBMS has to replay the entire log, which can take a long time if the log file is large. Thus, the DBMS can periodically make a checkpoint where it flushes all buffers out to disk.
Blocking Checkpoint Implementation:
CHECKPOINT
entry to the log and flush to stable
storage.Physical Logging: - Record the changes made to a specific location in the database
Logical Logging: - Record the high level operations executed by transactions. Not necessarily restricted to a single page. Requires less data, but can be difficult to implement for non-deterministic queries. (RAND() will be tricky).
Physiological Logging: - Hybrid approach where log records target a single page but don’t specify the organization of the page.
Prev: multi-version-concurrency-control Next: crash-recovery-algorithms