Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions doc/cephfs/cephfs-mirroring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,44 @@ This allows a user to add a non-existent directory for synchronization. The mirr
will mark such a directory as failed and retry (less frequently). When the directory is
created, the mirror daemon will clear the failed state upon successful synchronization.

Adding a new snapshot or a new directory manually in the .snap directory of the
remote filesystem will result in failed status of the corresponding configured directory.
In the remote filesystem::

$ ceph fs subvolume snapshot create cephfs subvol1 snap2 group1
or
$ mkdir /d0/.snap/snap2

$ ceph --admin-daemon /var/run/ceph/cephfs-mirror.asok fs mirror peer status cephfs@360 a2dc7784-e7a1-4723-b103-03ee8d8768f8
{
"/d0": {
"state": "failed",
"failure_reason": "snapshot 'snap2' has invalid metadata",
"last_synced_snap": {
"id": 120,
"name": "snap1",
"sync_duration": 0.079997898999999997,
"sync_time_stamp": "274900.558797s"
},
"snaps_synced": 2,
"snaps_deleted": 0,
"snaps_renamed": 0
},
"/f0": {
"state": "failed",
"snaps_synced": 0,
"snaps_deleted": 0,
"snaps_renamed": 0
}
}

When the snapshot or the directory is removed from the remote filesystem, the mirror daemon will
clear the failed state upon successful synchronization of the pending snapshots, if any.

.. note:: Treat the remote filesystem as read-only. Nothing is inherently enforced by CephFS.
But with the right mds caps, users would not be able to snapshot directories in the
remote file system.

When mirroring is disabled, the respective `fs mirror status` command for the file system
will not show up in command help.

