Skip to content

fault_manager: min_free_disk_mb keeps free space under the rosbag storage path - #861

Draft
bburda wants to merge 1 commit into
feat/rosbag-retention-4bfrom
feat/rosbag-retention-5a
Draft

bburda wants to merge 1 commit into
feat/rosbag-retention-4bfrom
feat/rosbag-retention-5a

Conversation

@bburda

@bburda bburda commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Today the fault manager limits recordings only by the sizes it wrote into their rows, so other data that fills the disk is not seen. Issue 705 asks for a floor of free space on the filesystem of storage_path. This PR adds snapshots.rosbag.retention.min_free_disk_mb.

This PR is on top of nine PRs in the stack. Please review those first. The diff of this PR is against the branch of the PR directly below it.

What it adds:

  • min_free_disk_mb (MiB, default 0 = off). Below it, recordings are deleted in eviction order: lowest priority first, then cleared, healed, active, then oldest.
  • Measured. A pass measures the free space, deletes one whole recording, measures again, and stops when the floor is met or nothing more can be deleted. The size a recording is listed with is not used, because open files, hard links and block rounding make it differ from what a deletion frees.
  • When it runs. One pass at a time, on the retention worker:
    • after each store that kept the new recording, at that recording's priority. It never deletes a higher priority, and the new recording goes only as the last resort.
    • in the periodic job, with no priority limit.
  • Open-time check. When a new recording is about to open and the free space is already below the floor with nothing at the fault's priority to delete, the recording does not start (one INFO line).
  • Test switch. The environment variable ROS2_MEDKIT_TEST_STORAGE_CAPACITY_FILE makes the fault manager compute free space as a capacity from a file minus the bytes under the storage path. Tests then do not depend on other writers of the disk. It logs a WARN at startup, cannot be set over the API, and must never be set on a robot.
  • Docs: docs/config/fault-manager.rst, the example retention file, the fault manager README and design doc.

What changes for users

  • Without retention parameters nothing changes.
  • New top-level field min_free_disk_mb. A configuration that sets only this field is a configured retention: quota eviction then follows the eviction order, with every priority 0. An invalid value is reported as ROSBAG_RETENTION_CONFIG_INVALID, and while the configuration is invalid the floor is off.
  • The periodic job (sweep_interval_sec) now also runs when only the floor is set. The startup policy line ends with floor: off or floor: <n> MB.
  • The floor is a target. Other writers can change the free space between two measurements. When PostgreSQL shares the disk, the floor is also its headroom.
  • New log lines. Recording removed: <id> (min_free_disk_mb) per removed recording, and floor pass: removed=<n> free=<bytes> floor=<bytes> met=<true|false> source=<filesystem|test-capacity> at DEBUG per pass.

Issue


Type

  • Bug fix
  • New feature or tests
  • Breaking change
  • Documentation only

Testing

  • colcon build --packages-up-to ros2_medkit_fault_manager --cmake-args -DPOSTGRES_SUPPORT=ON, then colcon test --packages-select ros2_medkit_fault_manager and colcon test-result --verbose.
  • The real-process test is src/ros2_medkit_fault_manager/test/integration/test_rosbag_free_space.test.py. It covers:
    • a store deleting lower priorities first, until the floor is met;
    • a store never deleting a higher priority, with the new recording dropped;
    • over_quota: keep not breaking the floor;
    • a store whose cap kept nothing, which runs no pass;
    • the open-time check;
    • the periodic pass with no priority limit;
    • a storage path not created yet, measured on its parent with the real filesystem;
    • the floor off, and invalid values.
  • test_rosbag_capture.cpp has one in-process case for a removal step that fails, because no real storage reaches that path.
  • I ran this on Jazzy, also with another process writing to the same disk. Humble and Lyrical run in CI. clang-tidy on the changed files reports nothing new.

Checklist

  • Breaking changes are clearly described (and announced in docs / changelog if needed)
  • Tests were added or updated if needed
  • Docs were updated if behavior or public API changed

@bburda
bburda added this pull request to stack #836 December 1, 2026 13:21
@bburda
bburda force-pushed the feat/rosbag-retention-5a branch from 89cc257 to 17a60e8 Compare December 1, 2026 15:43
std::map<std::string, size_t> index_by_path;
// The first recording of each fault code: the storage reads the rows oldest first.
std::map<std::string, std::string> first_path_by_code;
for (const auto & row : storage_.get_all_rosbag_files()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The floor candidates are all stored rows, but only the filesystem of the current storage_path is measured. If storage_path is moved to another disk and the database is kept, the old recordings are still found at startup, and once the new disk drops below the floor each pass deletes them one by one without freeing any measured space, until it runs out of candidates. Skipping candidates whose directory is on a different device than the measured path (st_dev) would keep the floor from deleting data it cannot reclaim.

return step;
}
auto chosen = std::find_if(candidates.begin(), candidates.end(), [&last_resort_recording_id](const auto & c) {
return c.recording_id != last_resort_recording_id;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This skips the pass's own recording and takes the first candidate in rank order, so a recording stored after it is not protected. With a floor-only config (all priority 0), recording R1 is stored and its pass is queued, R2 is stored before that pass reaches the last candidates, and the pass deletes R2 and keeps the older R1. R2's own pass then finds nothing to do. That inverts the oldest-first order the docs describe. Skipping candidates created after the pass's own recording, or ranking it in place instead of skipping it, would keep the order.

@bburda
bburda force-pushed the feat/rosbag-retention-5a branch from 17a60e8 to b7fd9f0 Compare December 2, 2026 12:15
…rage path

* feat(fault_manager): min_free_disk_mb keeps free space under the rosbag storage path
* feat(fault_manager): a test capacity file replaces the free-space measurement in tests
* fix(fault_manager): no floor pass after a store that kept nothing; one WARN per failed step
* test(fault_manager): the in-doubt floor test counts every WARN of the pass
@bburda
bburda force-pushed the feat/rosbag-retention-5a branch from b7fd9f0 to 957d7db Compare December 2, 2026 18:24

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants