In
computer science, write-ahead logging (WAL) is a family of techniques for providing
atomicity and
durability (two of the
ACID
In computer science, ACID ( atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequ ...
properties) in
database systems.
A write ahead log is an append-only auxiliary disk-resident structure used for crash and transaction recovery. The changes are first recorded in the log, which must be written to
stable storage, before the changes are written to the database.
The main functionality of a write-ahead log can be summarized as:
* Allow the page cache to buffer updates to disk-resident pages while ensuring durability semantics in the larger context of a database system.
* Persist all operations on disk until the cached copies of pages affected by these operations are synchronized on disk. Every operation that modifies the database state has to be logged on disk before the contents on the associated pages can be modified
* Allow lost in-memory changes to be reconstructed from the operation log in case of a crash.
In a system using WAL, all modifications are written to a
log
Log most often refers to:
* Trunk (botany), the stem and main wooden axis of a tree, called logs when cut
** Logging, cutting down trees for logs
** Firewood, logs used for fuel
** Lumber or timber, converted from wood logs
* Logarithm, in mathe ...
before they are applied. Usually both redo and undo information is stored in the log.
The purpose of this can be illustrated by an example. Imagine a program that is in the middle of performing some operation when the machine it is running on loses power. Upon restart, that program might need to know whether the operation it was performing succeeded, succeeded partially, or failed. If a write-ahead log is used, the program can check this log and compare what it was supposed to be doing when it unexpectedly lost power to what was actually done. On the basis of this comparison, the program could decide to undo what it had started, complete what it had started, or keep things as they are.
After a certain amount of operations, the program should perform a
checkpoint
Checkpoint may refer to:
Places
* Border checkpoint, a place on the land border between two states where travellers and/or goods are inspected
* Security checkpoint, erected and enforced within contiguous areas under military or paramilitary co ...
, writing all the changes specified in the WAL to the database and clearing the log.
WAL allows updates of a database to be done
in-place
In computer science, an in-place algorithm is an algorithm which transforms input using no auxiliary data structure. However, a small amount of extra storage space is allowed for auxiliary variables. The input is usually overwritten by the output ...
. Another way to implement atomic updates is with
shadow paging, which is not in-place. The main advantage of doing updates in-place is that it reduces the need to modify indexes and block lists.
ARIES
Aries may refer to:
*Aries (astrology), an astrological sign
*Aries (constellation), a constellation of stars in the zodiac
Arts, entertainment and media
* ''Aries'' (album), by Luis Miguel, 1993
* ''Aries'' (EP), by Alice Chater, 2020
* "Aries" ...
is a popular algorithm in the WAL family.
Modern
file system
In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
s typically use a variant of WAL for at least file system
metadata
Metadata is "data that provides information about other data", but not the content of the data, such as the text of a message or the image itself. There are many distinct types of metadata, including:
* Descriptive metadata – the descriptive ...
; this is called
journaling.
References
*
Database algorithms
{{database-stub