diff --git a/lib/Admin_Bootstrap.cpp b/lib/Admin_Bootstrap.cpp index 1b60314d5..9d156981d 100644 --- a/lib/Admin_Bootstrap.cpp +++ b/lib/Admin_Bootstrap.cpp @@ -939,7 +939,7 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) { #endif /* PROXYSQLGENAI */ if (ProxySQL_PluginManager* plugin_manager = proxysql_get_plugin_manager()) { - auto merge_plugin_tables = [this](std::vector* target, const std::vector& defs, const char* db_name) { + auto merge_plugin_tables = [this](std::vector* target, const std::vector& defs, const char* db_name) -> bool { for (const auto& def : defs) { bool duplicate_name = false; for (const auto* existing : *target) { @@ -949,17 +949,20 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) { } } if (duplicate_name) { - proxy_warning("Skipping plugin table %s for %s because the table name already exists\n", - def.table_name, db_name); - continue; + proxy_error("Plugin table %s for %s conflicts with an existing table name\n", + def.table_name, db_name); + return false; } insert_into_tables_defs(target, def.table_name, def.table_def); } + return true; }; - merge_plugin_tables(tables_defs_admin, plugin_manager->tables(ProxySQL_PluginDBKind::admin_db), "admin"); - merge_plugin_tables(tables_defs_config, plugin_manager->tables(ProxySQL_PluginDBKind::config_db), "config"); - merge_plugin_tables(tables_defs_stats, plugin_manager->tables(ProxySQL_PluginDBKind::stats_db), "stats"); + if (!merge_plugin_tables(tables_defs_admin, plugin_manager->tables(ProxySQL_PluginDBKind::admin_db), "admin") || + !merge_plugin_tables(tables_defs_config, plugin_manager->tables(ProxySQL_PluginDBKind::config_db), "config") || + !merge_plugin_tables(tables_defs_stats, plugin_manager->tables(ProxySQL_PluginDBKind::stats_db), "stats")) { + return false; + } } // init ldap here diff --git a/lib/ProxySQL_PluginManager.cpp b/lib/ProxySQL_PluginManager.cpp index 5e78f9449..ccaafb4e7 100644 --- a/lib/ProxySQL_PluginManager.cpp +++ b/lib/ProxySQL_PluginManager.cpp @@ -272,14 +272,18 @@ size_t ProxySQL_PluginManager::size() const { } const std::vector& ProxySQL_PluginManager::tables(ProxySQL_PluginDBKind kind) const { + static const std::vector empty_tables {}; + switch (kind) { case ProxySQL_PluginDBKind::admin_db: return tables_admin_; case ProxySQL_PluginDBKind::config_db: return tables_config_; case ProxySQL_PluginDBKind::stats_db: - default: return tables_stats_; + default: + proxy_warning("Invalid plugin table registry kind requested: %d\n", static_cast(kind)); + return empty_tables; } } diff --git a/src/main.cpp b/src/main.cpp index 57f77e631..8b5c15762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -985,7 +985,10 @@ void ProxySQL_Main_init_Admin_module(const bootstrap_info_t& bootstrap_info) { //GloProxyStats->init(); GloProxyStats->print_version(); GloAdmin = new ProxySQL_Admin(); - GloAdmin->init(bootstrap_info); + if (!GloAdmin->init(bootstrap_info)) { + proxy_error("Admin module initialization failed\n"); + exit(EXIT_FAILURE); + } GloAdmin->print_version(); if (binary_sha1) { proxy_info("ProxySQL SHA1 checksum: %s\n", binary_sha1); diff --git a/test/tap/tests/unit/plugin_registry_unit-t.cpp b/test/tap/tests/unit/plugin_registry_unit-t.cpp index 17efe89d4..0bef24e97 100644 --- a/test/tap/tests/unit/plugin_registry_unit-t.cpp +++ b/test/tap/tests/unit/plugin_registry_unit-t.cpp @@ -13,7 +13,7 @@ ProxySQL_PluginCommandResult fake_plugin_command(const ProxySQL_PluginCommandCon } // namespace int main() { - plan(13); + plan(15); ProxySQL_PluginManager mgr; char table_name[] = "mysqlx_users"; @@ -45,8 +45,16 @@ int main() { "invalid_table", "CREATE TABLE invalid_table (id INTEGER)" }; + ProxySQL_PluginTableDef stats_def { + ProxySQL_PluginDBKind::stats_db, + "mysqlx_stats", + "CREATE TABLE mysqlx_stats (id INTEGER)" + }; mgr.register_table_for_test(invalid_def); ok(mgr.tables(ProxySQL_PluginDBKind::admin_db).size() == static_cast(1), "invalid db kind is rejected"); + mgr.register_table_for_test(stats_def); + ok(mgr.tables(ProxySQL_PluginDBKind::stats_db).size() == static_cast(1), "plugin stats table is stored"); + ok(mgr.tables(static_cast(255)).empty(), "invalid table accessor returns empty"); ok(mgr.tables(ProxySQL_PluginDBKind::config_db).size() == static_cast(0), "config tables start empty"); ok(!mgr.register_command_for_test("SELECT 1"), "unnamespaced admin SQL is rejected"); ok(mgr.register_command("PLUGIN MYSQLX LOAD USERS TO RUNTIME", &fake_plugin_command), "namespaced command registration succeeds");