sysutil: fill ballast files with random data instead of zeroes - #174809
Open
NAVEENKUMARKR777 wants to merge 1 commit into
Open
sysutil: fill ballast files with random data instead of zeroes#174809NAVEENKUMARKR777 wants to merge 1 commit into
NAVEENKUMARKR777 wants to merge 1 commit into
Conversation
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>
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resizeLargeFileNaiveis used to create emergency ballast files onplatforms without
fallocatesupport: all non-Linux platforms, and Linuxfilesystems that report
fallocateas unsupported (eg some ZFSconfigurations, 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 therequested 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
fallocateitself 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 filevia 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
TestResizeLargeFilecontinues 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