Skip to content

commitlog,durability: Support preallocation of disk space - #3437

Merged
kim merged 13 commits into
masterfrom
kim/commitlog/fallocate
Nov 10, 2025
Merged

kim merged 13 commits into
masterfrom
kim/commitlog/fallocate

Conversation

@kim

@kim kim commented Oct 20, 2025 •

Copy link
Copy Markdown
Contributor

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 Can land in any release window. Will not block a release deployment. label Oct 27, 2025
@kim
kim requested a review from Shubham8287 November 6, 2025 18:03

@Shubham8287 Shubham8287 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I reviewed this PR long back but completely forgot to hit the button.

Tests seems good.

@kim
kim enabled auto-merge November 10, 2025 14:40
@kim
kim added this pull request to the merge queue Nov 10, 2025
Merged via the queue into master with commit cfd0d4b Nov 10, 2025
23 of 25 checks passed
@kim
kim deleted the kim/commitlog/fallocate branch November 10, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any Can land in any release window. Will not block a release deployment.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants