Reinitialize MySQL Tool Handler when MCP variables change

When LOAD MCP VARIABLES TO RUNTIME is called and the MCP server is
already running, the MySQL Tool Handler is now recreated with the
current configuration values. This allows changing MySQL connection
parameters without restarting ProxySQL.

The reinitialization:
1. Deletes the old MySQL Tool Handler
2. Creates a new one with current mcp-mysql_* values
3. Initializes the new handler
4. Logs success or failure
pull/5310/head
Rene Cannao 3 months ago
parent 49e6ac5bc6
commit 991f0138d8

@ -26,6 +26,7 @@ using json = nlohmann::json;
#include "proxysql_config.h"
#include "proxysql_restapi.h"
#include "MCP_Thread.h"
#include "MySQL_Tool_Handler.h"
#include "ProxySQL_MCP_Server.hpp"
#include "proxysql_utils.h"
#include "prometheus_helpers.h"
@ -1391,7 +1392,33 @@ void ProxySQL_Admin::flush_mcp_variables___runtime_to_database(SQLite3DB* db, bo
}
}
} else {
proxy_info("MCP: Server already running\n");
// Server is already running - check if MySQL configuration changed
// and reinitialize the tool handler if needed
proxy_info("MCP: Server already running, checking MySQL tool handler reinitialization\n");
if (GloMCPH->mysql_tool_handler) {
// Delete old handler
delete GloMCPH->mysql_tool_handler;
GloMCPH->mysql_tool_handler = NULL;
}
// Create new tool handler with current configuration
proxy_info("MCP: Reinitializing MySQL Tool Handler with current configuration\n");
GloMCPH->mysql_tool_handler = new MySQL_Tool_Handler(
GloMCPH->variables.mcp_mysql_hosts ? GloMCPH->variables.mcp_mysql_hosts : "",
GloMCPH->variables.mcp_mysql_ports ? GloMCPH->variables.mcp_mysql_ports : "",
GloMCPH->variables.mcp_mysql_user ? GloMCPH->variables.mcp_mysql_user : "",
GloMCPH->variables.mcp_mysql_password ? GloMCPH->variables.mcp_mysql_password : "",
GloMCPH->variables.mcp_mysql_schema ? GloMCPH->variables.mcp_mysql_schema : "",
GloMCPH->variables.mcp_catalog_path ? GloMCPH->variables.mcp_catalog_path : ""
);
if (GloMCPH->mysql_tool_handler->init() != 0) {
proxy_error("MCP: Failed to reinitialize MySQL Tool Handler\n");
delete GloMCPH->mysql_tool_handler;
GloMCPH->mysql_tool_handler = NULL;
} else {
proxy_info("MCP: MySQL Tool Handler reinitialized successfully\n");
}
}
} else {
// Stop the server if running

Loading…
Cancel
Save