From 6041a7e12fc015f3acad92c4e6b5644988df2f5e Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Fri, 17 Oct 2014 09:44:52 +0300 Subject: [PATCH 1/6] Added server state information to trace log printing --- .../routing/readwritesplit/readwritesplit.c | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 07820b076..5a239a5ef 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -2696,34 +2696,38 @@ static bool select_connect_backend_servers( switch(select_criteria) { case LEAST_GLOBAL_CONNECTIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d MaxScale connections : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->stats.n_current))); + "MaxScale connections : %d in \t%s:%d %s", + b->backend_server->stats.n_current, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_ROUTER_CONNECTIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d RWSplit connections : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_conn_count))); + "RWSplit connections : %d in \t%s:%d %s", + b->backend_conn_count, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_CURRENT_OPERATIONS: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d current operations : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->stats.n_current_ops))); + "current operations : %d in \t%s:%d %s", + b->backend_server->stats.n_current_ops, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); break; case LEAST_BEHIND_MASTER: LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE, - "%s:%d replication lag : %d", - b->backend_server->name, - b->backend_server->port, - b->backend_server->rlag))); + "replication lag : %d in \t%s:%d %s", + b->backend_server->rlag, + b->backend_server->name, + b->backend_server->port, + STRSRVSTATUS(b->backend_server)))); default: break; } From e8758d36784a0c40770318052da4dc07a2b27d05 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Fri, 17 Oct 2014 10:57:02 +0100 Subject: [PATCH 2/6] Fix problems in tests, fix issue in server.c (bug 581) --- server/core/server.c | 2 +- server/core/test/testserver.c | 7 ++++--- server/core/test/testusers.c | 11 ++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/core/server.c b/server/core/server.c index 167ae4f23..3fabd2b34 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -162,7 +162,7 @@ SERVER *server; server = allServers; while (server) { - if (strcmp(server->unique_name, name) == 0) + if (server->unique_name && strcmp(server->unique_name, name) == 0) break; server = server->next; } diff --git a/server/core/test/testserver.c b/server/core/test/testserver.c index 3b05188ab..b1065ace0 100644 --- a/server/core/test/testserver.c +++ b/server/core/test/testserver.c @@ -63,13 +63,14 @@ char *status; ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name."); ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server."); status = server_status(server); - ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down prior to being set."); + ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running by default."); if (NULL != status) free(status); server_set_status(server, SERVER_MASTER); status = server_status(server); - ss_info_dassert(0 == strcmp("Master, Down", status), "Should find correct status."); + ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status."); server_clear_status(server, SERVER_MASTER); - ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down after status cleared."); + status = server_status(server); + ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared."); if (NULL != status) free(status); ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers."); printServer(server); diff --git a/server/core/test/testusers.c b/server/core/test/testusers.c index 3f13cad9b..c2b2c9f15 100644 --- a/server/core/test/testusers.c +++ b/server/core/test/testusers.c @@ -41,7 +41,8 @@ static int test1() { -USERS *users; +USERS *users; +char *authdata; int result, count; /* Poll tests */ @@ -52,13 +53,17 @@ int result, count; ss_dfprintf(stderr, "\t..done\nAdd a user"); count = users_add(users, "username", "authorisation"); ss_info_dassert(1 == count, "Should add one user"); - ss_info_dassert(strcmp("authorisation", users_fetch(users, "username")), "User authorisation should be correct"); + authdata = users_fetch(users, "username"); + ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL"); + ss_info_dassert(0 == strcmp("authorisation", authdata), "User authorisation should be correct"); ss_dfprintf(stderr, "\t..done\nPrint users"); usersPrint(users); ss_dfprintf(stderr, "\t..done\nUpdate a user"); count = users_update(users, "username", "newauth"); ss_info_dassert(1 == count, "Should update just one user"); - ss_info_dassert(strcmp("newauth", users_fetch(users, "username")), "User authorisation should be correctly updated"); + authdata = users_fetch(users, "username"); + ss_info_dassert(NULL != authdata, "Fetch valid user must not return NULL"); + ss_info_dassert(0 == strcmp("newauth", authdata), "User authorisation should be correctly updated"); ss_dfprintf(stderr, "\t..done\nDelete a user."); count = users_delete(users, "username"); ss_info_dassert(1 == count, "Should delete just one user"); From bdff2236079c9b41b32d2be24534387a9bcbf93d Mon Sep 17 00:00:00 2001 From: counterpoint Date: Fri, 17 Oct 2014 14:10:16 +0100 Subject: [PATCH 3/6] Modify atomic_add to use built in GCC function where available. Correct comments. --- server/core/atomic.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/server/core/atomic.c b/server/core/atomic.c index b14e1ccb1..c1bd5b244 100644 --- a/server/core/atomic.c +++ b/server/core/atomic.c @@ -29,23 +29,32 @@ */ /** - * Implementation of an atomic add operation for the X86 processor. + * Implementation of an atomic add operation for the GCC environment, or the + * X86 processor. If we are working within GNU C then we can use the GCC + * atomic add built in function, which is portable across platforms that + * implement GCC. Otherwise, this function currently supports only X86 + * architecture (without further development). + * * Adds a value to the contents of a location pointed to by the first parameter. - * The add operation is atomic and the return value is the value stored in the location - * prior to the operation. The number that is added may be signed, therefore atomic_subtract - * is merely an atomic add with a negative value. + * The add operation is atomic and the return value is the value stored in the + * location prior to the operation. The number that is added may be signed, + * therefore atomic_subtract is merely an atomic add with a negative value. * * @param variable Pointer the the variable to add to * @param value Value to be added - * @return Pointer to the value of variable before the add occured + * @return The value of variable before the add occurred */ int atomic_add(int *variable, int value) { +#ifdef __GNUC__ + return (int) __sync_fetch_and_add (variable, value); +#else asm volatile( "lock; xaddl %%eax, %2;" :"=a" (value) : "a" (value), "m" (*variable) : "memory" ); return value; +#endif } From db7bc39c7c706fc1ffbf170223657e288b06c362 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Fri, 17 Oct 2014 15:40:29 +0200 Subject: [PATCH 4/6] use ${CMAKE_BINARY_DIR} prefix for files generated by CMake so that files are created in build dir and source dir is never modified by building --- CMakeLists.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c133c311..5e9190d0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,10 +15,11 @@ check_dirs() set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules) -configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_SOURCE_DIR}/server/include/version.h) -configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_SOURCE_DIR}/maxscale.conf.prep @ONLY) -configure_file(${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.in ${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.prep @ONLY) -configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.prep @ONLY) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/server/include) +configure_file(${CMAKE_SOURCE_DIR}/server/include/version.h.in ${CMAKE_BINARY_DIR}/server/include/version.h) +configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf.prep @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/init.d/maxscale.in ${CMAKE_BINARY_DIR}/etc/init.d/maxscale.prep @ONLY) +configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_BINARY_DIR}/etc/ubuntu/init.d/maxscale.prep @ONLY) set(CMAKE_C_FLAGS "-Wall -fPIC") @@ -71,6 +72,7 @@ include_directories(query_classifier) include_directories(server/include) include_directories(server/inih) include_directories(server/modules/include) +include_directories(${CMAKE_BINARY_DIR}/server/include) add_subdirectory(utils) add_subdirectory(log_manager) @@ -82,11 +84,11 @@ add_subdirectory(client) # Install startup scripts and ldconfig files if( NOT ( (DEFINED INSTALL_SYSTEM_FILES) AND ( NOT ( INSTALL_SYSTEM_FILES ) ) ) ) - install(FILES maxscale.conf.prep RENAME maxscale.conf DESTINATION /etc/ld.so.conf.d/ PERMISSIONS WORLD_EXECUTE WORLD_READ) + install(FILES ${CMAKE_BINARY_DIR}/maxscale.conf.prep RENAME maxscale.conf DESTINATION /etc/ld.so.conf.d/ PERMISSIONS WORLD_EXECUTE WORLD_READ) if(DEB_BASED) - install(FILES etc/ubuntu/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/etc/ubuntu/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) else() - install(FILES etc/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) + install(FILES ${CMAKE_BINARY_DIR}/etc/init.d/maxscale.prep RENAME maxscale DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE) endif() message(STATUS "Installing maxscale.conf to: /etc/ld.so.conf.d") message(STATUS "Installing startup scripts to: /etc/init.d") @@ -148,4 +150,4 @@ add_custom_target(testall COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null" COMMAND /bin/sh -c "make test || echo \"Test results written to: ${CMAKE_BINARY_DIR}/Testing/Temporary/\"" COMMAND killall maxscale - COMMENT "Running full test suite..." VERBATIM) \ No newline at end of file + COMMENT "Running full test suite..." VERBATIM) From 0ca36e7b639e7cac0536802566b33589e18a4379 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Fri, 17 Oct 2014 16:41:02 +0200 Subject: [PATCH 5/6] added "make uninstall" target as described in http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F --- CMakeLists.txt | 10 ++++++++++ cmake_uninstall.cmake.in | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 cmake_uninstall.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e9190d0d..d58980f51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,3 +151,13 @@ add_custom_target(testall COMMAND /bin/sh -c "make test || echo \"Test results written to: ${CMAKE_BINARY_DIR}/Testing/Temporary/\"" COMMAND killall maxscale COMMENT "Running full test suite..." VERBATIM) + +# uninstall target +# see http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) \ No newline at end of file diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 000000000..7740ff850 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,24 @@ +# "make uninstall" helper +# see http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F + +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) From 319dd4b3e66c7390e5a9cda786092cd8ab0bebe0 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 20 Oct 2014 09:01:13 +0200 Subject: [PATCH 6/6] Fix for no db in change_user Fix for no db in change_user --- server/modules/protocol/mysql_common.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index c098263c2..7fa0b1967 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -1110,22 +1110,22 @@ int gw_send_change_user_to_backend( // add the user bytes += strlen(user); - // the NULL + // NULL byte for user string bytes++; // next will be + 1 (scramble_len) + 20 (fixed_scramble) + (dbname + NULL term) + 2 bytes charset - if (curr_passwd != NULL) { - bytes += GW_MYSQL_SCRAMBLE_SIZE; - bytes++; - } else { - bytes++; - } - - if (curr_db != NULL) { - bytes += strlen(curr_db); - bytes++; + if (curr_passwd != NULL) { + bytes += GW_MYSQL_SCRAMBLE_SIZE; } + // 1 byte for scramble_len + bytes++; + + if (curr_db != NULL) { + bytes += strlen(curr_db); + } + // NULL byte for dbname string + bytes++; // the charset bytes += 2;