Skip to content
Closed
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
13 changes: 13 additions & 0 deletions qa/suites/rados/mgr/tasks/4-units/mgr_module_loading_time.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
overrides:
ceph:
log-ignorelist:
- \(CEPHADM_STRAY_DAEMON\)
- \(CEPHADM_STRAY_HOST\)
- \(MGR_DOWN\)
- evicting unresponsive client

tasks:
- workunit:
clients:
client.0:
- mgr/test_mgr_module_loading_time.sh
67 changes: 67 additions & 0 deletions qa/workunits/mgr/test_mgr_module_loading_time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# Set up orchestrator...
# This will create CEPHADM_STRAY_HOST warnings, but we just want to be able to run an orch command.
ceph mgr module enable cephadm
ceph orch set backend cephadm

# Check cluster status
ceph -s

# Run balancer for a bit to add upmap entires to the osdmap
# (helps detect balancer scalability issues that affect module
# loading time, i.e. https://tracker.ceph.com/issues/68657)
ceph osd set-require-min-compat-client reef
ceph balancer mode upmap-read
for i in {1..5}; do
ceph balancer on
sleep 1
done
ceph osd dump

# Delay loading on the balancer module
ceph config set mgr mgr_module_load_delay_name balancer

# Test case 1: Delay exceeds max load time
echo "Testing with module load delay of 6 seconds..."
ceph config set mgr mgr_module_load_delay 6

output=$(ceph mgr fail; ceph orch status 2>&1)

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.

ACK.

echo "$output"
if [[ "$output" == *"Error ETIMEDOUT: Warning: due to ceph-mgr restart, some PG states may not be up to date"* ]]; then
echo "PASS: Expected command timeout occurred."
else
echo "FAIL: Command did not fail as expected."
exit 1
fi

# Test case 2: Delay within acceptable load time
echo "Testing with module load delay of 4 seconds..."
ceph config set mgr mgr_module_load_delay 4

for i in $(seq 1 100); do
output=$(ceph mgr fail && ceph orch status 2>&1)
echo "$output"
if [[ "$output" == *"Error ETIMEDOUT: Warning: due to ceph-mgr restart, some PG states may not be up to date"* ]]; then
echo "FAIL: Command failed with acceptable delay in iteration $i."
exit 1
fi
sleep 1
done
echo "PASS: All commands succeeded with acceptable delay."

# Test case 3: No injected delay; testing real module loading time
echo "Testing with module load delay of 0 seconds..."
ceph config set mgr mgr_module_load_delay 0

for i in $(seq 1 100); do
output=$(ceph mgr fail && ceph orch status 2>&1)
echo "$output"
if [[ "$output" == *"Error ETIMEDOUT: Warning: due to ceph-mgr restart, some PG states may not be up to date"* ]]; then
echo "FAIL: Command unexpectedly timed out in iteration $i."
exit 1
fi
sleep 1
done

echo "PASS: All tests completed successfully."
34 changes: 34 additions & 0 deletions src/common/options/mgr.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ options:
flags:
- no_mon_update
- cluster_create
# retry every N seconds
- name: mgr_module_load_interval
type: uint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
type: uint
type: millisecs

Would be better. See for example mds_log_trim_upkeep_interval.

level: advanced
default: 1
desc: The mgr will retry loading a module every ``N`` seconds.
services:
- mgr
with_legacy: true
# fail if the module fails to load in time
- name: mgr_module_load_timeout
type: uint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

level: advanced
default: 5
desc: Max length of time that the mgr should retry loading a module before issuing an error code.
services:
- mgr
with_legacy: true
- name: mgr_module_load_delay
type: uint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

level: dev
default: 0
desc: Amount of seconds a mgr module delays loading. For testing purposes only.
services:
- mgr
- name: mgr_module_load_delay_name
type: str
level: dev
desc: Choose which mgr module to inject a load delay. For testing purposes only.
flags:
- runtime
with_legacy: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with_legacy is deprecated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you mean just for this config option, or for each new config option?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any new config should not have with_legacy: true.

