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
112 changes: 69 additions & 43 deletions qa/tasks/cephfs/test_scrub_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import errno
import time
from teuthology.exceptions import CommandFailedError
from teuthology.contextutil import safe_while
import os
from tasks.cephfs.cephfs_test_case import CephFSTestCase

Expand All @@ -30,22 +31,46 @@ def _resume_scrub(self, expected):
self.assertEqual(res['return_code'], expected)
def _get_scrub_status(self):
return self.fs.rank_tell(["scrub", "status"])
def _check_task_status(self, expected_status):
task_status = self.fs.get_task_status("scrub status")
active = self.fs.get_active_names()
log.debug("current active={0}".format(active))
self.assertTrue(task_status[active[0]].startswith(expected_status))
def _check_task_status(self, expected_status, timo=120):
""" check scrub status for current active mds in ceph status """
with safe_while(sleep=1, tries=120, action='wait for task status') as proceed:
while proceed():
active = self.fs.get_active_names()
log.debug("current active={0}".format(active))
task_status = self.fs.get_task_status("scrub status")
try:
if task_status[active[0]].startswith(expected_status):
return True
except KeyError:
pass

def _check_task_status_na(self, timo=120):
Comment thread
vshankar marked this conversation as resolved.
Resolved
""" check absence of scrub status in ceph status """
with safe_while(sleep=1, tries=120, action='wait for task status') as proceed:
while proceed():
active = self.fs.get_active_names()
log.debug("current active={0}".format(active))
task_status = self.fs.get_task_status("scrub status")
if not active[0] in task_status:
return True

def create_scrub_data(self, test_dir):
for i in range(32):
dirname = "dir.{0}".format(i)
dirpath = os.path.join(test_dir, dirname)
self.mount_a.run_shell_payload(f"""
set -e
mkdir -p {dirpath}
for ((i = 0; i < 32; i++)); do
dd if=/dev/urandom of={dirpath}/filename.$i bs=1M conv=fdatasync count=1
done
""")

def test_scrub_abort(self):
test_dir = "scrub_control_test_path"
abs_test_path = "/{0}".format(test_dir)

log.info("mountpoint: {0}".format(self.mount_a.mountpoint))
client_path = os.path.join(self.mount_a.mountpoint, test_dir)
log.info("client_path: {0}".format(client_path))

log.info("Cloning repo into place")
TestScrubChecks.clone_repo(self.mount_a, client_path)
self.create_scrub_data(test_dir)

out_json = self.fs.rank_tell(["scrub", "start", abs_test_path, "recursive"])
self.assertNotEqual(out_json, None)
Expand All @@ -56,8 +81,8 @@ def test_scrub_abort(self):
self.assertTrue("no active" in out_json['status'])

# sleep enough to fetch updated task status
time.sleep(10)
self._check_task_status("idle")
checked = self._check_task_status_na()
self.assertTrue(checked)

def test_scrub_pause_and_resume(self):
test_dir = "scrub_control_test_path"
Expand All @@ -67,8 +92,7 @@ def test_scrub_pause_and_resume(self):
client_path = os.path.join(self.mount_a.mountpoint, test_dir)
log.info("client_path: {0}".format(client_path))

log.info("Cloning repo into place")
_ = TestScrubChecks.clone_repo(self.mount_a, client_path)
self.create_scrub_data(test_dir)

out_json = self.fs.rank_tell(["scrub", "start", abs_test_path, "recursive"])
self.assertNotEqual(out_json, None)
Expand All @@ -78,25 +102,22 @@ def test_scrub_pause_and_resume(self):
out_json = self._get_scrub_status()
self.assertTrue("PAUSED" in out_json['status'])

# sleep enough to fetch updated task status
time.sleep(10)
self._check_task_status("paused")
checked = self._check_task_status("paused")
self.assertTrue(checked)

# resume and verify
self._resume_scrub(0)
out_json = self._get_scrub_status()
self.assertFalse("PAUSED" in out_json['status'])

checked = self._check_task_status_na()
self.assertTrue(checked)

def test_scrub_pause_and_resume_with_abort(self):
test_dir = "scrub_control_test_path"
abs_test_path = "/{0}".format(test_dir)

log.info("mountpoint: {0}".format(self.mount_a.mountpoint))
client_path = os.path.join(self.mount_a.mountpoint, test_dir)
log.info("client_path: {0}".format(client_path))

log.info("Cloning repo into place")
_ = TestScrubChecks.clone_repo(self.mount_a, client_path)
self.create_scrub_data(test_dir)

out_json = self.fs.rank_tell(["scrub", "start", abs_test_path, "recursive"])
self.assertNotEqual(out_json, None)
Expand All @@ -106,36 +127,46 @@ def test_scrub_pause_and_resume_with_abort(self):
out_json = self._get_scrub_status()
self.assertTrue("PAUSED" in out_json['status'])

# sleep enough to fetch updated task status
time.sleep(10)
self._check_task_status("paused")
checked = self._check_task_status("paused")
self.assertTrue(checked)

