Skip to content

fault_manager: make all rosbag retention decisions in one component - #835

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

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

Conversation

@bburda

@bburda bburda commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Issue 705 adds configurable rosbag retention. Today the cap, the quota, the clear and the stale-row cleanup each decide on their own, in the storage backends and in RosbagCapture. Each rule for priority, healing or age would have to be written in three backends and in RosbagCapture.

This PR depends on the first PR of the stack (rosbag-retention-0a, the apply_rosbag_changes primitive). Please review that one first. The diff of this PR is against its branch.

What it changes:

  • New core::RosbagRetention. It holds the store, the per-fault cap, the quota, the clear and the stale-recording cleanup on top of apply_rosbag_changes, each under one retention mutex. The store runs its cleared check, cap, insert and quota step in one hold. The retention never deletes files. Each call returns the directories that no row names any more.
  • The directories a store frees are deleted on the store's own thread (the capture pool or the store worker, never the executor) before Bag file created / Bag file completed is logged, as before. The directories a clear or a stale-row cleanup frees are deleted by a new RetentionWorker, a one-thread worker that the node owns and drains at shutdown after RosbagCapture::stop(). A RosbagCapture built with the old constructor makes its own retention and an inline worker, so standalone captures stay synchronous.
  • The storage mutators store_rosbag_file(s), delete_rosbag_file(s), delete_rosbag_recording and set_max_rosbags_per_fault are removed from FaultStorage and the three backends, and so is RosbagCapture::evict_bags_over_quota.
  • Tests that seeded rows now use apply_rosbag_changes. The cap, quota and removal tests go through RosbagRetention. The cap tests are one typed suite over the in-memory, SQLite and PostgreSQL backends.
  • The real-process tests from the first PR pass unchanged. New real-process checks cover a clear that removes on the worker after the service replied, SIGTERM with removals still queued, and a clear of a recording whose directory is already gone.

Which recordings are kept or deleted does not change.

What changes for users

  • Every removed recording is now logged after the removal happened, with its reason. New lines: Recording removed: <id> (max_bags_per_fault) and Recording removed: <id> (fault cleared). A quota eviction keeps the existing Deleted old bag '<path>' to enforce storage limit line. A removal that fails is logged as a WARN with the path, the reason and the error. A directory that was already missing is not logged as removed. A failed removal of a stale row was silent before and is now a WARN.
  • A ClearFault no longer deletes the bag directory on the executor thread. The service returns first and the worker deletes the directory, so a large bag is still on disk for a short time after the reply. The Auto-cleanup: deleted bag file for fault line is written once the directories are gone.
  • At shutdown the node waits for the queued removals before it exits.

Issue


Type

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

Testing

  • colcon build --packages-up-to ros2_medkit_fault_manager (add --cmake-args -DPOSTGRES_SUPPORT=ON for the PostgreSQL backend), then colcon test --packages-select ros2_medkit_fault_manager and colcon test-result --verbose.
  • The real-process tests are test_rosbag_quota.test.py and test_rosbag_quota_pg.test.py in src/ros2_medkit_fault_manager/test/integration. Run them with ctest -R rosbag.
  • To see the log lines, enable rosbag capture with auto_cleanup: true, confirm a fault and clear it: the log shows Recording removed: <id> (fault cleared), then Auto-cleanup: deleted bag file for fault '<code>'. test_removals_are_logged checks that each line is written after its directory is gone.
  • 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 November 27, 2026 19:25
@bburda
bburda force-pushed the feat/rosbag-retention-0b branch from 7f0f1a2 to 52e1659 Compare December 1, 2026 15:43
// fault's other, healthy recordings with it because one of them vanished.
try {
storage_->delete_rosbag_recording(rosbag_info->recording_id);
auto removal = rosbag_retention_->forget_recording(rosbag_info->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.

Only IgnorableConnectionException and RosbagCommitInDoubt are caught around this best-effort cleanup. A plain storage error (SQLite busy after the timeout, IOERR or full disk, or any non-connection PostgreSQL error) escapes the GetRosbag callback, leaves rclcpp::spin and stops the node, so a read can take the fault manager down. The same applies to the ListRosbags site below (around line 932). Catching std::exception here, as the startup check already does around the same call, would keep the rows and let the next lookup retry.

@bburda
bburda force-pushed the feat/rosbag-retention-0b branch from 52e1659 to 20258b8 Compare December 2, 2026 12:15
* test(fault_manager): pin that a shutdown inside a post-roll removes the recording its cap replaced
* feat(fault_manager): make every rosbag retention decision in one component
* fix(fault_manager): log each recording removal after it happened
* fix(fault_manager): remove and log every recording through one helper
* fix(fault_manager): log a removal only when something was removed
@bburda
bburda force-pushed the feat/rosbag-retention-0b branch from 20258b8 to 7f381ec 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