Skip to content

How does Altibase guarantee transaction durability?#

Overview#

This FAQ explains how Altibase guarantees transaction durability and how to set the durability level to balance durability and performance.

Version#

All versions of Altibase

Transactions and ACID#

Durability is one of the ACID properties that a transaction must satisfy. Before explaining how Altibase guarantees durability, this section briefly reviews transactions and the ACID properties.

Transaction#

A database transaction is a logical unit of work that consists of one or more SQL statements. A transaction begins when a user executes the first SQL statement and ends when it is committed or rolled back explicitly with a COMMIT or ROLLBACK statement. Executing a DDL statement commits the transaction implicitly.

ACID Properties#

To maintain database integrity, a transaction must satisfy the following four ACID properties.

  • Atomicity: Either all of the SQL statements in a transaction are executed, or none of them are. A transaction cannot partially succeed.
  • Consistency: A properly executed transaction does not break the consistency of the database.
  • Isolation: When multiple transactions run at the same time, no transaction can access the results of the others.
  • Durability: Once a transaction is committed, its changes are not lost under any circumstances, including system failures.

Altibase satisfies all ACID properties to guarantee reliable transaction processing.

Durability#

Durability means that once a transaction is committed, the committed changes must be preserved even if a database failure occurs before the changed data is physically written to disk.

Altibase guarantees durability by combining checkpointing with transaction logging.

Logging and Checkpointing#

When a change occurs, the log needed to undo or reapply that change is created and written to the log buffer, and then written to the log file on disk.

  • Undo log: Allows the database to be restored to its state before the change if the transaction is rolled back or a failure occurs.
  • Redo log: Allows the change to be reapplied from the log if a failure occurs before the committed changes are written to the data files or checkpoint image files on disk.

How changed data is written to disk depends on the table type.

  • Disk tables: Follow the WAL (Write-Ahead Logging) protocol. Before a changed page is written to the data file, its change log is always written to the log file first.
  • Memory tables: Use ping-pong checkpointing, which alternates between two checkpoint images, to guarantee consistency. A checkpoint writes the changed pages to the image that is not currently valid. Only after the log has been written to the log file does Altibase switch the new image to the valid image. If a failure occurs during a checkpoint, the database is recovered from the previously valid image and the log.

Impact of Durability on Performance#

To guarantee durability, the log of a committed transaction must be written to the log file on disk. If every commit waits for its log to be written to disk, the commit response time increases by the disk I/O time. This is especially true when data is processed in memory, as with Altibase memory tables, because writing the log to disk accounts for a large share of the commit processing time.

Durability Levels#

You need to choose an appropriate balance between transaction durability and processing performance. Altibase provides four durability levels, each defined by a combination of two properties: COMMIT_WRITE_WAIT_MODE and LOG_BUFFER_TYPE.

Level Commit mode
(COMMIT_WRITE_WAIT_MODE)
Log buffer
(LOG_BUFFER_TYPE)
Loss of committed data after a failure
Durability Level 2 Asynchronous commit (0) Altibase log buffer (1) If Altibase or the system fails, logs not yet written to the log file may be lost
Durability Level 3 (default) Asynchronous commit (0) OS kernel log buffer (0) No loss if only Altibase fails. If the OS fails or power is lost, logs not yet written to disk may be lost
Durability Level 4 Synchronous commit (1) OS kernel log buffer (0) No loss, because the logs of committed transactions are on disk
Durability Level 5 Synchronous commit (1) Altibase log buffer (1) No loss, because the logs of committed transactions are on disk

Durability Level 2: Asynchronous Commit, Altibase Log Buffer#

A transaction does not wait for its log to be written to disk at commit. Logs accumulate in the Altibase log buffer, and the log flush thread periodically writes them to the log file. As a result, if Altibase fails, logs not yet written to the log file may be lost.

Use this level when commit response time matters and some data loss is acceptable.

Durability Level 3: Asynchronous Commit, OS Kernel Log Buffer#

This is the default setting for Altibase. A transaction does not wait for its log to be written to disk at commit. Logs are written to the OS kernel log buffer, and the log flush thread periodically requests that they be written to disk. Because the OS manages the kernel log buffer, the logs survive if only Altibase fails. However, if the OS fails or power is lost, logs not yet written to disk may be lost.

Durability Level 4: Synchronous Commit, OS Kernel Log Buffer#

Logs are written to the OS kernel log buffer. At commit, a transaction confirms that its logs, up to and including the commit log, have been written to the log file on disk before returning the commit result. As a result, the logs of committed transactions are always on disk.

Durability Level 5: Synchronous Commit, Altibase Log Buffer#

Logs are written to the Altibase log buffer. At commit, a transaction confirms that its logs, up to and including the commit log, have been written to the log file on disk before returning the commit result. As a result, the logs of committed transactions are always on disk.

At Levels 4 and 5, when multiple transactions commit at the same time, their logs can be written together in a single disk write (group commit). If you cannot tolerate any loss of committed data, use Level 4 or Level 5.

Note

For temporary data that does not need durability, you can use a volatile tablespace. A volatile tablespace does not write logs to disk, but all of its data is lost when Altibase restarts, so durability is not guaranteed.

Setting the Durability Level#

The durability level is determined by the combination of two properties. COMMIT_WRITE_WAIT_MODE determines whether a commit waits for its log to be written to disk, and LOG_BUFFER_TYPE determines which buffer holds the log before it is written to disk.

COMMIT_WRITE_WAIT_MODE#

Determines whether a commit waits until its log is written to the log file on disk. You can change it for the entire system or for individual sessions while Altibase is running.

Value Meaning
0 (default) Asynchronous commit.
A transaction returns the commit result as soon as its log is written to the log buffer.
It does not wait for disk I/O, but if a failure occurs before the log is written to disk, committed changes may be lost.
1 Synchronous commit.
A transaction returns the commit result only after its log is written to the log file on disk.
Committed changes are not lost even if a failure occurs, but every commit waits for disk I/O.

LOG_BUFFER_TYPE#

Determines which buffer holds the log before it is written to disk. You cannot change it while Altibase is running.

Value Meaning
0 (default) OS kernel log buffer.
Altibase opens the log file as a memory-mapped file and writes the log to the OS kernel area, and the OS writes it to disk.
Because the log is in memory managed by the OS, it is not lost if only Altibase fails.
1 Altibase log buffer.
Altibase writes the log to its own process memory and writes it to disk directly.
If Altibase fails, logs not yet written to disk are lost.