From fc6f49fe8a89c993b75d67d28cad2a2a345e3c34 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 29 Jan 2016 16:50:31 +0200 Subject: [PATCH] Link against Connector-C. Now, qc_mysqlembedded is linked against MySQL's embedded library, and MaxScale itself against Connector-C. So, in order to build MaxScale, Connector-C must be installed. This has been tested with Connector-C 2.2.1. The build variable MYSQLCLIENT_LIBRARIES is no longer used. --- CMakeLists.txt | 6 ----- cmake/FindMySQLClient.cmake | 22 +++++++++---------- query_classifier/CMakeLists.txt | 2 +- .../qc_mysqlembedded/CMakeLists.txt | 6 +++++ query_classifier/test/CMakeLists.txt | 6 +++++ rabbitmq_consumer/CMakeLists.txt | 4 ++-- server/CMakeLists.txt | 2 ++ server/core/CMakeLists.txt | 2 +- server/core/dbusers.c | 5 +++++ server/core/gateway.c | 10 +-------- server/modules/filter/mqfilter.c | 1 - .../include/mysql_client_server_protocol.h | 11 +++++++++- server/modules/routing/binlog/CMakeLists.txt | 2 +- .../routing/binlog/test/CMakeLists.txt | 2 +- .../routing/schemarouter/test/CMakeLists.txt | 4 ++-- server/modules/routing/test/CMakeLists.txt | 6 ++--- 16 files changed, 52 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b975c62db..51735eda8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,12 +157,6 @@ set(CMAKE_CXX_FLAGS_DEBUG "${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT") set(CMAKE_CXX_FLAGS_RELEASE "") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-ggdb") -subdirs(MYSQL_DIR_ALL ${MYSQL_DIR}) -foreach(DIR ${MYSQL_DIR_ALL}) - include_directories(${DIR}) -endforeach() - -include_directories(${MYSQL_DIR}/..) include_directories(utils) include_directories(log_manager) include_directories(query_classifier) diff --git a/cmake/FindMySQLClient.cmake b/cmake/FindMySQLClient.cmake index 5b4f53eff..a08c9692c 100644 --- a/cmake/FindMySQLClient.cmake +++ b/cmake/FindMySQLClient.cmake @@ -2,32 +2,32 @@ # The following variables are set: # MYSQLCLIENT_FOUND - System has MySQL client # MYSQLCLIENT_STATIC_FOUND - System has statically linked MySQL client -# MYSQLCLIENT_LIBRARIES - The MySQL client library -# MYSQLCLIENT_STATIC_LIBRARIES - The static MySQL client library +# MARIADB_CONNECTOR_LIB - The MySQL client library +# MARIADB_CONNECTOR_STATIC_LIB - The static MySQL client library # MYSQLCLIENT_HEADERS - The MySQL client headers -find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb) -if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND") +find_library(MARIADB_CONNECTOR_LIB NAMES mysqlclient PATH_SUFFIXES mysql mariadb) +if(${MARIADB_CONNECTOR_LIB} MATCHES "NOTFOUND") set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "") message(STATUS "Dynamic MySQL client library not found.") - unset(MYSQLCLIENT_LIBRARIES) + unset(MARIADB_CONNECTOR_LIB) else() set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "") - message(STATUS "Found dynamic MySQL client library: ${MYSQLCLIENT_LIBRARIES}") + message(STATUS "Found dynamic MySQL client library: ${MARIADB_CONNECTOR_LIB}") endif() set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_library(MYSQLCLIENT_STATIC_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb) +find_library(MARIADB_CONNECTOR_STATIC_LIB NAMES mysqlclient PATH_SUFFIXES mysql mariadb) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) -if(${MYSQLCLIENT_STATIC_LIBRARIES} MATCHES "NOTFOUND") +if(${MARIADB_CONNECTOR_STATIC_LIB} MATCHES "NOTFOUND") set(MYSQLCLIENT_STATIC_FOUND FALSE CACHE INTERNAL "") message(STATUS "Static MySQL client library not found.") - unset(MYSQLCLIENT_STATIC_LIBRARIES) + unset(MARIADB_CONNECTOR_STATIC_LIB) else() set(MYSQLCLIENT_STATIC_FOUND TRUE CACHE INTERNAL "") - message(STATUS "Found statc MySQL client library: ${MYSQLCLIENT_STATIC_LIBRARIES}") + message(STATUS "Found statc MySQL client library: ${MARIADB_CONNECTOR_STATIC_LIB}") endif() -find_path(MYSQLCLIENT_HEADERS mysql.h PATH_SUFFIXES mysql mariadb) \ No newline at end of file +find_path(MYSQLCLIENT_HEADERS mysql.h PATH_SUFFIXES mysql mariadb) diff --git a/query_classifier/CMakeLists.txt b/query_classifier/CMakeLists.txt index 4780df0e9..68f4d993c 100644 --- a/query_classifier/CMakeLists.txt +++ b/query_classifier/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(query_classifier SHARED query_classifier.cc) -target_link_libraries(query_classifier ${MYSQL_EMBEDDED_LIB} aio crypt crypto dl m ${PCRE_LINK_FLAGS} ssl stdc++ z) +target_link_libraries(query_classifier maxscale-common) set_target_properties(query_classifier PROPERTIES VERSION "1.0.0") set_target_properties(query_classifier PROPERTIES LINK_FLAGS -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/query_classifier.map) set_target_properties(query_classifier PROPERTIES LINK_FLAGS -Wl,-z,defs) diff --git a/query_classifier/qc_mysqlembedded/CMakeLists.txt b/query_classifier/qc_mysqlembedded/CMakeLists.txt index 67066754d..d2fc724f1 100644 --- a/query_classifier/qc_mysqlembedded/CMakeLists.txt +++ b/query_classifier/qc_mysqlembedded/CMakeLists.txt @@ -1,3 +1,9 @@ +subdirs(MYSQL_DIR_ALL ${MYSQL_DIR}) +foreach(DIR ${MYSQL_DIR_ALL}) + include_directories(${DIR}) +endforeach() +include_directories(${MYSQL_INCLUDE}) + add_library(qc_mysqlembedded SHARED qc_mysqlembedded.cc) target_link_libraries(qc_mysqlembedded ${MYSQL_EMBEDDED_LIB} aio crypt crypto dl m ${PCRE_LINK_FLAGS} ssl stdc++ z) diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt index 61b5702f1..f1c36e080 100644 --- a/query_classifier/test/CMakeLists.txt +++ b/query_classifier/test/CMakeLists.txt @@ -1,3 +1,9 @@ +subdirs(MYSQL_DIR_ALL ${MYSQL_DIR}) +foreach(DIR ${MYSQL_DIR_ALL}) + include_directories(${DIR}) +endforeach() +include_directories(${MYSQL_INCLUDE}) + if(${ERRMSG} MATCHES "ERRMSG-NOTFOUND") message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=") else() diff --git a/rabbitmq_consumer/CMakeLists.txt b/rabbitmq_consumer/CMakeLists.txt index bad2de7b3..b585fd435 100644 --- a/rabbitmq_consumer/CMakeLists.txt +++ b/rabbitmq_consumer/CMakeLists.txt @@ -29,9 +29,9 @@ add_subdirectory(inih) add_executable (consumer ${CMAKE_BINARY_DIR}/consumer.c) if(MYSQLCLIENT_STATIC_FOUND) - target_link_libraries(consumer ${MYSQLCLIENT_STATIC_LIBRARIES} rabbitmq inih ssl crypt crypto dl z m pthread) + target_link_libraries(consumer ${MARIADB_CONNECTOR_STATIC_LIB} rabbitmq inih ssl crypt crypto dl z m pthread) else() - target_link_libraries(consumer ${MYSQLCLIENT_LIBRARIES} rabbitmq inih ssl crypt crypto dl z m pthread) + target_link_libraries(consumer ${MARIADB_CONNECTOR_LIB} rabbitmq inih ssl crypt crypto dl z m pthread) endif() install(TARGETS consumer DESTINATION ${MAXSCALE_BINDIR}) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 6cd174190..f4f9d1aca 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories(${MARIADB_CONNECTOR_INCLUDE}) + add_subdirectory(core) add_subdirectory(modules) add_subdirectory(inih) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 4918f7fa2..173a2347a 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(maxscale-common SHARED adminusers.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c maxscale_pcre2.c memlog.c modutil.c monitor.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc ${CMAKE_SOURCE_DIR}/utils/skygw_utils.cc statistics.c) -target_link_libraries(maxscale-common ${MYSQLCLIENT_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++) +target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIB} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++) if(WITH_JEMALLOC) target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES}) diff --git a/server/core/dbusers.c b/server/core/dbusers.c index c807e9ed4..aa554a79c 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -2186,6 +2186,10 @@ MYSQL *gw_mysql_init() { if (gw_mysql_set_timeouts(con) == 0) { + // MYSQL_OPT_USE_REMOTE_CONNECTION must be set if the embedded + // libary is used. With Connector-C (at least 2.2.1) the call + // fails. +#if !defined(LIBMARIADB) if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL) != 0) { MXS_ERROR("Failed to set external connection. " @@ -2193,6 +2197,7 @@ MYSQL *gw_mysql_init() mysql_close(con); con = NULL; } +#endif } else { diff --git a/server/core/gateway.c b/server/core/gateway.c index 20f3d9709..5987735fb 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -507,15 +507,7 @@ static void libmysqld_done(void) { if (libmysqld_started) { - // TODO: qc_end() (if qc_mysqlembedded is used) also calls mysql_library_end(), - // TODO: which refers to the mysql_library_end() in the embedded library. This - // TODO: one would call the mysql_library_end() in the client library. It seems - // TODO: that would work, but for the fact that both de-initialize some lower - // TODO: level library, which in turn does not work. Thus, for the time being - // TODO: this call is not made. - // TODO: Linking MaxScale with Connector-C would likely make this problem - // TODO: go away. - //mysql_library_end(); + mysql_library_end(); } } diff --git a/server/modules/filter/mqfilter.c b/server/modules/filter/mqfilter.c index be9a07a63..002da6dca 100644 --- a/server/modules/filter/mqfilter.c +++ b/server/modules/filter/mqfilter.c @@ -80,7 +80,6 @@ #include #include #include -#include #include MODULE_INFO info = diff --git a/server/modules/include/mysql_client_server_protocol.h b/server/modules/include/mysql_client_server_protocol.h index 83acb80e9..b48d321ea 100644 --- a/server/modules/include/mysql_client_server_protocol.h +++ b/server/modules/include/mysql_client_server_protocol.h @@ -64,6 +64,7 @@ #include #include #include +#include #define GW_MYSQL_VERSION "MaxScale " MAXSCALE_VERSION #define GW_MYSQL_LOOP_TIMEOUT 300000000 @@ -224,9 +225,15 @@ typedef enum ), } gw_mysql_capabilities_t; +// mysql.h from Connector-C exposes this enum, while mysql.h from +// MariaDB does not. +// TODO: This should probably be removed as Connector-C will be +// TODO: a pre-requisite for building MaxScale. +#if defined(LIBMARIADB) +typedef enum enum_server_command mysql_server_cmd_t; +#else /** Copy from enum in mariadb-5.5 mysql_com.h */ typedef enum mysql_server_cmd { - MYSQL_COM_UNDEFINED = -1, MYSQL_COM_SLEEP = 0, MYSQL_COM_QUIT, MYSQL_COM_INIT_DB, @@ -259,7 +266,9 @@ typedef enum mysql_server_cmd { MYSQL_COM_DAEMON, MYSQL_COM_END /*< Must be the last */ } mysql_server_cmd_t; +#endif +static const mysql_server_cmd_t MYSQL_COM_UNDEFINED = (mysql_server_cmd_t)-1; /** * List of server commands, and number of response packets are stored here. diff --git a/server/modules/routing/binlog/CMakeLists.txt b/server/modules/routing/binlog/CMakeLists.txt index 1e2035ad2..0eaf5c27b 100644 --- a/server/modules/routing/binlog/CMakeLists.txt +++ b/server/modules/routing/binlog/CMakeLists.txt @@ -6,7 +6,7 @@ install(TARGETS binlogrouter DESTINATION ${MAXSCALE_LIBDIR}) add_executable(maxbinlogcheck maxbinlogcheck.c blr_file.c blr_cache.c blr_master.c blr_slave.c blr.c) # maxbinlogcheck refers to my_uuid_init and my_uuin. They are non-public functions and # should not be used. They are found only from the embedded lib. -target_link_libraries(maxbinlogcheck maxscale-common query_classifier ${EMBEDDED_LIB}) +target_link_libraries(maxbinlogcheck maxscale-common query_classifier ${MYSQL_EMBEDDED_LIB}) install(TARGETS maxbinlogcheck DESTINATION bin) diff --git a/server/modules/routing/binlog/test/CMakeLists.txt b/server/modules/routing/binlog/test/CMakeLists.txt index ad02de4f9..0f967487d 100644 --- a/server/modules/routing/binlog/test/CMakeLists.txt +++ b/server/modules/routing/binlog/test/CMakeLists.txt @@ -2,6 +2,6 @@ if(BUILD_TESTS) add_executable(testbinlogrouter testbinlog.c ../blr.c ../blr_slave.c ../blr_master.c ../blr_file.c ../blr_cache.c) # testbinlogrouter refers to my_uuid_init and my_uuin. They are non-public functions and # should not be used. They are found only from the embedded lib. - target_link_libraries(testbinlogrouter maxscale-common query_classifier ${EMBEDDED_LIB}) + target_link_libraries(testbinlogrouter maxscale-common query_classifier ${MYSQL_EMBEDDED_LIB}) add_test(TestBinlogRouter ${CMAKE_CURRENT_BINARY_DIR}/testbinlogrouter) endif() diff --git a/server/modules/routing/schemarouter/test/CMakeLists.txt b/server/modules/routing/schemarouter/test/CMakeLists.txt index 7974c87f9..1d1bbcc3d 100644 --- a/server/modules/routing/schemarouter/test/CMakeLists.txt +++ b/server/modules/routing/schemarouter/test/CMakeLists.txt @@ -1,9 +1,9 @@ if(MYSQLCLIENT_FOUND AND BUILD_TESTS) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/test.cmake @ONLY) add_executable(testschemarouter testschemarouter.c) - target_link_libraries(testschemarouter ${MYSQLCLIENT_LIBRARIES} ssl crypto dl z m rt pthread) + target_link_libraries(testschemarouter ${MARIADB_CONNECTOR_LIB} ssl crypto dl z m rt pthread) add_executable(testschemarouter2 testschemarouter2.c) - target_link_libraries(testschemarouter2 ${MYSQLCLIENT_LIBRARIES} ssl crypto dl z m rt pthread) + target_link_libraries(testschemarouter2 ${MARIADB_CONNECTOR_LIB} ssl crypto dl z m rt pthread) add_test(NAME TestSchemaRouter COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/test.cmake) endif() diff --git a/server/modules/routing/test/CMakeLists.txt b/server/modules/routing/test/CMakeLists.txt index 19c51b4a1..fc622c4df 100644 --- a/server/modules/routing/test/CMakeLists.txt +++ b/server/modules/routing/test/CMakeLists.txt @@ -1,6 +1,6 @@ if(MYSQLCLIENT_FOUND) add_executable(testconnect testconnect.c) - message(STATUS "Linking against: ${MYSQLCLIENT_LIBRARIES}") - target_link_libraries(testconnect ${MYSQLCLIENT_LIBRARIES} ssl crypto dl z m rt pthread) + message(STATUS "Linking against: ${MARIADB_CONNECTOR_LIB}") + target_link_libraries(testconnect ${MARIADB_CONNECTOR_LIB} ssl crypto dl z m rt pthread) add_test(NAME ReadConnRouterAuthTest COMMAND $ 10000 ${TEST_HOST} ${MASTER_PORT} ${TEST_HOST} ${TEST_PORT} 1.10) -endif() \ No newline at end of file +endif()