[MDEV-27095] Simplify spider init queries Created: 2021-11-19 Updated: 2023-12-07 Resolved: 2023-10-06 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - Spider |
| Affects Version/s: | 10.3, 10.4, 10.5, 10.6, 10.7, 10.11 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Critical |
| Reporter: | Daniel Black | Assignee: | Yuchen Pei |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | race | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
The loading of the spider plugin causes a background thread to be created and the set of sql in storage/spider/spd_init_query.h to be run. Running mysql_upgrade at the same time the initialization of spider is occurring can cause problems as One of the conflicts was
Other similar conflicts can occur on plugin and udf function installation
Other simplifications are: spider_fix_one_table looks like a simple modification of the ALTER TABLE syntax to use the column IF NOT EXISTS syntax of https://mariadb.com/kb/en/alter-table/ would negate the need for this function. mysql.spider_fix_system_tables, a procedure with zero arguments that sets user variables could be inline. Or better, removed and use the executable comment syntax in https://mariadb.com/kb/en/comment-syntax/#executable-comment-syntax to run statements based on the server version. Can the following be implemented another way install plugin [spider_rewrite soname 'ha_spider' (INSTALL PLUGIN has IF NOT EXISTS from 10.4) Can the udf functions created another way? Is there are reason (all of) this couldn't be part of mysql-upgrade? wrapped under conditional upgrade if spider is installed? |
| Comments |
| Comment by Daniel Black [ 2021-11-30 ] | |||||||||||||||||||||||||||||||||
|
In The other option that is probably also equally valid is ensuring that INSTALL PLUGIN and similar SQL on the system tables acquires metadata locks of the tables correctly (worthy of another task) if found to be deficient. | |||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-02-01 ] | |||||||||||||||||||||||||||||||||
|
We are fixing Spider's initialization mechanism in | |||||||||||||||||||||||||||||||||
| Comment by Roel Van de Paar [ 2022-11-26 ] | |||||||||||||||||||||||||||||||||
|
This issue can also cause other unforseen issues. Today I observed this testcase failure outcome in MTR:
Note that mysql.spider_tables is missing. The testcase being used was simple:
Rerunning it made the testcase pass. This is thought to be due to the background initialization of Spider. | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-04-20 ] | |||||||||||||||||||||||||||||||||
danblack Could you provide an example invocation / reproducible testcase showing the conflicts? I skimmed through Apart from that, this ticket seems to be mostly about simplifying the init queries or moving the migration part to mysql_upgrade, in order to fix spider init issues like | |||||||||||||||||||||||||||||||||
| Comment by Roel Van de Paar [ 2023-04-22 ] | |||||||||||||||||||||||||||||||||
|
Created an MTR testcase to see if any spider init issues can be seen when running mariadb-upgrade. Did not observe any issues in 1000+ trials.
i.e. add # before the Performance Schema load line in mysql-test/include/mysql_upgrade_preparation.inc.
With main/test.test containing:
| |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-04-26 ] | |||||||||||||||||||||||||||||||||
|
Ok, so here's an idea: 1. separate out the udf creation statements from spider_init_queries to say spider_bg_init_queries This way: 1. spider_init_queries does not depend on opening any existing system tables like mysql.proc ( The only caveat is that users may not be able to call any of the spider udf's during startup if they have not been created yet. But that seems acceptable. [1] https://github.com/MariaDB/server/commit/27109b7bd80 I am marking the present issue as blocking I have not looked into other related issues like * This would a good opportunity to reduce the number of sts, crd, and init query bg threads to 1 (MDEV-27998). | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-05-01 ] | |||||||||||||||||||||||||||||||||
|
The issues with the Spider init ( The spider init queries require:
For Aria engine, we can rearrange the plugin init order so that dynamic plugins like the spider are initialised after builtin plugins like Aria. For udfs, we can separate out these queries to a background thread to wait for server start. The problem is when we load spider in bootstrap. In mysqld_main() is that it does the following things in order
The mysql_install_db script passes the creation of mysql database as part of the bootstrap queries. AIUI mysqld_main() assumes at this stage any builtin or dynamic (from plugin-load-add) storage engine either have been initialised to accept these queries, or will be taken care of by the bootstrap queries ("insider help"). For example, innodb system tables mysql.innodb_table_stats and mysql.innodb_index_stats are created using bootstrap queries which guarantees the mysql database exists first. Spider does not have any "insider help" and cannot assume that mysql database exists when it is being initialised. Worse, it is possible that the spider storage engine is used before the mysql database is creatred: consider the following bootstrap queries: drop table if exists foo.bar; The drop table statement may require all storage engine to be initialised, but spider requires the mysql database for initialisation. If we put spider init queries into a background thread waiting for the creation of the mysql database, it will deadlock on these queries. I can think of 3 ways to fix this, in the order of increasing amount of work: 1. advise users to not use plugin-load-add=ha_spider, but use init_file with a file including install soname ha_spider; instead. If possible, abort with an error on or ignore plugin-load-add=ha_spider. This also means no spider during bootstrap because --bootstrap causes the server to exit upon execution of the bootstrap queries thus skipping everything that may happen afterwards including init_file. It is tempting to ban plugin-load-add=ha_spider only for bootstrap, but given the complexity introduced by the plugin init reordering and udf creation background thread and the risk of race conditions and deadlocks, it is much simpler to just run all the init queries synchronously and ban plugin-load-add=ha_spider altogether. For simplicity, I think the first option is the best for now. | |||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-05-01 ] | |||||||||||||||||||||||||||||||||
|
I don't think disallowing plugin-load-add=ha_spider is an option. It breaks the rather basic user expectation, and I'm afraid it's a rather slippery road to start on. Making spider to skip its init queries on bootstrap — that would be fine. We'll still need to solve the dependency problem — the fact that some plugins might need other plugins as prerequisites had always been an issue that needed to be fixed, but we've successfully managed to sidestep it for many years. moving spider init queries out of ha_spider.so is, basically, MDEV-19850 spider init queries can be simplified a great deal too. No need to query I_S tables all the time. But the dependency on Aria won't go away, because of alter table mysql.spider_link_failed_log engine=Aria etc. | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-05-02 ] | |||||||||||||||||||||||||||||||||
|
Thanks for the comment serg. As with the discussions at #spider, after refining on the first idea above, I think it is worth trying to re-interpret plugin-load-add=ha_spider as a "internal" file containing install soname ha_spider;. Here is a PoC: https://github.com/MariaDB/server/commit/603a4c218b7 This way we can get rid of the bg thread completely. It also means we can decouple the present issue from | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-05-03 ] | |||||||||||||||||||||||||||||||||
|
Hi holyfoot, PTAL thanks:
The commit to fix the init bugs | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-05-03 ] | |||||||||||||||||||||||||||||||||
|
I wrote a testcase with plugin-load-add=ha_spider in a .cnf file, and each time the server starts, spider gets loaded fine:
| |||||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2023-07-11 ] | |||||||||||||||||||||||||||||||||
|
ok to push. | |||||||||||||||||||||||||||||||||
| Comment by Yuchen Pei [ 2023-07-11 ] | |||||||||||||||||||||||||||||||||
|
Thanks holyfoot. Yes we can consider this as part of Updates on 2023-10-06: close as duplicate to |