fix: expose plugin db handles during startup

mysqlx-plugin-impl
Rene Cannao 2 months ago
parent cd15afdd1e
commit fd5f029474

@ -338,6 +338,18 @@ extern AI_Features_Manager *GloAI;
extern void (*flush_logs_function)();
SQLite3DB* proxysql_plugin_get_admindb() {
return GloAdmin ? GloAdmin->admindb : nullptr;
}
SQLite3DB* proxysql_plugin_get_configdb() {
return GloAdmin ? GloAdmin->configdb : nullptr;
}
SQLite3DB* proxysql_plugin_get_statsdb() {
return GloAdmin ? GloAdmin->statsdb : nullptr;
}
extern Web_Interface *GloWebInterface;
extern ProxySQL_Cluster *GloProxyCluster;

@ -6,6 +6,10 @@
#include "proxysql.h"
SQLite3DB* proxysql_plugin_get_admindb();
SQLite3DB* proxysql_plugin_get_configdb();
SQLite3DB* proxysql_plugin_get_statsdb();
namespace {
ProxySQL_PluginManager* g_active_plugin_manager = nullptr;
@ -39,15 +43,15 @@ void register_command_service(const char* sql, proxysql_plugin_admin_command_cb
}
SQLite3DB* get_admindb_service() {
return nullptr;
return proxysql_plugin_get_admindb();
}
SQLite3DB* get_configdb_service() {
return nullptr;
return proxysql_plugin_get_configdb();
}
SQLite3DB* get_statsdb_service() {
return nullptr;
return proxysql_plugin_get_statsdb();
}
void log_message_service(int level, const char* message) {

@ -5,6 +5,8 @@
namespace {
ProxySQL_PluginServices* fake_services = nullptr;
void fake_log_event(const char *event) {
const char *log_path = std::getenv("PROXYSQL_FAKE_PLUGIN_LOG");
if (log_path == nullptr || *log_path == '\0') {
@ -20,12 +22,22 @@ void fake_log_event(const char *event) {
std::fclose(log_file);
}
bool fake_init(ProxySQL_PluginServices *) {
bool fake_init(ProxySQL_PluginServices *services) {
fake_services = services;
fake_log_event("init");
return true;
}
bool fake_start() {
if (fake_services == nullptr ||
fake_services->get_admindb == nullptr ||
fake_services->get_configdb == nullptr ||
fake_services->get_statsdb == nullptr ||
fake_services->get_admindb() == nullptr ||
fake_services->get_configdb() == nullptr ||
fake_services->get_statsdb() == nullptr) {
return false;
}
fake_log_event("start");
return true;
}

@ -12,6 +12,26 @@
extern ProxySQL_GlobalVariables GloVars;
namespace {
char g_fake_admin_db = '\0';
char g_fake_config_db = '\0';
char g_fake_stats_db = '\0';
} // namespace
SQLite3DB* proxysql_plugin_get_admindb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_admin_db);
}
SQLite3DB* proxysql_plugin_get_configdb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_config_db);
}
SQLite3DB* proxysql_plugin_get_statsdb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_stats_db);
}
int main() {
plan(7);

@ -7,6 +7,26 @@
#error "PROXYSQL_FAKE_PLUGIN_PATH must be defined"
#endif
namespace {
char g_fake_admin_db = '\0';
char g_fake_config_db = '\0';
char g_fake_stats_db = '\0';
} // namespace
SQLite3DB* proxysql_plugin_get_admindb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_admin_db);
}
SQLite3DB* proxysql_plugin_get_configdb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_config_db);
}
SQLite3DB* proxysql_plugin_get_statsdb() {
return reinterpret_cast<SQLite3DB*>(&g_fake_stats_db);
}
static void test_loader_round_trip() {
ProxySQL_PluginManager mgr;
std::string err;
@ -22,7 +42,7 @@ static void test_loader_round_trip() {
ok(!mgr.start_all(err), "start_all rejects uninitialized plugins");
ok(!err.empty(), "start_all without init reports an error");
ok(mgr.init_all(err), "init_all succeeds");
ok(mgr.start_all(err), "start_all succeeds");
ok(mgr.start_all(err), "start_all succeeds once DB handle callbacks are available");
ok(mgr.stop_all(), "stop_all succeeds");
}

Loading…
Cancel
Save