Commit 011586c0 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-15686: Loading MyRocks plugin back after it has been unloaded causes a crash

- Disallow loading of MyRocks (or any auxilary) plugins after it has been
  unloaded.
- Do it carefully - Plugin's system variables may be accesssed (e.g. default
  value is set) after the first rocksdb_done_func() call but before
  the secon rocksdb_init_func() call.
parent 907aae25
......@@ -3957,14 +3957,25 @@ static rocksdb::Status check_rocksdb_options_compatibility(
return status;
}
bool prevent_myrocks_loading= false;
/*
Storage Engine initialization function, invoked when plugin is loaded.
*/
static int rocksdb_init_func(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
{
my_error(ER_INTERNAL_ERROR, MYF(0),
"Loading MyRocks plugin after it has been unloaded is not "
"supported. Please restart mysqld");
DBUG_RETURN(1);
}
// Validate the assumption about the size of ROCKSDB_SIZEOF_HIDDEN_PK_COLUMN.
static_assert(sizeof(longlong) == 8, "Assuming that longlong is 8 bytes.");
......@@ -4505,12 +4516,27 @@ static int rocksdb_done_func(void *const p) {
}
#endif /* HAVE_purify */
rocksdb_db_options = nullptr;
rocksdb_tbl_options = nullptr;
/*
MariaDB: don't clear rocksdb_db_options and rocksdb_tbl_options.
MyRocks' plugin variables refer to them.
The plugin cannot be loaded again (see prevent_myrocks_loading) but plugin
variables are processed before myrocks::rocksdb_init_func is invoked, so
they must point to valid memory.
*/
//rocksdb_db_options = nullptr;
rocksdb_db_options->statistics = nullptr;
//rocksdb_tbl_options = nullptr;
rocksdb_stats = nullptr;
my_error_unregister(HA_ERR_ROCKSDB_FIRST, HA_ERR_ROCKSDB_LAST);
/*
Prevent loading the plugin after it has been loaded and then unloaded. This
doesn't work currently.
*/
prevent_myrocks_loading= true;
DBUG_RETURN(error);
}
......
......@@ -1414,4 +1414,5 @@ struct Rdb_inplace_alter_ctx : public my_core::inplace_alter_handler_ctx {
const int MYROCKS_MARIADB_PLUGIN_MATURITY_LEVEL= MariaDB_PLUGIN_MATURITY_GAMMA;
extern bool prevent_myrocks_loading;
} // namespace myrocks
......@@ -10,3 +10,11 @@ insert into test.t1 values (1);
connection default;
DROP TABLE t1;
UNINSTALL SONAME 'ha_rocksdb';
#
# MDEV-15686: Loading MyRocks plugin back after it has been unloaded causes a crash
#
call mtr.add_suppression("Plugin 'ROCKSDB.*' init function returned error.");
call mtr.add_suppression("Plugin 'ROCKSDB.*' registration as a INFORMATION SCHEMA failed.");
call mtr.add_suppression("Plugin 'ROCKSDB' registration as a STORAGE ENGINE failed");
INSTALL SONAME 'ha_rocksdb';
ERROR HY000: Internal error: Loading MyRocks plugin after it has been unloaded is not supported. Please restart mysqld
......@@ -26,3 +26,13 @@ connection default;
# Cleanup
DROP TABLE t1;
UNINSTALL SONAME 'ha_rocksdb';
--echo #
--echo # MDEV-15686: Loading MyRocks plugin back after it has been unloaded causes a crash
--echo #
call mtr.add_suppression("Plugin 'ROCKSDB.*' init function returned error.");
call mtr.add_suppression("Plugin 'ROCKSDB.*' registration as a INFORMATION SCHEMA failed.");
call mtr.add_suppression("Plugin 'ROCKSDB' registration as a STORAGE ENGINE failed");
--error ER_INTERNAL_ERROR
INSTALL SONAME 'ha_rocksdb';
......@@ -142,6 +142,9 @@ static int rdb_i_s_cfstats_fill_table(
static int rdb_i_s_cfstats_init(void *p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -235,6 +238,9 @@ static int rdb_i_s_dbstats_fill_table(
static int rdb_i_s_dbstats_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -336,6 +342,8 @@ static int rdb_i_s_perf_context_fill_table(
static int rdb_i_s_perf_context_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -403,6 +411,9 @@ static int rdb_i_s_perf_context_global_fill_table(
static int rdb_i_s_perf_context_global_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -1017,6 +1028,9 @@ static int rdb_i_s_ddl_fill_table(my_core::THD *const thd,
static int rdb_i_s_ddl_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
my_core::ST_SCHEMA_TABLE *schema;
DBUG_ASSERT(p != nullptr);
......@@ -1032,6 +1046,9 @@ static int rdb_i_s_ddl_init(void *const p) {
static int rdb_i_s_cfoptions_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -1047,6 +1064,9 @@ static int rdb_i_s_cfoptions_init(void *const p) {
static int rdb_i_s_global_info_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -1063,6 +1083,10 @@ static int rdb_i_s_compact_stats_init(void *p) {
my_core::ST_SCHEMA_TABLE *schema;
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
schema = reinterpret_cast<my_core::ST_SCHEMA_TABLE *>(p);
......@@ -1237,6 +1261,9 @@ static int rdb_i_s_index_file_map_fill_table(
static int rdb_i_s_index_file_map_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -1320,6 +1347,9 @@ static int rdb_i_s_lock_info_fill_table(
static int rdb_i_s_lock_info_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......@@ -1450,6 +1480,9 @@ static int rdb_i_s_trx_info_fill_table(
static int rdb_i_s_trx_info_init(void *const p) {
DBUG_ENTER_FUNC();
if (prevent_myrocks_loading)
DBUG_RETURN(1);
DBUG_ASSERT(p != nullptr);
my_core::ST_SCHEMA_TABLE *schema;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment