Repository navigation
mgr: add retry logic for module loading #61325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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) | ||
| 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." | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -159,6 +159,40 @@ options: | |||||
| flags: | ||||||
| - no_mon_update | ||||||
| - cluster_create | ||||||
| # retry every N seconds | ||||||
| - name: mgr_module_load_interval | ||||||
| type: uint | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Would be better. See for example |
||||||
| 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any new config should not have |
||||||
| services: | ||||||
| - mgr | ||||||
| - name: cephadm_path | ||||||
| type: str | ||||||
| level: advanced | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
| 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)); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 which also has checks for whether the module is loaded properly. That should be consolidated. Only the |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| 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); | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For applications using the ceph/src/mgr/PyModuleRegistry.cc Lines 363 to 365 in 55982ea
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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -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 | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.