# abort and verify
self._abort_scrub(0)
out_json = self._get_scrub_status()
self.assertTrue("PAUSED" in out_json['status'])
self.assertTrue("0 inodes" in out_json['status'])

# sleep enough to fetch updated task status
time.sleep(10)
self._check_task_status("paused")
# scrub status should still be paused...
checked = self._check_task_status("paused")
self.assertTrue(checked)

# resume and verify
self._resume_scrub(0)
out_json = self._get_scrub_status()
self.assertTrue("no active" in out_json['status'])

# sleep enough to fetch updated task status
time.sleep(10)
self._check_task_status("idle")
checked = self._check_task_status_na()
self.assertTrue(checked)

def test_scrub_task_status_on_mds_failover(self):
# sleep enough to fetch updated task status
time.sleep(10)

(original_active, ) = self.fs.get_active_names()
original_standbys = self.mds_cluster.get_standby_daemons()
self._check_task_status("idle")

test_dir = "scrub_control_test_path"
abs_test_path = "/{0}".format(test_dir)

self.create_scrub_data(test_dir)

out_json = self.fs.rank_tell(["scrub", "start", abs_test_path, "recursive"])
self.assertNotEqual(out_json, None)

# pause and verify
self._pause_scrub(0)
out_json = self._get_scrub_status()
self.assertTrue("PAUSED" in out_json['status'])

checked = self._check_task_status("paused")
self.assertTrue(checked)

# Kill the rank 0
self.fs.mds_stop(original_active)
Expand All @@ -150,12 +181,7 @@ def promoted():
original_standbys))
self.wait_until_true(promoted, timeout=grace*2)

mgr_beacon_grace = float(self.fs.get_config("mgr_service_beacon_grace", service_type="mon"))

def status_check():
task_status = self.fs.get_task_status("scrub status")
return original_active not in task_status
self.wait_until_true(status_check, timeout=mgr_beacon_grace*2)
self._check_task_status_na()

class TestScrubChecks(CephFSTestCase):
"""
Expand Down
13 changes: 10 additions & 3 deletions src/mds/MDSRank.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3676,7 +3676,10 @@ void MDSRank::get_task_status(std::map<std::string, std::string> *status) {

// scrub summary for now..
std::string_view scrub_summary = scrubstack->scrub_summary();
status->emplace(SCRUB_STATUS_KEY, std::move(scrub_summary));
if (!ScrubStack::is_idle(scrub_summary)) {
send_status = true;
status->emplace(SCRUB_STATUS_KEY, std::move(scrub_summary));
}
}

void MDSRank::schedule_update_timer_task() {
Expand All @@ -3692,13 +3695,17 @@ void MDSRank::send_task_status() {
std::map<std::string, std::string> status;
get_task_status(&status);

if (!status.empty()) {
dout(20) << __func__ << ": updating " << status.size() << " status keys" << dendl;
if (send_status) {
if (status.empty()) {
send_status = false;
}

dout(20) << __func__ << ": updating " << status.size() << " status keys" << dendl;
int r = mgrc->service_daemon_update_task_status(std::move(status));
if (r < 0) {
derr << ": failed to update service daemon status: " << cpp_strerror(r) << dendl;
}

}

schedule_update_timer_task();
Expand Down
2 changes: 2 additions & 0 deletions src/mds/MDSRank.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ class MDSRank {

bool standby_replaying = false; // true if current replay pass is in standby-replay mode
private:
bool send_status = true;

// "task" string that gets displayed in ceph status
inline static const std::string SCRUB_STATUS_KEY = "scrub status";

Expand Down
4 changes: 4 additions & 0 deletions src/mds/ScrubStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class ScrubStack {
*/
std::string_view scrub_summary();

static bool is_idle(std::string_view state_str) {
return state_str == "idle";
}

bool is_scrubbing() const { return !inode_stack.empty(); }

MDCache *mdcache;
Expand Down
18 changes: 15 additions & 3 deletions src/mgr/DaemonServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,21 @@ bool DaemonServer::handle_close(const ref_t<MMgrClose>& m)
void DaemonServer::update_task_status(DaemonKey key, const ref_t<MMgrReport>& m) {
dout(10) << "got task status from " << key << dendl;

auto p = pending_service_map.get_daemon(key.type, key.name);
if (!map_compare(p.first->task_status, *m->task_status)) {
p.first->task_status = *m->task_status;
bool service_map_dirty = false;
if ((*m->task_status).empty()) {
auto removed = pending_service_map.rm_daemon(key.type, key.name);
if (removed) {
service_map_dirty = true;
}
} else {
auto p = pending_service_map.get_daemon(key.type, key.name);
if (!map_compare(p.first->task_status, *m->task_status)) {
service_map_dirty = true;
p.first->task_status = *m->task_status;
}
}

if (service_map_dirty) {
pending_service_map_dirty = pending_service_map.epoch;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mgr/MgrClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void MgrClient::reconnect()
if (service_daemon) {
daemon_dirty_status = true;
}
task_dirty_status = true;

// Don't send an open if we're just a client (i.e. doing
// command-sending, not stats etc)
Expand Down