Skip to content

Commit ebd9263

Browse files
committed
Merge PR ceph#53564 into main
* refs/pull/53564/head: qa: add split/merge dirfrag tests for scrub mds: Add fragment to scrub Reviewed-by: Venky Shankar <[email protected]> Reviewed-by: Dhairya Parmar <[email protected]>
2 parents 3a53726 + 18ec6e5 commit ebd9263

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

qa/tasks/cephfs/test_scrub_checks.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class TestScrubChecks(CephFSTestCase):
199199

200200
MDSS_REQUIRED = 1
201201
CLIENTS_REQUIRED = 1
202+
def get_dsplits(self, dir_ino):
203+
return self.fs.rank_asok(['dump', 'inode', str(dir_ino)])['dirfragtree']['splits']
202204

203205
def test_scrub_checks(self):
204206
self._checks(0)
@@ -362,6 +364,86 @@ def test_scrub_repair(self):
362364
# fragstat should be fixed
363365
self.mount_a.run_shell(["rmdir", test_dir])
364366

367+
def test_scrub_merge_dirfrags(self):
368+
"""
369+
That a directory is merged during scrub.
370+
"""
371+
372+
test_path = "testdir"
373+
abs_test_path = f"/{test_path}"
374+
split_size = 20
375+
merge_size = 5
376+
split_bits = 1
377+
self.config_set('mds', 'mds_bal_split_size', split_size)
378+
self.config_set('mds', 'mds_bal_merge_size', merge_size)
379+
self.config_set('mds', 'mds_bal_split_bits', split_bits)
380+
381+
self.mount_a.run_shell(["mkdir", test_path])
382+
dir_ino=self.mount_a.path_to_ino(test_path)
383+
384+
self.assertEqual(len(self.get_dsplits(dir_ino)), 0)
385+
self.mount_a.create_n_files(f"{test_path}/file", split_size * 2)
386+
387+
self.mount_a.umount_wait()
388+
389+
self.fs.flush()
390+
self.fs.mds_fail_restart()
391+
self.fs.wait_for_daemons()
392+
393+
split_size = 100
394+
merge_size = 30
395+
self.config_set('mds', 'mds_bal_split_size', split_size)
396+
self.config_set('mds', 'mds_bal_merge_size', merge_size)
397+
398+
#Assert to ensure split is present
399+
self.assertGreater(len(self.get_dsplits(dir_ino)), 0)
400+
out_json = self.fs.run_scrub(["start", abs_test_path, "recursive"])
401+
self.assertNotEqual(out_json, None)
402+
403+
#Wait until no splits to confirm merge by scrub
404+
self.wait_until_true(
405+
lambda: len(self.get_dsplits(dir_ino)) == 0,
406+
timeout=30
407+
)
408+
409+
def test_scrub_split_dirfrags(self):
410+
"""
411+
That a directory is split during scrub.
412+
"""
413+
414+
test_path = "testdir"
415+
abs_test_path = f"/{test_path}"
416+
split_size = 20
417+
merge_size = 5
418+
split_bits = 1
419+
420+
self.mount_a.run_shell(["mkdir", test_path])
421+
dir_ino=self.mount_a.path_to_ino(test_path)
422+
423+
self.assertEqual(len(self.get_dsplits(dir_ino)), 0)
424+
self.mount_a.create_n_files(f"{test_path}/file", split_size + 1)
425+
426+
self.mount_a.umount_wait()
427+
428+
self.fs.flush()
429+
self.fs.mds_fail_restart()
430+
self.fs.wait_for_daemons()
431+
432+
self.config_set('mds', 'mds_bal_split_size', split_size)
433+
self.config_set('mds', 'mds_bal_merge_size', merge_size)
434+
self.config_set('mds', 'mds_bal_split_bits', split_bits)
435+
436+
#Assert to ensure no splits are present
437+
self.assertEqual(len(self.get_dsplits(dir_ino)), 0)
438+
out_json = self.fs.run_scrub(["start", abs_test_path, "recursive"])
439+
self.assertNotEqual(out_json, None)
440+
441+
#Wait until split is present to confirm split by scrub
442+
self.wait_until_true(
443+
lambda: len(self.get_dsplits(dir_ino)) > 0,
444+
timeout=30
445+
)
446+
365447
def test_stray_evaluation_with_scrub(self):
366448
"""
367449
test that scrub can iterate over ~mdsdir and evaluate strays

src/mds/MDCache.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12639,6 +12639,9 @@ void MDCache::force_readonly()
1263912639
mds->mdlog->flush();
1264012640
}
1264112641

12642+
void MDCache::maybe_fragment(CDir *dir) {
12643+
mds->balancer->maybe_fragment(dir, false);
12644+
}
1264212645

1264312646
// ==============================================================
1264412647
// debug crap

src/mds/MDCache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class MDCache {
275275
bool is_readonly() { return readonly; }
276276
void force_readonly();
277277

278+
void maybe_fragment(CDir* dir);
279+
278280
static file_layout_t gen_default_file_layout(const MDSMap &mdsmap);
279281
static file_layout_t gen_default_log_layout(const MDSMap &mdsmap);
280282

src/mds/ScrubStack.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ void ScrubStack::scrub_dirfrag(CDir *dir, bool *done)
470470
<< " log and `damage ls` output for details";
471471
}
472472

473+
mdcache->maybe_fragment(dir);
473474
dir->scrub_finished();
474475
dir->auth_unpin(this);
475476

0 commit comments

Comments
 (0)