Skip to content

tools/cephfs_mirror: Fix crash loading persisted sync stats on restart - #70752

Merged
kotreshhr merged 2 commits into
ceph:mainfrom
kotreshhr:mirror-crash
Aug 7, 2026
Merged

kotreshhr merged 2 commits into
ceph:mainfrom
kotreshhr:mirror-crash

Conversation

@kotreshhr

@kotreshhr kotreshhr commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

PeerReplayer::apply_persisted_dir_sync_stat() took a reference into
a json_spirit::mValue for last_synced_snap, then reused that same
mValue for nested field lookups. The get_json_value() overwrote the
parent value and left a dangling Object reference, which could abort
the daemon when directories were re-acquired after a mirror daemon
restart or a mgr failover.

The fix is to Copy last_synced_snap before reading nested fields,
add typed JSON helpers (moved to Utils) that check types before
get_* calls, and catch std::exception so unexpected parse failures
are logged instead of taking down cephfs-mirror.

Fixes: https://tracker.ceph.com/issues/78932
Signed-off-by: Kotresh HR [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@kotreshhr
kotreshhr requested review from Copilot and removed request for Copilot July 31, 2026 19:19
@github-actions github-actions Bot added cephfs Ceph File System tests labels Jul 31, 2026
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Copilot AI balanced review requested due to automatic review settings July 31, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Prevents cephfs-mirror crashes when restoring malformed persisted synchronization statistics.

Changes:

  • Adds type-safe JSON field helpers.
  • Safely copies nested JSON objects and catches parsing exceptions.
  • Adds an integration test covering corrupted persisted statistics.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/tools/cephfs_mirror/Utils.h Declares typed JSON helpers.
src/tools/cephfs_mirror/Utils.cc Implements validated JSON extraction.
src/tools/cephfs_mirror/PeerReplayer.cc Safely restores persisted sync statistics.
qa/tasks/cephfs/test_mirroring.py Tests recovery from malformed statistics.

Comment thread src/tools/cephfs_mirror/Utils.cc Resolved
@kotreshhr
kotreshhr marked this pull request as ready for review August 1, 2026 07:11
@kotreshhr

Copy link
Copy Markdown
Contributor Author

@karthik-us1 karthik-us1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nits, along with the copilot requested changes.

Comment thread src/tools/cephfs_mirror/PeerReplayer.cc Resolved
Comment thread src/tools/cephfs_mirror/PeerReplayer.cc Resolved
Copilot AI review requested due to automatic review settings August 3, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/tools/cephfs_mirror/PeerReplayer.cc Resolved
PeerReplayer::apply_persisted_dir_sync_stat() took a reference into
a json_spirit::mValue for last_synced_snap, then reused that same
mValue for nested field lookups. The get_json_value() overwrote the
parent value and left a dangling Object reference, which could abort
the daemon when directories were re-acquired after a mirror daemon
restart or a mgr failover.

The fix is to Copy last_synced_snap before reading nested fields,
add typed JSON helpers (moved to Utils) that check types before
get_* calls, and catch std::exception so unexpected parse failures
are logged instead of taking down cephfs-mirror.

Fixes: https://tracker.ceph.com/issues/78932
Signed-off-by: Kotresh HR <[email protected]>
Verify cephfs-mirror stays up and continues syncing after
loading intentionally corrupted last_synced_snap fields
from omap.

Fixes: https://tracker.ceph.com/issues/78932
Signed-off-by: Kotresh HR <[email protected]>
Copilot AI review requested due to automatic review settings August 4, 2026 11:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/tools/cephfs_mirror/PeerReplayer.cc:820

  • Numeric duration values are still accepted without range checks. A corrupt value such as -1 or 1e100 is restored here and is immediately converted to uint64_t during initialization (update_directory_last_sync_perf_counters, lines 520-528); it also reaches std::llround in format_time (lines 3618-3620). Those out-of-range conversions are not protected by this try/catch. Validate all three persisted durations as finite, non-negative, and representable by int64_t before storing them, and extend the corruption test with a numeric out-of-range duration.
      if (get_json_real(last_synced_snap, "crawl_duration", &value)) {
        sync_stat.last_sync_crawl_duration = value;
      }
      if (get_json_real(last_synced_snap, "datasync_queue_wait_duration", &value)) {
        sync_stat.last_sync_datasync_queue_wait_duration = value;

@kotreshhr

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@kotreshhr

Copy link
Copy Markdown
Contributor Author

This PR has been added to main integration testing by khiremat started 2026-08-04-09:36.

@kotreshhr

Copy link
Copy Markdown
Contributor Author

@kotreshhr
kotreshhr merged commit 172b86e into ceph:main Aug 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants