Skip to content

sysutil: fill ballast files with random data instead of zeroes - #174809

Open
NAVEENKUMARKR777 wants to merge 1 commit into
cockroachdb:masterfrom
NAVEENKUMARKR777:fix/ballast-zfs-compression
Open

sysutil: fill ballast files with random data instead of zeroes#174809
NAVEENKUMARKR777 wants to merge 1 commit into
cockroachdb:masterfrom
NAVEENKUMARKR777:fix/ballast-zfs-compression

Conversation

@NAVEENKUMARKR777

Copy link
Copy Markdown

Summary

resizeLargeFileNaive is used to create emergency ballast files on
platforms without fallocate support: all non-Linux platforms, and Linux
filesystems that report fallocate as unsupported (eg some ZFS
configurations, per the reproduction in #78606). It previously wrote
zero-filled buffers to reserve the requested disk space.

Some filesystems compress long runs of zeroes down to almost nothing (eg ZFS
with compression=on), so the ballast file's logical size matched the
requested size but its actual on-disk footprint did not — as demonstrated in
the original report, a 559GB ballast occupied only ~2.7MB of pool space.
This defeats the purpose of a ballast file: reserving real, reclaimable disk
space that can be freed by deleting the file when a node runs low on disk.

This exact fix (write random data instead of zeroes for the buffer-writing
fallback path) was proposed and agreed on by @knz, @nicktrav, and @jbowens
in the issue thread back in 2022, but was never implemented.

This only addresses the buffer-writing fallback path. It does not address
the separate, harder case raised later in the thread where fallocate
itself reports success without actually reserving space on some
filesystems — that needs separate investigation (eg checking on-disk usage
after allocation) and is out of scope here.

Test plan

Added TestResizeLargeFileNaiveIncompressible, which writes a ballast file
via the naive path and verifies a standard compressor (compress/flate)
cannot shrink its content by more than a small margin, directly regression
testing the compressibility issue from #78606. Existing TestResizeLargeFile
continues to pass unmodified.

Resolves: #78606
Epic: none

Release note (bug fix): Fixed a bug where the automatically-created
emergency ballast file could fail to reserve real disk space on filesystems
that compress zero-filled data (such as ZFS with compression enabled),
preventing it from being useful as a safety margin when a node ran low on
disk space.

🤖 Generated with Claude Code

resizeLargeFileNaive is used to create emergency ballast files on
platforms without fallocate support (all non-Linux platforms, and
Linux filesystems that report fallocate as unsupported, eg some ZFS
configurations). It previously wrote zero-filled buffers to reserve
the requested disk space.

Some filesystems compress long runs of zeroes down to almost nothing
(eg ZFS with compression=on), so the ballast file's logical size
matched the requested size but its actual on-disk footprint did not.
This defeats the purpose of a ballast file, which is to reserve real,
reclaimable disk space that can be freed by deleting the file when a
node runs out of disk.

Fill the file with pseudo-random data instead. The data need not be
cryptographically random, only resistant to compression, so a single
64MB buffer is generated once and reused for the whole file, keeping
large ballasts fast to create.

Resolves: cockroachdb#78606
Epic: none

Release note (bug fix): Fixed a bug where the automatically-created
emergency ballast file could fail to reserve real disk space on
filesystems that compress zero-filled data (such as ZFS with
compression enabled), preventing it from being useful as a safety
margin when a node ran low on disk space.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@blathers-crl

blathers-crl Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

I have added a few people who may be able to assist in reviewing:

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Sep 7, 2026
@blathers-crl
blathers-crl Bot requested a review from nicktrav September 7, 2026 08:06
@cockroachlabs-cla-agent

cockroachlabs-cla-agent Bot commented Sep 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community X-blathers-triaged blathers was able to find an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storage: ballast file has no effect under zfs with compression=on

1 participant