Remove MySQL dependency from gateway.cc

The MySQL initialization is now performed by the MySQLClient module.
This commit is contained in:
Johan Wikman
2017-01-05 20:05:15 +02:00
parent 8fc5bdc2f1
commit 2d849e0ab2
2 changed files with 64 additions and 114 deletions

View File

@ -51,7 +51,6 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <openssl/opensslconf.h> #include <openssl/opensslconf.h>
#include <mysql.h>
#include <ini.h> #include <ini.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/config.h> #include <maxscale/config.h>
@ -103,11 +102,6 @@ static int pidfd = PIDFD_CLOSED;
*/ */
static bool do_exit = FALSE; static bool do_exit = FALSE;
/**
* Flag to indicate whether MySQL is successfully initialized.
*/
static bool libmysql_initialized = FALSE;
/** /**
* If MaxScale is started to run in daemon process the value is true. * If MaxScale is started to run in daemon process the value is true.
*/ */
@ -152,7 +146,6 @@ static void log_flush_cb(void* arg);
static int write_pid_file(); /* write MaxScale pidfile */ static int write_pid_file(); /* write MaxScale pidfile */
static void unlink_pidfile(void); /* remove pidfile */ static void unlink_pidfile(void); /* remove pidfile */
static void unlock_pidfile(); static void unlock_pidfile();
static void libmysqld_done(void);
static bool file_write_header(FILE* outfile); static bool file_write_header(FILE* outfile);
static bool file_write_footer(FILE* outfile); static bool file_write_footer(FILE* outfile);
static void write_footer(void); static void write_footer(void);
@ -557,15 +550,6 @@ void cleanup_process_datadir()
} }
} }
static void libmysqld_done(void)
{
if (libmysql_initialized)
{
mysql_library_end();
}
}
static void write_footer(void) static void write_footer(void)
{ {
file_write_footer(stdout); file_write_footer(stdout);
@ -975,20 +959,9 @@ static void usage(void)
void worker_thread_main(void* arg) void worker_thread_main(void* arg)
{ {
if (modules_thread_init()) if (modules_thread_init())
{
/** Init mysql thread context for use with a mysql handle and a parser */
if (mysql_thread_init() == 0)
{ {
poll_waitevents(arg); poll_waitevents(arg);
/** Release mysql thread context */
mysql_thread_end();
}
else
{
MXS_ERROR("Could not perform thread initialization for MySQL. Exiting thread.");
}
modules_thread_finish(); modules_thread_finish();
} }
else else
@ -1292,7 +1265,6 @@ int main(int argc, char **argv)
bool parent_process; bool parent_process;
int child_status; int child_status;
THREAD* threads = NULL; /*< thread list */ THREAD* threads = NULL; /*< thread list */
char mysql_home[PATH_MAX + 1];
char* cnf_file_path = NULL; /*< conf file, to be freed */ char* cnf_file_path = NULL; /*< conf file, to be freed */
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */ char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
THREAD log_flush_thr; THREAD log_flush_thr;
@ -1324,8 +1296,7 @@ int main(int argc, char **argv)
datadir[PATH_MAX] = '\0'; datadir[PATH_MAX] = '\0';
file_write_header(stderr); file_write_header(stderr);
/*< /*<
* Register functions which are called at exit except libmysqld-related, * Register functions which are called at exit.
* which must be registered later to avoid ordering issues.
*/ */
for (i = 0; exitfunp[i] != NULL; i++) for (i = 0; exitfunp[i] != NULL; i++)
{ {
@ -1713,22 +1684,6 @@ int main(int argc, char **argv)
CRYPTO_set_id_callback(pthread_self); CRYPTO_set_id_callback(pthread_self);
#endif #endif
/* register exit function for embedded MySQL library */
l = atexit(libmysqld_done);
if (l != 0)
{
const char* fprerr =
"Failed to register exit function for\n* "
"embedded MySQL library.\n* Exiting.";
const char* logerr =
"Failed to register exit function libmysql_done "
"for MaxScale. Exiting.";
print_log_n_stderr(true, true, logerr, fprerr, 0);
rc = MAXSCALE_INTERNALERROR;
goto return_main;
}
/** /**
* Resolve the full pathname for configuration file and check for * Resolve the full pathname for configuration file and check for
* read accessibility. * read accessibility.
@ -1753,12 +1708,6 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
/** Use the cache dir for the mysql folder of the embedded library */
snprintf(mysql_home, PATH_MAX, "%s/mysql", get_cachedir());
mysql_home[PATH_MAX] = '\0';
setenv("MYSQL_HOME", mysql_home, 1);
/** /**
* Init Log Manager for MaxScale. * Init Log Manager for MaxScale.
*/ */
@ -1808,9 +1757,8 @@ int main(int argc, char **argv)
MXS_NOTICE("MariaDB MaxScale %s started", MAXSCALE_VERSION); MXS_NOTICE("MariaDB MaxScale %s started", MAXSCALE_VERSION);
MXS_NOTICE("MaxScale is running in process %i", getpid()); MXS_NOTICE("MaxScale is running in process %i", getpid());
/* /*
* Set the data directory for the mysqld library. We use * Set the data directory. We use a unique directory name to avoid conflicts
* a unique directory name to avoid conflicts if multiple * if multiple instances of MaxScale are being run on the same machine.
* instances of MaxScale are being run on the same machine.
*/ */
if (create_datadir(get_datadir(), datadir)) if (create_datadir(get_datadir(), datadir))
{ {
@ -1876,52 +1824,6 @@ int main(int argc, char **argv)
cnf->config_check = config_check; cnf->config_check = config_check;
if (mysql_library_init(0, NULL, NULL))
{
if (!daemon_mode)
{
const char* fprerr = "Failed to initialise the MySQL library. Exiting.";
print_log_n_stderr(false, true, fprerr, fprerr, 0);
if (mysql_errno(NULL) == 2000)
{
if (strncmp(mysql_error(NULL),
"Unknown MySQL error",
strlen("Unknown MySQL error")) != 0)
{
fprintf(stderr,
"*\n* Error : MySQL Error should "
"be \"Unknown MySQL error\" "
"instead of\n* %s\n* Hint "
":\n* Ensure that you have "
"MySQL error messages file, errmsg.sys in "
"\n* %s/mysql\n* Ensure that Embedded "
"Server Library version matches "
"exactly with that of the errmsg.sys "
"file.\n*\n",
mysql_error(NULL),
get_langdir());
}
else
{
fprintf(stderr,
"*\n* Error : MySQL Error %d, %s"
"\n*\n",
mysql_errno(NULL),
mysql_error(NULL));
}
}
}
MXS_ERROR("mysql_library_init failed. It is a "
"mandatory component, required by router services and "
"the MaxScale core. Error %d, %s. Exiting.",
mysql_errno(NULL),
mysql_error(NULL));
rc = MAXSCALE_NOLIBRARY;
goto return_main;
}
libmysql_initialized = TRUE;
if (!config_check) if (!config_check)
{ {
/** Check if a MaxScale process is already running */ /** Check if a MaxScale process is already running */
@ -1958,12 +1860,6 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
/**
* Init mysql thread context for main thread as well. Needed when users
* are queried from backends.
*/
mysql_thread_init();
/** Start all monitors */ /** Start all monitors */
monitorStartAll(); monitorStartAll();
@ -2076,8 +1972,6 @@ int main(int argc, char **argv)
log_exit_status(); log_exit_status();
MXS_NOTICE("MaxScale is shutting down."); MXS_NOTICE("MaxScale is shutting down.");
/** Release mysql thread context*/
mysql_thread_end();
utils_end(); utils_end();
cleanup_process_datadir(); cleanup_process_datadir();

View File

@ -60,6 +60,11 @@
#include <maxscale/gw_authenticator.h> #include <maxscale/gw_authenticator.h>
#include <maxscale/session.h> #include <maxscale/session.h>
static int process_init(void);
static void process_finish(void);
static int thread_init(void);
static void thread_finish(void);
static int gw_MySQLAccept(DCB *listener); static int gw_MySQLAccept(DCB *listener);
static int gw_MySQLListener(DCB *listener, char *config_bind); static int gw_MySQLListener(DCB *listener, char *config_bind);
static int gw_read_client_event(DCB* dcb); static int gw_read_client_event(DCB* dcb);
@ -120,10 +125,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
"The client to MaxScale MySQL protocol implementation", "The client to MaxScale MySQL protocol implementation",
"V1.1.0", "V1.1.0",
&MyObject, &MyObject,
NULL, /* Process init. */ process_init,
NULL, /* Process finish. */ process_finish,
NULL, /* Thread init. */ thread_init,
NULL, /* Thread finish. */ thread_finish,
{ {
{MXS_END_MODULE_PARAMS} {MXS_END_MODULE_PARAMS}
} }
@ -133,6 +138,57 @@ MXS_MODULE* MXS_CREATE_MODULE()
} }
/*lint +e14 */ /*lint +e14 */
/**
* Performs process wide initialization.
*
* @return 0 if successful, non-zero otherwise.
*/
static int process_init(void)
{
int rv = mysql_library_init(0, NULL, NULL);
if (rv != 0)
{
MXS_ERROR("MySQL initialization failed, MariaDB MaxScale will exit. "
"MySQL Error: %d, %s.", mysql_errno(NULL), mysql_error(NULL));
}
return rv;
}
/**
* Performs process wide finalization.
*/
static void process_finish(void)
{
mysql_library_end();
}
/**
* Performs thread-specific initialization.
*
* @return 0 if successful, non-zero otherwise.
*/
static int thread_init(void)
{
int rv = mysql_thread_init();
if (rv != 0)
{
MXS_ERROR("MySQL thread initialization failed, the thread will exit.");
}
return rv;
}
/**
* Performs thread specific finalization.
*/
static void thread_finish(void)
{
mysql_thread_end();
}
/** /**
* The default authenticator name for this protocol * The default authenticator name for this protocol
* *