services:
- mgr
- name: cephadm_path
type: str
level: advanced
Expand Down
8 changes: 8 additions & 0 deletions src/mgr/ActivePyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ void ActivePyModules::start_one(PyModuleRef py_module)
// Send all python calls down a Finisher to avoid blocking
// C++ code, and avoid any potential lock cycles.
finisher.queue(new LambdaContext([this, active_module, name](int) {
// Delay loading in testing scenarios
uint64_t delay = g_conf().get_val<uint64_t>("mgr_module_load_delay");
std::string delayed_module = g_conf().get_val<std::string>("mgr_module_load_delay_name");
if ((name == delayed_module) && (delay > 0)) {
dout(4) << "Delaying load time for module '" << name
<< "' by " << delay << " seconds..." << dendl;
std::this_thread::sleep_for(std::chrono::seconds(delay));
}
int r = active_module->load(this);
std::lock_guard l(lock);
pending_modules.erase(name);
Expand Down
46 changes: 29 additions & 17 deletions src/mgr/DaemonServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2545,14 +2545,38 @@ bool DaemonServer::_handle_command(
return true;
}

// Validate that the module is enabled
auto& py_handler_name = py_command.module_name;
PyModuleRef module = py_modules.get_module(py_handler_name);
ceph_assert(module);
if (!module->is_enabled()) {
ss << "Module '" << py_handler_name << "' is not enabled (required by "
"command '" << prefix << "'): use `ceph mgr module enable "
<< py_handler_name << "` to enable it";
dout(4) << ss.str() << dendl;
cmdctx->reply(-EOPNOTSUPP, ss);
return true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may also be good to issue a cluster log warning that API calls are being made to the ceph-mgr which require a module to be loaded.

}

// Validate that the module is active
auto& mod_name = py_command.module_name;
uint64_t interval = cct->_conf->mgr_module_load_interval;
uint64_t timeout = cct->_conf->mgr_module_load_timeout;
uint64_t retries = floor(timeout / interval);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

floor is unnecessary for integers.

while (!py_modules.is_module_active(mod_name) && (retries-- > 0)) {
// Retry loading...
dout(4) << "Module '" << mod_name << "' is not active (required by command '"
<< prefix << "'): retrying in " << interval << " secs (" << retries
<< " retries left)." << dendl;
// Sleep for the retry interval
std::this_thread::sleep_for(std::chrono::seconds(interval));

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.

OK, so mgr starts taking care about delaying requests till the module gets initialized. Seems sane.

@ljflores ljflores Jan 15, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, we basically give the mgr a little more time to retry loading the module. It's not a guarantee that the module loads in time, but if it doesn't load in the 5 seconds we give it, there is something bigger going on, and we will issue an ETIMEDOUT. But this will help account for slower hardware and any kind of latency in the cluster.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This blocks the messenger thread. I don't think we can structure it this way. Note also

https://github.com/ceph/ceph/pull/61325/files#diff-2de410c19e44c5a7ca3ca756e0464f8101e0218002090e36c55b3b68c40040e6R2601-R2619

which also has checks for whether the module is loaded properly. That should be consolidated.

Only the mod_finisher should block waiting for the module to load and there should be a condition variable that wakes the finisher thread rather than unconditionally wait interval seconds.

}

if (!py_modules.is_module_active(mod_name)) {
ss << "Module '" << mod_name << "' is not enabled/loaded (required by "
"command '" << prefix << "'): use `ceph mgr module enable "
<< mod_name << "` to enable it";
ss << "Module '" << mod_name << "' failed to load in time (required by "
"command '" << prefix << "').";
dout(4) << ss.str() << dendl;
cmdctx->reply(-EOPNOTSUPP, ss);
cmdctx->reply(-ETIMEDOUT, ss);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
cmdctx->reply(-ETIMEDOUT, ss);
cmdctx->reply(-EAGAIN, ss);

For applications using the ceph-mgr provided CLI, we want retries prompted by returning EAGAIN. See for example:

// We do not expect to be called before active modules is up, but
// it's straightfoward to handle this case so let's do it.
return -EAGAIN;

There is also a PR relating to that: #60194

Since this code has a built-in expectation that a module may eventually load, we should tell the caller to try again later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggest also issuing a cluster log error that a module is failing to load to satisfy commands.

return true;
}

Expand All @@ -2561,24 +2585,12 @@ bool DaemonServer::_handle_command(
dout(10) << "passing through command '" << prefix << "' size " << cmdctx->cmdmap.size() << dendl;
Finisher& mod_finisher = py_modules.get_active_module_finisher(mod_name);

mod_finisher.queue(new LambdaContext([this, cmdctx, session, py_command, prefix, op]
mod_finisher.queue(new LambdaContext([this, cmdctx, session, py_command, prefix, op, py_handler_name, module]
(int r_) mutable {
std::stringstream ss;

dout(10) << "dispatching command '" << prefix << "' size " << cmdctx->cmdmap.size() << dendl;

// Validate that the module is enabled
auto& py_handler_name = py_command.module_name;
PyModuleRef module = py_modules.get_module(py_handler_name);
ceph_assert(module);
if (!module->is_enabled()) {
ss << "Module '" << py_handler_name << "' is not enabled (required by "
"command '" << prefix << "'): use `ceph mgr module enable "
<< py_handler_name << "` to enable it";
dout(4) << ss.str() << dendl;
cmdctx->reply(-EOPNOTSUPP, ss);
return;
}

// Hack: allow the self-test method to run on unhealthy modules.
// Fix this in future by creating a special path for self test rather
Expand Down