Skip to content

Conversation

@kim
Copy link
Contributor

@kim kim commented Oct 20, 2025

When a new commitlog segment is created, allocate disk space for it up
to the maximum segment size. Also do this when resuming writes to an
existing segment, such that segments created without preallocation will
allocate as well when the database is opened.

Preallocation is gated behind the feature "fallocate", because it is not
always desirable to preallocate, e.g. for local standalone users.

The feature can only be enabled on Linux targets, because allocation is
done using the Linux-specific fallocate(2) system call.

Unlike ftruncate(2) or the portable posix_fallocate(3), fallocate(2)
supports allocating disk space without zeroing. This is currently
required, because the commitlog format does not handle padding bytes.

If not enough space can be allocated, the commitlog refuses writes. For
commitlogs that were created without preallocation, this means that the
commitlog cannot even be opened in this situation.

The local durability impl will crash if it detects that the commitlog is
unable to allocate enough space.

This means that a database will eventually crash and be unable to start in
an out-of-space situation.

Allocated space is not included in the reported size of the commitlog.
Instead, allocated blocks are reported separately.

Expected complexity level and risk

3 - Disk size monitoring may need to be adjusted.

Testing

  • Adds a test that demonstrates the crash behavior of [spacetimedb_durability::Local]
    when there is insufficient space. The test performs I/O against a loop device.
  • Modified the repo::Memory impl so that it can run out of space. No test currently
    utilizes this, but existing tests assuming infinite space still pass.

kim added 11 commits October 20, 2025 12:48
When a new commitlog segment is created, allocate disk space for it up
to the maximum segment size. Also do this when resuming writes to an
existing segment, such that segments created without preallocation will
allocate as well when the database is opened.

Preallocation is gated behind the feature "fallocate", because it is not
always desirable to preallocate, e.g. for local `standalone` users.

The feature can only be enabled on Linux targets, because allocation is
done using the Linux-specific `fallocate(2)` system call.

Unlike `ftruncate(2)` or the portable `posix_fallocate(3)`, `fallocate(2)`
supports allocating disk space without zeroing. This is currently
required, because the commitlog format does not handle padding bytes.

The commitlog refuses writes if not enough space can be allocated. For
commitlogs that were created without preallocation, this means that the
commitlog cannot even be opened.

The local durability impl will crash if it detects that the commitlog is
unable to allocate enough space.

This means that a database will eventually crash and unable to start in
an out-of-space situation.

Allocated space is not included in the reported size of the commitlog.
Instead, allocated blocks are reported separately.
@kim kim marked this pull request as ready for review October 27, 2025 10:45
@bfops bfops added the release-any To be landed in any release window label Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants