From fd04c35555645e157d1a990fbec647a46f2b345c Mon Sep 17 00:00:00 2001 From: Bartosz Burda Date: Tue, 1 Dec 2026 14:41:07 +0100 Subject: [PATCH] fault_manager: check the recorded rosbag directories at startup * 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 --- docs/config/fault-manager.rst | 36 ++ src/ros2_medkit_fault_manager/CMakeLists.txt | 5 + src/ros2_medkit_fault_manager/README.md | 12 + .../design/index.rst | 54 ++- .../core/rosbag_retention.hpp | 27 +- .../fault_manager_node.hpp | 30 +- .../src/core/rosbag_retention.cpp | 130 +++++-- .../src/fault_manager_node.cpp | 203 +++++++++- .../test/integration/rosbag_fm_harness.py | 73 ++++ .../test_retention_config_pg.test.py | 47 ++- .../integration/test_rosbag_quota.test.py | 10 +- .../integration/test_rosbag_quota_pg.test.py | 3 + .../test_rosbag_storage_availability.test.py | 346 ++++++++++++++++++ 13 files changed, 912 insertions(+), 64 deletions(-) create mode 100644 src/ros2_medkit_fault_manager/test/integration/test_rosbag_storage_availability.test.py diff --git a/docs/config/fault-manager.rst b/docs/config/fault-manager.rst index c03769a7b..ea86e11a9 100644 --- a/docs/config/fault-manager.rst +++ b/docs/config/fault-manager.rst @@ -755,6 +755,42 @@ A post-fault-only bag on a quiet or heavily filtered system can contain zero messages. It still finalises normally on both ``mcap`` and ``sqlite3``, is listed by the bulk-data endpoints and can be downloaded; only its payload is empty. +**Recordings whose directory is gone.** At startup, before it serves requests and also with rosbag +capture off, the fault manager reads every rosbag row once and looks for the directory of each +recording. When it finds at least one of them, or there are no rows, it removes the rows of every +recording whose directory is gone. When there are rows and it finds none of their directories, the +storage path is treated as unavailable, for example a disk that is not mounted: nothing is removed, +one ERROR names the effective storage path (``storage_path``, or the system temp directory when it +is empty) and the number of rows, and the fault manager reports the fault +``ROSBAG_STORAGE_UNAVAILABLE`` (severity ``CRITICAL``, source the fault manager node, description the +path and the number of rows). That fault starts no capture. When the rows cannot be read at startup (a +PostgreSQL server that cannot be reached), one WARN is logged and nothing is checked. A lookup that +fails (no permission, an I/O error, a symbolic link loop) finds nothing and proves nothing: such a +recording is not removed, does not make the storage available and, while the storage is unavailable, +is kept like the recordings that are gone. ``GetRosbag`` answers that the file cannot be looked up, +and ``ListRosbags`` leaves it out with one WARN per call. + +After startup, ``GetRosbag`` and ``ListRosbags`` remove the rows of a recording whose directory is +gone when they meet it. While the storage is unavailable they keep those rows: ``ListRosbags`` leaves +them out of the list and ``GetRosbag`` answers that the file is not on disk. To recover, mount the +disk. The first ``GetRosbag`` or ``ListRosbags`` call that finds an existing recorded directory clears +the fault. Rows that this call found missing stay until a later call removes them. A start that finds +a recorded directory, or no rows, clears the fault too. Clearing the fault by hand keeps the rows. + +While the storage is unavailable, the recordings it could not find are kept by every rule: the +startup reclassification, a clear, a heal, the cap (``max_bags`` and ``keep_first`` count only the +other recordings), the quota eviction, the age limits and the free-space floor skip them; in the +eviction order, ``keep_first`` ranks the first of the other recordings. They still +count toward ``max_total_storage_mb``: when only they keep the storage over it, the new recording is +kept and a WARN names the bytes they take. Recording goes on: a new recording is +written to the storage path as it is, listed and served, and managed by the rules as usual. The floor +then measures the filesystem the new recordings are written to, not the disk that is not mounted. +Only the directory of a recording that was stored when the fault manager started ends the +unavailable state, so a new recording never clears the fault. The check +compares only the rows with the file system: there is no marker file and no store identity, and a +directory that no row names is not removed. With no rows the storage counts as available, so a disk +that is not mounted while no recording is stored is not detected. + **What a closed recording contains.** The recording directory holds the storage files rosbag2 wrote, its ``metadata.yaml``, and a ``manifest.json`` the fault manager writes once the writer is closed and before the recording is listed. The diff --git a/src/ros2_medkit_fault_manager/CMakeLists.txt b/src/ros2_medkit_fault_manager/CMakeLists.txt index 73a00b187..2552c117b 100644 --- a/src/ros2_medkit_fault_manager/CMakeLists.txt +++ b/src/ros2_medkit_fault_manager/CMakeLists.txt @@ -315,6 +315,11 @@ endif() medkit_add_launch_test(test_rosbag_free_space test/integration/test_rosbag_free_space.test.py TIMEOUT 600 LABELS "integration") + # The startup check of the recorded directories: rows of missing recordings, an unavailable storage + # path (no recorded directory found), its recovery and an empty store. Two runs per case. + medkit_add_launch_test(test_rosbag_storage_availability test/integration/test_rosbag_storage_availability.test.py + TIMEOUT 300 LABELS "integration") + if(POSTGRES_SUPPORT) medkit_add_launch_test(test_rosbag_quota_pg test/integration/test_rosbag_quota_pg.test.py TIMEOUT 300 LABELS "integration") diff --git a/src/ros2_medkit_fault_manager/README.md b/src/ros2_medkit_fault_manager/README.md index 0e58cc4ae..44b18a9a4 100644 --- a/src/ros2_medkit_fault_manager/README.md +++ b/src/ros2_medkit_fault_manager/README.md @@ -132,6 +132,18 @@ dependencies of this package, so a normal install pulls in both backends. See `docs/config/fault-manager.rst` and `docs/tutorials/snapshots.rst` for the full parameter list and recording lifecycle. +At startup, also with capture off, the fault manager reads the rosbag rows once and looks for the directory of each +recording. When it finds one, or there are no rows, it removes the rows of the recordings whose directory is gone. +With rows and no directory found, the storage path is treated as unavailable (for example a disk that is not +mounted): nothing is removed, one ERROR names the path (`storage_path`, or the system temp directory when it is +empty) and the row count, and the fault `ROSBAG_STORAGE_UNAVAILABLE` is reported. While it is unavailable, +`GetRosbag`, `ListRosbags` and every rule (status actions, cap, quota eviction, age, floor) keep the recordings it +could not find, and recording goes on into the path as it is, with new recordings managed as usual. Mount the disk: +the first `GetRosbag` or `ListRosbags` call that finds the directory of a recording stored before the start clears +the fault (a recording made since never does), and a later call removes the rows still missing. A start that finds a +directory, or no rows, clears the fault too. A failed read of the rows at startup logs one WARN and checks nothing. +There is no marker file: a disk that is not mounted while no recording is stored is not detected. + #### Rosbag Retention Rules `snapshots.rosbag.retention.*` sets a `priority` (0-1000), an `over_quota` choice (`keep` or `drop`), a diff --git a/src/ros2_medkit_fault_manager/design/index.rst b/src/ros2_medkit_fault_manager/design/index.rst index 93b62cf46..5b52c5418 100644 --- a/src/ros2_medkit_fault_manager/design/index.rst +++ b/src/ros2_medkit_fault_manager/design/index.rst @@ -624,9 +624,9 @@ Rosbag retention and posts the directories to the retention worker. - ``delete_generation``: the code's delete generation, read by ``RosbagCapture`` when a code joins a recording. -- ``forget_recording``: removes the rows of a recording whose directory is gone, for - ``GetRosbag`` and ``ListRosbags``. The node builds the retention also with rosbag capture off, - so this cleanup runs then too. +- ``forget_recording``: removes the rows of a recording whose directory is gone, for the node's + startup storage check, ``GetRosbag`` and ``ListRosbags``. The node builds the retention also with + rosbag capture off, so this cleanup runs then too. - ``sweep_expired(now_ns)``: one pass of the age sweep. It returns at once unless ``kConfigured`` and ``RetentionPolicy::sweeps()`` (a level sets a ``max_age_sec`` key above 0). Otherwise it reads ``get_all_rosbag_files`` and ``get_all_faults`` once each, and removes in one change set the link of @@ -699,6 +699,47 @@ drops both. The timer is created cancelled and runs on the executor thread only while something is pending: the flag, or the startup report or clear that the core has not accepted yet. +The report and the clear of the own faults go through ``report_own_fault``, ``ensure_own_fault`` and +``clear_own_fault``, which take the fault code (the first two also the description). Both own faults +record nothing. + +**Startup storage check.** ``FaultManagerNode::check_rosbag_storage_at_startup()`` runs once in the +constructor, after the retention and the worker and before the startup reclassification and the +services, also with rosbag capture off, so its result is known before any rule removes a row. It reads ``get_all_rosbag_files`` once, keeps one directory +per recording id and checks each with ``std::filesystem::exists`` outside the retention mutex; an +error of that call counts as neither found nor missing (``look_up_directory``), so it is not +forgotten, does not make the storage available, and is protected when the storage is unavailable. +``GetRosbag`` and ``ListRosbags`` treat a failed lookup the same way: not served, not removed, no +recovery. It logs ``rosbag storage check: rows= +recordings= missing= available=`` at DEBUG. A directory found, or no rows: each +missing recording goes through ``forget_recording``, its directories are posted to the retention +worker, and a ``ROSBAG_STORAGE_UNAVAILABLE`` of an earlier start is cleared. Rows but no directory: +``unavailable_recordings_`` takes every recording id and the node passes them to +``RosbagRetention::protect_recordings``, nothing is removed, one ERROR names the effective storage +path and the row count, and the fault is reported. A failed read logs one WARN and sets nothing. The +report or clear runs in the first own-fault pass of the constructor; one the core does not accept +stays pending for the own-fault timer, and a successful clear of the fault drops a pending report. + +``unavailable_recordings_`` lives on the executor thread. While it is not empty, ``GetRosbag`` and +``ListRosbags`` do not call ``forget_recording`` for a missing directory. ``ListRosbags`` reads it +once per call, so the call that finds a directory keeps the rows it found missing. Either handler +calls ``recorded_directory_found(recording_id)`` for each existing directory; only an id in the set +empties it, calls ``RosbagRetention::release_recordings`` and clears the fault at once, arming the +own-fault timer when the core does not accept the clear, so a recording stored while the storage is +unavailable never ends that state. + +**Protected recordings.** ``protect_recordings`` and ``release_recordings`` set and drop, under the +retention mutex, the recording ids no removal decision of ``RosbagRetention`` removes: the age sweep, +``evict_one_for_space`` and ``has_space_candidate`` (through ``space_candidates``), the quota eviction +(``decide_quota`` and ``evict``; the total still counts their sizes, ``admits_new_recording`` does +not count them as evictable, and when the oldest-first store stays over the quota with protected +bytes, its WARN names those bytes instead of saying the new recording alone exceeds it), the cap (``cap_changes`` neither counts nor removes them, and takes ``keep_first``'s first recording from +the rows it counts; ``decide_quota`` and ``space_candidates`` take it for the eviction order from +``first_paths``, which skips them too), the status +actions (``on_status_change``: heal, clear, startup reclassification; the delete generation still +advances) and ``forget_recording``. A decision skips their rows and, while a set is held, logs +``: skipped protected rosbag row(s)`` once at DEBUG. + The node publishes the mode and the policy once, with ``RosbagRetention::set_policy``, after it builds the retention and before capture starts. Each decision loads that snapshot once with ``std::atomic_load`` and uses it throughout. @@ -736,9 +777,10 @@ depends on the path: logged. The executor never runs a store. A bag that never got a row is discarded on the same thread. A store in doubt (``kInDoubt``) returns no paths: the new directory stays, and a cap victim's directory can stay with no row when the commit was applied. -- Clear, heal, startup reclassification and stale rows (the executor): the rows go inside the - service call or the constructor. The node's ``RetentionWorker``, one thread with a FIFO queue, - removes the directories, so the clear and report services return before a large bag is removed. +- Clear, heal, startup reclassification and stale rows (the executor; stale rows also in the startup + storage check): the rows go inside the service call or the constructor. The node's + ``RetentionWorker``, one thread with a FIFO queue, removes the directories, so the clear and + report services return before a large bag is removed. - Age sweep (the retention worker): the periodic job calls ``sweep_expired`` with the system clock, then removes the returned directories on the same thread once the retention mutex is released, and logs ``retention sweep: now= removed=`` at DEBUG. ``now`` is the time the pass diff --git a/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/core/rosbag_retention.hpp b/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/core/rosbag_retention.hpp index 24b532c8d..ba41e7175 100644 --- a/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/core/rosbag_retention.hpp +++ b/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/core/rosbag_retention.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,13 @@ class RosbagRetention { /// decisions run: each decision uses the snapshot it loaded. void set_policy(RetentionMode mode, std::shared_ptr policy); + /// Keep every row of @p recording_ids: each removal decision below skips them, and the quota still counts their + /// sizes. Replaces the set held before. While a set is held, each decision logs the rows it skipped at DEBUG. + void protect_recordings(std::unordered_set recording_ids); + + /// Drop the set of protect_recordings(). + void release_recordings(); + /// Priority of a stored recording: the highest priority of the faults it is linked to, 0 /// unless kConfigured. /// @throws a storage failure @@ -251,6 +259,7 @@ class RosbagRetention { private: struct Eviction { std::vector unlink_paths; + size_t protected_bytes{0}; ///< Bytes of the protected recordings the eviction skipped }; struct FaultFacts; @@ -297,9 +306,21 @@ class RosbagRetention { const std::vector & fault_codes, const std::map & first_path_by_code, FactsCache & cache); - /// The recordings the floor may delete at @p priority_limit, in eviction order. Expects mutex_ held. + /// The recordings the floor may delete at @p priority_limit, in eviction order. Counts the protected rows left out + /// in @p skipped. Expects mutex_ held. /// @throws a failure of a read - std::vector space_candidates(const RetentionPolicyState & state, int64_t priority_limit); + std::vector space_candidates(const RetentionPolicyState & state, int64_t priority_limit, + size_t & skipped); + + /// The first recording of each fault code among @p rows (read oldest first) that are not protected: what + /// keep_first keeps in the eviction order. Expects mutex_ held. + std::map first_paths(const std::vector & rows) const; + + /// Whether protect_recordings() holds @p recording_id. Expects mutex_ held. + bool is_protected(const std::string & recording_id) const; + + /// One DEBUG line with the protected rows @p decision skipped, only while a set is held. Expects mutex_ held. + void log_protected(const char * decision, size_t skipped) const; /// Whether a clear of @p fault_code deletes its recordings (on_fault_cleared). Expects mutex_ held. /// @throws a failure of the fault read @@ -355,6 +376,8 @@ class RosbagRetention { std::mutex mutex_; /// One entry per fault code that had a delete action. Guarded by mutex_; only looked up by code. std::unordered_map delete_generations_; + /// Recordings no removal decision removes. Guarded by mutex_. + std::unordered_set protected_; }; } // namespace ros2_medkit_fault_manager::core diff --git a/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/fault_manager_node.hpp b/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/fault_manager_node.hpp index 8b7045a75..c5a013ca4 100644 --- a/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/fault_manager_node.hpp +++ b/src/ros2_medkit_fault_manager/include/ros2_medkit_fault_manager/fault_manager_node.hpp @@ -184,18 +184,29 @@ class FaultManagerNode : public rclcpp::Node { /// The \`snapshots.rosbag.retention.*\` overrides, keyed relative to that prefix. Declares nothing. core::FlatParams read_retention_overrides(); - /// Report the retention configuration fault through the core. True when the core accepted it. - bool report_retention_config_fault(); + /// Report an own fault (severity CRITICAL, source this node) through the core. True when the core accepted it. + bool report_own_fault(const char * fault_code, const std::string & description); - /// Report the fault unless it is CONFIRMED. True when nothing is left to do. - bool ensure_retention_config_fault(); + /// Report the own fault unless it is CONFIRMED. True when nothing is left to do. + bool ensure_own_fault(const char * fault_code, const std::string & description); - /// Clear the fault if it is stored. True when nothing is left to do. - bool clear_retention_config_fault(); + /// Clear the own fault if it is stored. True when nothing is left to do. + bool clear_own_fault(const char * fault_code); + + /// Run the pending report or clear of the storage fault. True when nothing is left to do. + bool storage_fault_step(); /// One pass of the own-fault work. True while something stays pending. bool retention_pass(); + /// Once at startup, also with rosbag capture off: removes the rows of recordings whose directory is gone, or, when + /// rows exist and no recorded directory does, marks the storage unavailable and reports ROSBAG_STORAGE_UNAVAILABLE. + void check_rosbag_storage_at_startup(); + + /// GetRosbag or ListRosbags found the directory of @p recording_id. A recording the startup check found missing + /// makes an unavailable storage available again; any other does nothing. + void recorded_directory_found(const std::string & recording_id); + /// A fault moved to CONFIRMED: the own fault is reported again. Runs under the core mutex: it only records the /// request and arms the timer. void on_confirmed(const std::string & fault_code); @@ -249,6 +260,13 @@ class FaultManagerNode : public rclcpp::Node { bool retention_reraise_{false}; /// Armed while an own-fault action is pending, cancelled otherwise. rclcpp::TimerBase::SharedPtr retention_timer_; + /// The recordings stored when the startup check found no directory. While not empty the storage is unavailable: + /// GetRosbag and ListRosbags keep the rows of missing directories until they find a directory of one of these. + std::set unavailable_recordings_; + enum class StorageFaultAction { kNone, kReport, kClear }; + /// The report or clear of ROSBAG_STORAGE_UNAVAILABLE the core has not accepted yet. + StorageFaultAction storage_fault_action_{StorageFaultAction::kNone}; + std::string storage_fault_description_; std::string storage_type_; int32_t confirmation_threshold_{-1}; bool healing_enabled_{false}; diff --git a/src/ros2_medkit_fault_manager/src/core/rosbag_retention.cpp b/src/ros2_medkit_fault_manager/src/core/rosbag_retention.cpp index ff16f5e0f..869c0c687 100644 --- a/src/ros2_medkit_fault_manager/src/core/rosbag_retention.cpp +++ b/src/ros2_medkit_fault_manager/src/core/rosbag_retention.cpp @@ -219,6 +219,37 @@ void RosbagRetention::set_policy(RetentionMode mode, std::shared_ptr recording_ids) { + std::lock_guard lock(mutex_); + protected_ = std::move(recording_ids); +} + +void RosbagRetention::release_recordings() { + std::lock_guard lock(mutex_); + protected_.clear(); +} + +std::map RosbagRetention::first_paths(const std::vector & rows) const { + std::map first_path_by_code; + for (const auto & row : rows) { + // A protected recording is kept anyway; keep_first ranks the first of the others. + if (!is_protected(row.recording_id.empty() ? rosbag_recording_id(row.file_path) : row.recording_id)) { + first_path_by_code.emplace(row.fault_code, row.file_path); + } + } + return first_path_by_code; +} + +bool RosbagRetention::is_protected(const std::string & recording_id) const { + return protected_.count(recording_id) != 0; +} + +void RosbagRetention::log_protected(const char * decision, size_t skipped) const { + if (!protected_.empty()) { + logf(log_sink_, LogLevel::kDebug, logger_name_, "%s: skipped %zu protected rosbag row(s)", decision, skipped); + } +} + StoreOutcome RosbagRetention::store(std::vector rows, const DeleteGenerations & joined) { for ([[maybe_unused]] const auto & row : rows) { assert(!row.recording_id.empty() && row.recording_id == rosbag_recording_id(row.file_path)); @@ -287,12 +318,19 @@ StoreOutcome RosbagRetention::store_oldest_first(const std::vector limits_.max_total_bytes) { - logf(log_sink_, LogLevel::kWarn, logger_name_, - "Recording '%s' alone exceeds snapshots.rosbag.max_total_storage_mb (%zu MB); it is kept, and the " - "storage stays over the limit until a newer recording replaces it", - keep_recording_id.c_str(), limits_.max_total_bytes / (1024 * 1024)); + if (eviction.protected_bytes == 0) { + logf(log_sink_, LogLevel::kWarn, logger_name_, + "Recording '%s' alone exceeds snapshots.rosbag.max_total_storage_mb (%zu MB); it is kept, and the " + "storage stays over the limit until a newer recording replaces it", + keep_recording_id.c_str(), limits_.max_total_bytes / (1024 * 1024)); + } else { + logf(log_sink_, LogLevel::kWarn, logger_name_, + "Recording '%s' is kept over snapshots.rosbag.max_total_storage_mb (%zu MB): %zu bytes of the total are " + "recordings of the unavailable storage path, which no rule removes until it is found again", + keep_recording_id.c_str(), limits_.max_total_bytes / (1024 * 1024), eviction.protected_bytes); + } } } catch (const std::exception & e) { outcome.quota_failed = true; @@ -495,20 +533,21 @@ RosbagRetention::QuotaDecision RosbagRetention::decide_quota(const std::vector first_path_by_code; - for (const auto & row : stored) { - first_path_by_code.emplace(row.fault_code, row.file_path); - } + // The first recording of each fault code, from the rows before this store. + const auto first_path_by_code = first_paths(stored); const RecordingRank fresh = rank_of(state, codes_by_path.at(bag_path), cache); decision.priority = fresh.priority; std::vector allowed; + size_t skipped = 0; for (auto & candidate : candidates) { if (candidate.path == bag_path) { continue; } + if (is_protected(candidate.recording_id)) { + skipped += codes_by_path.at(candidate.path).size(); + continue; + } const auto & codes = codes_by_path.at(candidate.path); candidate.rank = rank_of(state, codes, cache); if (candidate.rank.priority > fresh.priority) { @@ -517,6 +556,7 @@ RosbagRetention::QuotaDecision RosbagRetention::decide_quota(const std::vector> codes_by_path; for (const auto & row : after) { - codes_by_path[row.file_path].push_back(row.fault_code); + // The quota eviction skips a protected recording. + if (!is_protected(row.recording_id)) { + codes_by_path[row.file_path].push_back(row.fault_code); + } } for (const auto & entry : codes_by_path) { if (rank_of(*state, entry.second, cache).priority <= priority) { @@ -796,7 +839,12 @@ RemovalOutcome RosbagRetention::on_status_change(StatusChange change, const std: // Advanced before the removal: a recording the code joined earlier loses its row at its store, // also when this removal throws. ++delete_generations_[fault_code]; - const auto rows = storage_.get_rosbag_files(fault_code); + auto rows = storage_.get_rosbag_files(fault_code); + const auto skipped = std::remove_if(rows.begin(), rows.end(), [this](const RosbagFileInfo & row) { + return is_protected(row.recording_id); + }); + log_protected(change == StatusChange::kHealed ? "heal" : "clear", static_cast(rows.end() - skipped)); + rows.erase(skipped, rows.end()); RosbagChangeSet changes; for (const auto & row : rows) { changes.remove.push_back({row.fault_code, row.file_path}); @@ -814,6 +862,10 @@ RemovalOutcome RosbagRetention::forget_recording(const std::string & recording_i } std::lock_guard lock(mutex_); const auto rows = storage_.get_rosbag_files_by_recording(recording_id); + if (is_protected(recording_id)) { + log_protected("stale-row removal", rows.size()); + return {}; + } RosbagChangeSet changes; changes.remove_recordings.push_back(recording_id); return remove(rows, changes, RemovalReason::kStale); @@ -838,7 +890,13 @@ SweepOutcome RosbagRetention::sweep_expired(int64_t now_ns) { std::string code = fault.fault_code; faults.emplace(std::move(code), std::move(fault)); } + size_t skipped = 0; for (const auto & row : rows) { + const std::string id = row.recording_id.empty() ? rosbag_recording_id(row.file_path) : row.recording_id; + if (is_protected(id)) { + ++skipped; + continue; + } const auto fault = faults.find(row.fault_code); if (fault == faults.end()) { continue; @@ -858,9 +916,9 @@ SweepOutcome RosbagRetention::sweep_expired(int64_t now_ns) { continue; } changes.remove.push_back({row.fault_code, row.file_path}); - const std::string id = row.recording_id.empty() ? rosbag_recording_id(row.file_path) : row.recording_id; freed_by_path.emplace(row.file_path, FreedRecording{row.file_path, id, reason}); } + log_protected("age sweep", skipped); } catch (const std::exception & e) { logf(log_sink_, LogLevel::kWarn, logger_name_, "Rosbag age sweep could not read the storage; nothing is removed until the next pass: %s", e.what()); @@ -905,8 +963,8 @@ SweepOutcome RosbagRetention::sweep_expired(int64_t now_ns) { return outcome; } -std::vector RosbagRetention::space_candidates(const RetentionPolicyState & state, - int64_t priority_limit) { +std::vector +RosbagRetention::space_candidates(const RetentionPolicyState & state, int64_t priority_limit, size_t & skipped) { struct Ranked { SpaceCandidate candidate; std::vector codes; @@ -916,10 +974,9 @@ std::vector RosbagRetention::space_candidates(c }; std::vector ranked; std::map index_by_path; - // The first recording of each fault code: the storage reads the rows oldest first. - std::map first_path_by_code; - for (const auto & row : storage_.get_all_rosbag_files()) { - first_path_by_code.emplace(row.fault_code, row.file_path); + const auto rows = storage_.get_all_rosbag_files(); + const auto first_path_by_code = first_paths(rows); + for (const auto & row : rows) { const auto known = index_by_path.emplace(row.file_path, ranked.size()); if (known.second) { Ranked entry; @@ -936,6 +993,10 @@ std::vector RosbagRetention::space_candidates(c FactsCache cache; std::vector allowed; for (auto & entry : ranked) { + if (is_protected(entry.candidate.recording_id)) { + skipped += entry.codes.size(); + continue; + } entry.rank = rank_of(state, entry.codes, cache); if (entry.rank.priority > priority_limit) { continue; @@ -961,8 +1022,9 @@ SpaceStep RosbagRetention::evict_one_for_space(int64_t priority_limit, const std const auto state = std::atomic_load(&state_); SpaceStep step; std::vector candidates; + size_t skipped = 0; try { - candidates = space_candidates(*state, priority_limit); + candidates = space_candidates(*state, priority_limit, skipped); } catch (const std::exception & e) { logf(log_sink_, LogLevel::kWarn, logger_name_, "Rosbag free-space pass could not read the storage; nothing is removed until the next pass: %s", e.what()); @@ -975,6 +1037,7 @@ SpaceStep RosbagRetention::evict_one_for_space(int64_t priority_limit, const std step.result = SpaceStep::Result::kFailed; return step; } + log_protected("free-space step", skipped); if (candidates.empty()) { return step; } @@ -1020,8 +1083,9 @@ SpaceStep RosbagRetention::evict_one_for_space(int64_t priority_limit, const std bool RosbagRetention::has_space_candidate(int64_t priority_limit) { std::lock_guard lock(mutex_); const auto state = std::atomic_load(&state_); + size_t skipped = 0; try { - return !space_candidates(*state, priority_limit).empty(); + return !space_candidates(*state, priority_limit, skipped).empty(); } catch (...) { return true; } @@ -1136,6 +1200,7 @@ RosbagChangeSet RosbagRetention::cap_changes(const std::vector & }; std::set> dropped; std::set done; + size_t skipped = 0; for (const auto & incoming : rows) { const std::string & code = incoming.fault_code; if (!done.insert(code).second) { @@ -1175,10 +1240,15 @@ RosbagChangeSet RosbagRetention::cap_changes(const std::vector & size_t rank = 0; for (auto it = stored.rbegin(); it != stored.rend(); ++it) { recording_ids.emplace(it->file_path, it->recording_id); + // Neither counted nor removed: the cap applies to the other recordings. + if (is_protected(it->recording_id)) { + ++skipped; + continue; + } candidates.push_back({it->created_at_ns, rank++, it->file_path, true, false}); } - // The first link is read before the change: an upsert of it does not make another one first. - const std::string first_path = keep_first && !stored.empty() ? stored.back().file_path : std::string(); + // The first link the cap counts, read before the change: an upsert of it does not make another one first. + const std::string first_path = keep_first && !candidates.empty() ? candidates.front().file_path : std::string(); for (const auto & row : rows) { if (row.fault_code != code) { continue; @@ -1219,6 +1289,9 @@ RosbagChangeSet RosbagRetention::cap_changes(const std::vector & } } + if (store_logs) { + log_protected("cap", skipped); + } for (const auto & row : rows) { if (dropped.count({row.fault_code, row.file_path}) == 0) { changes.insert.push_back(row); @@ -1238,16 +1311,19 @@ void RosbagRetention::evict(size_t max_bytes, const std::string & keep_recording std::vector paths_oldest_first; std::unordered_map recording_by_path; std::unordered_map bytes_by_path; + std::unordered_map rows_by_path; for (const auto & row : storage_.get_all_rosbag_files()) { // The rows arrive oldest first, so a path's first row gives the recording's age. if (recording_by_path.emplace(row.file_path, row.recording_id).second) { paths_oldest_first.push_back(row.file_path); } + ++rows_by_path[row.file_path]; // The storage counts the largest row per path. auto & bytes = bytes_by_path[row.file_path]; bytes = std::max(bytes, row.size_bytes); } + size_t skipped = 0; for (const auto & path : paths_oldest_first) { if (current_bytes <= max_bytes) { break; @@ -1255,6 +1331,11 @@ void RosbagRetention::evict(size_t max_bytes, const std::string & keep_recording if (!keep_recording_id.empty() && recording_by_path[path] == keep_recording_id) { continue; } + if (is_protected(recording_by_path[path])) { + skipped += rows_by_path[path]; + out.protected_bytes += bytes_by_path[path]; + continue; + } // By recording, not by fault code: a fault's newer recordings must stay. RosbagChangeSet changes; changes.remove_recordings.push_back(recording_by_path[path]); @@ -1263,6 +1344,7 @@ void RosbagRetention::evict(size_t max_bytes, const std::string & keep_recording // Saturate: the quota must never be met by underflow. current_bytes -= std::min(current_bytes, bytes_by_path[path]); } + log_protected("quota eviction", skipped); } RemovalOutcome RosbagRetention::remove(const std::vector & rows, const RosbagChangeSet & changes, diff --git a/src/ros2_medkit_fault_manager/src/fault_manager_node.cpp b/src/ros2_medkit_fault_manager/src/fault_manager_node.cpp index 640274c26..84a6fe922 100644 --- a/src/ros2_medkit_fault_manager/src/fault_manager_node.cpp +++ b/src/ros2_medkit_fault_manager/src/fault_manager_node.cpp @@ -57,6 +57,7 @@ using core::validate_fault_code; constexpr const char * kRetentionParamPrefix = "snapshots.rosbag.retention."; constexpr const char * kRetentionConfigFaultCode = "ROSBAG_RETENTION_CONFIG_INVALID"; +constexpr const char * kStorageUnavailableFaultCode = "ROSBAG_STORAGE_UNAVAILABLE"; std::string join(const std::vector & items, const char * separator) { std::string text; @@ -173,6 +174,29 @@ std::string validate_recording_id(const std::string & recording_id) { return ""; // Valid } +/// The directory the recordings are written under: storage_path, or the system temp directory when it is empty. +std::string effective_storage_path(const std::string & storage_path) { + if (!storage_path.empty()) { + return storage_path; + } + std::error_code ec; + const auto temp = std::filesystem::temp_directory_path(ec); + return ec ? std::string{} : temp.string(); +} + +/// A lookup of a recorded directory. kFailed (EACCES, EIO, ELOOP) proves neither that it exists nor that it is gone. +enum class DirectoryLookup { kFound, kMissing, kFailed }; + +DirectoryLookup look_up_directory(const std::string & path, std::string & error) { + std::error_code ec; + const bool found = std::filesystem::exists(path, ec); + if (ec) { + error = ec.message(); + return DirectoryLookup::kFailed; + } + return found ? DirectoryLookup::kFound : DirectoryLookup::kMissing; +} + /// Service QoS for ~/report_fault, in the type the linked rclcpp takes. Not KEEP_ALL: the response /// writer shares this QoS, and a client that stops acknowledging would fill its history. auto report_fault_qos(size_t depth) { @@ -259,6 +283,8 @@ FaultManagerNode::FaultManagerNode(const rclcpp::NodeOptions & options) : Node(" : retention_policy_ != nullptr ? core::RetentionMode::kConfigured : core::RetentionMode::kUnconfigured, retention_policy_); + // Before any rule removes a row: an unavailable storage protects every recorded row. + check_rosbag_storage_at_startup(); // Runs after the override files are loaded, so a code with its own healing_enabled: true keeps // its HEALED status. Each flipped fault is audited, or the audit log's verify() would not see it. @@ -484,8 +510,8 @@ FaultManagerNode::~FaultManagerNode() { } core::CaptureResult FaultManagerNode::enqueue_capture(const std::string & fault_code) { - // The retention configuration fault records nothing. - if (fault_code == kRetentionConfigFaultCode) { + // The own faults record nothing. + if (fault_code == kRetentionConfigFaultCode || fault_code == kStorageUnavailableFaultCode) { return {}; } if (!capture_pool_) { @@ -584,12 +610,17 @@ void FaultManagerNode::handle_clear_fault( // it back. This is decided here and not from the cleared event: a storage can commit the clear and drop the // connection before that event. const auto & auto_cleared = outcome.auto_cleared_codes; - if (outcome.success && - (request->fault_code == kRetentionConfigFaultCode || - std::find(auto_cleared.begin(), auto_cleared.end(), kRetentionConfigFaultCode) != auto_cleared.end())) { + const auto cleared = [&](const char * code) { + return outcome.success && (request->fault_code == code || + std::find(auto_cleared.begin(), auto_cleared.end(), code) != auto_cleared.end()); + }; + if (cleared(kRetentionConfigFaultCode)) { retention_candidates_.clear(); retention_reraise_ = false; } + if (cleared(kStorageUnavailableFaultCode) && storage_fault_action_ == StorageFaultAction::kReport) { + storage_fault_action_ = StorageFaultAction::kNone; + } response->success = outcome.success; response->message = std::move(outcome.message); response->auto_cleared_codes = std::move(outcome.auto_cleared_codes); @@ -835,43 +866,57 @@ void FaultManagerNode::warn_on_unused_overrides() { } } -bool FaultManagerNode::report_retention_config_fault() { +bool FaultManagerNode::report_own_fault(const char * fault_code, const std::string & description) { fd::FaultReport report; - report.fault_code = kRetentionConfigFaultCode; + report.fault_code = fault_code; report.kind = fd::ReportKind::kFailed; report.severity = fd::severity::kCritical; - report.description = retention_fault_description_; + report.description = description; report.source_id = get_fully_qualified_name(); return core_->report(report).accepted; } -bool FaultManagerNode::ensure_retention_config_fault() { - const auto detail = core_->get(kRetentionConfigFaultCode); +bool FaultManagerNode::ensure_own_fault(const char * fault_code, const std::string & description) { + const auto detail = core_->get(fault_code); if (detail.success) { - return detail.fault.status == fd::fault_status::kConfirmed || report_retention_config_fault(); + return detail.fault.status == fd::fault_status::kConfirmed || report_own_fault(fault_code, description); } - return detail.not_found && report_retention_config_fault(); + return detail.not_found && report_own_fault(fault_code, description); } -bool FaultManagerNode::clear_retention_config_fault() { - const auto detail = core_->get(kRetentionConfigFaultCode); +bool FaultManagerNode::clear_own_fault(const char * fault_code) { + const auto detail = core_->get(fault_code); if (!detail.success) { return detail.not_found; } if (detail.fault.status == fd::fault_status::kCleared) { return true; } - const auto outcome = core_->clear(kRetentionConfigFaultCode, true); + const auto outcome = core_->clear(fault_code, true); return outcome.success || outcome.not_found; } +bool FaultManagerNode::storage_fault_step() { + bool done = true; + if (storage_fault_action_ == StorageFaultAction::kReport) { + done = report_own_fault(kStorageUnavailableFaultCode, storage_fault_description_); + } else if (storage_fault_action_ == StorageFaultAction::kClear) { + done = clear_own_fault(kStorageUnavailableFaultCode); + } + if (done) { + storage_fault_action_ = StorageFaultAction::kNone; + } + return done; +} + bool FaultManagerNode::retention_pass() { RCLCPP_DEBUG(get_logger(), "Retention config fault pass: startup=%d candidates=%zu", static_cast(retention_startup_pending_), retention_candidates_.size()); bool again = false; if (retention_startup_pending_) { retention_startup_pending_ = - !(retention_degraded_ ? report_retention_config_fault() : clear_retention_config_fault()); + !(retention_degraded_ ? report_own_fault(kRetentionConfigFaultCode, retention_fault_description_) + : clear_own_fault(kRetentionConfigFaultCode)); again = retention_startup_pending_; } for (auto it = retention_candidates_.begin(); it != retention_candidates_.end();) { @@ -885,9 +930,12 @@ bool FaultManagerNode::retention_pass() { it = retention_candidates_.erase(it); } if (retention_reraise_) { - retention_reraise_ = !ensure_retention_config_fault(); + retention_reraise_ = !ensure_own_fault(kRetentionConfigFaultCode, retention_fault_description_); again = again || retention_reraise_; } + if (storage_fault_action_ != StorageFaultAction::kNone) { + again = !storage_fault_step() || again; + } RCLCPP_DEBUG(get_logger(), "Retention config fault pass: %s", again ? "retrying" : "nothing pending"); return again; } @@ -899,6 +947,87 @@ void FaultManagerNode::arm_retention_timer() { } } +void FaultManagerNode::check_rosbag_storage_at_startup() { + std::vector rows; + try { + rows = storage_->get_all_rosbag_files(); + } catch (const std::exception & e) { + RCLCPP_WARN(get_logger(), "Rosbag storage check skipped: the rosbag rows could not be read: %s", e.what()); + return; + } + // One directory per recording, read outside the retention mutex. + std::map directories; + for (const auto & row : rows) { + directories.emplace(row.recording_id, row.file_path); + } + size_t found = 0; + std::vector missing; // proven gone + std::vector not_found; // gone or not looked up + std::string first_failure; + for (const auto & [recording_id, path] : directories) { + std::string error; + const auto lookup = look_up_directory(path, error); + if (lookup == DirectoryLookup::kFound) { + ++found; + continue; + } + not_found.push_back(recording_id); + if (lookup == DirectoryLookup::kMissing) { + missing.push_back(recording_id); + } else if (first_failure.empty()) { + first_failure.append("'").append(path).append("': ").append(error); + } + } + if (!first_failure.empty()) { + 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(); + RCLCPP_DEBUG(get_logger(), "rosbag storage check: rows=%zu recordings=%zu missing=%zu available=%s", rows.size(), + directories.size(), missing.size(), available ? "true" : "false"); + if (!available) { + // A recording stored later is written under the path as it is and proves nothing. + unavailable_recordings_.insert(not_found.begin(), not_found.end()); + rosbag_retention_->protect_recordings({not_found.begin(), not_found.end()}); + storage_fault_description_ = + "Rosbag storage path '" + effective_storage_path(config_.snapshots_rosbag_storage_path) + + "' is unavailable: no directory of the " + std::to_string(rows.size()) + " stored rosbag rows exists"; + RCLCPP_ERROR(get_logger(), + "%s. No row is removed until GetRosbag or ListRosbags finds a recorded directory; check that the " + "disk is mounted.", + storage_fault_description_.c_str()); + storage_fault_action_ = StorageFaultAction::kReport; + return; + } + // Clears the fault of an earlier start that found no directory. + storage_fault_action_ = StorageFaultAction::kClear; + for (const auto & recording_id : missing) { + try { + auto removal = rosbag_retention_->forget_recording(recording_id); + retention_worker_->post_removals("forget", std::move(removal.unlink_paths)); + } catch (const RosbagCommitInDoubt & e) { + RCLCPP_WARN(get_logger(), "Stale rows of recording '%s' may still be stored: %s", recording_id.c_str(), e.what()); + } catch (const std::exception & e) { + RCLCPP_WARN(get_logger(), "Failed to remove the stale rows of recording '%s': %s", recording_id.c_str(), + e.what()); + } + } +} + +void FaultManagerNode::recorded_directory_found(const std::string & recording_id) { + if (unavailable_recordings_.count(recording_id) == 0) { + return; + } + unavailable_recordings_.clear(); + rosbag_retention_->release_recordings(); + RCLCPP_INFO(get_logger(), "Rosbag storage path '%s' is available again: the directory of recording '%s' was found", + effective_storage_path(config_.snapshots_rosbag_storage_path).c_str(), recording_id.c_str()); + storage_fault_action_ = StorageFaultAction::kClear; + if (!storage_fault_step()) { + arm_retention_timer(); + } +} + void FaultManagerNode::sweep_expired_recordings() { // The line carries the time the pass decided with, not the time it logged. const int64_t now_ns = wall_clock_.now_ns(); @@ -1260,10 +1389,22 @@ void FaultManagerNode::handle_get_rosbag(const std::shared_ptrfile_path)) { + std::string lookup_error; + const auto lookup = look_up_directory(rosbag_info->file_path, lookup_error); + if (lookup == DirectoryLookup::kFailed) { + // Neither served nor removed. + response->success = false; + response->error_message = + "Rosbag file cannot be looked up on disk: " + rosbag_info->file_path + ": " + lookup_error; + return; + } + if (lookup == DirectoryLookup::kMissing) { response->success = false; response->error_message = "Rosbag file not found on disk: " + rosbag_info->file_path; + // While the storage path is unavailable the rows stay: the directory can come back. + if (!unavailable_recordings_.empty()) { + return; + } // Clean up the stale record BY RECORDING. Deleting by fault code would take the // fault's other, healthy recordings with it because one of them vanished. try { @@ -1279,6 +1420,7 @@ void FaultManagerNode::handle_get_rosbag(const std::shared_ptrrecording_id); response->success = true; response->file_path = rosbag_info->file_path; @@ -1319,9 +1461,25 @@ void FaultManagerNode::handle_list_rosbags( } std::set reaped; // one cleanup per recording, not per row + // Read once: the call that finds the storage again keeps the rows it found missing. + const bool keep_missing = !unavailable_recordings_.empty(); + size_t failed_lookups = 0; + std::string first_failure; for (const auto & info : rosbags) { + std::string lookup_error; + const auto lookup = look_up_directory(info.file_path, lookup_error); + if (lookup == DirectoryLookup::kFailed) { + // Neither listed nor removed. + if (failed_lookups++ == 0) { + first_failure.append("'").append(info.file_path).append("': ").append(lookup_error); + } + continue; + } // Skip rosbags whose files no longer exist on disk - if (!std::filesystem::exists(info.file_path)) { + if (lookup == DirectoryLookup::kMissing) { + if (keep_missing) { + continue; + } // BY RECORDING: the bytes are gone for every fault that referenced them, so // leaving the sibling rows would keep charging the quota for nothing. Deleting // by fault code would instead take that fault's healthy recordings with it. @@ -1344,6 +1502,7 @@ void FaultManagerNode::handle_list_rosbags( } continue; } + recorded_directory_found(info.recording_id); response->fault_codes.push_back(info.fault_code); response->recording_ids.push_back(info.recording_id); @@ -1353,6 +1512,10 @@ void FaultManagerNode::handle_list_rosbags( response->sizes_bytes.push_back(core::rosbag_served_bytes(info.file_path, info.size_bytes)); response->created_at_ns.push_back(info.created_at_ns); } + if (failed_lookups > 0) { + RCLCPP_WARN(get_logger(), "ListRosbags left out %zu row(s) whose directory could not be looked up, first %s", + failed_lookups, first_failure.c_str()); + } // One retention call for the whole response: a per-recording read costs one storage transaction each. try { diff --git a/src/ros2_medkit_fault_manager/test/integration/rosbag_fm_harness.py b/src/ros2_medkit_fault_manager/test/integration/rosbag_fm_harness.py index 1ec413fbc..421b4fdca 100644 --- a/src/ros2_medkit_fault_manager/test/integration/rosbag_fm_harness.py +++ b/src/ros2_medkit_fault_manager/test/integration/rosbag_fm_harness.py @@ -55,6 +55,7 @@ FM_NODE = 'fault_manager' QOS_MATCH_PARAM = 'snapshots.rosbag.qos_match' OWN_CODE = 'ROSBAG_RETENTION_CONFIG_INVALID' +STORAGE_CODE = 'ROSBAG_STORAGE_UNAVAILABLE' ALL_STATUSES = ('PREFAILED', 'PREPASSED', 'CONFIRMED', 'HEALED', 'CLEARED') # prctl option: the kernel sends the child this signal when the test process dies. PR_SET_PDEATHSIG = 1 @@ -576,6 +577,15 @@ def base_params(db_path, storage_path, **overrides): # The DEBUG line that ends every min_free_disk_mb pass: removed, free, floor, met, source. FLOOR_PASS = (r'floor pass: removed=(\d+) free=(\d+|unknown) floor=(\d+) met=(true|false) ' r'source=(filesystem|test-capacity)') +# The DEBUG line of the startup storage check: rows, recordings, recordings missing, available. +STORAGE_CHECK = (r'rosbag storage check: rows=(\d+) recordings=(\d+) missing=(\d+) ' + r'available=(true|false)') +# The ERROR of a storage path where no recorded directory exists: the path and the row count. +STORAGE_UNAVAILABLE = (r"\[ERROR\].*Rosbag storage path '([^']*)' is unavailable: no directory of " + r'the (\d+) stored rosbag rows exists') +# The WARN of a startup storage check that could not read the rows. +STORAGE_CHECK_SKIPPED = (r'\[WARN\].*Rosbag storage check skipped: the rosbag rows could not ' + r'be read') def expired_at(last_failed_ns, limit_sec=AGE_SEC): @@ -848,3 +858,66 @@ def check_critical_evicts_lower_priority(self): self.assert_recording_present('ERR_OLD', paths['ERR_OLD']) self.assert_recording_present('CRIT_A', critical) self.assertLessEqual(storage_bytes(self.storage), 7 * MIB) + + def storage_fault_statuses(self): + return [fault.status for fault in self.client.list_faults(ALL_STATUSES, include_muted=True) + if fault.fault_code == STORAGE_CODE] + + def wait_storage_fault(self, status): + """Poll until the storage fault is stored once, with `status`.""" + seen = [] + + def reached(): + seen[:] = self.storage_fault_statuses() + return seen == [status] + self.assertTrue(poll(reached), f'{STORAGE_CODE} is {seen}, never [{status!r}]') + + def startup_check(self, fm): + """Return the line of the startup storage check, logged before the node said it started.""" + check = fm.wait_line(STORAGE_CHECK, timeout=0) + self.assertIsNotNone(check, 'no startup storage check:\n' + fm.output()[-3000:]) + self.assertEqual(fm.count_lines(STORAGE_CHECK), 1, fm.output()[-3000:]) + return check + + def record_then_unmount(self, codes): + """Record one recording per code in one run, then rename the storage directory away.""" + with self.fm_run() as fm: + paths = [self.record(fm, code, 0.25) for code in codes] + self.unmount() + return paths + + def unmount(self): + self.unmounted = self.storage + '.unmounted' + os.rename(self.storage, self.unmounted) + + def mount(self): + os.rename(self.unmounted, self.storage) + + def assert_started_unavailable(self, fm, rows): + """Check a start that found no directory of `rows`: rows kept, one ERROR, the own fault.""" + self.assertEqual(sorted(self.stored_rows()), sorted(rows)) + # Logged before the node logs that it started. + unavailable = fm.wait_line(STORAGE_UNAVAILABLE, timeout=0) + self.assertIsNotNone(unavailable, fm.output()[-3000:]) + self.assertEqual(unavailable.group(1), self.storage) + self.assertEqual(int(unavailable.group(2)), len(rows)) + self.assertEqual(fm.count_lines(r'\[ERROR\]'), 1, fm.output()[-3000:]) + self.wait_storage_fault('CONFIRMED') + check = self.startup_check(fm) + self.assertEqual(check.group(1), str(len(rows)), check.string) + self.assertEqual(check.group(4), 'false', check.string) + + def check_unavailable_at_startup(self): + """Check that a start with no recorded directory keeps the rows, also on a listing.""" + self.record_then_unmount(('FIRST', 'SECOND')) + rows = self.stored_rows() + self.assertEqual(len(rows), 2, rows) + with self.fm_run() as fm: + self.assert_started_unavailable(fm, rows) + for listing in (self.client.list_rosbags(all_recordings=True), + self.client.list_rosbags()): + self.assertTrue(listing.success, listing.error_message) + self.assertEqual(list(listing.recording_ids), []) + self.assertEqual(sorted(self.stored_rows()), sorted(rows)) + self.assertEqual(fm.count_lines(r'\[ERROR\]'), 1, fm.output()[-3000:]) + self.assertEqual(self.storage_fault_statuses(), ['CONFIRMED']) diff --git a/src/ros2_medkit_fault_manager/test/integration/test_retention_config_pg.test.py b/src/ros2_medkit_fault_manager/test/integration/test_retention_config_pg.test.py index 13089724a..60ccce8f0 100644 --- a/src/ros2_medkit_fault_manager/test/integration/test_retention_config_pg.test.py +++ b/src/ros2_medkit_fault_manager/test/integration/test_retention_config_pg.test.py @@ -14,7 +14,7 @@ # limitations under the License. """ -The retention configuration fault against a PostgreSQL server that is unreachable at start. +Own faults and the startup storage check against a PostgreSQL server unreachable at start. A TCP proxy owned by the test sits between the fault manager and the server and refuses connections until the test opens it. ROS2_MEDKIT_TEST_PG_CONN names the server, as @@ -23,6 +23,7 @@ import os import pathlib +import shutil import socket import sys import threading @@ -37,7 +38,9 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from rosbag_fm_harness import poll, RetentionCase # noqa: E402 +from rosbag_fm_harness import ( # noqa: E402 + poll, RetentionCase, STORAGE_CHECK, STORAGE_CHECK_SKIPPED, STORAGE_CODE, +) import yaml # noqa: E402 OWN_CODE = 'ROSBAG_RETENTION_CONFIG_INVALID' @@ -132,6 +135,7 @@ def setUp(self): self.addCleanup(self.proxy.refuse_connections) netloc = f'{parts.username}:{parts.password}@127.0.0.1:{self.proxy.port}' self.url = urllib.parse.urlunsplit(parts._replace(netloc=netloc, path='/' + self.database)) + self.direct_url = urllib.parse.urlunsplit(parts._replace(path='/' + self.database)) @staticmethod def _admin(url, statement): @@ -146,6 +150,16 @@ def _admin(url, statement): def storage_params(self): return {'storage_type': 'postgres', 'database_url': self.url} + def stored_rows(self): + """Return (fault_code, file_path) of every rosbag row, read past the proxy.""" + conn = psycopg2.connect(self.direct_url) + try: + with conn.cursor() as cur: + cur.execute('SELECT fault_code, file_path FROM rosbag_files ORDER BY id') + return cur.fetchall() + finally: + conn.close() + def write_params(self, retention): path = os.path.join(os.path.dirname(self.db), 'retention.yaml') tree = {'fault_manager': {'ros__parameters': {'snapshots': {'rosbag': { @@ -188,3 +202,32 @@ def test_stored_fault_cleared_once_the_server_is_reachable(self): self.wait_first_attempt_refused(fm) self.proxy.accept_connections() self.wait_own_status('CLEARED') + + def test_storage_check_skipped_while_the_server_is_unreachable(self): + self.proxy.accept_connections() + with self.fm_run() as fm: + gone = self.record(fm, 'GONE', 0.25) + kept = self.record(fm, 'KEPT', 0.25) + shutil.rmtree(gone) + rows = self.stored_rows() + self.assertEqual(sorted(rows), [('GONE', gone), ('KEPT', kept)]) + self.proxy.refuse_connections() + with self.fm_run() as fm: + # The check logs before the node logs that it started. + self.assertEqual(fm.count_lines(STORAGE_CHECK_SKIPPED), 1, fm.output()[-3000:]) + self.assertEqual(fm.count_lines(STORAGE_CHECK), 0, fm.output()[-3000:]) + self.assertEqual(sorted(self.stored_rows()), sorted(rows)) + self.proxy.accept_connections() + listings = [] + + def listed(): + listings[:] = [self.client.list_rosbags(all_recordings=True)] + return listings[0].success + self.assertTrue(poll(listed, interval=0.5), listings[0].error_message) + # The lazy removal runs as without the check. + self.assertEqual(list(listings[0].recording_ids), [os.path.basename(kept)]) + self.assertEqual(self.stored_rows(), [('KEPT', kept)]) + codes = [fault.fault_code for fault in self.client.list_faults(ALL_STATUSES)] + self.assertIn('KEPT', codes) + self.assertNotIn(STORAGE_CODE, codes) + self.assertEqual(fm.count_lines(r'\[ERROR\]'), 0, fm.output()[-3000:]) diff --git a/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota.test.py b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota.test.py index d78db0c8d..560f9f62a 100644 --- a/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota.test.py +++ b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota.test.py @@ -508,14 +508,16 @@ def test_stale_rows(self): with self.subTest('rosbag off on the next run'): self.new_scratch() with self.fm_run() as fm: + kept = self.record(fm, 'KEPT', 1) bag = self.record(fm, 'STALE_A', 1) - shutil.rmtree(bag) - self.assertEqual(self.row_paths('STALE_A'), [bag]) with self.fm_run(**{'snapshots.rosbag.enabled': False}): + # Removed after the startup check, which found both directories. + shutil.rmtree(bag) + self.assertEqual(self.row_paths('STALE_A'), [bag]) listed = self.client.list_rosbags() self.assertTrue(listed.success, listed.error_message) - self.assertEqual(list(listed.fault_codes), []) - self.assertEqual(self.stored_rows(), []) + self.assertEqual(list(listed.fault_codes), ['KEPT']) + self.assertEqual(self.stored_rows(), [('KEPT', kept)]) with self.subTest('rosbag on, directory removed while running'): self.new_scratch() diff --git a/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota_pg.test.py b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota_pg.test.py index 751769379..a68e889b4 100644 --- a/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota_pg.test.py +++ b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota_pg.test.py @@ -91,6 +91,9 @@ def test_heal_deletes(self): def test_active_ages_out(self): self.check_active_ages_out() + def test_unavailable_at_startup(self): + self.check_unavailable_at_startup() + def test_clear_removes_the_row_and_the_directory(self): with self.fm_run() as fm: bag = self.record(fm, 'PG_A', 1) diff --git a/src/ros2_medkit_fault_manager/test/integration/test_rosbag_storage_availability.test.py b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_storage_availability.test.py new file mode 100644 index 000000000..5a3f26b8c --- /dev/null +++ b/src/ros2_medkit_fault_manager/test/integration/test_rosbag_storage_availability.test.py @@ -0,0 +1,346 @@ +# Copyright 2026 bburda +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +The startup check of the recorded directories against a real fault_manager_node on SQLite. + +A case starts the fault manager twice on one SQLite file and one storage directory. Between the +runs it removes a recording's directory, or renames the storage directory away as a disk that is +not mounted. +""" + +import errno +import os +import pathlib +import shutil +import sys +import time + +from launch import LaunchDescription +import launch_testing +import launch_testing.actions +import launch_testing.util + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) + +from rosbag_fm_harness import ( # noqa: E402 + AGE_REMOVAL, AGE_SEC, FLOOR_PASS, HEALING, MIB, NS_PER_SEC, RetentionCase, rules, sqlite_exec, + sqlite_rows, STORAGE_UNAVAILABLE, SWEEP_EVERY_SECOND, SWEEP_LINE, +) + +NOT_ON_DISK = 'Rosbag file not found on disk' +CAPACITY_ENV = 'ROS2_MEDKIT_TEST_STORAGE_CAPACITY_FILE' +FLOOR_MB = 64 +# How far back the age case moves the last FAILED report of its fault. +LONG_AGO_NS = 3600 * NS_PER_SEC +CAP_REMOVAL = r'Recording removed: (\S+) \(its max_bags\)' +QUOTA_OVER_PROTECTED = (r"Recording '(\S+)' is kept over snapshots\.rosbag\.max_total_storage_mb " + r'\((\d+) MB\): (\d+) bytes of the total are recordings of the ' + r'unavailable storage path') +QUOTA_ALONE = r'alone exceeds snapshots\.rosbag\.max_total_storage_mb' +FREE_REMOVAL = r'Recording removed: (\S+) \(min_free_disk_mb\)' + + +def generate_test_description(): + return LaunchDescription([launch_testing.util.KeepAliveProc(), + launch_testing.actions.ReadyToTest()]), {} + + +class TestRosbagStorageAvailability(RetentionCase): + + def recording_ids(self, listing): + self.assertTrue(listing.success, listing.error_message) + return list(listing.recording_ids) + + def start_unavailable(self, codes): + """Record `codes`, unmount, and start a fault manager that finds no directory.""" + paths = self.record_then_unmount(codes) + rows = self.stored_rows() + self.assertEqual(sorted(path for _, path in rows), sorted(paths)) + return paths, rows + + def test_startup_removes_rows_of_missing_bags(self): + with self.fm_run() as fm: + kept_a = self.record(fm, 'KEPT_A', 0.25) + gone = self.record(fm, 'GONE', 0.25) + kept_b = self.record(fm, 'KEPT_B', 0.25) + shutil.rmtree(gone) + # Rosbag capture off: the check still runs. + with self.fm_run(**{'snapshots.rosbag.enabled': False}) as fm: + self.assertEqual(sorted(self.stored_rows()), + [('KEPT_A', kept_a), ('KEPT_B', kept_b)]) + self.assertTrue(os.path.isdir(kept_a)) + self.assertTrue(os.path.isdir(kept_b)) + check = self.startup_check(fm) + self.assertEqual(check.groups(), ('3', '3', '1', 'true'), check.string) + self.assertEqual(fm.count_lines(r'\[ERROR\]'), 0, fm.output()[-3000:]) + self.assertEqual(self.storage_fault_statuses(), []) + + def test_unavailable_at_startup(self): + self.check_unavailable_at_startup() + + def test_available_again_after_a_listing(self): + (first, second), rows = self.start_unavailable(('FIRST', 'SECOND')) + with self.fm_run() as fm: + self.assert_started_unavailable(fm, rows) + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), []) + self.mount() + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(second), os.path.basename(first)]) + self.wait_storage_fault('CLEARED') + shutil.rmtree(second) + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(first)]) + self.assertEqual(self.stored_rows(), [('FIRST', first)]) + self.assertEqual(fm.count_lines(STORAGE_UNAVAILABLE), 1) + + def test_get_rosbag_keeps_rows_while_unavailable(self): + (first, second), rows = self.start_unavailable(('FIRST', 'SECOND')) + with self.fm_run() as fm: + self.assert_started_unavailable(fm, rows) + missing = self.client.get_rosbag('FIRST') + self.assertFalse(missing.success) + self.assertIn(NOT_ON_DISK, missing.error_message) + self.assertEqual(sorted(self.stored_rows()), sorted(rows)) + self.wait_storage_fault('CONFIRMED') + self.mount() + found = self.client.get_rosbag('FIRST') + self.assertTrue(found.success, found.error_message) + self.assertEqual(found.file_path, first) + self.wait_storage_fault('CLEARED') + shutil.rmtree(second) + self.assertFalse(self.client.get_rosbag('SECOND').success) + self.assertEqual(self.stored_rows(), [('FIRST', first)]) + + def test_recovery_call_keeps_rows_it_found_missing(self): + # The listing serves the newest first: the recovery call meets NEW, then the missing OLD. + (old, new), rows = self.start_unavailable(('OLD', 'NEW')) + with self.fm_run() as fm: + self.assert_started_unavailable(fm, rows) + self.mount() + shutil.rmtree(old) + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(new)]) + self.assertEqual(sorted(self.stored_rows()), sorted(rows)) + self.wait_storage_fault('CLEARED') + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(new)]) + self.assertEqual(self.stored_rows(), [('NEW', new)]) + + def test_new_recording_does_not_end_unavailable(self): + (first, second), rows = self.start_unavailable(('FIRST', 'SECOND')) + with self.fm_run() as fm: + self.assert_started_unavailable(fm, rows) + # Written under the storage path while the disk is not mounted. + fresh = self.record(fm, 'FRESH', 0.25) + all_rows = sorted(rows + [('FRESH', fresh)]) + for _ in range(2): + self.assertEqual( + self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(fresh)]) + self.assertEqual(self.storage_fault_statuses(), ['CONFIRMED']) + self.assertEqual(sorted(self.stored_rows()), all_rows) + served = self.client.get_rosbag('FRESH') + self.assertTrue(served.success, served.error_message) + self.assertEqual(self.storage_fault_statuses(), ['CONFIRMED']) + self.assertEqual(sorted(self.stored_rows()), all_rows) + # The disk mounts over the path: the fresh recording moves under it. + for name in os.listdir(self.storage): + shutil.move(os.path.join(self.storage, name), self.unmounted) + os.rmdir(self.storage) + self.mount() + self.assertEqual( + self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(path) for path in (fresh, second, first)]) + self.wait_storage_fault('CLEARED') + self.assertEqual(sorted(self.stored_rows()), all_rows) + + def test_reclassification_keeps_rows_while_unavailable(self): + with self.fm_run(**HEALING) as fm: + healed = self.record(fm, 'HEALS', 0.25) + self.heal('HEALS') + rows = self.stored_rows() + self.assertEqual(rows, [('HEALS', healed)]) + self.unmount() + # Healing off: the start reclassifies HEALS as CLEARED, and its rule deletes on a clear. + with self.fm_run(**rules({'defaults.on_cleared': 'delete'})) as fm: + self.assert_started_unavailable(fm, rows) + self.assertEqual(self.client.get_fault('HEALS').fault.status, 'CLEARED') + + def test_age_keeps_rows_while_unavailable(self): + (aged,) = self.record_then_unmount(('AGED',)) + rows = self.stored_rows() + past = time.time_ns() - LONG_AGO_NS + sqlite_exec(self.db, 'UPDATE faults SET last_occurred_ns = ?, last_failed_ns = ? ' + 'WHERE fault_code = ?', past, past, 'AGED') + with self.fm_run(**rules({'defaults.max_age_sec.active': AGE_SEC, + **SWEEP_EVERY_SECOND})) as fm: + self.assert_started_unavailable(fm, rows) + since = 0 + for _ in range(2): + swept, index = fm.wait_line_at(SWEEP_LINE, since=since) + self.assertIsNotNone(swept, fm.output()[-3000:]) + self.assertEqual(swept.group(2), '0', swept.string) + since = index + 1 + self.assertEqual(self.stored_rows(), rows) + self.mount() + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(aged)]) + self.wait_storage_fault('CLEARED') + removed = fm.wait_line(AGE_REMOVAL.format('active'), since=since) + self.assertIsNotNone(removed, fm.output()[-3000:]) + self.assertEqual(removed.group(1), os.path.basename(aged)) + self.assert_recording_gone('AGED', aged) + + def test_floor_keeps_rows_while_unavailable(self): + self.record_then_unmount(('FLOORED',)) + rows = self.stored_rows() + # Free space is the capacity less the files under the storage path, so far below the floor. + capacity = os.path.join(os.path.dirname(self.db), 'capacity') + with open(capacity, 'w') as handle: + handle.write(f'{MIB}\n') + with self.fm_run(env_extra={CAPACITY_ENV: capacity}, + **rules({'min_free_disk_mb': FLOOR_MB, **SWEEP_EVERY_SECOND})) as fm: + self.assert_started_unavailable(fm, rows) + floor_pass = fm.wait_line(FLOOR_PASS) + self.assertIsNotNone(floor_pass, fm.output()[-3000:]) + self.assertEqual(floor_pass.group(1), '0', floor_pass.string) + self.assertEqual(floor_pass.group(4), 'false', floor_pass.string) + self.assertEqual(floor_pass.group(5), 'test-capacity', floor_pass.string) + self.assertEqual(self.stored_rows(), rows) + + def test_new_recordings_follow_the_rules_while_unavailable(self): + (first, second), rows = self.start_unavailable(('FIRST', 'SECOND')) + # max_bags_per_fault 1, and a clear keeps. + with self.fm_run(**{'snapshots.rosbag.auto_cleanup': False}) as fm: + self.assert_started_unavailable(fm, rows) + # Still CONFIRMED from the first run: a new recording needs a new confirmation. + self.assertTrue(self.client.clear('FIRST').success) + fresh = self.record(fm, 'FIRST', 0.25) + self.assertEqual(sorted(self.row_paths('FIRST')), sorted([first, fresh])) + mark = fm.mark() + self.assertTrue(self.client.clear('FIRST').success) + newer = self.record(fm, 'FIRST', 0.25) + removed = fm.wait_line(CAP_REMOVAL, since=mark) + self.assertIsNotNone(removed, fm.output()[-3000:]) + self.assertEqual(removed.group(1), os.path.basename(fresh)) + self.assertFalse(os.path.exists(fresh)) + self.assertEqual(sorted(self.row_paths('FIRST')), sorted([first, newer])) + self.assertEqual(self.row_paths('SECOND'), [second]) + self.assertEqual(self.storage_fault_statuses(), ['CONFIRMED']) + + def test_failed_lookup_is_not_a_found_directory(self): + # The storage path in a directory of its own: a loop there leaves the database reachable. + disk = os.path.join(os.path.dirname(self.db), 'disk') + self.storage = os.path.join(disk, 'bags') + with self.fm_run(**HEALING) as fm: + healed = self.record(fm, 'HEALS', 0.25) + self.heal('HEALS') + rows = self.stored_rows() + self.assertEqual(rows, [('HEALS', healed)]) + # A symlink to itself: every lookup under it fails with ELOOP, also for root. + os.rename(disk, disk + '.real') + os.symlink('disk', disk) + with self.assertRaises(OSError) as lookup: + os.stat(healed) + self.assertEqual(lookup.exception.errno, errno.ELOOP) + # Healing off: the start reclassifies HEALS as CLEARED, and its rule deletes on a clear. + with self.fm_run(**rules({'defaults.on_cleared': 'delete'})) as fm: + self.assert_started_unavailable(fm, rows) + self.assertEqual(self.startup_check(fm).group(3), '0') + self.assertEqual(self.client.get_fault('HEALS').fault.status, 'CLEARED') + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), []) + served = self.client.get_rosbag('HEALS') + self.assertFalse(served.success) + self.assertIn('cannot be looked up', served.error_message) + self.assertEqual(self.stored_rows(), rows) + self.assertEqual(self.storage_fault_statuses(), ['CONFIRMED']) + os.remove(disk) + os.rename(disk + '.real', disk) + self.assertEqual(self.recording_ids(self.client.list_rosbags(all_recordings=True)), + [os.path.basename(healed)]) + self.wait_storage_fault('CLEARED') + self.assertEqual(self.stored_rows(), rows) + + def test_keep_first_counts_only_unprotected_recordings(self): + (old,), rows = self.start_unavailable(('KEEPER',)) + keeper = rules({'fault_codes.KEEPER.max_bags': 2, 'fault_codes.KEEPER.keep_first': True, + 'fault_codes.KEEPER.on_cleared': 'keep'}) + with self.fm_run(**keeper) as fm: + self.assert_started_unavailable(fm, rows) + fresh = [] + for _ in range(3): + # A new recording needs a new confirmation. + self.assertTrue(self.client.clear('KEEPER').success) + fresh.append(self.record(fm, 'KEEPER', 0.25)) + self.assertEqual(sorted(self.row_paths('KEEPER')), sorted([old, fresh[0], fresh[2]])) + self.assertFalse(os.path.exists(fresh[1])) + + def test_floor_ranks_keep_first_among_unprotected(self): + (old,), rows = self.start_unavailable(('KEEPER',)) + # Free space is the capacity less the files under the storage path: two 1 MiB recordings + # stay above the floor, a third breaks it by about half a recording. + capacity = os.path.join(os.path.dirname(self.db), 'capacity') + with open(capacity, 'w') as handle: + handle.write(f'{FLOOR_MB * MIB + 5 * MIB // 2}\n') + # One priority for every code; no cap but KEEPER's; no periodic pass. + params = {'snapshots.rosbag.max_bags_per_fault': 0, + **rules({'fault_codes.KEEPER.max_bags': 3, 'fault_codes.KEEPER.keep_first': True, + 'fault_codes.KEEPER.on_cleared': 'keep', 'min_free_disk_mb': FLOOR_MB, + 'sweep_interval_sec': 86400})} + with self.fm_run(env_extra={CAPACITY_ENV: capacity}, **params) as fm: + self.assert_started_unavailable(fm, rows) + # A new recording needs a new confirmation. + self.assertTrue(self.client.clear('KEEPER').success) + first = self.record(fm, 'KEEPER', 1) + other = self.record(fm, 'OTHER_A', 1) + mark = fm.mark() + newest = self.record(fm, 'OTHER_B', 1) + removed, index = fm.wait_line_at(FREE_REMOVAL, since=mark) + self.assertIsNotNone(removed, fm.output()[-3000:]) + self.assertEqual(removed.group(1), os.path.basename(other)) + floor_pass = fm.wait_line(FLOOR_PASS, since=index) + self.assertIsNotNone(floor_pass, fm.output()[-3000:]) + self.assertEqual((floor_pass.group(1), floor_pass.group(4)), ('1', 'true'), + floor_pass.string) + self.assertEqual(sorted(self.row_paths('KEEPER')), sorted([old, first])) + self.assertTrue(os.path.isdir(first)) + self.assertEqual(self.row_paths('OTHER_A'), []) + self.assertEqual(self.row_paths('OTHER_B'), [newest]) + + def test_quota_names_the_protected_bytes(self): + with self.fm_run() as fm: + old = self.record(fm, 'OLD', 2) + self.unmount() + rows = self.stored_rows() + old_bytes = [size for _, path, size, _ in sqlite_rows(self.db) if path == old] + self.assertEqual(len(old_bytes), 1) + # The new recording fits the quota alone; with the protected one it does not. + with self.fm_run(**{'snapshots.rosbag.max_total_storage_mb': 3}) as fm: + self.assert_started_unavailable(fm, rows) + mark = fm.mark() + fresh = self.record(fm, 'FRESH', 2) + warned = fm.wait_line(QUOTA_OVER_PROTECTED, since=mark) + self.assertIsNotNone(warned, fm.output()[-3000:]) + self.assertEqual(warned.groups(), (os.path.basename(fresh), '3', str(old_bytes[0]))) + self.assertEqual(fm.count_lines(QUOTA_ALONE), 0, fm.output()[-3000:]) + self.assertEqual(sorted(self.stored_rows()), sorted(rows + [('FRESH', fresh)])) + + def test_zero_rows_is_available(self): + self.assertFalse(os.path.exists(self.storage)) + with self.fm_run() as fm: + check = self.startup_check(fm) + self.assertEqual(check.groups(), ('0', '0', '0', 'true'), check.string) + self.assertEqual(fm.count_lines(r'\[ERROR\]'), 0, fm.output()[-3000:]) + self.assertEqual(self.storage_fault_statuses(), [])