catalyst / moodle-tool_excimer

A Moodle tool to find bottlenecks in your code safely in production
https://moodle.org/plugins/tool_excimer
GNU General Public License v3.0
12 stars 9 forks source link

Upgrade bug DELETE FROM mdl_tool_excimer_page_groups WHERE CHAR_LENGTH(name) > 255 #359

Closed brendanheywood closed 2 months ago

brendanheywood commented 2 months ago

One avenue to investigate is to make sure that excimer is not attempting to profile itself during the upgrade, so its trying to write to a table it is deleting from. Might be a complete red herring too

DELETE FROM mdl_tool_excimer_page_groups WHERE  CHAR_LENGTH(name) > 255
[array (
)]
Error code: dmlwriteexception
* line 497 of /lib/dml/moodle_database.php: dml_write_exception thrown
* line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
* line 1712 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
* line 495 of /admin/tool/excimer/db/upgrade.php: call to mysqli_native_moodle_database->delete_records_select()
* line 789 of /lib/upgradelib.php: call to xmldb_tool_excimer_upgrade()
* line 1967 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()

!!! Error writing to database !!!
!! Lock wait timeout exceeded; try restarting transaction
DELETE FROM mdl_tool_excimer_page_groups WHERE  CHAR_LENGTH(name) > 255
[array (
)]
Error code: dmlwriteexception !!
!! Stack trace: * line 497 of /lib/dml/moodle_database.php: dml_write_exception thrown
* line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
* line 1712 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
* line 495 of /admin/tool/excimer/db/upgrade.php: call to mysqli_native_moodle_database->delete_records_select()
* line 789 of /lib/upgradelib.php: call to xmldb_tool_excimer_upgrade()
* line 1967 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()
 !!
keevan commented 2 months ago

Interesting. I did take a quick peek during my last issue dig, and writes shouldn't happen for the upgrade path since it is not enabled for moodle_needs_upgrade().

If true, it could be due to some other request triggering the write?

keevan commented 2 months ago

I tried replicating this locally, and I couldn't, unless I ran the problematic DELETE from where id NOT IN query, that was recently fixed.

My hypothesis: this is a symptom of the aforementioned bad DELETE query still running in the background. When I restored a prod-like DB state locally and ran the upgrade with no queries running prior, it went through fine, everytime.

brendanheywood commented 2 months ago

Happy with this