Skip to content

fault_manager: check the recorded rosbag directories at startup - #862

Draft
bburda wants to merge 1 commit into
feat/rosbag-retention-5afrom
feat/rosbag-retention-5b
Draft

bburda wants to merge 1 commit into
feat/rosbag-retention-5afrom
feat/rosbag-retention-5b

Conversation

@bburda

@bburda bburda commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Today rows whose bag directory is gone are removed lazily, by the first GetRosbag or ListRosbags call that finds the directory missing. A disk that did not mount therefore empties the recording list at the first listing. Issue 705 rule 7 asks for a check at startup instead: rows of bags that no longer exist are removed, and if none of the recorded bags is found, the storage path is treated as unavailable and nothing is removed.

This PR is on top of ten 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:

  • Startup check. After the retention starts and before the services start, the fault manager reads the rosbag rows once and looks up each recording's directory.

    • At least one directory found, or no rows: the storage is available, and rows of missing recordings are removed.
    • No directory found while rows exist: the storage is unavailable. Nothing is removed, one ERROR names the effective storage path and the row count, and the new fault ROSBAG_STORAGE_UNAVAILABLE (CRITICAL) is reported.
  • While unavailable, no rule removes the missing recordings. That covers:

    • lazy removal in GetRosbag and ListRosbags;
    • the age sweep, the free-space floor, the quota and the per-fault cap;
    • status actions, including the startup reclassification.

    Recording goes on as before. New recordings follow the rules as usual. max_bags and keep_first count only the other recordings. The quota still counts the missing recordings' sizes, and its warning names those bytes.

  • Recovery. The first GetRosbag or ListRosbags call that finds the directory of a recording stored at startup clears the state and the fault. A new recording written under the unmounted path does not count. The rows that call found missing are kept until a later call.

  • Failed lookups. A directory lookup that fails (for example a symbolic link loop or an I/O error) is neither found nor missing:

    • its row is kept;
    • the lookup does not count as recovery;
    • GetRosbag answers with the error.

    Before this PR, such a ListRosbags call threw out of the service callback and the fault manager stopped with exit code 1. I reproduced that on the branch below this PR; main has the same call.

  • Docs: docs/config/fault-manager.rst, the fault manager README and design doc.

What changes for users

  • Rows of missing bags are removed at startup. Before, the first listing removed them. This also happens with rosbag capture off.
  • A storage path whose recorded bags are all missing is reported as ROSBAG_STORAGE_UNAVAILABLE. To recover, mount the disk. The first listing that finds a recorded directory clears the fault, and a restart with the disk mounted clears it too.
  • With zero rows the storage counts as available. A disk that is not mounted and has no recorded bag is not detected.
  • A storage that cannot be read at startup (for example PostgreSQL unreachable) logs one WARN and skips the check. The lazy removal then works as before.

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 (with ROS2_MEDKIT_TEST_PG_CONN for the PostgreSQL cases) and colcon test-result --verbose.

  • The real-process test is src/ros2_medkit_fault_manager/test/integration/test_rosbag_storage_availability.test.py, with two process runs on one database per case. It covers:

    • startup removal, also with capture off;
    • the unavailable state, GetRosbag and ListRosbags while unavailable, and recovery;
    • a new recording that does not end the state;
    • zero rows;
    • the reclassification, the age sweep, the floor, the cap, keep_first and the quota while unavailable;
    • a failed lookup.

    test_rosbag_quota_pg.test.py and test_retention_config_pg.test.py have the PostgreSQL cases, including an unreachable server at startup.

  • One subtest of test_rosbag_quota.test.py (rosbag off on the next run) removed the only recorded directory between runs and expected the listing to remove its row. Under rule 7 that start is unavailable, so the subtest now keeps a second recording and removes the directory after startup.

  • I ran this on Jazzy with PostgreSQL 14. 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-5b branch from 0fdf71d to 9c9ccc2 Compare December 1, 2026 15:43
RCLCPP_WARN(get_logger(), "%zu recorded rosbag directories could not be looked up and are kept, first %s",
not_found.size() - missing.size(), first_failure.c_str());
}
const bool available = found > 0 || rows.empty();

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.

With storage_path empty the bags go to the system temp dir, which a reboot usually wipes, while the default SQLite database in /var/lib survives. After such a reboot no directory is found, so this marks the storage unavailable, raises a CRITICAL ROSBAG_STORAGE_UNAVAILABLE that new recordings never clear, and protects every stale row for good. Those rows still count toward the quota, so once they get close to max_total_storage_mb each store evicts every other recording. For the temp-dir fallback the old behaviour (forget the missing rows) looks right, and for a real mount a marker file in storage_path would also stop a bag written onto the bare mount point from counting as found on the next start.

* feat(fault_manager): check the recorded rosbag directories at startup
* fix(fault_manager): a new recording does not end an unavailable rosbag storage
* fix(fault_manager): no rule removes the missing recordings while the storage is unavailable
* fix(fault_manager): a failed directory lookup proves nothing, and keep_first counts only unprotected recordings
* fix(fault_manager): keep_first ranks the first unprotected recording in the eviction order
@bburda
bburda force-pushed the feat/rosbag-retention-5b branch from b22e622 to fd04c35 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