Expand Down
76 changes: 76 additions & 0 deletions qa/tasks/cephfs/test_mirroring.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ def check_peer_status(self, fs_name, fs_id, peer_spec, dir_name, expected_snap_n
self.assertTrue(res[dir_name]['last_synced_snap']['name'] == expected_snap_name)
self.assertTrue(res[dir_name]['snaps_synced'] == expected_snap_count)

def check_peer_status_idle(self, fs_name, fs_id, peer_spec, dir_name, expected_snap_name,
expected_snap_count):
peer_uuid = self.get_peer_uuid(peer_spec)
res = self.mirror_daemon_command(f'peer status for fs: {fs_name}',
'fs', 'mirror', 'peer', 'status',
f'{fs_name}@{fs_id}', peer_uuid)
self.assertTrue(dir_name in res)
self.assertTrue('idle' == res[dir_name]['state'])
self.assertTrue(expected_snap_name == res[dir_name]['last_synced_snap']['name'])
self.assertTrue(expected_snap_count == res[dir_name]['snaps_synced'])

def check_peer_status_deleted_snap(self, fs_name, fs_id, peer_spec, dir_name,
expected_delete_count):
peer_uuid = self.get_peer_uuid(peer_spec)
Expand Down Expand Up @@ -1499,3 +1510,68 @@ def test_get_set_mirror_dirty_snap_id(self):
self.mount_b.setfattr("d1/d2/d3", "ceph.mirror.dirty_snap_id", attr)
val = self.mount_b.getfattr("d1/d2/d3", "ceph.mirror.dirty_snap_id")
self.assertEqual(attr, val, f"Mismatch for ceph.mirror.dirty_snap_id value: {attr} vs {val}")

def test_cephfs_mirror_remote_snap_corrupt_fails_synced_snapshot(self):
"""
That making manual changes to the remote .snap directory shows 'peer status' state: "failed"
for a synced snapshot and then restores to "idle" when those changes are reverted.
"""
log.debug('reconfigure client auth caps')
self.get_ceph_cmd_result(
'auth', 'caps', "client.{0}".format(self.mount_b.client_id),
'mds', 'allow rwps',
'mon', 'allow r',
'osd', 'allow rw pool={0}, allow rw pool={1}'.format(
self.backup_fs.get_data_pool_name(),
self.backup_fs.get_data_pool_name()))
log.debug(f'mounting filesystem {self.secondary_fs_name}')
self.mount_b.umount_wait()
self.mount_b.mount_wait(cephfs_name=self.secondary_fs_name)

self.enable_mirroring(self.primary_fs_name, self.primary_fs_id)
peer_spec = "client.mirror_remote@ceph"
self.peer_add(self.primary_fs_name, self.primary_fs_id, peer_spec, self.secondary_fs_name)
dir_name = 'd0'
self.mount_a.run_shell(['mkdir', dir_name])
self.add_directory(self.primary_fs_name, self.primary_fs_id, f'/{dir_name}')

# take a snapshot
snap_name = "snap_a"
expected_snap_count = 1
self.mount_a.run_shell(['mkdir', f'{dir_name}/.snap/{snap_name}'])

time.sleep(30)
# confirm snapshot synced and status 'idle'
self.check_peer_status_idle(self.primary_fs_name, self.primary_fs_id,
peer_spec, f'/{dir_name}', snap_name, expected_snap_count)

remote_snap_name = 'snap_b'
remote_snap_path = f'{dir_name}/.snap/{remote_snap_name}'
failure_reason = f"snapshot '{remote_snap_name}' has invalid metadata"
dir_name = f'/{dir_name}'

# create a directory in the remote fs and check status 'failed'
self.mount_b.run_shell(['sudo', 'mkdir', remote_snap_path], omit_sudo=False)
peer_uuid = self.get_peer_uuid(peer_spec)
with safe_while(sleep=1, tries=60, action=f'wait for failed status: {peer_spec}') as proceed:
while proceed():
res = self.mirror_daemon_command(f'peer status for fs: {self.primary_fs_name}',
'fs', 'mirror', 'peer', 'status',
f'{self.primary_fs_name}@{self.primary_fs_id}', peer_uuid)
if('failed' == res[dir_name]['state'] and \
failure_reason == res.get(dir_name, {}).get('failure_reason', {}) and \
snap_name == res[dir_name]['last_synced_snap']['name'] and \
expected_snap_count == res[dir_name]['snaps_synced']):
break
# remove the directory in the remote fs and check status restores to 'idle'
Comment thread
joscollin marked this conversation as resolved.
Resolved
self.mount_b.run_shell(['sudo', 'rmdir', remote_snap_path], omit_sudo=False)
with safe_while(sleep=1, tries=60, action=f'wait for idle status: {peer_spec}') as proceed:
while proceed():
res = self.mirror_daemon_command(f'peer status for fs: {self.primary_fs_name}',
'fs', 'mirror', 'peer', 'status',
f'{self.primary_fs_name}@{self.primary_fs_id}', peer_uuid)
if('idle' == res[dir_name]['state'] and 'failure_reason' not in res and \
snap_name == res[dir_name]['last_synced_snap']['name'] and \
expected_snap_count == res[dir_name]['snaps_synced']):
break
self.disable_mirroring(self.primary_fs_name, self.primary_fs_id)
8 changes: 6 additions & 2 deletions src/tools/cephfs_mirror/PeerReplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,9 @@ int PeerReplayer::build_snap_map(const std::string &dir_root,
uint64_t snap_id;
if (is_remote) {
if (!info.nr_snap_metadata) {
derr << ": snap_path=" << snap_path << " has invalid metadata in remote snapshot"
<< dendl;
std::string failed_reason = "snapshot '" + snap + "' has invalid metadata";
derr << ": " << failed_reason << dendl;
m_snap_sync_stats.at(dir_root).last_failed_reason = failed_reason;
Comment thread
joscollin marked this conversation as resolved.
Resolved
rv = -EINVAL;
} else {
auto metadata = decode_snap_metadata(info.snap_metadata, info.nr_snap_metadata);
Expand Down Expand Up @@ -1807,6 +1808,9 @@ void PeerReplayer::peer_status(Formatter *f) {
f->open_object_section(dir_root);
if (sync_stat.failed) {
f->dump_string("state", "failed");
if (sync_stat.last_failed_reason) {
f->dump_string("failure_reason", *sync_stat.last_failed_reason);
}
} else if (!sync_stat.current_syncing_snap) {
f->dump_string("state", "idle");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/tools/cephfs_mirror/PeerReplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class PeerReplayer {
struct SnapSyncStat {
uint64_t nr_failures = 0; // number of consecutive failures
boost::optional<monotime> last_failed; // lat failed timestamp
boost::optional<std::string> last_failed_reason;
bool failed = false; // hit upper cap for consecutive failures
boost::optional<std::pair<uint64_t, std::string>> last_synced_snap;
boost::optional<std::pair<uint64_t, std::string>> current_syncing_snap;
Expand Down Expand Up @@ -177,6 +178,7 @@ class PeerReplayer {
sync_stat.nr_failures = 0;
sync_stat.failed = false;
sync_stat.last_failed = boost::none;
sync_stat.last_failed_reason = boost::none;
}

void _set_last_synced_snap(const std::string &dir_root, uint64_t snap_id,
Expand Down