diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..e21a14d5e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,141 @@ +cmake_minimum_required(VERSION 2.6) + +include(macros.cmake) + +enable_testing() +set_variables() +set_maxscale_version() + +set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories." FORCE) + +project(MaxScale) + +check_deps() +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) + + +set(CMAKE_C_FLAGS "-Wall -fPIC") +set(CMAKE_CXX_FLAGS "-Wall -fPIC") + +if(BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -pthread -pipe -DSS_DEBUG -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -pthread -pipe -DSS_DEBUG -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4") + message(STATUS "Generating debugging symbols") +elseif(BUILD_TYPE MATCHES Optimized) + if(NOT (DEFINED OLEVEL)) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") + message(STATUS "Optimization level at: 2") + endif() +else() + +endif() + +if(DEFINED OLEVEL ) + if((OLEVEL GREATER -1) AND (OLEVEL LESS 4) ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O${OLEVEL}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O${OLEVEL}") + message(STATUS "Optimization level at: ${OLEVEL}") + else() + message(WARNING "Optimization level was set to a bad value, ignoring it. (Valid values are 0-3)") + endif() +endif() + +if(GCOV) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") +endif() + + +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) +include_directories(server/include) +include_directories(server/inih) +include_directories(server/modules/include) + +add_subdirectory(utils) +add_subdirectory(log_manager) +add_subdirectory(query_classifier) +add_subdirectory(server) +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) + if(DEB_BASED) + install(FILES 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) + endif() + message(STATUS "Installing maxscale.conf to: /etc/ld.so.conf.d") + message(STATUS "Installing startup scripts to: /etc/init.d") +endif() + +file(GLOB DOCS Documentation/*.pdf) +message(STATUS "Installing MaxScale to: ${CMAKE_INSTALL_PREFIX}/") + +install(FILES server/MaxScale_template.cnf DESTINATION etc) +install(FILES ${ERRMSG} DESTINATION mysql) +install(FILES ${DOCS} DESTINATION Documentation) + +# See if we are on a RPM-capable or DEB-capable system +find_program(RPMBUILD rpmbuild) +find_program(DEBBUILD dpkg-buildpackage) + +if(NOT ( ${RPMBUILD} STREQUAL "RPMBUILD-NOTFOUND" ) ) + message(STATUS "Generating RPM packages") + set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM") +endif() + +if(NOT ( ${DEBBUILD} STREQUAL "DEBBUILD-NOTFOUND" ) ) + set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") + execute_process(COMMAND dpgk --print-architecture OUTPUT_VARIABLE DEB_ARCHITECTURE) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCHITECTURE}) + set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + message(STATUS "Generating DEB packages for ${DEB_ARCHITECTURE}") +endif() + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MaxScale") +set(CPACK_PACKAGE_VERSION_MAJOR "${MAXSCALE_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${MAXSCALE_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${MAXSCALE_VERSION_PATCH}") +set(CPACK_PACKAGE_CONTACT "MariaDB Corporation Ab") +set(CPACK_PACKAGE_FILE_NAME "maxscale-${MAXSCALE_VERSION}") +set(CPACK_PACKAGE_NAME "maxscale") +set(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") +set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/README) +set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +set(CPACK_RPM_SPEC_INSTALL_POST "/sbin/ldconfig") +set(CPACK_RPM_PACKAGE_NAME "maxscale") +set(CPACK_RPM_PACKAGE_VENDOR "MariaDB Corporation Ab") +set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/etc /etc/ld.so.conf.d /etc/init.d /etc/rc.d/init.d") +set(CPACK_RPM_SPEC_MORE_DEFINE "%define ignore \#") +set(CPACK_RPM_USER_FILELIST "%ignore /etc/init.d") +set(CPACK_RPM_USER_FILELIST "%ignore /etc/ld.so.conf.d") +set(CPACK_RPM_USER_FILELIST "%ignore /etc") +include(CPack) +add_custom_target(testall + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DINSTALL_DIR=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND make install + 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 diff --git a/COPYRIGHT b/COPYRIGHT index 47d6ca846..83c3e4f14 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,4 +1,4 @@ -This source code is distributed as part of SkySQL MaxScale. It is free +This source code is distributed as part of MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. @@ -12,9 +12,9 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -Copyright SkySQL Ab 2013 +Copyright MariaDB Corporation Ab 2013 -SkySQL Corporation Ab +MariaDB Corporation Corporation Ab Tekniikantie 12 02150 Espoo Finland diff --git a/Documentation/MaxScale 1.0.1beta Release Notes.pdf b/Documentation/MaxScale 1.0.1beta Release Notes.pdf new file mode 100644 index 000000000..7430fca50 Binary files /dev/null and b/Documentation/MaxScale 1.0.1beta Release Notes.pdf differ diff --git a/Documentation/MaxScale 1.0beta Release Notes.pdf b/Documentation/history/MaxScale 1.0beta Release Notes.pdf similarity index 100% rename from Documentation/MaxScale 1.0beta Release Notes.pdf rename to Documentation/history/MaxScale 1.0beta Release Notes.pdf diff --git a/Makefile b/Makefile index 63f92751f..aee79e163 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description @@ -57,7 +57,7 @@ depend: install: (cd server; make DEST=$(DEST) install) (cd log_manager; make DEST=$(DEST) install) - (cd query_classifier; make DEST=$(DEST) install) + (cd query_classifier;touch depend; make DEST=$(DEST) install) (cd client; make DEST=$(DEST) install) cleantests: diff --git a/README b/README index cdc9b35ac..eeb103c1d 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ -/** \mainpage MaxScale by SkySQL +/** \mainpage MaxScale by MariaDB Corporation -The SkySQL MaxScale is an intelligent proxy that allows forwarding of +The MariaDB Corporation MaxScale is an intelligent proxy that allows forwarding of database statements to one or more database servers using complex rules, a semantic understanding of the database statements and the roles of the various servers within the backend cluster of databases. @@ -28,7 +28,7 @@ issues and communicate with the MaxScale community. Send email to [maxscale@googlegroups.com](mailto:maxscale@googlegroups.com) or use the [forum](http://groups.google.com/forum/#!forum/maxscale) interface -Bugs can be reported in the SkySQL bugs database +Bugs can be reported in the MariaDB Corporation bugs database [bug.skysql.com](http://bugs.skysql.com) \section Building Building MaxScale @@ -59,6 +59,10 @@ to the --relocate option. rpm -i --force --relocate=/usr/=$PREFIX/usr/ MariaDB-5.5.34-centos6-x86_64-common.rpm MariaDB-5.5.34-centos6-x86_64-compat.rpm MariaDB-5.5.34-centos6-x86_64-devel.rpm +You can also use the included 'unpack_rpm.sh' script to unpack the RPMs without installing them. + + ./unpack_rpm + This README assumes $PREFIX = $HOME. MaxScale may be built with the embedded MariaDB library either linked @@ -152,6 +156,71 @@ max_connections=4096 Please check errmsg.sys is found in the MaxScale install_dir DEST/MaxScale/mysql +\section Building Building MaxScale with CMake + +You can also build MaxScale with CMake which makes the build process a bit more simple. + +All the same dependencies are required as with the normal MaxScale build with the addition of CMake +version 2.6 for regular builds and 2.8.12 or newer if you wish to generate packages. + +CMake tries to find all the required directories and files on its own but if it can't find them or you wish to +explicitly state the locations you can pass additional options to CMake by using the -D flag. To confirm the variable +values, you can run CMake in interactive mode by using the -i flag or use a CMake GUI (for example, ccmake for command line). + +It is highly recommended to make a separate build directory to build into. This keeps the source and build trees clean and +makes it easy to get rid of everything you built by simply deleting the build directory. + +To build MaxScale using CMake: + + cd + + mkdir build + + cd build + + cmake .. + + make + + make install + +This generates the required makefiles in the current directory, compiles and links all the programs and installs +all the required files in their right places. + +If you have your headers and libraries in non-standard locations, you can define those locations at configuration time as such: + + cmake -D= + +By default, MaxScale installs to '/usr/local/skysql/maxscale' and places init.d scripts and ldconfig files into their folders. Change the INSTALL_DIR +variable to your desired installation directory and set INSTALL_SYSTEM_FILES=N to prevent the init.d script and ldconfig file installation. + +If you run into any trouble while configuring CMake, you can always remove the 'CMakeCache.txt' file to clear CMake's +internal cache. This resets all values to their defaults and can be used to fix a 'stuck' configuration of CMake. This +is also a good reason why you should always build into a separate directory, because you can safely wipe the build directory clean without the +danger of deleting important files when something goes wrong. + +The default values that CMake uses can be found in the 'macros.cmake' file. If you wish to change these, edit the 'macros.cmake' file +or define the variables manually at configuration time. + +All the variables that control the CMake build process: + +INSTALL_DIR= Installation directory +BUILD_TYPE=[None|Debug|Release] Type of the build, defaults to Release (optimized) +INSTALL_SYSTEM_FILES=[Y|N] Install startup scripts and ld configuration files +EMBEDDED_LIB= Path to the embedded library location (libmysqld.a for static and libmysqld.so for dynamic) +MYSQL_DIR= Path to MySQL headers +ERRMSG= Path to errmsg.sys file +STATIC_EMBEDDED=[Y|N] Whether to link the static or the dynamic verson of the library +GCOV=[Y|N] Generate gcov output +OLEVEL=<0-3> Level of optimization +BUILD_TESTS=[Y|N] Build tests +DEPS_OK=[Y|N] Check dependencies, use N when you want to force a recheck of values +DEBUG_OUTPUT=[Y|N] Produce debugging output when configuring CMake +RABBITMQ_LIB= Path to RabbitMQ-C libraries +RABBITMQ_HEADERS= Path to RabbitMQ-C headers +MYSQL_CLIENT_LIB= Path to MySQL client libraries +MYSQL_CLIENT_HEADERS= Path to MySQL client headers + \section Running Running MaxScale MaxScale consists of a core executable and a number of modules that implement diff --git a/VERSION b/VERSION index 896b9bc9d..1f6191473 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0-beta +1.0.1-beta diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 000000000..c284931b2 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(maxadmin maxadmin.c) +find_library(HIST edit) +if(HIST) + add_definitions(-DHISTORY) + target_link_libraries(maxadmin ${HIST}) +endif() +install(TARGETS maxadmin DESTINATION bin) \ No newline at end of file diff --git a/client/Makefile b/client/Makefile index 22220db2d..e97cc878b 100644 --- a/client/Makefile +++ b/client/Makefile @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2014 +# Copyright MariaDB Corporation Ab 2014 # # Revision History # Date Who Description diff --git a/client/maxadmin.c b/client/maxadmin.c index dfb4dcfb5..45e010bb3 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -273,7 +273,10 @@ char c; } else if (*buf) { - sendCommand(so, buf); + if (!sendCommand(so, buf)) + { + return 0; + } } } @@ -298,6 +301,7 @@ connectMaxScale(char *hostname, char *port) { struct sockaddr_in addr; int so; +int keepalive = 1; if ((so = socket(AF_INET, SOCK_STREAM, 0)) < 0) { @@ -315,6 +319,9 @@ int so; hostname, port, strerror(errno)); return -1; } + if (setsockopt(so, SOL_SOCKET, + SO_KEEPALIVE, &keepalive , sizeof(keepalive ))) + perror("setsockopt"); return so; } @@ -387,11 +394,14 @@ authMaxScale(int so, char *user, char *password) { char buf[20]; - read(so, buf, 4); + if (read(so, buf, 4) != 4) + return 0; write(so, user, strlen(user)); - read(so, buf, 8); + if (read(so, buf, 8) != 8) + return 0; write(so, password, strlen(password)); - read(so, buf, 6); + if (read(so, buf, 6) != 6) + return 0; return strncmp(buf, "FAILED", 6); } @@ -412,10 +422,11 @@ sendCommand(int so, char *cmd) char buf[80]; int i, j, newline = 1; - write(so, cmd, strlen(cmd)); + if (write(so, cmd, strlen(cmd)) == -1) + return 0; while (1) { - if ((i = read(so, buf, 80)) == -1) + if ((i = read(so, buf, 80)) <= 0) return 0; for (j = 0; j < i; j++) { diff --git a/client/test/maxadmin_stress.sh b/client/test/maxadmin_stress.sh new file mode 100644 index 000000000..8d495dd4c --- /dev/null +++ b/client/test/maxadmin_stress.sh @@ -0,0 +1,53 @@ +#!/bin/sh +failure=0 +passed=0 + +clients=20 +cmdcnt=1000 + +echo Running $clients parallel iterations of $cmdcnt commands + +for ((cnt=0; cnt<$clients; cnt++ )); do + for ((i=0; i<$cmdcnt; i++ )); do + maxadmin -pskysql show services; + done >/dev/null & +done >& /dev/null + +peak=0 +while [ "`jobs -p`" != "" ]; do + jobs >& /dev/null + zombies=`maxadmin -pskysql list dcbs | grep -ci zombies` + if [ $zombies -gt $peak ] ; then + peak=$zombies + fi + sleep 1 +done +if [ $peak -gt 10 ]; then + echo "High peak zombie count ($peak): Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Zombie collection ($peak): Passed" +fi +zombies=`maxadmin -pskysql list dcbs | grep -ci zombies` +if [ $zombies != "0" ]; then + echo "Residual zombie DCBs: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Residual zombie DCBs: Passed" +fi +sessions=`maxadmin -pskysql list services | awk -F\| '/ cli/ { print $3 }'` +if [ $sessions -gt 3 ]; then + echo "Session shutdown, $sessions: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Session shutdown: Passed" +fi + +sessions=`maxadmin -pskysql list services | awk -F\| '/ cli/ { print $4 }'` + +echo "Test run complete. $passed passes, $failure failures" +echo "$sessions CLI sessions executed" +exit $failure diff --git a/client/test/maxadmin_test.sh b/client/test/maxadmin_test.sh new file mode 100644 index 000000000..b04312da4 --- /dev/null +++ b/client/test/maxadmin_test.sh @@ -0,0 +1,210 @@ +#!/bin/sh +failure=0 +passed=0 +maxadmin -pskysql help >& /dev/null +if [ $? -eq "1" ]; then + echo "Auth test (correct password): Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Auth test (correct password): Passed" +fi +maxadmin -pwrongpasswd help >& /dev/null +if [ $? -eq "0" ]; then + echo "Auth test (wrong password): Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Auth test (wrong password): Passed" +fi +maxadmin --password=skysql help >& /dev/null +if [ $? -eq "1" ]; then + echo "Auth test (long option): Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Auth test (long option): Passed" +fi + +maxadmin -pskysql enable log debug >& /dev/null +if [ $? -eq "1" ]; then + echo "Enable debug log: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Enable debug log: Passed" +fi + +maxadmin -pskysql enable log trace >& /dev/null +if [ $? -eq "1" ]; then + echo "Enable trace log: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Enable trace log: Passed" +fi + +maxadmin -pskysql disable log debug >& /dev/null +if [ $? -eq "1" ]; then + echo "Disable debug log: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Disable debug log: Passed" +fi + +maxadmin -pskysql disable log trace >& /dev/null +if [ $? -eq "1" ]; then + echo "Disable trace log: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Disable trace log: Passed" +fi + +for cmd in clients dcbs filters listeners modules monitors services servers sessions threads +do + maxadmin -pskysql list $cmd | grep -s '-' >& /dev/null + if [ $? -eq "1" ]; then + echo "list command ($cmd): Failed" + failure=`expr $failure + 1` + else + passed=`expr $passed + 1` + echo "list command ($cmd): Passed" + fi +done + +for cmd in dcbs dbusers epoll filters modules monitors services servers sessions threads users +do + maxadmin -pskysql show $cmd | grep -s ' ' >& /dev/null + if [ $? -eq "1" ]; then + echo "show command ($cmd): Failed" + failure=`expr $failure + 1` + else + passed=`expr $passed + 1` + echo "show command ($cmd): Passed" + fi +done + +master=`maxadmin -pskysql list servers | awk '/Master/ { print $1; }'` +if [ $? -eq "1" ]; then + echo "Extract master server: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Extract master server: Passed" +fi +if [ "$master" = "" ]; then + echo "Get master server: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Get master server: Passed" +fi +maxadmin -pskysql show server $master | grep -s 'Master' >& /dev/null +if [ $? -eq "1" ]; then + echo "show server master: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "show server master: Passed" +fi + +maxadmin -pskysql set server $master maint >& /dev/null +if [ $? -eq "1" ]; then + echo "set server: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "set server: Passed" +fi +maxadmin -pskysql list servers | grep $master | grep -s Maint >& /dev/null +if [ $? -eq "1" ]; then + echo "set maintenance mode: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "set maintenance mode: Passed" +fi +maxadmin -pskysql clear server $master maint >& /dev/null +if [ $? -eq "1" ]; then + echo "clear server: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "clear server: Passed" +fi +maxadmin -pskysql list servers | grep $master | grep -s Maint >& /dev/null +if [ $? -eq "0" ]; then + echo "clear maintenance mode: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "clear maintenance mode: Passed" +fi + +dcbs=`maxadmin -pskysql list dcbs | awk -F\| '/listening/ { if ( NF > 1 ) print $1 }'` +if [ $? -eq "1" ]; then + echo "Get dcb listeners: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Get dcb listeners: Passed" +fi + +for i in $dcbs +do + maxadmin -pskysql show dcb $i | grep -s 'listening' >& /dev/null + if [ $? -eq "1" ]; then + echo "show dcb listeners: Failed" + failure=`expr $failure + 1` + else + passed=`expr $passed + 1` + echo "show dcb listeners: Passed" + fi +done + +sessions=`maxadmin -pskysql list sessions | awk -F\| '/Listener/ { if ( NF > 1 ) print $1 }'` +if [ $? -eq "1" ]; then + echo "Get listener sessions: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Get listener sessions: Passed" +fi + +for i in $sessions +do + maxadmin -pskysql show session $i | grep -s 'Listener' >& /dev/null + if [ $? -eq "1" ]; then + echo "show session listeners: Failed" + failure=`expr $failure + 1` + else + passed=`expr $passed + 1` + echo "show session listeners: Passed" + fi +done + +filters=`maxadmin -pskysql list filters | awk -F\| '{ if ( NF > 1 ) print $1 }'| grep -v Options` +if [ $? -eq "1" ]; then + echo "Get Filter list: Failed" + failure=`expr $failure + 1` +else + passed=`expr $passed + 1` + echo "Get filter list: Passed" +fi + +for i in $filters +do + maxadmin -pskysql show filter $i | grep -s 'Filter' >& /dev/null + if [ $? -eq "1" ]; then + echo "show filter: Failed" + failure=`expr $failure + 1` + else + passed=`expr $passed + 1` + echo "show filter: Passed" + fi +done + +echo "Test run complete. $passed passes, $failure failures" +exit $failure diff --git a/debian/control b/debian/control index be0a062ec..cb85e28ea 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Package: maxscale Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: MaxScale - The SkySQL MaxScale is an intelligent proxy that allows forwarding of + The MariaDB Corporation MaxScale is an intelligent proxy that allows forwarding of database statements to one or more database servers using complex rules, a semantic understanding of the database statements and the roles of the various servers within the backend cluster of databases. diff --git a/etc/init.d/maxscale b/etc/init.d/maxscale index dde616fb3..40f368326 100755 --- a/etc/init.d/maxscale +++ b/etc/init.d/maxscale @@ -1,6 +1,6 @@ #!/bin/sh # -# maxscale: The SkySQL MaxScale database proxy +# maxscale: The MariaDB Corporation MaxScale database proxy # # description: MaxScale provides database specific proxy functionality # diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in new file mode 100755 index 000000000..00c9777aa --- /dev/null +++ b/etc/init.d/maxscale.in @@ -0,0 +1,157 @@ +#!/bin/sh +# +# maxscale: The MariaDB Corporation MaxScale database proxy +# +# description: MaxScale provides database specific proxy functionality +# +# processname: maxscale +# +### BEGIN INIT INFO +# Provides: maxscale +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: The maxscale database proxy +# Description: MaxScale is a database proxy server that can be used to front end +# database clusters offering different routing, filtering and protocol choices +### END INIT INFO + +############################################# +# MaxScale HOME, PIDFILE, LIB +############################################# + +export MAXSCALE_HOME=@INSTALL_DIR@ +export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib + +############################### +# LSB Exit codes (non-Status) +############################### +_RETVAL_GENERIC=1 +_RETVAL_NOT_INSTALLED=5 +_RETVAL_NOT_RUNNING=7 + +############################### +# LSB Status action Exit codes +############################### +_RETVAL_STATUS_OK=0 +_RETVAL_STATUS_NOT_RUNNING=3 + +# Sanity checks. +[ -x $MAXSCALE_HOME/bin/maxscale ] || exit $_RETVAL_NOT_INSTALLED + +# Source function library. +. /etc/rc.d/init.d/functions + +# we can rearrange this easily +processname=maxscale +servicename=maxscale + +RETVAL=0 + +start() { + echo -n $"Starting MaxScale: " + my_check=`status -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale` + CHECK_RET=$? + [ $CHECK_RET -eq 0 ] && echo -n " found $my_check" && success && CHECK_RET=0 + + daemon --pidfile $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale >& /dev/null + + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename + + if [ $CHECK_RET -ne 0 ]; then + sleep 2 + my_check=`status -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale` + CHECK_RET=$? + [ $CHECK_RET -eq 0 ] && echo -n $my_check && success || failure + fi + + # Return rigth code + if [ $RETVAL -ne 0 ]; then + failure + RETVAL=$_RETVAL_NOT_RUNNING + fi + + echo + + return $RETVAL +} + +stop() { + echo -n $"Stopping MaxScale: " + killproc -p $MAXSCALE_PIDFILE -TERM + + RETVAL=$? + + echo + + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$servicename + + # Return rigth code + if [ $RETVAL -ne 0 ]; then + RETVAL=$_RETVAL_NOT_RUNNING + fi + + return $RETVAL +} + +reload() { + echo -n $"Reloading MaxScale: " + + killproc -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale -HUP + RETVAL=$? + echo +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + # return 0 on success + # return 3 on any error + + echo -n $"Checking MaxScale status: " + status -p $MAXSCALE_PIDFILE 'MaxScale' + RETVAL=$? + + if [ $RETVAL -ne 0 ]; then + echo -ne "\033[1A" + [ $RETVAL -eq 1 ] && warning || failure + echo -ne "\033[1B" + + RETVAL=$_RETVAL_STATUS_NOT_RUNNING + else + echo -ne "\033[1A" + success + echo -ne "\033[1B" + RETVAL=$_RETVAL_STATUS_OK + fi + + exit $RETVAL + ;; + restart) + stop + start + ;; + condrestart) + if [ -f /var/lock/subsys/$servicename ]; then + stop + start + fi + ;; + reload) + reload + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}" + ;; +esac +exit $RETVAL diff --git a/etc/ubuntu/init.d/maxscale b/etc/ubuntu/init.d/maxscale index c81ffb475..82bc05632 100755 --- a/etc/ubuntu/init.d/maxscale +++ b/etc/ubuntu/init.d/maxscale @@ -1,6 +1,6 @@ #!/bin/sh # -# maxscale: The SkySQL MaxScale database proxy +# maxscale: The MariaDB Corporation MaxScale database proxy # # description: MaxScale provides database specific proxy functionality # diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in new file mode 100644 index 000000000..3610b8fd9 --- /dev/null +++ b/etc/ubuntu/init.d/maxscale.in @@ -0,0 +1,145 @@ +#!/bin/sh +# +# maxscale: The MariaDB Corporation MaxScale database proxy +# +# description: MaxScale provides database specific proxy functionality +# +# processname: maxscale +# +### BEGIN INIT INFO +# Provides: maxscale +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: The maxscale database proxy +# Description: MaxScale is a database proxy server that can be used to front end +# database clusters offering different routing, filtering and protocol choices +### END INIT INFO + +############################################# +# MaxScale HOME, PIDFILE, LIB +############################################# + +export MAXSCALE_HOME=@INSTALL_DIR@ +export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib + +############################### +# LSB Exit codes (non-Status) +############################### +_RETVAL_GENERIC=1 +_RETVAL_NOT_INSTALLED=5 +_RETVAL_NOT_RUNNING=7 + +############################### +# LSB Status action Exit codes +############################### +_RETVAL_STATUS_OK=0 +_RETVAL_STATUS_NOT_RUNNING=3 + +# Sanity checks. +[ -x $MAXSCALE_HOME/bin/maxscale ] || exit $_RETVAL_NOT_INSTALLED + +################################# +# stop/start/status related vars +################################# +NAME=maxscale +DAEMON=$MAXSCALE_HOME/bin/maxscale + +# Source function library. +. /lib/lsb/init-functions + +# we can rearrange this easily +processname=maxscale +servicename=maxscale + +RETVAL=0 + +start() { + log_daemon_msg "Starting MaxScale" + start_daemon -p $MAXSCALE_PIDFILE $DAEMON 2> /dev/null + + sleep 2 + + status_of_proc -p $MAXSCALE_PIDFILE $DAEMON $NAME + + log_end_msg $? +} + +stop() { + log_daemon_msg "Stopping MaxScale" + killproc -p $PIDFILE $DAEMON 2>&1 /dev/null + + maxscale_wait_stop + + log_end_msg $? +} + +reload() { + log_daemon_msg "Reloading MaxScale" + + killproc -p $MAXSCALE_PIDFILE $DAEMON 1 + + log_end_msg $? +} + +maxscale_wait_stop() { + PIDTMP=$(pidofproc -p $MAXSCALE_PIDFILE $MAXSCALE_HOME/bin/maxscale) + kill -TERM "${PIDTMP:-}" 2> /dev/null; + if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then + local i=0 + while kill -0 "${PIDTMP:-}" 2> /dev/null; do + if [ $i = '60' ]; then + break + STATUS=2 + fi + [ "$VERBOSE" != no ] && log_progress_msg "." + sleep 1 + i=$(($i+1)) + done + return $STATUS + else + return $STATUS + fi +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + # return 0 on success + # return 3 on any error + + log_daemon_msg "Checking MaxScale" + status_of_proc -p $MAXSCALE_PIDFILE $DAEMON $NAME + RETVAL=$? + + if [ $RETVAL -ne 0 ]; then + [ $RETVAL -eq 1 ] + + RETVAL=$_RETVAL_STATUS_NOT_RUNNING + else + RETVAL=$_RETVAL_STATUS_OK + fi + + log_end_msg $RETVAL + ;; + restart) + stop + start + ;; + reload) + reload + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload}" + ;; +esac +exit $RETVAL diff --git a/log_manager/CMakeLists.txt b/log_manager/CMakeLists.txt new file mode 100644 index 000000000..1cbe6cd87 --- /dev/null +++ b/log_manager/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(log_manager SHARED log_manager.cc) +target_link_libraries(log_manager pthread aio stdc++) +install(TARGETS log_manager DESTINATION lib) +if(BUILD_TESTS) + add_subdirectory(test) +endif() \ No newline at end of file diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 2b274a610..f690661b6 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include @@ -75,7 +75,7 @@ int lm_enabled_logfiles_bitmask = 0; * Path to directory in which all files are stored to shared memory * by the OS. */ -const char* shm_pathname = "/dev/shm"; +const char* shm_pathname_prefix = "/dev/shm/"; /** Logfile ids from call argument '-s' */ char* shmem_id_str = NULL; @@ -404,7 +404,7 @@ return_succp: /** - * @node Initializes log managing routines in SkySQL Gateway. + * @node Initializes log managing routines in MariaDB Corporation MaxScale. * * Parameters: * @param p_ctx - in, give @@ -755,7 +755,12 @@ static int logmanager_write_log( break; } } - wp[safe_str_len-1] = '\n'; + /** remove double line feed */ + if (wp[safe_str_len-2] == '\n') + { + wp[safe_str_len-2]=' '; + } + wp[safe_str_len-1] = '\n'; blockbuf_unregister(bb); /** @@ -2063,11 +2068,34 @@ static bool logfile_init( * pointing to shm file is created and located to the file * directory. */ - if (store_shmem) { - logfile->lf_filepath = strdup(shm_pathname); + if (store_shmem) + { + char* c; + pid_t pid = getpid(); + int len = strlen(shm_pathname_prefix)+ + get_decimal_len((size_t)pid); + + c = (char *)calloc(len, sizeof(char)); + + if (c == NULL) + { + succp = false; + goto file_create_fail; + } + sprintf(c, "%s%d", shm_pathname_prefix, pid); + logfile->lf_filepath = c; + + if (mkdir(c, S_IRWXU | S_IRWXG) != 0 && + errno != EEXIST) + { + succp = false; + goto file_create_fail; + } logfile->lf_linkpath = strdup(fn->fn_logpath); logfile->lf_linkpath = add_slash(logfile->lf_linkpath); - } else { + } + else + { logfile->lf_filepath = strdup(fn->fn_logpath); } logfile->lf_filepath = add_slash(logfile->lf_filepath); @@ -2146,7 +2174,7 @@ static bool logfile_init( } } } - file_create_fail: +file_create_fail: if (namecreatefail || nameconflicts) { logfile->lf_name_seqno += 1; @@ -2161,7 +2189,7 @@ static bool logfile_init( free(logfile->lf_full_link_name); logfile->lf_full_link_name = NULL; } - + goto return_with_succp; } } while (namecreatefail || nameconflicts); /** diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 6a4c1d6cc..c6d207702 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ diff --git a/log_manager/test/CMakeLists.txt b/log_manager/test/CMakeLists.txt new file mode 100644 index 000000000..d3a22939e --- /dev/null +++ b/log_manager/test/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(testlog testlog.c) +add_executable(testorder testorder.c) +target_link_libraries(testlog pthread log_manager utils) +target_link_libraries(testorder pthread log_manager utils) +add_test(NAME TestLogOrder COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/logorder.sh ${CMAKE_CURRENT_BINARY_DIR}/test.log 500 0 500 ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file diff --git a/log_manager/test/logorder.sh b/log_manager/test/logorder.sh index bbdcaf0f7..49ca43c83 100755 --- a/log_manager/test/logorder.sh +++ b/log_manager/test/logorder.sh @@ -2,24 +2,33 @@ if [[ $# -lt 4 ]] then - echo "Usage: logorder.sh " + echo "Usage: logorder.sh " echo "To disable log flushing, use 0 for flush frequency" exit fi rm *.log +if [ $# -eq 5 ] +then + TDIR=$5 +else + TDIR=$PWD +fi + #Create large messages -$PWD/testorder $1 $2 $3 + +$TDIR/testorder $1 $2 $3 TESTLOG=$4 MCOUNT=$1 -BLOCKS=`cat skygw_err1.log |tr -s ' '|grep -o 'block:[[:digit:]]\+'|cut -d ':' -f 2` -MESSAGES=`cat skygw_err1.log |tr -s ' '|grep -o 'message|[[:digit:]]\+'|cut -d '|' -f 2` +BLOCKS=`cat $TDIR/skygw_err1.log |tr -s ' '|grep -o 'block:[[:digit:]]\+'|cut -d ':' -f 2` +MESSAGES=`cat $TDIR/skygw_err1.log |tr -s ' '|grep -o 'message|[[:digit:]]\+'|cut -d '|' -f 2` prev=0 error=0 +all_errors=0 for i in $BLOCKS do @@ -27,6 +36,7 @@ do if [[ $i -le $prev ]] then error=1 + all_errors=1 echo "block mismatch: $i was after $prev." >> $TESTLOG fi prev=$i @@ -48,6 +58,7 @@ do if [[ $i -ne $(( prev + 1 )) ]] then error=1 + all_errors=1 echo "message mismatch: $i was after $prev." >> $TESTLOG fi prev=$i @@ -59,3 +70,9 @@ then else echo "Error: block buffer messages were written in the wrong order" >> $TESTLOG fi + +if [ $# -eq 5 ] +then + cat $TESTLOG + exit $all_errors +fi diff --git a/log_manager/test/testlog.c b/log_manager/test/testlog.c index c21d30e17..797af4d07 100644 --- a/log_manager/test/testlog.c +++ b/log_manager/test/testlog.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ diff --git a/log_manager/test/testorder.c b/log_manager/test/testorder.c index e2bb94a7b..4dbad0833 100644 --- a/log_manager/test/testorder.c +++ b/log_manager/test/testorder.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/macros.cmake b/macros.cmake new file mode 100644 index 000000000..cc29a5e09 --- /dev/null +++ b/macros.cmake @@ -0,0 +1,227 @@ +macro(set_maxscale_version) + + #MaxScale version number + set(MAXSCALE_VERSION_MAJOR "1") + set(MAXSCALE_VERSION_MINOR "0") + set(MAXSCALE_VERSION_PATCH "1") + set(MAXSCALE_VERSION_NUMERIC "${MAXSCALE_VERSION_MAJOR}.${MAXSCALE_VERSION_MINOR}.${MAXSCALE_VERSION_PATCH}") + set(MAXSCALE_VERSION "${MAXSCALE_VERSION_MAJOR}.${MAXSCALE_VERSION_MINOR}.${MAXSCALE_VERSION_PATCH}-beta") + +endmacro() + +macro(set_variables) + + # Installation directory + set(INSTALL_DIR "/usr/local/skysql/maxscale/" CACHE PATH "MaxScale installation directory.") + + # Build type + set(BUILD_TYPE "None" CACHE STRING "Build type, possible values are:None, Debug, Optimized.") + + # hostname or IP address of MaxScale's host + set(TEST_HOST "127.0.0.1" CACHE STRING "hostname or IP address of MaxScale's host") + + # port of read connection router module + set(TEST_PORT_RW "4008" CACHE STRING "port of read connection router module") + + # port of read/write split router module + set(TEST_PORT_RW "4006" CACHE STRING "port of read/write split router module") + + # port of read/write split router module with hints + set(TEST_PORT_RW_HINT "4006" CACHE STRING "port of read/write split router module with hints") + + # master test server server_id + set(TEST_MASTER_ID "3000" CACHE STRING "master test server server_id") + + # username of MaxScale user + set(TEST_USER "maxuser" CACHE STRING "username of MaxScale user") + + # password of MaxScale user + set(TEST_PASSWORD "maxpwd" CACHE STRING "password of MaxScale user") + + # Use static version of libmysqld + set(STATIC_EMBEDDED TRUE CACHE BOOL "Use static version of libmysqld") + + # Build RabbitMQ components + set(BUILD_RABBITMQ FALSE CACHE BOOL "Build RabbitMQ components") + + # Use gcov build flags + set(GCOV FALSE CACHE BOOL "Use gcov build flags") + + # Install init.d scripts and ldconf configuration files + set(INSTALL_SYSTEM_FILES TRUE CACHE BOOL "Install init.d scripts and ldconf configuration files") + + # Build tests + set(BUILD_TESTS FALSE CACHE BOOL "Build tests") + +endmacro() + +macro(check_deps) + + # Check for libraries MaxScale depends on + set(MAXSCALE_DEPS aio ssl crypt crypto z m dl rt pthread) + foreach(lib ${MAXSCALE_DEPS}) + find_library(lib${lib} ${lib}) + if((DEFINED lib${lib}) AND (${lib${lib}} STREQUAL "lib${lib}-NOTFOUND")) + set(DEPS_ERROR TRUE) + set(FAILED_DEPS "${FAILED_DEPS} lib${lib}") + elseif(DEBUG_OUTPUT) + message(STATUS "Library was found at: ${lib${lib}}") + endif() + endforeach() + + if(DEPS_ERROR) + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find dependencies: ${FAILED_DEPS}") + endif() + +endmacro() + +macro(check_dirs) + + # This variable is used to prevent redundant checking of dependencies + set(DEPS_OK TRUE CACHE BOOL "If all the dependencies were found.") + + # Find the MySQL headers if they were not defined + if(DEFINED MYSQL_DIR) + if(DEBUG_OUTPUT) + message(STATUS "Searching for MySQL headers at: ${MYSQL_DIR}") + endif() + find_path(MYSQL_DIR_LOC mysql.h PATHS ${MYSQL_DIR} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) + endif() + find_path(MYSQL_DIR_LOC mysql.h PATH_SUFFIXES mysql mariadb) + if(DEBUG_OUTPUT) + message(STATUS "Search returned: ${MYSQL_DIR_LOC}") + endif() + if(${MYSQL_DIR_LOC} STREQUAL "MYSQL_DIR_LOC-NOTFOUND") + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Fatal Error: MySQL headers were not found.") + else() + message(STATUS "Using MySQL headers found at: ${MYSQL_DIR}") + set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE) + endif() + set(MYSQL_DIR_LOC "" INTERNAL) + + # Find the errmsg.sys file if it was not defied + if( DEFINED ERRMSG ) + find_file(ERRMSG_FILE errmsg.sys PATHS ${ERRMSG} NO_DEFAULT_PATH) + endif() + find_file(ERRMSG_FILE errmsg.sys PATHS /usr/share/mysql /usr/local/share/mysql PATH_SUFFIXES english) + if(${ERRMSG_FILE} MATCHES "ERRMSG_FILE-NOTFOUND") + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Fatal Error: The errmsg.sys file was not found, please define the path to it by using -DERRMSG=") + else() + message(STATUS "Using errmsg.sys found at: ${ERRMSG_FILE}") + endif() + set(ERRMSG ${ERRMSG_FILE} CACHE FILEPATH "Path to the errmsg.sys file." FORCE) + set(ERRMSG_FILE "" INTERNAL) + + # Find the embedded mysql library + if(STATIC_EMBEDDED) + + set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + if (DEFINED EMBEDDED_LIB) + if(DEBUG_OUTPUT) + message(STATUS "Searching for libmysqld.a at: ${EMBEDDED_LIB}") + endif() + find_library(EMBEDDED_LIB_STATIC libmysqld.a PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) + else() + find_library(EMBEDDED_LIB_STATIC libmysqld.a PATH_SUFFIXES mysql mariadb) + endif() + if(DEBUG_OUTPUT) + message(STATUS "Search returned: ${EMBEDDED_LIB_STATIC}") + endif() + set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) + set(OLD_SUFFIXES "" INTERNAL) + + else() + if (DEFINED EMBEDDED_LIB) + if(DEBUG_OUTPUT) + message(STATUS "Searching for libmysqld.so at: ${EMBEDDED_LIB}") + endif() + find_library(EMBEDDED_LIB_DYNAMIC mysqld PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) + else() + find_library(EMBEDDED_LIB_DYNAMIC mysqld PATH_SUFFIXES mysql mariadb) + endif() + if(DEBUG_OUTPUT) + message(STATUS "Search returned: ${EMBEDDED_LIB_DYNAMIC}") + endif() + set(EMBEDDED_LIB ${EMBEDDED_LIB_DYNAMIC} CACHE FILEPATH "Path to libmysqld" FORCE) + + endif() + set(EMBEDDED_LIB_DYNAMIC "" INTERNAL) + set(EMBEDDED_LIB_STATIC "" INTERNAL) + + # Inform the user about the embedded library + if( (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_STATIC-NOTFOUND") OR (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_DYNAMIC-NOTFOUND")) + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Library not found: libmysqld. If your install of MySQL is in a non-default location, please provide the location with -DEMBEDDED_LIB=") + else() + get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH) + message(STATUS "Using embedded library: ${EMBEDDED_LIB}") + endif() + + + # Check which init.d script to install + find_file(RPM_FNC functions PATHS /etc/rc.d/init.d) + if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND") + find_file(DEB_FNC init-functions PATHS /lib/lsb) + if(${DEB_FNC} MATCHES "DEB_FNC-NOTFOUND") + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find required init-functions in /lib/lsb/ or /etc/rc.d/init.d/, please confirm that your system files are OK.") + else() + set(DEB_BASED TRUE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.") + endif() + else() + set(DEB_BASED FALSE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.") + endif() + set(DEB_FNC "" INTERNAL) + set(RPM_FNC "" INTERNAL) + + #Check RabbitMQ headers and libraries + if(BUILD_RABBITMQ) + + if(DEFINED RABBITMQ_LIB) + find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH) + endif() + find_library(RMQ_LIB rabbitmq) + if(RMQ_LIB STREQUAL "RMQ_LIB-NOTFOUND") + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=") + else() + set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE) + message(STATUS "Using RabbitMQ libraries found at: ${RABBITMQ_LIB}") + endif() + + if(DEFINED RABBITMQ_HEADERS) + find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH) + endif() + find_file(RMQ_HEADERS amqp.h) + if(RMQ_HEADERS STREQUAL "RMQ_HEADERS-NOTFOUND") + set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=") + else() + set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE) + message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}") + endif() + + endif() + +endmacro() + +function(subdirs VAR DIRPATH) + +if(${CMAKE_VERSION} VERSION_LESS 2.12 ) +set(COMP_VAR PATH) +else() +set(COMP_VAR DIRECTORY) +endif() + file(GLOB_RECURSE SDIR ${DIRPATH}/*) + foreach(LOOP ${SDIR}) + get_filename_component(LOOP ${LOOP} ${COMP_VAR}) + list(APPEND ALLDIRS ${LOOP}) + endforeach() + list(REMOVE_DUPLICATES ALLDIRS) + set(${VAR} "${ALLDIRS}" CACHE PATH " " FORCE) +endfunction() \ No newline at end of file diff --git a/maxscale.conf.in b/maxscale.conf.in new file mode 100644 index 000000000..0283479f1 --- /dev/null +++ b/maxscale.conf.in @@ -0,0 +1,2 @@ +@INSTALL_DIR@/modules +@INSTALL_DIR@/lib diff --git a/query_classifier/CMakeLists.txt b/query_classifier/CMakeLists.txt new file mode 100644 index 000000000..42270cd2c --- /dev/null +++ b/query_classifier/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(query_classifier SHARED query_classifier.cc) +install(TARGETS query_classifier DESTINATION lib) +if(BUILD_TESTS) + add_subdirectory(test) +endif() diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index f034d770f..6eea51cdb 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -1,7 +1,7 @@ /** * @section LICENCE * - * This file is distributed as part of the SkySQL Gateway. It is + * This file is distributed as part of the MariaDB Corporation MaxScale. It is * free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the * Free Software Foundation, version 2. @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * - * Copyright SkySQL Ab + * Copyright MariaDB Corporation Ab * * @file * @@ -359,17 +359,37 @@ static bool create_parse_tree( Parser_state parser_state; bool failp = FALSE; const char* virtual_db = "skygw_virtual"; - +#if defined(SS_DEBUG_EXTRA) + LOGIF(LM, (skygw_log_write_flush( + LOGFILE_MESSAGE, + "[readwritesplit:create_parse_tree] 1."))); +#endif if (parser_state.init(thd, thd->query(), thd->query_length())) { failp = TRUE; goto return_here; } - mysql_reset_thd_for_next_command(thd); - - /** Set some database to thd so that parsing won't fail because of - * missing database. Then parse. */ - failp = thd->set_db(virtual_db, strlen(virtual_db)); +#if defined(SS_DEBUG_EXTRA) + LOGIF(LM, (skygw_log_write_flush( + LOGFILE_MESSAGE, + "[readwritesplit:create_parse_tree] 2."))); +#endif + mysql_reset_thd_for_next_command(thd); +#if defined(SS_DEBUG_EXTRA) + LOGIF(LM, (skygw_log_write_flush( + LOGFILE_MESSAGE, + "[readwritesplit:create_parse_tree] 3."))); +#endif + /** + * Set some database to thd so that parsing won't fail because of + * missing database. Then parse. + */ + failp = thd->set_db(virtual_db, strlen(virtual_db)); +#if defined(SS_DEBUG_EXTRA) + LOGIF(LM, (skygw_log_write_flush( + LOGFILE_MESSAGE, + "[readwritesplit:create_parse_tree] 4."))); +#endif if (failp) { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, @@ -377,6 +397,11 @@ static bool create_parse_tree( } failp = parse_sql(thd, &parser_state, NULL); +#if defined(SS_DEBUG_EXTRA) + LOGIF(LM, (skygw_log_write_flush( + LOGFILE_MESSAGE, + "[readwritesplit:create_parse_tree] 5."))); +#endif if (failp) { LOGIF(LD, (skygw_log_write( LOGFILE_DEBUG, @@ -614,7 +639,17 @@ static skygw_query_type_t resolve_query_type( type |= QUERY_TYPE_PREPARE_NAMED_STMT; goto return_qtype; break; - + + case SQLCOM_SHOW_DATABASES: + type |= QUERY_TYPE_SHOW_DATABASES; + goto return_qtype; + break; + + case SQLCOM_SHOW_TABLES: + type |= QUERY_TYPE_SHOW_TABLES; + goto return_qtype; + break; + default: break; } @@ -798,8 +833,7 @@ static skygw_query_type_t resolve_query_type( LOGIF(LD, (skygw_log_write( LOGFILE_DEBUG, "%lu [resolve_query_type] " - "Unknown functype %d. Something " - "has gone wrong.", + "Functype %d.", pthread_self(), ftype))); break; @@ -1350,3 +1384,49 @@ static void parsing_info_set_plain_str( pi->pi_query_plain_str = str; } + +/** + * Generate a string of query type value. + * Caller must free the memory of the resulting string. + * + * @param qtype Query type value, combination of values listed in + * query_classifier.h + * + * @return string representing the query type value + */ +char* skygw_get_qtype_str( + skygw_query_type_t qtype) +{ + int t1 = (int)qtype; + int t2 = 1; + skygw_query_type_t t = QUERY_TYPE_UNKNOWN; + char* qtype_str = NULL; + + /** + * Test values (bits) and clear matching bits from t1 one by one until + * t1 is completely cleared. + */ + while (t1 != 0) + { + if (t1&t2) + { + t = (skygw_query_type_t)t2; + + if (qtype_str == NULL) + { + qtype_str = strdup(STRQTYPE(t)); + } + else + { + size_t len = strlen(STRQTYPE(t)); + /** reallocate space for delimiter, new string and termination */ + qtype_str = (char *)realloc(qtype_str, strlen(qtype_str)+1+len+1); + snprintf(qtype_str+strlen(qtype_str), 1+len+1, "|%s", STRQTYPE(t)); + } + /** Remove found value from t1 */ + t1 &= ~t2; + } + t2 <<= 1; + } + return qtype_str; +} diff --git a/query_classifier/query_classifier.h b/query_classifier/query_classifier.h index 4ad960524..db2011642 100644 --- a/query_classifier/query_classifier.h +++ b/query_classifier/query_classifier.h @@ -1,5 +1,5 @@ /* -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -Copyright SkySQL Ab +Copyright MariaDB Corporation Ab */ @@ -54,7 +54,9 @@ typedef enum { QUERY_TYPE_PREPARE_STMT = 0x020000, /*< Prepared stmt with id provided by server:all */ QUERY_TYPE_EXEC_STMT = 0x040000, /*< Execute prepared statement:master or any */ QUERY_TYPE_CREATE_TMP_TABLE = 0x080000, /*< Create temporary table:master (could be all) */ - QUERY_TYPE_READ_TMP_TABLE = 0x100000 /*< Read temporary table:master (could be any) */ + QUERY_TYPE_READ_TMP_TABLE = 0x100000, /*< Read temporary table:master (could be any) */ + QUERY_TYPE_SHOW_DATABASES = 0x200000, /*< Show list of databases */ + QUERY_TYPE_SHOW_TABLES = 0x400000 /*< Show list of tables */ } skygw_query_type_t; @@ -91,6 +93,7 @@ bool parse_query (GWBUF* querybuf); parsing_info_t* parsing_info_init(void (*donefun)(void *)); void parsing_info_done(void* ptr); bool query_is_parsed(GWBUF* buf); +char* skygw_get_qtype_str(skygw_query_type_t qtype); EXTERN_C_BLOCK_END diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt new file mode 100644 index 000000000..ceaad8110 --- /dev/null +++ b/query_classifier/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(canonical_tests) \ No newline at end of file diff --git a/query_classifier/test/canonical_tests/CMakeLists.txt b/query_classifier/test/canonical_tests/CMakeLists.txt new file mode 100644 index 000000000..4777fad8d --- /dev/null +++ b/query_classifier/test/canonical_tests/CMakeLists.txt @@ -0,0 +1,12 @@ +file(COPY ${ERRMSG} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +if(${ERRMSG} MATCHES "ERRMSG-NOTFOUND") + message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=") +endif() +add_executable(canonizer canonizer.c) +target_link_libraries(canonizer pthread query_classifier z dl ssl aio crypt crypto rt m ${EMBEDDED_LIB} fullcore stdc++) +add_test(NAME TestCanonicalQuery COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/canontest.sh + ${CMAKE_CURRENT_BINARY_DIR}/test.log + ${CMAKE_CURRENT_SOURCE_DIR}/input.sql + ${CMAKE_CURRENT_BINARY_DIR}/output.sql + ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql + $) diff --git a/query_classifier/test/canonical_tests/canonizer.c b/query_classifier/test/canonical_tests/canonizer.c index b9b17222f..7e33fe4a1 100644 --- a/query_classifier/test/canonical_tests/canonizer.c +++ b/query_classifier/test/canonical_tests/canonizer.c @@ -7,7 +7,7 @@ #include static char* server_options[] = { - "SkySQL Gateway", + "MariaDB Corporation MaxScale", "--datadir=./", "--language=./", "--skip-innodb", diff --git a/query_classifier/test/canonical_tests/canontest.sh b/query_classifier/test/canonical_tests/canontest.sh index 8382103c1..dd931504f 100755 --- a/query_classifier/test/canonical_tests/canontest.sh +++ b/query_classifier/test/canonical_tests/canontest.sh @@ -1,5 +1,5 @@ #! /bin/sh -if [[ $# -ne 4 ]] +if [[ $# -lt 4 ]] then echo "Usage: canontest.sh " exit 0 @@ -9,13 +9,29 @@ INPUT=$2 OUTPUT=$3 EXPECTED=$4 DIFFLOG=diff.out -$PWD/canonizer $INPUT $OUTPUT + +if [ $# -eq 5 ] +then + EXECUTABLE=$5 +else + EXECUTABLE=$PWD/canonizer +fi + +$EXECUTABLE $INPUT $OUTPUT diff $OUTPUT $EXPECTED > $DIFFLOG if [ $? -eq 0 ] then echo "PASSED" >> $TESTLOG + exval=0 else echo "FAILED" >> $TESTLOG echo "Diff output: " >> $TESTLOG cat $DIFFLOG >> $TESTLOG + exval=1 +fi + +if [ $# -eq 5 ] +then + cat $TESTLOG + exit $exval fi diff --git a/query_classifier/test/canonical_tests/expected.sql b/query_classifier/test/canonical_tests/expected.sql index fabb27dc7..1126f6016 100755 --- a/query_classifier/test/canonical_tests/expected.sql +++ b/query_classifier/test/canonical_tests/expected.sql @@ -1,7 +1,7 @@ -select md5(?) =?, sleep(?), rand(?); -select * from my1 where md5(?) =?; -select md5(?) =?; -select * from my1 where md5(?) =?; +select md5("?") =?, sleep(?), rand(?) +select * from my1 where md5("?") =? +select md5("?") =? +select * from my1 where md5("?") =? select sleep(?) select * from tst where lname='?' select ?,?,?,?,?,? from tst @@ -13,5 +13,5 @@ create table tst(fname varchar(30), lname varchar(30)) update tst set lname="?" where fname like '?' or lname like '?' delete from tst where lname like '?' and fname like '?' select ? from tst where fname='?' or lname like '?' -select ?,?,?,? from tst where name='?' or name='?' or name='?' +select ?,?,?,? from tst where name='?' or name='?' or name='?' or name='?' select count(?),count(?),count(?),count(?),count (?),count(?) from tst diff --git a/query_classifier/test/testmain.c b/query_classifier/test/testmain.c index 00000de98..08a25d4fa 100644 --- a/query_classifier/test/testmain.c +++ b/query_classifier/test/testmain.c @@ -13,7 +13,7 @@ static char datadir[1024] = ""; static char mysqldir[1024] = ""; static char* server_options[] = { - "SkySQL Gateway", + "MariaDB Corporation MaxScale", "--datadir=", "--default-storage-engine=myisam", NULL diff --git a/rabbitmq_consumer/CMakeLists.txt b/rabbitmq_consumer/CMakeLists.txt index 30d16d630..aee18a6da 100644 --- a/rabbitmq_consumer/CMakeLists.txt +++ b/rabbitmq_consumer/CMakeLists.txt @@ -1,44 +1,21 @@ -cmake_minimum_required (VERSION 2.6) +if (NOT ( DEFINED MYSQL_CLIENT_LIB ) ) + find_library(MYSQL_CLIENT_LIB NAMES mysqlclient PATHS /usr/lib /usr/lib64 PATH_SUFFIXES mysql mariadb) +endif() -set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /usr/lib/mariadb /usr/lib64/mariadb) -set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/include /usr/local/include /usr/include/mysql /usr/local/include/mysql /usr/include/mariadb /usr/local/include/mariadb) +if (NOT ( DEFINED MYSQL_CLIENT_HEADERS ) ) + find_path(MYSQL_CLIENT_HEADERS NAMES mysql.h PATH_SUFFIXES mysql mariadb) +endif() -include(InstallRequiredSystemLibraries) - -project (consumer) - -find_path(MYSQL_INCLUDE_DIRS mysql.h) -find_library(MYSQL_LIBRARIES NAMES mysqlclient) -find_library(RABBITMQ_C_LIBRARIES NAMES rabbitmq) - -include_directories(${MYSQL_INCLUDE_DIRS}) -include_directories(${RABBITMQ_C_INCLUDE_DIRS}) -include_directories(${CMAKE_SOURCE_DIR}/inih) - -add_subdirectory (inih) -link_directories(${CMAKE_SOURCE_DIR}/inih) - -if(RABBITMQ_C_LIBRARIES AND MYSQL_LIBRARIES AND MYSQL_INCLUDE_DIRS) - -add_executable (consumer consumer.c ${MYSQL_LIBRARIES} ${RABBITMQ_C_LIBRARIES}) -target_link_libraries(consumer mysqlclient) -target_link_libraries(consumer rabbitmq) -target_link_libraries(consumer inih) -install(TARGETS consumer DESTINATION bin) -install(FILES consumer.cnf DESTINATION share/consumer) +if( ( RABBITMQ_LIB AND RABBITMQ_HEADERS ) AND ( NOT ( ${MYSQL_CLIENT_LIB} STREQUAL "MYSQL_CLIENT_LIB-NOTFOUND" ) ) AND ( NOT ( ${MYSQL_CLIENT_HEADERS} STREQUAL "MYSQL_CLIENT_HEADERS-NOTFOUND" ) ) ) + include_directories(${MYSQL_CLIENT_HEADERS}) + add_executable (consumer consumer.c) + target_link_libraries(consumer ${MYSQL_CLIENT_LIB} rabbitmq inih) + install(TARGETS consumer DESTINATION bin) + install(FILES consumer.cnf DESTINATION etc) -else(RABBITMQ_C_LIBRARIES AND MYSQL_LIBRARIES AND MYSQL_INCLUDE_DIRS) -message(FATAL_ERROR "Error: Can not find requred libraries: libmysqld, librabbitmq.") +else() -endif(RABBITMQ_C_LIBRARIES AND MYSQL_LIBRARIES AND MYSQL_INCLUDE_DIRS) + message(FATAL_ERROR "Error: Can not find requred libraries and headers: librabbitmq libmysqlclient") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "RabbitMQ Consumer Client") -set(CPACK_PACKAGE_NAME "RabbitMQ Consumer") -set(CPACK_GENERATOR "RPM") -set(CPACK_PACKAGE_VERSION_MAJOR "1") -set(CPACK_PACKAGE_VERSION_MINOR "0") -set(CPACK_RPM_PACKAGE_NAME "rabbitmq-consumer") -set(CPACK_RPM_PACKAGE_VENDOR "SkySQL Ab") -set(CPACK_RPM_PACKAGE_AUTOREQPROV " no") -include(CPack) \ No newline at end of file +endif() diff --git a/replication_listener/COPYING.SkySQL b/replication_listener/COPYING.SkySQL index 9845b0fe8..52951686d 100644 --- a/replication_listener/COPYING.SkySQL +++ b/replication_listener/COPYING.SkySQL @@ -1,7 +1,7 @@ -Portions of this software contain modifications contributed by SkySQL, Ab. +Portions of this software contain modifications contributed by MariaDB Corporation, Ab. These contributions are used with the following license: -Copyright (c) 2013, SkySQL Ab. All rights reserved. +Copyright (c) 2013, MariaDB Corporation Ab. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -12,7 +12,7 @@ are met: copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of the SkySQL Ab. nor the names of its + * Neither the name of the MariaDB Corporation Ab. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/replication_listener/access_method_factory.cpp b/replication_listener/access_method_factory.cpp index 2f6f6ca3b..7261b9355 100644 --- a/replication_listener/access_method_factory.cpp +++ b/replication_listener/access_method_factory.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Removed unnecessary file driver Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/access_method_factory.h b/replication_listener/access_method_factory.h index af245fa36..e402a1185 100644 --- a/replication_listener/access_method_factory.h +++ b/replication_listener/access_method_factory.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or diff --git a/replication_listener/basic_content_handler.cpp b/replication_listener/basic_content_handler.cpp index 7d24b9c0f..9b209ab28 100644 --- a/replication_listener/basic_content_handler.cpp +++ b/replication_listener/basic_content_handler.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added GTID event handler Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/basic_content_handler.h b/replication_listener/basic_content_handler.h index 449d0f8d4..5debfb672 100644 --- a/replication_listener/basic_content_handler.h +++ b/replication_listener/basic_content_handler.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added GTID event handler Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/binary_log.cpp b/replication_listener/binary_log.cpp index 0e643269d..199cf65c4 100644 --- a/replication_listener/binary_log.cpp +++ b/replication_listener/binary_log.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for setting binlog position based on GTID - Added support for MySQL and MariDB server types diff --git a/replication_listener/binlog_api.h b/replication_listener/binlog_api.h index 2a73423af..fb6e24f77 100644 --- a/replication_listener/binlog_api.h +++ b/replication_listener/binlog_api.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for setting binlog position based on GTID - Added support for MySQL and MariDB server types diff --git a/replication_listener/binlog_driver.cpp b/replication_listener/binlog_driver.cpp index ef2512b5c..86c3ea954 100644 --- a/replication_listener/binlog_driver.cpp +++ b/replication_listener/binlog_driver.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. - Copyright (c) 2013, SkySQL Ab + Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by - SkySQL, Ab. Those modifications are gratefully acknowledged and are described + MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/binlog_driver.h b/replication_listener/binlog_driver.h index cdec99e06..73e60587d 100644 --- a/replication_listener/binlog_driver.h +++ b/replication_listener/binlog_driver.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB - Added support for setting binlog position based on GTID diff --git a/replication_listener/binlog_event.cpp b/replication_listener/binlog_event.cpp index 77723e310..d1f4da802 100644 --- a/replication_listener/binlog_event.cpp +++ b/replication_listener/binlog_event.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/binlog_event.h b/replication_listener/binlog_event.h index 2b0d650e2..3c8285044 100644 --- a/replication_listener/binlog_event.h +++ b/replication_listener/binlog_event.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/gtid.cpp b/replication_listener/gtid.cpp index e5e1c1516..ed9d80bea 100644 --- a/replication_listener/gtid.cpp +++ b/replication_listener/gtid.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/replication_listener/gtid.h b/replication_listener/gtid.h index b0ca43548..359ae9d04 100644 --- a/replication_listener/gtid.h +++ b/replication_listener/gtid.h @@ -1,7 +1,7 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/replication_listener/listener_exception.h b/replication_listener/listener_exception.h index b9da4f0ae..7ff656ea8 100644 --- a/replication_listener/listener_exception.h +++ b/replication_listener/listener_exception.h @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/replication_listener/protocol.cpp b/replication_listener/protocol.cpp index 0bc58b458..8d07f6877 100644 --- a/replication_listener/protocol.cpp +++ b/replication_listener/protocol.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB Author: Jan Lindström (jan.lindstrom@skysql.com diff --git a/replication_listener/tcp_driver.cpp b/replication_listener/tcp_driver.cpp index a36b8bf68..216077249 100644 --- a/replication_listener/tcp_driver.cpp +++ b/replication_listener/tcp_driver.cpp @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB - Added support for starting binlog dump from GTID position - Added error handling using exceptions diff --git a/replication_listener/tcp_driver.h b/replication_listener/tcp_driver.h index 268f3dcee..7d4d96c94 100644 --- a/replication_listener/tcp_driver.h +++ b/replication_listener/tcp_driver.h @@ -1,10 +1,10 @@ /* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2013, SkySQL Ab +Copyright (c) 2013-2014, MariaDB Corporation Ab Portions of this file contain modifications contributed and copyrighted by -SkySQL, Ab. Those modifications are gratefully acknowledged and are described +MariaDB Corporation, Ab. Those modifications are gratefully acknowledged and are described briefly in the source code. This program is free software; you can redistribute it and/or @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* -SkySQL change details: +MariaDB Corporation change details: - Added support for GTID event handling for both MySQL and MariaDB - Added support for starting binlog dump from GTID position - Added support for MariaDB server diff --git a/replication_listener/tests/event_dump.cpp b/replication_listener/tests/event_dump.cpp index 3fd33d1a7..d9c415374 100644 --- a/replication_listener/tests/event_dump.cpp +++ b/replication_listener/tests/event_dump.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/script/make-binary-tarball.sh b/script/make-binary-tarball.sh index 416a10675..531306ddb 100755 --- a/script/make-binary-tarball.sh +++ b/script/make-binary-tarball.sh @@ -14,7 +14,7 @@ echo "Looking for MaxScale in [${BINARY_PATH}]" if [ -s "${BINARY_PATH}/bin/maxscale" ]; then if [ -x "${BINARY_PATH}/bin/maxscale" ]; then - MAXSCALE_VERSION=`strings ${BINARY_PATH}/bin/maxscale | grep "SkySQL MaxScale" | awk '{print $3}' | head -1` + MAXSCALE_VERSION=`strings ${BINARY_PATH}/bin/maxscale | grep "MariaDB Corporation MaxScale" | awk '{print $3}' | head -1` echo "Found MaxScale, version: ${MAXSCALE_VERSION}" fi else diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt new file mode 100644 index 000000000..a42c625ae --- /dev/null +++ b/server/CMakeLists.txt @@ -0,0 +1,6 @@ +add_subdirectory(core) +add_subdirectory(modules) +add_subdirectory(inih) +if(BUILD_TESTS) +add_subdirectory(test) +endif() \ No newline at end of file diff --git a/server/Makefile b/server/Makefile index fda9d14c1..93a181a07 100644 --- a/server/Makefile +++ b/server/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt new file mode 100644 index 000000000..bddf95239 --- /dev/null +++ b/server/core/CMakeLists.txt @@ -0,0 +1,23 @@ +if(BUILD_TESTS) + file(GLOB FULLCORE_SRC *.c) + add_library(fullcore STATIC ${FULLCORE_SRC}) + target_link_libraries(fullcore log_manager utils pthread ${EMBEDDED_LIB} ssl aio rt crypt dl crypto inih z m stdc++) +endif() +add_executable(maxscale atomic.c buffer.c spinlock.c gateway.c + gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c + poll.c config.c users.c hashtable.c dbusers.c thread.c gwbitmask.c + monitor.c adminusers.c secrets.c filter.c modutil.c hint.c housekeeper.c) +target_link_libraries(maxscale ${EMBEDDED_LIB} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++) +install(TARGETS maxscale DESTINATION bin) + +add_executable(maxkeys maxkeys.c secrets.c utils.c) +target_link_libraries(maxkeys log_manager utils pthread crypt crypto) +install(TARGETS maxkeys DESTINATION bin) + +add_executable(maxpasswd maxpasswd.c secrets.c utils.c) +target_link_libraries(maxpasswd log_manager utils pthread crypt crypto) +install(TARGETS maxpasswd DESTINATION bin) + +if(BUILD_TESTS) + add_subdirectory(test) +endif() \ No newline at end of file diff --git a/server/core/Makefile b/server/core/Makefile index 7ad4e1b01..26c6482eb 100644 --- a/server/core/Makefile +++ b/server/core/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description @@ -47,7 +47,7 @@ CC=cc CFLAGS=-c -I/usr/include -I../include -I../modules/include -I../inih \ $(MYSQL_HEADERS) \ -I$(LOGPATH) -I$(UTILSPATH) \ - -Wall -g + -Wall -pedantic -g LDFLAGS=-rdynamic -L$(LOGPATH) \ -Wl,-rpath,$(DEST)/lib \ diff --git a/server/core/adminusers.c b/server/core/adminusers.c index 61cd7c077..e547a1ff5 100644 --- a/server/core/adminusers.c +++ b/server/core/adminusers.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/core/atomic.c b/server/core/atomic.c index f8dd4a07f..b14e1ccb1 100644 --- a/server/core/atomic.c +++ b/server/core/atomic.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/buffer.c b/server/core/buffer.c index 290da6bde..bb40a8d40 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -65,20 +65,20 @@ gwbuf_alloc(unsigned int size) GWBUF *rval; SHARED_BUF *sbuf; - // Allocate the buffer header + /* Allocate the buffer header */ if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL) { return NULL; } - // Allocate the shared data buffer + /* Allocate the shared data buffer */ if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL) { free(rval); return NULL; } - // Allocate the space for the actual data + /* Allocate the space for the actual data */ if ((sbuf->data = (unsigned char *)malloc(size)) == NULL) { free(rval); @@ -87,7 +87,7 @@ SHARED_BUF *sbuf; } spinlock_init(&rval->gwbuf_lock); rval->start = sbuf->data; - rval->end = rval->start + size; + rval->end = (void *)((char *)rval->start+size); sbuf->refcount = 1; rval->sbuf = sbuf; rval->next = NULL; @@ -197,8 +197,8 @@ GWBUF *gwbuf_clone_portion( atomic_add(&buf->sbuf->refcount, 1); clonebuf->sbuf = buf->sbuf; clonebuf->gwbuf_type = buf->gwbuf_type; /*< clone info bits too */ - clonebuf->start = (void *)((char*)buf->start)+start_offset; - clonebuf->end = (void *)((char *)clonebuf->start)+length; + clonebuf->start = (void *)((char*)buf->start+start_offset); + clonebuf->end = (void *)((char *)clonebuf->start+length); clonebuf->gwbuf_type = buf->gwbuf_type; /*< clone the type for now */ clonebuf->properties = NULL; clonebuf->hint = NULL; @@ -277,8 +277,6 @@ return_clonebuf: GWBUF * gwbuf_append(GWBUF *head, GWBUF *tail) { -GWBUF *ptr = head; - if (!head) return tail; CHK_GWBUF(head); @@ -311,7 +309,7 @@ GWBUF *rval = head; CHK_GWBUF(head); GWBUF_CONSUME(head, length); - CHK_GWBUF(head); + CHK_GWBUF(head); if (GWBUF_EMPTY(head)) { @@ -370,11 +368,36 @@ gwbuf_trim(GWBUF *buf, unsigned int n_bytes) gwbuf_consume(buf, GWBUF_LENGTH(buf)); return NULL; } - buf->end -= n_bytes; + buf->end = (void *)((char *)buf->end - n_bytes); return buf; } +/** + * Trim bytes from the end of a GWBUF structure that may be the first + * in a list. If the buffer has n_bytes or less then it will be freed and + * the next buffer in the list will be returned, or if none, NULL. + * + * @param head The buffer to trim + * @param n_bytes The number of bytes to trim off + * @return The buffer chain or NULL if buffer chain now empty + */ +GWBUF * +gwbuf_rtrim(GWBUF *head, unsigned int n_bytes) +{ +GWBUF *rval = head; + CHK_GWBUF(head); + GWBUF_RTRIM(head, n_bytes); + CHK_GWBUF(head); + + if (GWBUF_EMPTY(head)) + { + rval = head->next; + gwbuf_free(head); + } + return rval; +} + /** * Set given type to all buffers on the list. * * diff --git a/server/core/config.c b/server/core/config.c index 995e0e0f4..ead016000 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -131,7 +131,7 @@ CONFIG_PARAMETER *param, *p1; ptr->element = NULL; cntxt->next = ptr; } - /* Check to see if the paramter already exists for the section */ + /* Check to see if the parameter already exists for the section */ p1 = ptr->parameters; while (p1) { diff --git a/server/core/dbusers.c b/server/core/dbusers.c index 4f8de392b..c65aafdc9 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/dcb.c b/server/core/dcb.c index b8f9108de..36e088dfc 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -32,7 +32,7 @@ * 12/06/13 Mark Riddoch Initial implementation * 21/06/13 Massimiliano Pinto free_dcb is used * 25/06/13 Massimiliano Pinto Added checks to session and router_session - * 28/06/13 Mark Riddoch Changed the free mechanism ti + * 28/06/13 Mark Riddoch Changed the free mechanism to * introduce a zombie state for the * dcb * 02/07/2013 Massimiliano Pinto Addition of delayqlock, delayq and @@ -73,7 +73,7 @@ extern int lm_enabled_logfiles_bitmask; -static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */ +static DCB *allDCBs = NULL; /* Diagnostics need a list of DCBs */ static DCB *zombies = NULL; static SPINLOCK dcbspin = SPINLOCK_INIT; static SPINLOCK zombiespin = SPINLOCK_INIT; @@ -88,6 +88,7 @@ static DCB* dcb_get_next (DCB* dcb); static int dcb_null_write(DCB *dcb, GWBUF *buf); static int dcb_null_close(DCB *dcb); static int dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf); +static int dcb_isvalid_nolock(DCB *dcb); /** * Return the pointer to the lsit of zombie DCB's @@ -123,12 +124,6 @@ DCB *rval; rval->dcb_errhandle_called = false; #endif rval->dcb_role = role; -#if 1 - simple_mutex_init(&rval->dcb_write_lock, "DCB write mutex"); - simple_mutex_init(&rval->dcb_read_lock, "DCB read mutex"); - rval->dcb_write_active = false; - rval->dcb_read_active = false; -#endif spinlock_init(&rval->dcb_initlock); spinlock_init(&rval->writeqlock); spinlock_init(&rval->delayqlock); @@ -141,6 +136,13 @@ DCB *rval; rval->polloutbusy = 0; rval->writecheck = 0; rval->fd = -1; + + rval->evq.next = NULL; + rval->evq.prev = NULL; + rval->evq.pending_events = 0; + rval->evq.processing = 0; + spinlock_init(&rval->evq.eventqlock); + memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics rval->state = DCB_STATE_ALLOC; bitmask_init(&rval->memdata.bitmask); @@ -218,43 +220,11 @@ dcb_add_to_zombieslist(DCB *dcb) spinlock_release(&zombiespin); return; } -#if 1 /*< * Add closing dcb to the top of the list. */ dcb->memdata.next = zombies; zombies = dcb; -#else - if (zombies == NULL) { - zombies = dcb; - } else { - DCB *ptr = zombies; - while (ptr->memdata.next) - { - ss_info_dassert( - ptr->memdata.next->state == DCB_STATE_ZOMBIE, - "Next zombie is not in DCB_STATE_ZOMBIE state"); - - ss_info_dassert( - ptr != dcb, - "Attempt to add DCB to zombies list although it " - "is already there."); - - if (ptr == dcb) - { - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error : Attempt to add DCB to zombies " - "list when it is already in the list"))); - break; - } - ptr = ptr->memdata.next; - } - if (ptr != dcb) { - ptr->memdata.next = dcb; - } - } -#endif /*< * Set state which indicates that it has been added to zombies * list. @@ -389,8 +359,6 @@ DCB_CALLBACK *cb; spinlock_release(&dcb->cb_lock); bitmask_free(&dcb->memdata.bitmask); - simple_mutex_done(&dcb->dcb_read_lock); - simple_mutex_done(&dcb->dcb_write_lock); free(dcb); } @@ -404,15 +372,10 @@ DCB_CALLBACK *cb; * the memdata.bitmask then the DCB is no longer able to be * referenced and it can be finally removed. * - * The excluded DCB allows a thread to exclude a DCB from zombie processing. - * It is used when a thread calls dcb_process_zombies when there is - * a DCB that the caller knows it will continue processing with. - * * @param threadid The thread ID of the caller - * @param excluded The DCB the thread currently uses, NULL or valid DCB. */ DCB * -dcb_process_zombies(int threadid, DCB *excluded) +dcb_process_zombies(int threadid) { DCB *ptr, *lptr; DCB* dcb_list = NULL; @@ -446,9 +409,10 @@ bool succp = false; CHK_DCB(ptr); /* - * Skip processing of the excluded DCB + * Skip processing of DCB's that are + * in the event queue waiting to be processed. */ - if (ptr == excluded) + if (ptr->evq.next || ptr->evq.prev) { lptr = ptr; ptr = ptr->memdata.next; @@ -522,7 +486,6 @@ bool succp = false; /*< * Close file descriptor and move to clean-up phase. */ - ss_dassert(excluded != dcb); rc = close(dcb->fd); if (rc < 0) { @@ -1255,7 +1218,7 @@ printDCB(DCB *dcb) static void spin_reporter(void *dcb, char *desc, int value) { - dcb_printf((DCB *)dcb, "\t\t%-35s %d\n", desc, value); + dcb_printf((DCB *)dcb, "\t\t%-40s %d\n", desc, value); } @@ -1316,10 +1279,6 @@ DCB *dcb; dcb_printf(pdcb, "\t\tNo. of Writes: %d\n", dcb->stats.n_writes); dcb_printf(pdcb, "\t\tNo. of Buffered Writes: %d\n", dcb->stats.n_buffered); dcb_printf(pdcb, "\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts); - dcb_printf(pdcb, "\t\tNo. of busy polls: %d\n", dcb->stats.n_busypolls); - dcb_printf(pdcb, "\t\tNo. of read rechecks: %d\n", dcb->stats.n_readrechecks); - dcb_printf(pdcb, "\t\tNo. of busy write polls: %d\n", dcb->stats.n_busywrpolls); - dcb_printf(pdcb, "\t\tNo. of write rechecks: %d\n", dcb->stats.n_writerechecks); dcb_printf(pdcb, "\t\tNo. of High Water Events: %d\n", dcb->stats.n_high_water); dcb_printf(pdcb, "\t\tNo. of Low Water Events: %d\n", dcb->stats.n_low_water); if (dcb->flags & DCBF_CLONE) @@ -1427,10 +1386,6 @@ dprintDCB(DCB *pdcb, DCB *dcb) dcb->stats.n_buffered); dcb_printf(pdcb, "\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts); - dcb_printf(pdcb, "\t\tNo. of busy polls: %d\n", dcb->stats.n_busypolls); - dcb_printf(pdcb, "\t\tNo. of read rechecks: %d\n", dcb->stats.n_readrechecks); - dcb_printf(pdcb, "\t\tNo. of busy write polls: %d\n", dcb->stats.n_busywrpolls); - dcb_printf(pdcb, "\t\tNo. of write rechecks: %d\n", dcb->stats.n_writerechecks); dcb_printf(pdcb, "\t\tNo. of High Water Events: %d\n", dcb->stats.n_high_water); dcb_printf(pdcb, "\t\tNo. of Low Water Events: %d\n", @@ -1939,113 +1894,40 @@ dcb_isvalid(DCB *dcb) DCB *ptr; int rval = 0; + if (dcb) + { spinlock_acquire(&dcbspin); + rval = dcb_isvalid_nolock(dcb); + spinlock_release(&dcbspin); + } + + return rval; +} + + +/** + * Check the passed DCB to ensure it is in the list of allDCBS. + * Requires that the DCB list is already locked before call. + * + * @param dcb The DCB to check + * @return 1 if the DCB is in the list, otherwise 0 + */ +static int +dcb_isvalid_nolock(DCB *dcb) +{ +DCB *ptr; +int rval = 0; + + if (dcb) + { ptr = allDCBs; - while (ptr) + while (ptr && ptr != dcb) { - if (ptr == dcb) - { - rval = 1; - break; - } ptr = ptr->next; } - spinlock_release(&dcbspin); - - return rval; -} - -/** - * Called by the EPOLLIN event. Take care of calling the protocol - * read entry point and managing multiple threads competing for the DCB - * without blocking those threads. - * - * This mechanism does away with the need for a mutex on the EPOLLIN event - * and instead implements a queuing mechanism in which nested events are - * queued on the DCB such that when the thread processing the first event - * returns it will read the queued event and process it. This allows the - * thread that would otherwise have to wait to process the nested event - * to return immediately and and process other events. - * - * @param dcb The DCB that has data available - * @param thread_id The ID of the calling thread - * @param nozombies If non-zero then do not do zombie processing - */ -void -dcb_pollin(DCB *dcb, int thread_id, int nozombies) -{ - - spinlock_acquire(&dcb->pollinlock); - if (dcb->pollinbusy == 0) - { - dcb->pollinbusy = 1; - do { - if (dcb->readcheck) - { - dcb->stats.n_readrechecks++; - if (!nozombies) - dcb_process_zombies(thread_id, dcb); - } - dcb->readcheck = 0; - spinlock_release(&dcb->pollinlock); - dcb->func.read(dcb); - spinlock_acquire(&dcb->pollinlock); - } while (dcb->readcheck); - dcb->pollinbusy = 0; - } - else - { - dcb->stats.n_busypolls++; - dcb->readcheck = 1; - } - spinlock_release(&dcb->pollinlock); -} - - -/** - * Called by the EPOLLOUT event. Take care of calling the protocol - * write_ready entry point and managing multiple threads competing for the DCB - * without blocking those threads. - * - * This mechanism does away with the need for a mutex on the EPOLLOUT event - * and instead implements a queuing mechanism in which nested events are - * queued on the DCB such that when the thread processing the first event - * returns it will read the queued event and process it. This allows the - * thread that would otherwise have to wait to process the nested event - * to return immediately and and process other events. - * - * @param dcb The DCB thats available for writes - * @param thread_id The ID of the calling thread - * @param nozombies If non-zero then do not do zombie processing - */ -void -dcb_pollout(DCB *dcb, int thread_id, int nozombies) -{ - - spinlock_acquire(&dcb->polloutlock); - if (dcb->polloutbusy == 0) - { - dcb->polloutbusy = 1; - do { - if (dcb->writecheck) - { - if (!nozombies) - dcb_process_zombies(thread_id, dcb); - dcb->stats.n_writerechecks++; - } - dcb->writecheck = 0; - spinlock_release(&dcb->polloutlock); - dcb->func.write_ready(dcb); - spinlock_acquire(&dcb->polloutlock); - } while (dcb->writecheck); - dcb->polloutbusy = 0; - } - else - { - dcb->stats.n_busywrpolls++; - dcb->writecheck = 1; - } - spinlock_release(&dcb->polloutlock); + rval = (ptr == dcb); + } + return rval; } @@ -2058,33 +1940,11 @@ dcb_pollout(DCB *dcb, int thread_id, int nozombies) static DCB * dcb_get_next (DCB* dcb) { - DCB* p; - spinlock_acquire(&dcbspin); - - p = allDCBs; - - if (dcb == NULL || p == NULL) - { - dcb = p; - - } - else - { - while (p != NULL && dcb != p) - { - p = p->next; - } - - if (p != NULL) - { - dcb = p->next; - } - else - { - dcb = NULL; - } + if (dcb) { + dcb = dcb_isvalid_nolock(dcb) ? dcb->next : NULL; } + else dcb = allDCBs; spinlock_release(&dcbspin); return dcb; diff --git a/server/core/filter.c b/server/core/filter.c index b199e931f..a1f210354 100644 --- a/server/core/filter.c +++ b/server/core/filter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale from SkySQL. It is free + * This file is distributed as part of MaxScale from MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/core/gateway.c b/server/core/gateway.c index 79c2585fe..f3724e87d 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 * */ @@ -88,7 +88,7 @@ extern int lm_enabled_logfiles_bitmask; * is not fixed here and will be updated elsewhere. */ static char* server_options[] = { - "SkySQL Gateway", + "MariaDB Corporation MaxScale", "--no-defaults", "--datadir=", "--language=", @@ -387,7 +387,7 @@ static bool file_write_header( *t = time(NULL); *tm = *localtime(t); - header_buf1 = "\n\nSkySQL MaxScale " MAXSCALE_VERSION "\t"; + header_buf1 = "\n\nMariaDB Corporation MaxScale " MAXSCALE_VERSION "\t"; header_buf2 = strdup(asctime(tm)); if (header_buf2 == NULL) { @@ -1539,7 +1539,7 @@ int main(int argc, char **argv) } LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, - "SkySQL MaxScale %s (C) SkySQL Ab 2013,2014", + "MariaDB Corporation MaxScale %s (C) MariaDB Corporation Ab 2013-2014", MAXSCALE_VERSION))); LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, @@ -1646,6 +1646,7 @@ void shutdown_server() { poll_shutdown(); + hkshutdown(); log_flush_shutdown(); } diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c index 2662ab41d..d5ee3e429 100644 --- a/server/core/gw_utils.c +++ b/server/core/gw_utils.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 * */ @@ -34,6 +34,7 @@ * 25-09-2013 Massimiliano Pinto setipaddress uses getaddrinfo * 06-02-2014 Mark Riddoch Added parse_bindconfig * 10-02-2014 Massimiliano Pinto Added return code to setipaddress + * 02-09-2014 Martin Brampton Replace C++ comment with C comment * *@endverbatim */ @@ -148,7 +149,7 @@ void gw_daemonize(void) { } if (pid != 0) { - // exit from main + /* exit from main */ exit(0); } diff --git a/server/core/gwbitmask.c b/server/core/gwbitmask.c index d3f031080..7706f69f3 100644 --- a/server/core/gwbitmask.c +++ b/server/core/gwbitmask.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/core/hashtable.c b/server/core/hashtable.c index 0f129e825..1aedbebe0 100644 --- a/server/core/hashtable.c +++ b/server/core/hashtable.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/core/hint.c b/server/core/hint.c index 2d716771a..052c02486 100644 --- a/server/core/hint.c +++ b/server/core/hint.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/core/housekeeper.c b/server/core/housekeeper.c index 5aa5c7a29..50556b0c6 100644 --- a/server/core/housekeeper.c +++ b/server/core/housekeeper.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include @@ -42,6 +42,8 @@ static HKTASK *tasks = NULL; */ static SPINLOCK tasklock = SPINLOCK_INIT; +static int do_shutdown = 0; + static void hkthread(void *); /** @@ -172,6 +174,8 @@ void *taskdata; for (;;) { + if (do_shutdown) + return; thread_millisleep(1000); now = time(0); spinlock_acquire(&tasklock); @@ -194,3 +198,13 @@ void *taskdata; spinlock_release(&tasklock); } } + +/** + * Called to shutdown the housekeeper + * + */ +void +hkshutdown() +{ + do_shutdown = 1; +} diff --git a/server/core/load_utils.c b/server/core/load_utils.c index cba0c6533..9e2b36598 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/maxkeys.c b/server/core/maxkeys.c index 9ae59f8c7..ad1e28f86 100644 --- a/server/core/maxkeys.c +++ b/server/core/maxkeys.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/maxpasswd.c b/server/core/maxpasswd.c index d11980ba3..8d90a7631 100644 --- a/server/core/maxpasswd.c +++ b/server/core/maxpasswd.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/modutil.c b/server/core/modutil.c index 7247f181d..cb4ed0a28 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale from SkySQL. It is free + * This file is distributed as part of MaxScale from MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -76,7 +76,7 @@ unsigned char *ptr; ptr = GWBUF_DATA(buf); *length = *ptr++; *length += (*ptr++ << 8); - *length += (*ptr++ << 8); + *length += (*ptr++ << 16); ptr += 2; // Skip sequence id and COM_QUERY byte *length = *length - 1; *sql = (char *)ptr; @@ -111,7 +111,7 @@ unsigned char *ptr; ptr = GWBUF_DATA(buf); *residual = *ptr++; *residual += (*ptr++ << 8); - *residual += (*ptr++ << 8); + *residual += (*ptr++ << 16); ptr += 2; // Skip sequence id and COM_QUERY byte *residual = *residual - 1; *length = GWBUF_LENGTH(buf) - 5; @@ -143,7 +143,7 @@ GWBUF *addition; ptr = GWBUF_DATA(orig); length = *ptr++; length += (*ptr++ << 8); - length += (*ptr++ << 8); + length += (*ptr++ << 16); ptr += 2; // Skip sequence id and COM_QUERY byte newlength = strlen(sql); @@ -178,11 +178,11 @@ GWBUF *addition; * * @param buf GWBUF buffer including the query * - * @return Plaint text query if the packet type is COM_QUERY. Otherwise return + * @return Plain text query if the packet type is COM_QUERY. Otherwise return * a string including the packet type. */ -char* modutil_get_query( - GWBUF* buf) +char * +modutil_get_query(GWBUF *buf) { uint8_t* packet; mysql_server_cmd_t packet_type; diff --git a/server/core/monitor.c b/server/core/monitor.c index 3504be917..3fb1cbb6f 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -234,17 +234,17 @@ MONITOR *ptr; spinlock_acquire(&monLock); ptr = allMonitors; - dcb_printf(dcb, "+----------------------+---------------------\n"); - dcb_printf(dcb, "| %-20s | Status\n", "Monitor"); - dcb_printf(dcb, "+----------------------+---------------------\n"); + dcb_printf(dcb, "---------------------+---------------------\n"); + dcb_printf(dcb, "%-20s | Status\n", "Monitor"); + dcb_printf(dcb, "---------------------+---------------------\n"); while (ptr) { - dcb_printf(dcb, "| %-20s | %s\n", ptr->name, + dcb_printf(dcb, "%-20s | %s\n", ptr->name, ptr->state & MONITOR_STATE_RUNNING ? "Running" : "Stopped"); ptr = ptr->next; } - dcb_printf(dcb, "+----------------------+---------------------\n"); + dcb_printf(dcb, "---------------------+---------------------\n"); spinlock_release(&monLock); } diff --git a/server/core/poll.c b/server/core/poll.c index 15e4acadb..37784176e 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include @@ -30,6 +30,13 @@ #include #include #include +#include + +#define PROFILE_POLL 1 + +#if PROFILE_POLL +#include +#endif extern int lm_enabled_logfiles_bitmask; @@ -47,6 +54,11 @@ extern int lm_enabled_logfiles_bitmask; * etc. * 23/09/14 Mark Riddoch Make use of RDHUP conditional to allow CentOS 5 * builds. + * 24/09/14 Mark Riddoch Introduction of the event queue for processing the + * incoming events rather than processing them immediately + * in the loop after the epoll_wait. This allows for better + * thread utilisaiton and fairer scheduling of the event + * processing. * * @endverbatim */ @@ -65,6 +77,11 @@ static GWBITMASK poll_mask; static simple_mutex_t epoll_wait_mutex; /*< serializes calls to epoll_wait */ #endif static int n_waiting = 0; /*< No. of threads in epoll_wait */ +static int process_pollq(int thread_id); + + +DCB *eventq = NULL; +SPINLOCK pollqlock = SPINLOCK_INIT; /** * Thread load average, this is the average number of descriptors in each @@ -125,6 +142,8 @@ static struct { int n_nothreads; /*< Number of times no threads are polling */ int n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */ + int evq_length; /*< Event queue length */ + int evq_max; /*< Maximum event queue length */ } pollStats; /** @@ -338,6 +357,17 @@ return_rc: * deschedule a process if a timeout is included, but will not do this if a 0 timeout * value is given. this improves performance when the gateway is under heavy load. * + * In order to provide a fairer means of sharign the threads between the different + * DCB's the poll mechanism has been decoupled from the processing of the events. + * The events are now recieved via the epoll_wait call, a queue of DCB's that have + * events pending is maintained and as new events arrive the DCB is added to the end + * of this queue. If an eent arrives for a DCB alreayd in the queue, then the event + * bits are added to the DCB but the DCB mantains the same point in the queue unless + * the original events are already being processed. If they are being processed then + * the DCB is moved to the back of the queue, this means that a DCB that is receiving + * events at a high rate will not block the execution of events for other DCB's and + * should result in a fairer polling strategy. + * * @param arg The thread ID passed as a void * to satisfy the threading package */ void @@ -346,8 +376,6 @@ poll_waitevents(void *arg) struct epoll_event events[MAX_EVENTS]; int i, nfds; int thread_id = (int)arg; -bool no_op = false; -static bool process_zombies_only = false; /*< flag for all threads */ DCB *zombies = NULL; /** Add this thread to the bitmask of running polling threads */ @@ -362,20 +390,19 @@ DCB *zombies = NULL; while (1) { + /* Process of the queue of waiting requests */ + while (do_shutdown == 0 && process_pollq(thread_id)) + { + if (thread_data) + thread_data[thread_id].state = THREAD_ZPROCESSING; + zombies = dcb_process_zombies(thread_id); + } + atomic_add(&n_waiting, 1); #if BLOCKINGPOLL nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1); atomic_add(&n_waiting, -1); #else /* BLOCKINGPOLL */ - if (!no_op) { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] MaxScale thread " - "%d > epoll_wait <", - pthread_self(), - thread_id))); - no_op = TRUE; - } #if MUTEX_EPOLL simple_mutex_lock(&epoll_wait_mutex, TRUE); #endif @@ -396,32 +423,19 @@ DCB *zombies = NULL; pthread_self(), nfds, eno))); - no_op = FALSE; } - else if (nfds == 0) + /* + * If there are no new descriptors from the non-blocking call + * and nothing to proces on the event queue then for do a + * blocking call to epoll_wait. + */ + else if (nfds == 0 && process_pollq(thread_id) == 0) { - atomic_add(&n_waiting, -1); - if (process_zombies_only) { -#if MUTEX_EPOLL - simple_mutex_unlock(&epoll_wait_mutex); -#endif - goto process_zombies; - } else { - nfds = epoll_wait(epoll_fd, + atomic_add(&n_waiting, 1); + nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, EPOLL_TIMEOUT); - /*< - * When there are zombies to be cleaned up but - * no client requests, allow all threads to call - * dcb_process_zombies without having to wait - * for the timeout. - */ - if (nfds == 0 && dcb_get_zombies() != NULL) - { - process_zombies_only = true; - } - } } else { @@ -457,228 +471,64 @@ DCB *zombies = NULL; atomic_add(&load_samples, 1); atomic_add(&load_nfds, nfds); + /* + * Process every DCB that has a new event and add + * it to the poll queue. + * If the DCB is currently beign processed then we + * or in the new eent bits to the pending event bits + * and leave it in the queue. + * If the DCB was not already in the queue then it was + * idle and is added to the queue to process after + * setting the event bits. + */ for (i = 0; i < nfds; i++) { DCB *dcb = (DCB *)events[i].data.ptr; __uint32_t ev = events[i].events; - CHK_DCB(dcb); - if (thread_data) + spinlock_acquire(&pollqlock); + if (DCB_POLL_BUSY(dcb)) { - thread_data[thread_id].cur_dcb = dcb; - thread_data[thread_id].event = ev; + dcb->evq.pending_events |= ev; } - -#if defined(SS_DEBUG) - if (dcb_fake_write_ev[dcb->fd] != 0) { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "Added fake events %d to ev %d.", - pthread_self(), - dcb_fake_write_ev[dcb->fd], - ev))); - ev |= dcb_fake_write_ev[dcb->fd]; - dcb_fake_write_ev[dcb->fd] = 0; - } -#endif - ss_debug(spinlock_acquire(&dcb->dcb_initlock);) - ss_dassert(dcb->state != DCB_STATE_ALLOC); - ss_dassert(dcb->state != DCB_STATE_DISCONNECTED); - ss_dassert(dcb->state != DCB_STATE_FREED); - ss_debug(spinlock_release(&dcb->dcb_initlock);) - - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] event %d dcb %p " - "role %s", - pthread_self(), - ev, - dcb, - STRDCBROLE(dcb->dcb_role)))); - - if (ev & EPOLLOUT) + else { - int eno = 0; - eno = gw_getsockerrno(dcb->fd); - - if (eno == 0) { -#if MUTEX_BLOCK - simple_mutex_lock( - &dcb->dcb_write_lock, - true); - ss_info_dassert( - !dcb->dcb_write_active, - "Write already active"); - dcb->dcb_write_active = TRUE; - atomic_add( - &pollStats.n_write, - 1); - dcb->func.write_ready(dcb); - dcb->dcb_write_active = FALSE; - simple_mutex_unlock( - &dcb->dcb_write_lock); -#else - atomic_add(&pollStats.n_write, - 1); - dcb_pollout(dcb, thread_id, nfds); -#endif - } else { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "EPOLLOUT due %d, %s. " - "dcb %p, fd %i", - pthread_self(), - eno, - strerror(eno), - dcb, - dcb->fd))); - } - } - if (ev & EPOLLIN) - { -#if MUTEX_BLOCK - simple_mutex_lock(&dcb->dcb_read_lock, - true); - ss_info_dassert(!dcb->dcb_read_active, - "Read already active"); - dcb->dcb_read_active = TRUE; -#endif - - if (dcb->state == DCB_STATE_LISTENING) + dcb->evq.pending_events = ev; + if (eventq) { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "Accept in fd %d", - pthread_self(), - dcb->fd))); - atomic_add( - &pollStats.n_accept, 1); - dcb->func.accept(dcb); - } - else - { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "Read in dcb %p fd %d", - pthread_self(), - dcb, - dcb->fd))); - atomic_add(&pollStats.n_read, 1); -#if MUTEX_BLOCK - dcb->func.read(dcb); -#else - dcb_pollin(dcb, thread_id, nfds); -#endif - } -#if MUTEX_BLOCK - dcb->dcb_read_active = FALSE; - simple_mutex_unlock( - &dcb->dcb_read_lock); -#endif - } - if (ev & EPOLLERR) - { - int eno = gw_getsockerrno(dcb->fd); -#if defined(SS_DEBUG) - if (eno == 0) { - eno = dcb_fake_write_errno[dcb->fd]; - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "Added fake errno %d. " - "%s", - pthread_self(), - eno, - strerror(eno)))); - } - dcb_fake_write_errno[dcb->fd] = 0; -#endif - if (eno != 0) { - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "EPOLLERR due %d, %s.", - pthread_self(), - eno, - strerror(eno)))); - } - atomic_add(&pollStats.n_error, 1); - dcb->func.error(dcb); - } - - if (ev & EPOLLHUP) - { - int eno = 0; - eno = gw_getsockerrno(dcb->fd); - - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "EPOLLHUP on dcb %p, fd %d. " - "Errno %d, %s.", - pthread_self(), - dcb, - dcb->fd, - eno, - strerror(eno)))); - atomic_add(&pollStats.n_hup, 1); - spinlock_acquire(&dcb->dcb_initlock); - if ((dcb->flags & DCBF_HUNG) == 0) - { - dcb->flags |= DCBF_HUNG; - spinlock_release(&dcb->dcb_initlock); - dcb->func.hangup(dcb); + dcb->evq.prev = eventq->evq.prev; + eventq->evq.prev->evq.next = dcb; + eventq->evq.prev = dcb; + dcb->evq.next = eventq; } else - spinlock_release(&dcb->dcb_initlock); - } - -#ifdef EPOLLRDHUP - if (ev & EPOLLRDHUP) - { - int eno = 0; - eno = gw_getsockerrno(dcb->fd); - - LOGIF(LD, (skygw_log_write( - LOGFILE_DEBUG, - "%lu [poll_waitevents] " - "EPOLLRDHUP on dcb %p, fd %d. " - "Errno %d, %s.", - pthread_self(), - dcb, - dcb->fd, - eno, - strerror(eno)))); - atomic_add(&pollStats.n_hup, 1); - spinlock_acquire(&dcb->dcb_initlock); - if ((dcb->flags & DCBF_HUNG) == 0) { - dcb->flags |= DCBF_HUNG; - spinlock_release(&dcb->dcb_initlock); - dcb->func.hangup(dcb); + eventq = dcb; + dcb->evq.prev = dcb; + dcb->evq.next = dcb; + } + pollStats.evq_length++; + if (pollStats.evq_length > pollStats.evq_max) + { + pollStats.evq_max = pollStats.evq_length; } - else - spinlock_release(&dcb->dcb_initlock); } -#endif - } /*< for */ - no_op = FALSE; - } /*< if (nfds > 0) */ -process_zombies: - if (thread_data) - { - thread_data[thread_id].state = THREAD_ZPROCESSING; + spinlock_release(&pollqlock); + } } - zombies = dcb_process_zombies(thread_id, NULL); - - if (zombies == NULL) { - process_zombies_only = false; - } + /* + * If there was nothing to process then process the zombie queue + */ + if (process_pollq(thread_id) == 0) + { + if (thread_data) + { + thread_data[thread_id].state = THREAD_ZPROCESSING; + } + zombies = dcb_process_zombies(thread_id); + } + if (do_shutdown) { /*< @@ -701,6 +551,320 @@ process_zombies: } /*< while(1) */ } +/** + * Process of the queue of DCB's that have outstanding events + * + * The first event on the queue will be chosen to be executed by this thread, + * all other events will be left on the queue and may be picked up by other + * threads. When the processing is complete the thread will take the DCB off the + * queue if there are no pending events that have arrived since the thread started + * to process the DCB. If there are pending events the DCB will be moved to the + * back of the queue so that other DCB's will have a share of the threads to + * execute events for them. + * + * @param thread_id The thread ID of the calling thread + * @return 0 if no DCB's have been processed + */ +static int +process_pollq(int thread_id) +{ +DCB *dcb; +int found = 0; +uint32_t ev; + + spinlock_acquire(&pollqlock); + if (eventq == NULL) + { + /* Nothing to process */ + spinlock_release(&pollqlock); + return 0; + } + dcb = eventq; + if (dcb->evq.next == dcb->evq.prev && dcb->evq.processing == 0) + { + found = 1; + dcb->evq.processing = 1; + } + else if (dcb->evq.next == dcb->evq.prev) + { + /* Only item in queue is being processed */ + spinlock_release(&pollqlock); + return 0; + } + else + { + do { + dcb = dcb->evq.next; + } while (dcb != eventq && dcb->evq.processing == 1); + + if (dcb->evq.processing == 0) + { + /* Found DCB to process */ + dcb->evq.processing = 1; + found = 1; + } + } + if (found) + { + ev = dcb->evq.pending_events; + dcb->evq.pending_events = 0; + } + spinlock_release(&pollqlock); + + if (found == 0) + return 0; + + + CHK_DCB(dcb); + if (thread_data) + { + thread_data[thread_id].state = THREAD_PROCESSING; + thread_data[thread_id].cur_dcb = dcb; + thread_data[thread_id].event = ev; + } + +#if defined(SS_DEBUG) + if (dcb_fake_write_ev[dcb->fd] != 0) { + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "Added fake events %d to ev %d.", + pthread_self(), + dcb_fake_write_ev[dcb->fd], + ev))); + ev |= dcb_fake_write_ev[dcb->fd]; + dcb_fake_write_ev[dcb->fd] = 0; + } +#endif + ss_debug(spinlock_acquire(&dcb->dcb_initlock);) + ss_dassert(dcb->state != DCB_STATE_ALLOC); + ss_dassert(dcb->state != DCB_STATE_DISCONNECTED); + ss_dassert(dcb->state != DCB_STATE_FREED); + ss_debug(spinlock_release(&dcb->dcb_initlock);) + + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] event %d dcb %p " + "role %s", + pthread_self(), + ev, + dcb, + STRDCBROLE(dcb->dcb_role)))); + + if (ev & EPOLLOUT) + { + int eno = 0; + eno = gw_getsockerrno(dcb->fd); + + if (eno == 0) { +#if MUTEX_BLOCK + simple_mutex_lock( + &dcb->dcb_write_lock, + true); + ss_info_dassert( + !dcb->dcb_write_active, + "Write already active"); + dcb->dcb_write_active = TRUE; + atomic_add( + &pollStats.n_write, + 1); + dcb->func.write_ready(dcb); + dcb->dcb_write_active = FALSE; + simple_mutex_unlock( + &dcb->dcb_write_lock); +#else + atomic_add(&pollStats.n_write, + 1); + dcb->func.write_ready(dcb); +#endif + } else { + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "EPOLLOUT due %d, %s. " + "dcb %p, fd %i", + pthread_self(), + eno, + strerror(eno), + dcb, + dcb->fd))); + } + } + if (ev & EPOLLIN) + { +#if MUTEX_BLOCK + simple_mutex_lock(&dcb->dcb_read_lock, + true); + ss_info_dassert(!dcb->dcb_read_active, + "Read already active"); + dcb->dcb_read_active = TRUE; +#endif + + if (dcb->state == DCB_STATE_LISTENING) + { + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "Accept in fd %d", + pthread_self(), + dcb->fd))); + atomic_add( + &pollStats.n_accept, 1); + dcb->func.accept(dcb); + } + else + { + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "Read in dcb %p fd %d", + pthread_self(), + dcb, + dcb->fd))); + atomic_add(&pollStats.n_read, 1); + dcb->func.read(dcb); + } +#if MUTEX_BLOCK + dcb->dcb_read_active = FALSE; + simple_mutex_unlock( + &dcb->dcb_read_lock); +#endif + } + if (ev & EPOLLERR) + { + int eno = gw_getsockerrno(dcb->fd); +#if defined(SS_DEBUG) + if (eno == 0) { + eno = dcb_fake_write_errno[dcb->fd]; + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "Added fake errno %d. " + "%s", + pthread_self(), + eno, + strerror(eno)))); + } + dcb_fake_write_errno[dcb->fd] = 0; +#endif + if (eno != 0) { + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "EPOLLERR due %d, %s.", + pthread_self(), + eno, + strerror(eno)))); + } + atomic_add(&pollStats.n_error, 1); + dcb->func.error(dcb); + } + + if (ev & EPOLLHUP) + { + int eno = 0; + eno = gw_getsockerrno(dcb->fd); + + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "EPOLLHUP on dcb %p, fd %d. " + "Errno %d, %s.", + pthread_self(), + dcb, + dcb->fd, + eno, + strerror(eno)))); + atomic_add(&pollStats.n_hup, 1); + spinlock_acquire(&dcb->dcb_initlock); + if ((dcb->flags & DCBF_HUNG) == 0) + { + dcb->flags |= DCBF_HUNG; + spinlock_release(&dcb->dcb_initlock); + dcb->func.hangup(dcb); + } + else + spinlock_release(&dcb->dcb_initlock); + } + +#ifdef EPOLLRDHUP + if (ev & EPOLLRDHUP) + { + int eno = 0; + eno = gw_getsockerrno(dcb->fd); + + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [poll_waitevents] " + "EPOLLRDHUP on dcb %p, fd %d. " + "Errno %d, %s.", + pthread_self(), + dcb, + dcb->fd, + eno, + strerror(eno)))); + atomic_add(&pollStats.n_hup, 1); + spinlock_acquire(&dcb->dcb_initlock); + if ((dcb->flags & DCBF_HUNG) == 0) + { + dcb->flags |= DCBF_HUNG; + spinlock_release(&dcb->dcb_initlock); + dcb->func.hangup(dcb); + } + else + spinlock_release(&dcb->dcb_initlock); + } +#endif + + spinlock_acquire(&pollqlock); + if (dcb->evq.pending_events == 0) + { + /* No pending events so remove from the queue */ + if (dcb->evq.prev != dcb) + { + dcb->evq.prev->evq.next = dcb->evq.next; + dcb->evq.next->evq.prev = dcb->evq.prev; + if (eventq == dcb) + eventq = dcb->evq.next; + } + else + { + eventq = NULL; + } + dcb->evq.next = NULL; + dcb->evq.prev = NULL; + pollStats.evq_length--; + } + else + { + /* + * We have a pending event, move to the end of the queue + * if there are any other DCB's in the queue. + * + * If we are the first item on the queue this is easy, we + * just bump the eventq pointer. + */ + if (dcb->evq.prev != dcb) + { + if (eventq == dcb) + eventq = dcb->evq.next; + else + { + dcb->evq.prev->evq.next = dcb->evq.next; + dcb->evq.next->evq.prev = dcb->evq.prev; + dcb->evq.prev = eventq->evq.prev; + dcb->evq.next = eventq; + eventq->evq.prev = dcb; + dcb->evq.prev->evq.next = dcb; + } + } + } + dcb->evq.processing = 0; + spinlock_release(&pollqlock); + + return 1; +} + /** * Shutdown the polling loop */ @@ -721,6 +885,20 @@ poll_bitmask() return &poll_mask; } +/** + * Display an entry from the spinlock statistics data + * + * @param dcb The DCB to print to + * @param desc Description of the statistic + * @param value The statistic value + */ +static void +spin_reporter(void *dcb, char *desc, int value) +{ + dcb_printf((DCB *)dcb, "\t%-40s %d\n", desc, value); +} + + /** * Debug routine to print the polling statistics * @@ -745,6 +923,10 @@ int i; pollStats.n_accept); dcb_printf(dcb, "Number of times no threads polling: %d\n", pollStats.n_nothreads); + dcb_printf(dcb, "Current event queue length: %d\n", + pollStats.evq_length); + dcb_printf(dcb, "Maximum event queue length: %d\n", + pollStats.evq_max); dcb_printf(dcb, "No of poll completions with descriptors\n"); dcb_printf(dcb, "\tNo. of descriptors\tNo. of poll completions.\n"); @@ -754,6 +936,11 @@ int i; } dcb_printf(dcb, "\t>= %d\t\t\t%d\n", MAXNFDS, pollStats.n_fds[MAXNFDS-1]); + +#if SPINLOCK_PROFILE + dcb_printf(dcb, "Event queue lock statistics:\n"); + spinlock_stats(&pollqlock, spin_reporter, dcb); +#endif } /** diff --git a/server/core/secrets.c b/server/core/secrets.c index f9ac62aef..c0b82c347 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include @@ -74,16 +74,29 @@ int len; snprintf(secret_file, 255, "%s/etc/.secrets", home); /* Try to access secrets file */ - if (access(secret_file, R_OK) == -1) { + if (access(secret_file, R_OK) == -1) + { int eno = errno; errno = 0; - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error : access for secrets file " - "[%s] failed. Error %d, %s.", - secret_file, - eno, - strerror(eno)))); + if (eno == ENOENT) + { + LOGIF(LM, (skygw_log_write( + LOGFILE_MESSAGE, + "Encrypted password file %s can't be accessed " + "(%s). Password encryption is not used.", + secret_file, + strerror(eno)))); + } + else + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error : access for secrets file " + "[%s] failed. Error %d, %s.", + secret_file, + eno, + strerror(eno)))); + } return NULL; } diff --git a/server/core/server.c b/server/core/server.c index 43c535d0e..2afe3bd44 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/service.c b/server/core/service.c index a5e08f937..bf32846ce 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -91,10 +91,10 @@ static void service_add_qualified_param( * @param servname The service name * @param router Name of the router module this service uses * - * @return The newly created service or NULL if an error occured + * @return The newly created service or NULL if an error occurred */ SERVICE * -service_alloc(char *servname, char *router) +service_alloc(const char *servname, const char *router) { SERVICE *service; @@ -152,7 +152,7 @@ SERVICE *service; /** * Check to see if a service pointer is valid * - * @param service The poitner to check + * @param service The pointer to check * @return 1 if the service is in the list of all services */ int diff --git a/server/core/session.c b/server/core/session.c index eb9d42a2b..645ca7019 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/spinlock.c b/server/core/spinlock.c index ce64042e3..871ec42bb 100644 --- a/server/core/spinlock.c +++ b/server/core/spinlock.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,11 +13,11 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** - * @file spinlock.c - Spinlock operations for the SkySQL Gateway + * @file spinlock.c - Spinlock operations for the MariaDB Corporation MaxScale * * @verbatim * Revision History @@ -30,6 +30,7 @@ #include #include +#include /** * Initialise a spinlock. @@ -39,13 +40,13 @@ void spinlock_init(SPINLOCK *lock) { - lock->lock = 0; + lock->lock = 0; #if SPINLOCK_PROFILE - lock->spins = 0; - lock->acquired = 0; - lock->waiting = 0; - lock->max_waiting = 0; - lock->contended = 0; + lock->spins = 0; + lock->acquired = 0; + lock->waiting = 0; + lock->max_waiting = 0; + lock->contended = 0; #endif } @@ -62,24 +63,30 @@ int spins = 0; atomic_add(&(lock->waiting), 1); #endif - while (atomic_add(&(lock->lock), 1) != 0) - { - atomic_add(&(lock->lock), -1); + +#ifdef __GNUC__ + while (__sync_lock_test_and_set(&(lock->lock), 1)) + while (lock->lock) { +#else + while (atomic_add(&(lock->lock), 1) != 0) + { + atomic_add(&(lock->lock), -1); +#endif #if SPINLOCK_PROFILE atomic_add(&(lock->spins), 1); spins++; #endif } #if SPINLOCK_PROFILE - if (spins) - { - lock->contended++; - if (lock->maxspins < spins) - lock->maxspins = spins; - } - lock->acquired++; - lock->owner = THREAD_SHELF(); - atomic_add(&(lock->waiting), -1); + if (spins) + { + lock->contended++; + if (lock->maxspins < spins) + lock->maxspins = spins; + } + lock->acquired++; + lock->owner = THREAD_SHELF(); + atomic_add(&(lock->waiting), -1); #endif } @@ -92,16 +99,20 @@ int spins = 0; int spinlock_acquire_nowait(SPINLOCK *lock) { - if (atomic_add(&(lock->lock), 1) != 0) - { - atomic_add(&(lock->lock), -1); - return FALSE; - } -#if SPINLOCK_PROFILE - lock->acquired++; - lock->owner = THREAD_SHELF(); +#ifdef __GNUC__ + if (__sync_lock_test_and_set(&(lock->lock), 1)) return FALSE; +#else + if (atomic_add(&(lock->lock), 1) != 0) + { + atomic_add(&(lock->lock), -1); + return FALSE; + } #endif - return TRUE; +#if SPINLOCK_PROFILE + lock->acquired++; + lock->owner = THREAD_SHELF(); +#endif + return TRUE; } /* @@ -112,11 +123,16 @@ spinlock_acquire_nowait(SPINLOCK *lock) void spinlock_release(SPINLOCK *lock) { -#if SPINLOCK_PROFILE - if (lock->waiting > lock->max_waiting) - lock->max_waiting = lock->waiting; + #if SPINLOCK_PROFILE + if (lock->waiting > lock->max_waiting) + lock->max_waiting = lock->waiting; +#endif +#ifdef __GNUC__ + __sync_synchronize(); /* Memory barrier. */ + lock->lock = 0; +#else + atomic_add(&(lock->lock), -1); #endif - atomic_add(&(lock->lock), -1); } /** diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt new file mode 100644 index 000000000..914fe277e --- /dev/null +++ b/server/core/test/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(test_hash testhash.c) +add_executable(test_spinlock testspinlock.c) +add_executable(test_filter testfilter.c) +add_executable(test_adminusers testadminusers.c) +target_link_libraries(test_hash fullcore) +target_link_libraries(test_spinlock fullcore) +target_link_libraries(test_filter fullcore) +target_link_libraries(test_adminusers fullcore) +add_test(TestHash test_hash) +add_test(TestSpinlock test_spinlock) +add_test(TestFilter test_filter) +add_test(TestAdminUsers test_adminusers) + diff --git a/server/core/test/makefile b/server/core/test/makefile index 14f2828f2..ed0bbc23e 100644 --- a/server/core/test/makefile +++ b/server/core/test/makefile @@ -18,10 +18,11 @@ LDFLAGS=-rdynamic -L$(LOGPATH) -L$(EMBEDDED_LIB) \ -Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) \ -Wl,-rpath,$(EMBEDDED_LIB) -LIBS= -lz -lm -lcrypt -lcrypto -ldl -laio -lrt -pthread -llog_manager \ - -L../../inih/extra -linih -lssl -lstdc++ -lmysqld +LIBS= -L$(EMBEDDED_LIB) -lmysqld \ + -lz -lm -lcrypt -lcrypto -ldl -laio -lrt -pthread -llog_manager \ + -L../../inih/extra -linih -lssl -lstdc++ -TESTS=testhash testspinlock testfilter testadminusers +TESTS=testhash testspinlock testbuffer testmodutil testpoll testservice testdcb testfilter testadminusers cleantests: - $(DEL) *.o @@ -47,6 +48,39 @@ testspinlock: testspinlock.c -I$(ROOT_PATH)/utils \ testspinlock.c ../spinlock.o ../atomic.o ../thread.o -o testspinlock +testmodutil: testmodutil.c + $(CC) $(CFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + testmodutil.c ../modutil.o ../buffer.o ../atomic.o -o testmodutil + +testbuffer: testbuffer.c + $(CC) $(CFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + testbuffer.c ../buffer.o ../atomic.o -o testbuffer + +testpoll: testpoll.c + $(CC) $(CFLAGS) $(LDFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + -I$(ROOT_PATH)/log_manager \ + testpoll.c libcore.a $(UTILSPATH)/skygw_utils.o $(LIBS) -o testpoll + +testservice: testservice.c + $(CC) $(CFLAGS) $(LDFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + -I$(ROOT_PATH)/log_manager \ + testservice.c libcore.a $(UTILSPATH)/skygw_utils.o $(LIBS) -o testservice + +testdcb: testdcb.c + $(CC) $(CFLAGS) $(LDFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + -I$(ROOT_PATH)/log_manager \ + testdcb.c libcore.a $(UTILSPATH)/skygw_utils.o $(LIBS) -o testdcb + testfilter: testfilter.c libcore.a $(CC) $(CFLAGS) $(LDFLAGS) \ -I$(ROOT_PATH)/server/include \ diff --git a/server/core/test/test_mysql_users.c b/server/core/test/test_mysql_users.c index 97476b3ae..7dc789d83 100644 --- a/server/core/test/test_mysql_users.c +++ b/server/core/test/test_mysql_users.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/core/test/testadminusers.c b/server/core/test/testadminusers.c index 00ec3a452..4a67b1f5b 100644 --- a/server/core/test/testadminusers.c +++ b/server/core/test/testadminusers.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/core/test/testfilter.c b/server/core/test/testfilter.c index 55f7fadf3..bf97d7897 100644 --- a/server/core/test/testfilter.c +++ b/server/core/test/testfilter.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/core/test/testhash.c b/server/core/test/testhash.c index 3fa9d7f0d..9fc2fb9cf 100644 --- a/server/core/test/testhash.c +++ b/server/core/test/testhash.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/core/test/testspinlock.c b/server/core/test/testspinlock.c index ecdbdf108..14501cea5 100644 --- a/server/core/test/testspinlock.c +++ b/server/core/test/testspinlock.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -105,12 +105,16 @@ test2() { SPINLOCK lck; void *handle; +struct timespec sleeptime; + + sleeptime.tv_sec = 10; + sleeptime.tv_nsec = 0; acquire_time = 0; spinlock_init(&lck); spinlock_acquire(&lck); handle = thread_start(test2_helper, (void *)&lck); - sleep(10); + nanosleep(&sleeptime, NULL); spinlock_release(&lck); thread_wait(handle); @@ -122,12 +126,118 @@ void *handle; return 0; } -main(int argc, char **argv) +/** + * test3 spinlock_acquire tests process bound threads + * + * Check that spinlock correctly blocks all other threads whilst the spinlock + * is held. + * + * Start multiple threads that obtain spinlock and run process bound + */ +#define THREADS 5 +#define ITERATIONS 50000 +#define PROCESS_LOOP 10000 +#define SECONDS 15 +#define NANOTIME 100000 + +static int times_run, failures; +static volatile int active; +static int threadrun[THREADS]; +static int nowait[THREADS]; +static SPINLOCK lck; +static void +test3_helper(void *data) +{ +// SPINLOCK *lck = (SPINLOCK *)data; +int i; +int n = *(int *)data; +struct timespec sleeptime; +time_t rawtime; + + sleeptime.tv_sec = 0; + sleeptime.tv_nsec = 1; + + while (1) { + if (spinlock_acquire_nowait(&lck)) { + nowait[n]++; + } + else { + spinlock_acquire(&lck); + } + if (times_run++ > ITERATIONS) { + break; + } + threadrun[n]++; + /* + if (99 == (times_run % 100)) { + time ( &rawtime ); + fprintf(stderr, "%s Done %d iterations of test, in thread %d.\n", asctime (localtime ( &rawtime )), times_run, n); + } + */ + if (0 != active) { + fprintf(stderr, "spinlock: test 3 failed with active non-zero after lock obtained.\n"); + failures++; + } + else { + active = 1; + for (i=0; i #include diff --git a/server/core/users.c b/server/core/users.c index 3b4dadf15..ebd7412a8 100644 --- a/server/core/users.c +++ b/server/core/users.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/core/utils.c b/server/core/utils.c index 1b8c6b5fe..71c7888ed 100644 --- a/server/core/utils.c +++ b/server/core/utils.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 * */ @@ -27,8 +27,9 @@ * 10-06-2013 Massimiliano Pinto Initial implementation * 12-06-2013 Massimiliano Pinto Read function trought * the gwbuff strategy - * 13-06-2013 Massimiliano Pinto Gateway local authentication + * 13-06-2013 Massimiliano Pinto MaxScale local authentication * basics + * 02-09-2014 Martin Brampton Replaced C++ comments by C comments * * @endverbatim */ @@ -44,19 +45,19 @@ extern int lm_enabled_logfiles_bitmask; -// used in the hex2bin function +/* used in the hex2bin function */ #define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ X >= 'A' && X <= 'Z' ? X-'A'+10 :\ X >= 'a' && X <= 'z' ? X-'a'+10 :\ '\177') -// used in the bin2hex function +/* used in the bin2hex function */ char hex_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char hex_lower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; -////////////////////////////////////////// -//backend read event triggered by EPOLLIN -////////////////////////////////////////// +/***************************************** + * backend read event triggered by EPOLLIN +*****************************************/ int setnonblocking(int fd) { @@ -91,17 +92,17 @@ char *gw_strend(register const char *s) { return (char*) (s-1); } -/////////////////////////////// -// generate a random char -////////////////////////////// +/***************************************** +* generate a random char +*****************************************/ static char gw_randomchar() { return (char)((rand() % 78) + 30); } -///////////////////////////////// -// generate a random string -// output must be pre allocated -///////////////////////////////// +/***************************************** + * generate a random string + * output must be pre allocated +*****************************************/ int gw_generate_random_str(char *output, int len) { int i; @@ -116,10 +117,10 @@ int gw_generate_random_str(char *output, int len) { return 0; } -///////////////////////////////// -// hex string to binary data -// output must be pre allocated -///////////////////////////////// +/***************************************** + * hex string to binary data + * output must be pre allocated +*****************************************/ int gw_hex2bin(uint8_t *out, const char *in, unsigned int len) { const char *in_end= in + len; @@ -140,10 +141,10 @@ int gw_hex2bin(uint8_t *out, const char *in, unsigned int len) { return 0; } -///////////////////////////////// -// binary data to hex string -// output must be pre allocated -///////////////////////////////// +/***************************************** + * binary data to hex string + * output must be pre allocated +*****************************************/ char *gw_bin2hex(char *out, const uint8_t *in, unsigned int len) { const uint8_t *in_end= in + len; if (len == 0 || in == NULL) { @@ -159,12 +160,12 @@ char *gw_bin2hex(char *out, const uint8_t *in, unsigned int len) { return out; } -/////////////////////////////////////////////////////// -// fill a preallocated buffer with XOR(str1, str2) -// XOR between 2 equal len strings -// note that XOR(str1, XOR(str1 CONCAT str2)) == str2 -// and that XOR(str1, str2) == XOR(str2, str1) -/////////////////////////////////////////////////////// +/**************************************************** + * fill a preallocated buffer with XOR(str1, str2) + * XOR between 2 equal len strings + * note that XOR(str1, XOR(str1 CONCAT str2)) == str2 + * and that XOR(str1, str2) == XOR(str2, str1) +*****************************************************/ void gw_str_xor(uint8_t *output, const uint8_t *input1, const uint8_t *input2, unsigned int len) { const uint8_t *input1_end = NULL; input1_end = input1 + len; @@ -175,10 +176,10 @@ void gw_str_xor(uint8_t *output, const uint8_t *input1, const uint8_t *input2, u *output = '\0'; } -///////////////////////////////////////////////////////////// -// fill a 20 bytes preallocated with SHA1 digest (160 bits) -// for one input on in_len bytes -///////////////////////////////////////////////////////////// +/********************************************************** + * fill a 20 bytes preallocated with SHA1 digest (160 bits) + * for one input on in_len bytes +**********************************************************/ void gw_sha1_str(const uint8_t *in, int in_len, uint8_t *out) { unsigned char hash[SHA_DIGEST_LENGTH]; @@ -186,10 +187,10 @@ void gw_sha1_str(const uint8_t *in, int in_len, uint8_t *out) { memcpy(out, hash, SHA_DIGEST_LENGTH); } -///////////////////////////////////////////////////////////// -// fill 20 bytes preallocated with SHA1 digest (160 bits) -// for two inputs, in_len and in2_len bytes -///////////////////////////////////////////////////////////// +/******************************************************** + * fill 20 bytes preallocated with SHA1 digest (160 bits) + * for two inputs, in_len and in2_len bytes +********************************************************/ void gw_sha1_2_str(const uint8_t *in, int in_len, const uint8_t *in2, int in2_len, uint8_t *out) { SHA_CTX context; unsigned char hash[SHA_DIGEST_LENGTH]; diff --git a/server/include/adminusers.h b/server/include/adminusers.h index 07afa5390..4cc560e41 100644 --- a/server/include/adminusers.h +++ b/server/include/adminusers.h @@ -1,7 +1,7 @@ #ifndef _ADMINUSERS_H #define _ADMINUSERS_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/atomic.h b/server/include/atomic.h index 7fea0926e..f139d15d5 100644 --- a/server/include/atomic.h +++ b/server/include/atomic.h @@ -1,7 +1,7 @@ #ifndef _ATOMIC_H #define _ATOMIC_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/buffer.h b/server/include/buffer.h index eefdd431d..76eebe63d 100644 --- a/server/include/buffer.h +++ b/server/include/buffer.h @@ -1,7 +1,7 @@ #ifndef _BUFFER_H #define _BUFFER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -40,6 +40,9 @@ * 16/07/2013 Massimiliano Pinto Added command type for the queue * 10/07/2014 Mark Riddoch Addition of hints * 15/07/2014 Mark Riddoch Added buffer properties + * 03/10/2014 Martin Brampton Pointer arithmetic standard conformity + * Add more buffer handling macros + * Add gwbuf_rtrim (handle chains) * * @endverbatim */ @@ -47,6 +50,7 @@ #include #include #include +#include EXTERN_C_BLOCK_BEGIN @@ -146,19 +150,25 @@ typedef struct gwbuf { /*< * Macros to access the data in the buffers */ -/*< First valid, uncomsumed byte in the buffer */ +/*< First valid, unconsumed byte in the buffer */ #define GWBUF_DATA(b) ((b)->start) /*< Number of bytes in the individual buffer */ -#define GWBUF_LENGTH(b) ((b)->end - (b)->start) +#define GWBUF_LENGTH(b) ((char *)(b)->end - (char *)(b)->start) + +/*< Return the byte at offset byte from the start of the unconsumed portion of the buffer */ +#define GWBUF_DATA_CHAR(b, byte) (GWBUF_LENGTH(b) < ((byte)+1) ? -1 : *(((char *)(b)->start)+4)) + +/*< Check that the data in a buffer has the SQL marker*/ +#define GWBUF_IS_SQL(b) (0x03 == GWBUF_DATA_CHAR(b,4)) /*< True if all bytes in the buffer have been consumed */ -#define GWBUF_EMPTY(b) ((b)->start == (b)->end) +#define GWBUF_EMPTY(b) ((char *)(b)->start >= (char *)(b)->end) /*< Consume a number of bytes in the buffer */ -#define GWBUF_CONSUME(b, bytes) (b)->start += (bytes) +#define GWBUF_CONSUME(b, bytes) ((b)->start = bytes > ((char *)(b)->end - (char *)(b)->start) ? (b)->end : (void *)((char *)(b)->start + (bytes))); -#define GWBUF_RTRIM(b, bytes) (b)->end -= (bytes) +#define GWBUF_RTRIM(b, bytes) ((b)->end = bytes > ((char *)(b)->end - (char *)(b)->start) ? (b)->start : (void *)((char *)(b)->end - (bytes))); #define GWBUF_TYPE(b) (b)->gwbuf_type /*< @@ -170,6 +180,7 @@ extern GWBUF *gwbuf_clone(GWBUF *buf); extern GWBUF *gwbuf_append(GWBUF *head, GWBUF *tail); extern GWBUF *gwbuf_consume(GWBUF *head, unsigned int length); extern GWBUF *gwbuf_trim(GWBUF *head, unsigned int length); +extern GWBUF *gwbuf_rtrim(GWBUF *head, unsigned int length); extern unsigned int gwbuf_length(GWBUF *head); extern GWBUF *gwbuf_clone_portion(GWBUF *head, size_t offset, size_t len); extern GWBUF *gwbuf_clone_transform(GWBUF *head, gwbuf_type_t type); diff --git a/server/include/config.h b/server/include/config.h index 659fb6378..0582bc50e 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -1,7 +1,7 @@ #ifndef _CONFIG_H #define _CONFIG_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/server/include/dbusers.h b/server/include/dbusers.h index 3b0afe50b..f9f4a50ab 100644 --- a/server/include/dbusers.h +++ b/server/include/dbusers.h @@ -1,7 +1,7 @@ #ifndef _DBUSERS_H #define _DBUSERS_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/server/include/dcb.h b/server/include/dcb.h index 06687f349..c455fcbb8 100644 --- a/server/include/dcb.h +++ b/server/include/dcb.h @@ -1,7 +1,7 @@ #ifndef _DCB_H #define _DCB_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include @@ -53,7 +53,8 @@ struct service; * 07/02/2014 Massimiliano Pinto Added ipv4 data struct into for dcb * 07/05/2014 Mark Riddoch Addition of callback mechanism * 08/05/2014 Mark Riddoch Addition of writeq high and low watermarks - * 27/08/2014 Mark Ridddoch Addition of write event queuing + * 27/08/2014 Mark Riddoch Addition of write event queuing + * 23/09/2014 Mark Riddoch New poll processing queue * * @endverbatim */ @@ -65,7 +66,7 @@ struct dcb; * The operations that can be performed on the descriptor * * read EPOLLIN handler for the socket - * write Gateway data write entry point + * write MaxScale data write entry point * write_ready EPOLLOUT handler for the socket, indicates * that the socket is ready to send more data * error EPOLLERR handler for the socket @@ -73,7 +74,7 @@ struct dcb; * accept Accept handler for listener socket only * connect Create a connection to the specified server * for the session pased in - * close Gateway close entry point for the socket + * close MaxScale close entry point for the socket * listen Create a listener for the protocol * auth Authentication entry point * session Session handling entry point @@ -97,6 +98,14 @@ typedef struct gw_protocol { int (*session)(struct dcb *, void *); } GWPROTOCOL; +typedef struct { + struct dcb *next; + struct dcb *prev; + uint32_t pending_events; + int processing; + SPINLOCK eventqlock; +} DCBEVENTQ; + /** * The GWPROTOCOL version data. The following should be updated whenever * the GWPROTOCOL structure is changed. See the rules defined in modinfo.h @@ -114,10 +123,6 @@ typedef struct dcbstats { int n_buffered; /*< Number of buffered writes */ int n_high_water; /*< Number of crosses of high water mark */ int n_low_water; /*< Number of crosses of low water mark */ - int n_busypolls; /*< Number of read polls whiel reading */ - int n_readrechecks; /*< Number of rechecks for reads */ - int n_busywrpolls; /*< Number of write polls while writing */ - int n_writerechecks;/*< Number of rechecks for writes */ } DCBSTATS; /** @@ -204,12 +209,7 @@ typedef struct dcb { #endif dcb_role_t dcb_role; SPINLOCK dcb_initlock; -#if 1 - simple_mutex_t dcb_read_lock; - simple_mutex_t dcb_write_lock; - bool dcb_read_active; - bool dcb_write_active; -#endif + DCBEVENTQ evq; /**< The event queue for this DCB */ int fd; /**< The descriptor */ dcb_state_t state; /**< Current descriptor state */ int flags; /**< DCB flags */ @@ -271,8 +271,8 @@ int fail_accept_errno; #define DCB_BELOW_LOW_WATER(x) ((x)->low_water && (x)->writeqlen < (x)->low_water) #define DCB_ABOVE_HIGH_WATER(x) ((x)->high_water && (x)->writeqlen > (x)->high_water) -void dcb_pollin(DCB *, int, int); -void dcb_pollout(DCB *, int, int); +#define DCB_POLL_BUSY(x) ((x)->evq.next != NULL) + DCB *dcb_get_zombies(void); int gw_write( #if defined(SS_DEBUG) @@ -289,7 +289,7 @@ DCB *dcb_clone(DCB *); int dcb_read(DCB *, GWBUF **); int dcb_drain_writeq(DCB *); void dcb_close(DCB *); -DCB *dcb_process_zombies(int, DCB*); /* Process Zombies except the one behind the pointer */ +DCB *dcb_process_zombies(int); /* Process Zombies except the one behind the pointer */ void printAllDCBs(); /* Debug to print all DCB in the system */ void printDCB(DCB *); /* Debug print routine */ void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */ diff --git a/server/include/filter.h b/server/include/filter.h index 3076587e6..ad0b9a21a 100644 --- a/server/include/filter.h +++ b/server/include/filter.h @@ -1,7 +1,7 @@ #ifndef _FILTER_H #define _FILTER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/include/gw.h b/server/include/gw.h index 822884f9b..14adfb1a0 100644 --- a/server/include/gw.h +++ b/server/include/gw.h @@ -28,10 +28,10 @@ * Configuration for send and receive socket buffer sizes for * backend and cleint connections. */ -#define GW_BACKEND_SO_SNDBUF 32768 -#define GW_BACKEND_SO_RCVBUF 32768 -#define GW_CLIENT_SO_SNDBUF 32768 -#define GW_CLIENT_SO_RCVBUF 32768 +#define GW_BACKEND_SO_SNDBUF (128 * 1024) +#define GW_BACKEND_SO_RCVBUF (128 * 1024) +#define GW_CLIENT_SO_SNDBUF (128 * 1024) +#define GW_CLIENT_SO_RCVBUF (128 * 1024) #define GW_NOINTR_CALL(A) do { errno = 0; A; } while (errno == EINTR) #define GW_MYSQL_LOOP_TIMEOUT 300000000 diff --git a/server/include/gwbitmask.h b/server/include/gwbitmask.h index 6b3b6b622..87f1a8b98 100644 --- a/server/include/gwbitmask.h +++ b/server/include/gwbitmask.h @@ -1,7 +1,7 @@ #ifndef _GWBITMASK_H #define _GWBITMASK_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/server/include/hashtable.h b/server/include/hashtable.h index 175bd5d32..07c7d0950 100644 --- a/server/include/hashtable.h +++ b/server/include/hashtable.h @@ -1,7 +1,7 @@ #ifndef _HASTABLE_H #define _HASTABLE_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/hint.h b/server/include/hint.h index 03c319142..4cc687731 100644 --- a/server/include/hint.h +++ b/server/include/hint.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/include/housekeeper.h b/server/include/housekeeper.h index 597f19a91..14523747d 100644 --- a/server/include/housekeeper.h +++ b/server/include/housekeeper.h @@ -1,7 +1,7 @@ #ifndef _HOUSEKEEPER_H #define _HOUSEKEEPER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include @@ -47,4 +47,5 @@ typedef struct hktask { extern void hkinit(); extern int hktask_add(char *name, void (*task)(void *), void *data, int frequency); extern int hktask_remove(char *name); +extern void hkshutdown(); #endif diff --git a/server/include/maxscale.h b/server/include/maxscale.h index 4fb5dd75f..521c42dd9 100644 --- a/server/include/maxscale.h +++ b/server/include/maxscale.h @@ -1,7 +1,7 @@ #ifndef _MAXSCALE_H #define _MAXSCALE_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/include/modinfo.h b/server/include/modinfo.h index bc4107b39..759cea0fb 100644 --- a/server/include/modinfo.h +++ b/server/include/modinfo.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/include/modules.h b/server/include/modules.h index 199e3a24b..904e6cc7a 100644 --- a/server/include/modules.h +++ b/server/include/modules.h @@ -1,7 +1,7 @@ #ifndef _MODULES_H #define _MODULES_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/include/modutil.h b/server/include/modutil.h index a0624752a..3935e8e80 100644 --- a/server/include/modutil.h +++ b/server/include/modutil.h @@ -1,7 +1,7 @@ #ifndef _MODUTIL_H #define _MODUTIL_H /* - * This file is distributed as part of MaxScale from SkySQL. It is free + * This file is distributed as part of MaxScale from MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/include/monitor.h b/server/include/monitor.h index 04337d761..6123cd614 100644 --- a/server/include/monitor.h +++ b/server/include/monitor.h @@ -1,7 +1,7 @@ #ifndef _MONITOR_H #define _MONITOR_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/include/poll.h b/server/include/poll.h index 6524f1bbb..0e4fa08c9 100644 --- a/server/include/poll.h +++ b/server/include/poll.h @@ -1,7 +1,7 @@ #ifndef _POLL_H #define _POLL_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/include/rdtsc.h b/server/include/rdtsc.h new file mode 100644 index 000000000..b221417b7 --- /dev/null +++ b/server/include/rdtsc.h @@ -0,0 +1,61 @@ +#ifndef _RDTSC_H +#define _RDTSC_H +/* + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright MariaDB Corporation Ab 2014 + */ + +/** + * @file rdtsc.h Access the process time-stamp counter + * + * This is an Intel only facilty that is used to access an accurate time + * value, the granularity of which is related to the processor clock speed + * and the overhead for access is much lower than using any system call + * mechanism. + * + * + * @verbatim + * Revision History + * + * Date Who Description + * 19/09/2014 Mark Riddoch Initial implementation + * + * @endverbatim + */ + +typedef unsigned long long CYCLES; + +/** + * Get the current time-stamp counter value from the processor. This is the + * count of CPU cyceles as a 64 bit value. + * + * The value returned is related to the clock speed, to obtian a value in + * seconds divide the returned value by the clock frequency for the processor. + * + * Note, on multi-processsor systems care much be taken to avoid the thread + * moving to a different processor when taken succsive value of RDTSC to + * obtian accurate timing. This may be done by setting pocessor affinity for + * the thread. See sched_setaffinity/sched_getaffinity. + * + * @return CPU cycle count + */ +static __inline__ CYCLES rdtsc(void) +{ + unsigned long long int x; + __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); + return x; +} +#endif diff --git a/server/include/router.h b/server/include/router.h index 6c29fe1bf..c3401c43a 100644 --- a/server/include/router.h +++ b/server/include/router.h @@ -1,7 +1,7 @@ #ifndef _ROUTER_H #define _ROUTER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/secrets.h b/server/include/secrets.h index 0325d75ae..505e79154 100644 --- a/server/include/secrets.h +++ b/server/include/secrets.h @@ -1,7 +1,7 @@ #ifndef _SECRETS_H #define _SECRETS_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/server.h b/server/include/server.h index f6d146ccd..b8ca445f0 100644 --- a/server/include/server.h +++ b/server/include/server.h @@ -1,7 +1,7 @@ #ifndef _SERVER_H #define _SERVER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/server/include/service.h b/server/include/service.h index 139a08056..659e422aa 100644 --- a/server/include/service.h +++ b/server/include/service.h @@ -1,7 +1,7 @@ #ifndef _SERVICE_H #define _SERVICE_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include @@ -142,7 +142,7 @@ typedef enum count_spec_t {COUNT_NONE=0, COUNT_ATLEAST, COUNT_EXACT, COUNT_ATMOS #define SERVICE_STATE_ALLOC 1 /**< The service has been allocated */ #define SERVICE_STATE_STARTED 2 /**< The service has been started */ -extern SERVICE *service_alloc(char *, char *); +extern SERVICE *service_alloc(const char *, const char *); extern int service_free(SERVICE *); extern SERVICE *service_find(char *); extern int service_isvalid(SERVICE *); diff --git a/server/include/session.h b/server/include/session.h index cbd43fe40..86de23782 100644 --- a/server/include/session.h +++ b/server/include/session.h @@ -1,7 +1,7 @@ #ifndef _SESSION_H #define _SESSION_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/spinlock.h b/server/include/spinlock.h index e5f938815..47677119e 100644 --- a/server/include/spinlock.h +++ b/server/include/spinlock.h @@ -1,7 +1,7 @@ #ifndef _SPINLOCK_H #define _SPINLOCK_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/include/thread.h b/server/include/thread.h index e3ea6f0dc..9d391b9d7 100644 --- a/server/include/thread.h +++ b/server/include/thread.h @@ -1,7 +1,7 @@ #ifndef _THREAD_H #define _THREAD_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include diff --git a/server/include/users.h b/server/include/users.h index ffa091e3b..cf0bca17f 100644 --- a/server/include/users.h +++ b/server/include/users.h @@ -1,7 +1,7 @@ #ifndef _USERS_H #define _USERS_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/include/version.h.in b/server/include/version.h.in new file mode 100644 index 000000000..5aced69a5 --- /dev/null +++ b/server/include/version.h.in @@ -0,0 +1 @@ +#define MAXSCALE_VERSION "@MAXSCALE_VERSION@" diff --git a/server/inih/CMakeLists.txt b/server/inih/CMakeLists.txt new file mode 100644 index 000000000..24393e05d --- /dev/null +++ b/server/inih/CMakeLists.txt @@ -0,0 +1 @@ +add_library(inih ini.c) \ No newline at end of file diff --git a/server/modules/CMakeLists.txt b/server/modules/CMakeLists.txt new file mode 100644 index 000000000..f2d746ded --- /dev/null +++ b/server/modules/CMakeLists.txt @@ -0,0 +1,5 @@ +include_directories(monitor) +add_subdirectory(routing) +add_subdirectory(protocol) +add_subdirectory(monitor) +add_subdirectory(filter) \ No newline at end of file diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt new file mode 100644 index 000000000..f9dea236d --- /dev/null +++ b/server/modules/filter/CMakeLists.txt @@ -0,0 +1,27 @@ +if(BUILD_RABBITMQ) + add_library(mqfilter SHARED mqfilter.c) + target_link_libraries(mqfilter query_classifier log_manager utils rabbitmq) + install(TARGETS mqfilter DESTINATION modules) +endif() + +add_library(regexfilter SHARED regexfilter.c) +target_link_libraries(regexfilter log_manager utils) +install(TARGETS regexfilter DESTINATION modules) + +add_library(testfilter SHARED testfilter.c) +target_link_libraries(testfilter log_manager utils) +install(TARGETS testfilter DESTINATION modules) + +add_library(qlafilter SHARED qlafilter.c) +target_link_libraries(qlafilter log_manager utils) +install(TARGETS qlafilter DESTINATION modules) + +add_library(tee SHARED tee.c) +target_link_libraries(tee log_manager utils) +install(TARGETS tee DESTINATION modules) + +add_library(topfilter SHARED topfilter.c) +target_link_libraries(topfilter log_manager utils) +install(TARGETS topfilter DESTINATION modules) + +add_subdirectory(hint) \ No newline at end of file diff --git a/server/modules/filter/Makefile b/server/modules/filter/Makefile index c52c8a8fa..284c7b2dc 100644 --- a/server/modules/filter/Makefile +++ b/server/modules/filter/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of MaxScale form SkySQL. It is free +# This file is distributed as part of MaxScale form MariaDB Corporation. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2014 +# Copyright MariaDB Corporation Ab 2014 # # Revision History # Date Who Description diff --git a/server/modules/filter/hint/CMakeLists.txt b/server/modules/filter/hint/CMakeLists.txt new file mode 100644 index 000000000..f47cb637e --- /dev/null +++ b/server/modules/filter/hint/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(hintfilter SHARED hintfilter.c hintparser.c) +set_target_properties(hintfilter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) +target_link_libraries(hintfilter ssl log_manager utils) +install(TARGETS hintfilter DESTINATION modules) \ No newline at end of file diff --git a/server/modules/filter/hint/Makefile b/server/modules/filter/hint/Makefile index 4f2194739..202034b9c 100644 --- a/server/modules/filter/hint/Makefile +++ b/server/modules/filter/hint/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of MaxScale form SkySQL. It is free +# This file is distributed as part of MaxScale form MariaDB Corporation. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2014 +# Copyright MariaDB Corporation Ab 2014 # # Revision History # Date Who Description diff --git a/server/modules/filter/hint/hintfilter.c b/server/modules/filter/hint/hintfilter.c index e54319d5d..67c9f7f28 100644 --- a/server/modules/filter/hint/hintfilter.c +++ b/server/modules/filter/hint/hintfilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/modules/filter/hint/hintparser.c b/server/modules/filter/hint/hintparser.c index 77d9c98ec..a70e42fe2 100644 --- a/server/modules/filter/hint/hintparser.c +++ b/server/modules/filter/hint/hintparser.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/modules/filter/mqfilter.c b/server/modules/filter/mqfilter.c index 9761fa777..e6a6c12b1 100644 --- a/server/modules/filter/mqfilter.c +++ b/server/modules/filter/mqfilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/filter/qlafilter.c b/server/modules/filter/qlafilter.c index b3accfbf8..1367b685b 100644 --- a/server/modules/filter/qlafilter.c +++ b/server/modules/filter/qlafilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/filter/regexfilter.c b/server/modules/filter/regexfilter.c index 79cf70c09..fd2bbbf8a 100644 --- a/server/modules/filter/regexfilter.c +++ b/server/modules/filter/regexfilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/modules/filter/tee.c b/server/modules/filter/tee.c index 2d164ad42..e87e95f95 100644 --- a/server/modules/filter/tee.c +++ b/server/modules/filter/tee.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/filter/testfilter.c b/server/modules/filter/testfilter.c index 289ccf4a2..8f0c0f573 100644 --- a/server/modules/filter/testfilter.c +++ b/server/modules/filter/testfilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/modules/filter/topfilter.c b/server/modules/filter/topfilter.c index 9ca281ef1..4673cd2b8 100644 --- a/server/modules/filter/topfilter.c +++ b/server/modules/filter/topfilter.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of MaxScale by SkySQL. It is free + * This file is distributed as part of MaxScale by MariaDB Corporation. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index f493ec715..70be1f579 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -43,8 +43,8 @@ * High and Low water marks for the slave dcb. These values can be overriden * by the router options highwater and lowwater. */ -#define DEF_LOW_WATER 20000 -#define DEF_HIGH_WATER 300000 +#define DEF_LOW_WATER 2000 +#define DEF_HIGH_WATER 30000 /** * Some useful macros for examining the MySQL Response packets @@ -194,6 +194,7 @@ typedef struct router_instance { char *uuid; /*< UUID for the router to use w/master */ int masterid; /*< Server ID of the master */ int serverid; /*< Server ID to use with master */ + int initbinlog; /*< Initial binlog file number */ char *user; /*< User name to use with master */ char *password; /*< Password to use with master */ char *fileroot; /*< Root of binlog filename */ diff --git a/server/modules/include/debugcli.h b/server/modules/include/debugcli.h index b373cae6b..0f01da519 100644 --- a/server/modules/include/debugcli.h +++ b/server/modules/include/debugcli.h @@ -1,7 +1,7 @@ #ifndef _DEBUGCLI_H #define _DEBUGCLI_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/modules/include/httpd.h b/server/modules/include/httpd.h index 0d5e65604..0f9cbb7ad 100644 --- a/server/modules/include/httpd.h +++ b/server/modules/include/httpd.h @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /* diff --git a/server/modules/include/maxscaled.h b/server/modules/include/maxscaled.h index 3733772d8..01a3da227 100644 --- a/server/modules/include/maxscaled.h +++ b/server/modules/include/maxscaled.h @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -30,13 +30,15 @@ * @endverbatim */ #include +#include /** * The telnetd specific protocol structure to put in the DCB. */ typedef struct maxscaled { - int state; /**< The connection state */ - char *username; /**< The login name of the user */ + SPINLOCK lock; /**< Protocol structure lock */ + int state; /**< The connection state */ + char *username; /**< The login name of the user */ } MAXSCALED; #define MAXSCALED_STATE_LOGIN 1 /**< Issued login prompt */ diff --git a/server/modules/include/mysql_client_server_protocol.h b/server/modules/include/mysql_client_server_protocol.h index 18771aecd..15817527e 100644 --- a/server/modules/include/mysql_client_server_protocol.h +++ b/server/modules/include/mysql_client_server_protocol.h @@ -1,7 +1,7 @@ #ifndef _MYSQL_PROTOCOL_H #define _MYSQL_PROTOCOL_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /* diff --git a/server/modules/include/mysqlhint.h b/server/modules/include/mysqlhint.h index 3e936b847..f9561c5c0 100644 --- a/server/modules/include/mysqlhint.h +++ b/server/modules/include/mysqlhint.h @@ -1,7 +1,7 @@ #ifndef _MYSQLHINT_H #define _MYSQLHINT_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /* diff --git a/server/modules/include/readconnection.h b/server/modules/include/readconnection.h index 589296302..45eb2b51d 100644 --- a/server/modules/include/readconnection.h +++ b/server/modules/include/readconnection.h @@ -1,7 +1,7 @@ #ifndef _READCONNECTION_H #define _READCONNECTION_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/modules/include/readwritesplit.h b/server/modules/include/readwritesplit.h index 5b17dbc7d..46c3a2b16 100644 --- a/server/modules/include/readwritesplit.h +++ b/server/modules/include/readwritesplit.h @@ -1,7 +1,7 @@ #ifndef _RWSPLITROUTER_H #define _RWSPLITROUTER_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -224,6 +224,7 @@ typedef struct backend_ref_st { bref_state_t bref_state; int bref_num_result_wait; sescmd_cursor_t bref_sescmd_cur; + GWBUF* bref_pending_cmd; /*< For stmt which can't be routed due active sescmd execution */ #if defined(SS_DEBUG) skygw_chk_t bref_chk_tail; #endif diff --git a/server/modules/include/telnetd.h b/server/modules/include/telnetd.h index 2c1bcf32a..c427c2e8b 100644 --- a/server/modules/include/telnetd.h +++ b/server/modules/include/telnetd.h @@ -1,7 +1,7 @@ #ifndef _TELNETD_H #define _TELNETD_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/modules/monitor/CMakeLists.txt b/server/modules/monitor/CMakeLists.txt new file mode 100644 index 000000000..ac765e98d --- /dev/null +++ b/server/modules/monitor/CMakeLists.txt @@ -0,0 +1,11 @@ +add_library(mysqlmon SHARED mysql_mon.c) +target_link_libraries(mysqlmon log_manager utils) +install(TARGETS mysqlmon DESTINATION modules) + +add_library(galeramon SHARED galera_mon.c) +target_link_libraries(galeramon log_manager utils) +install(TARGETS galeramon DESTINATION modules) + +add_library(ndbclustermon SHARED ndbcluster_mon.c) +target_link_libraries(ndbclustermon log_manager utils) +install(TARGETS ndbclustermon DESTINATION modules) diff --git a/server/modules/monitor/Makefile b/server/modules/monitor/Makefile index 0f3bc5867..f178536d8 100644 --- a/server/modules/monitor/Makefile +++ b/server/modules/monitor/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index d2ad38264..02a646aa2 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -447,13 +447,20 @@ size_t nrounds = 0; } /** Wait base interval */ thread_millisleep(MON_BASE_INTERVAL_MS); - nrounds += 1; - - /** If monitor interval time isn't consumed skip checks */ - if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0) + /** + * Calculate how far away the monitor interval is from its full + * cycle and if monitor interval time further than the base + * interval, then skip monitoring checks. Excluding the first + * round. + */ + if (nrounds != 0 && + ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval) > + MON_BASE_INTERVAL_MS) { + nrounds += 1; continue; } + nrounds += 1; master_id = -1; ptr = handle->databases; diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index d7e0b34bd..7dd237ac2 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -611,13 +611,20 @@ size_t nrounds = 0; } /** Wait base interval */ thread_millisleep(MON_BASE_INTERVAL_MS); - nrounds += 1; - - /** If monitor interval time isn't consumed skip checks */ - if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0) + /** + * Calculate how far away the monitor interval is from its full + * cycle and if monitor interval time further than the base + * interval, then skip monitoring checks. Excluding the first + * round. + */ + if (nrounds != 0 && + ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval) > + MON_BASE_INTERVAL_MS) { + nrounds += 1; continue; } + nrounds += 1; /* reset num_servers */ num_servers = 0; diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index eb2d37bcd..018d695ff 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -1,7 +1,7 @@ #ifndef _MYSQLMON_H #define _MYSQLMON_H /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -15,7 +15,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/modules/monitor/ndbcluster_mon.c b/server/modules/monitor/ndbcluster_mon.c index 2e009e000..1997f274e 100644 --- a/server/modules/monitor/ndbcluster_mon.c +++ b/server/modules/monitor/ndbcluster_mon.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -445,13 +445,20 @@ size_t nrounds = 0; /** Wait base interval */ thread_millisleep(MON_BASE_INTERVAL_MS); - nrounds += 1; - - /** If monitor interval time isn't consumed skip checks */ - if ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval != 0) + /** + * Calculate how far away the monitor interval is from its full + * cycle and if monitor interval time further than the base + * interval, then skip monitoring checks. Excluding the first + * round. + */ + if (nrounds != 0 && + ((nrounds*MON_BASE_INTERVAL_MS)%handle->interval) > + MON_BASE_INTERVAL_MS) { + nrounds += 1; continue; } + nrounds += 1; master_id = -1; ptr = handle->databases; diff --git a/server/modules/protocol/CMakeLists.txt b/server/modules/protocol/CMakeLists.txt new file mode 100644 index 000000000..e51ff1495 --- /dev/null +++ b/server/modules/protocol/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library(MySQLClient SHARED mysql_client.c mysql_common.c) +target_link_libraries(MySQLClient log_manager utils) +install(TARGETS MySQLClient DESTINATION modules) + +add_library(MySQLBackend SHARED mysql_backend.c mysql_common.c) +target_link_libraries(MySQLBackend log_manager utils) +install(TARGETS MySQLBackend DESTINATION modules) + +add_library(telnetd SHARED telnetd.c) +target_link_libraries(telnetd log_manager utils) +install(TARGETS telnetd DESTINATION modules) + +add_library(HTTPD SHARED httpd.c) +target_link_libraries(HTTPD log_manager utils) +install(TARGETS HTTPD DESTINATION modules) + +add_library(maxscaled SHARED maxscaled.c) +target_link_libraries(maxscaled log_manager utils) +install(TARGETS maxscaled DESTINATION modules) + + + + + diff --git a/server/modules/protocol/Makefile b/server/modules/protocol/Makefile index 0b41d329e..8f6201e3e 100644 --- a/server/modules/protocol/Makefile +++ b/server/modules/protocol/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description diff --git a/server/modules/protocol/httpd.c b/server/modules/protocol/httpd.c index 7db1366ad..9729fb99d 100644 --- a/server/modules/protocol/httpd.c +++ b/server/modules/protocol/httpd.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -49,7 +49,7 @@ MODULE_INFO info = { }; #define ISspace(x) isspace((int)(x)) -#define HTTP_SERVER_STRING "Gateway(c) v.1.0.0" +#define HTTP_SERVER_STRING "MaxScale(c) v.1.0.0" static char *version_str = "V1.0.1"; static int httpd_read_event(DCB* dcb); @@ -233,7 +233,7 @@ HTTPD_session *client_data = NULL; * */ - dcb_printf(dcb, "Welcome to HTTPD Gateway (c) %s\n\n", version_str); + dcb_printf(dcb, "Welcome to HTTPD MaxScale (c) %s\n\n", version_str); if (strcmp(url, "/show") == 0) { if (strlen(query_string)) { diff --git a/server/modules/protocol/maxscaled.c b/server/modules/protocol/maxscaled.c index f580764f8..ebd67636d 100644 --- a/server/modules/protocol/maxscaled.c +++ b/server/modules/protocol/maxscaled.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include @@ -166,7 +166,6 @@ char *password; { dcb_printf(dcb, "FAILED"); maxscaled->state = MAXSCALED_STATE_LOGIN; - free(maxscaled->username); } gwbuf_consume(head, GWBUF_LENGTH(head)); free(password); @@ -276,16 +275,18 @@ int n_connect = 0; client_dcb->fd = so; client_dcb->remote = strdup(inet_ntoa(addr.sin_addr)); memcpy(&client_dcb->func, &MyObject, sizeof(GWPROTOCOL)); - client_dcb->session = - session_alloc(dcb->session->service, client_dcb); - maxscaled_pr = (MAXSCALED *)malloc(sizeof(MAXSCALED)); - client_dcb->protocol = (void *)maxscaled_pr; - - if (maxscaled_pr == NULL) - { + if ((maxscaled_pr = (MAXSCALED *)malloc(sizeof(MAXSCALED))) == NULL) + { + client_dcb->protocol = NULL; dcb_add_to_zombieslist(client_dcb); return n_connect; } + maxscaled_pr->username = NULL; + spinlock_init(&maxscaled_pr->lock); + client_dcb->protocol = (void *)maxscaled_pr; + + client_dcb->session = + session_alloc(dcb->session->service, client_dcb); if (poll_add_dcb(client_dcb) == -1) { @@ -294,7 +295,6 @@ int n_connect = 0; } n_connect++; maxscaled_pr->state = MAXSCALED_STATE_LOGIN; - maxscaled_pr->username = NULL; dcb_printf(client_dcb, "USER"); } } @@ -313,11 +313,16 @@ maxscaled_close(DCB *dcb) { MAXSCALED *maxscaled = dcb->protocol; - if (maxscaled && maxscaled->username) + if (!maxscaled) + return 0; + + spinlock_acquire(&maxscaled->lock); + if (maxscaled->username) { free(maxscaled->username); maxscaled->username = NULL; } + spinlock_release(&maxscaled->lock); return 0; } diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index 2772e8e7b..da1f73f4f 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include "mysql_client_server_protocol.h" @@ -27,7 +27,7 @@ * Revision History * Date Who Description * 14/06/2013 Mark Riddoch Initial version - * 17/06/2013 Massimiliano Pinto Added Gateway To Backends routines + * 17/06/2013 Massimiliano Pinto Added MaxScale To Backends routines * 27/06/2013 Vilho Raatikka Added skygw_log_write command as an example * and necessary headers. * 01/07/2013 Massimiliano Pinto Put Log Manager example code behind SS_DEBUG macros. diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index bace1eef5..b1559b94b 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -25,7 +25,7 @@ * Revision History * Date Who Description * 14/06/2013 Mark Riddoch Initial version - * 17/06/2013 Massimiliano Pinto Added Client To Gateway routines + * 17/06/2013 Massimiliano Pinto Added Client To MaxScale routines * 24/06/2013 Massimiliano Pinto Added: fetch passwords from service users' hashtable * 02/09/2013 Massimiliano Pinto Added: session refcount * 16/12/2013 Massimiliano Pinto Added: client closed socket detection with recv(..., MSG_PEEK) @@ -494,7 +494,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) { } /** - * Write function for client DCB: writes data from Gateway to Client + * Write function for client DCB: writes data from MaxScale to Client * * @param dcb The DCB of the client * @param queue Queue of buffers to write @@ -1180,9 +1180,9 @@ int gw_MySQLAccept(DCB *listener) conn_open[c_sock] = true; #endif /* set nonblocking */ - sendbuf = GW_BACKEND_SO_SNDBUF; + sendbuf = GW_CLIENT_SO_SNDBUF; setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen); - sendbuf = GW_BACKEND_SO_RCVBUF; + sendbuf = GW_CLIENT_SO_RCVBUF; setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen); setnonblocking(c_sock); diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index 78e82cb86..17a04a77b 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /* @@ -766,9 +766,9 @@ int gw_do_connect_to_backend( /* prepare for connect */ setipaddress(&serv_addr.sin_addr, host); serv_addr.sin_port = htons(port); - bufsize = GW_CLIENT_SO_SNDBUF; + bufsize = GW_BACKEND_SO_SNDBUF; setsockopt(so, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)); - bufsize = GW_CLIENT_SO_RCVBUF; + bufsize = GW_BACKEND_SO_RCVBUF; setsockopt(so, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize)); /* set socket to as non-blocking here */ setnonblocking(so); @@ -1313,7 +1313,7 @@ int gw_check_mysql_scramble_data(DCB *dcb, uint8_t *token, unsigned int token_le /** * gw_find_mysql_user_password_sha1 * - * The routine fetches look for an user int he Gateway users' table + * The routine fetches look for an user int he MaxScale users' table * The users' table is dcb->service->users or a different one specified with void *repository * * If found the HEX password, representing sha1(sha1(password)), is converted in binary data and @@ -1642,6 +1642,8 @@ void protocol_archive_srv_command( server_command_t* h1; int len = 0; + CHK_PROTOCOL(p); + spinlock_acquire(&p->protocol_lock); if (p->protocol_state != MYSQL_PROTOCOL_ACTIVE) @@ -1651,9 +1653,11 @@ void protocol_archive_srv_command( s1 = &p->protocol_command; - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, - "Move command %s from fd %d to command history.", + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [protocol_archive_srv_command] Move command %s from fd %d " + "to command history.", + pthread_self(), STRPACKETTYPE(s1->scom_cmd), p->owner_dcb->fd))); @@ -1692,6 +1696,7 @@ void protocol_archive_srv_command( retblock: spinlock_release(&p->protocol_lock); + CHK_PROTOCOL(p); } @@ -1724,8 +1729,8 @@ void protocol_add_srv_command( p->protocol_command.scom_next = server_command_init(NULL, cmd); } - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, "Added command %s to fd %d.", STRPACKETTYPE(cmd), p->owner_dcb->fd))); @@ -1735,8 +1740,8 @@ void protocol_add_srv_command( while (c != NULL && c->scom_cmd != MYSQL_COM_UNDEFINED) { - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, "fd %d : %d %s", p->owner_dcb->fd, c->scom_cmd, diff --git a/server/modules/protocol/telnetd.c b/server/modules/protocol/telnetd.c index aeb6607c4..d89962cd8 100644 --- a/server/modules/protocol/telnetd.c +++ b/server/modules/protocol/telnetd.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/modules/routing/CMakeLists.txt b/server/modules/routing/CMakeLists.txt new file mode 100644 index 000000000..9d2f25f76 --- /dev/null +++ b/server/modules/routing/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(testroute SHARED testroute.c) +target_link_libraries(testroute log_manager utils) +install(TARGETS testroute DESTINATION modules) + +add_library(readconnroute SHARED readconnroute.c) +target_link_libraries(readconnroute log_manager utils) +install(TARGETS readconnroute DESTINATION modules) + +add_library(debugcli SHARED debugcli.c debugcmd.c) +target_link_libraries(debugcli log_manager utils) +install(TARGETS debugcli DESTINATION modules) + +add_library(cli SHARED cli.c debugcmd.c) +target_link_libraries(cli log_manager utils) +install(TARGETS cli DESTINATION modules) + +add_subdirectory(readwritesplit) + diff --git a/server/modules/routing/GaleraHACRoute.c b/server/modules/routing/GaleraHACRoute.c index 33a9597cc..2f2627acb 100644 --- a/server/modules/routing/GaleraHACRoute.c +++ b/server/modules/routing/GaleraHACRoute.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of SkySQL MaxScale. It is free + * This file is distributed as part of MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/modules/routing/Makefile b/server/modules/routing/Makefile index 637d5f41c..5219635d3 100644 --- a/server/modules/routing/Makefile +++ b/server/modules/routing/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description @@ -66,7 +66,7 @@ libcli.so: $(CLIOBJ) $(CC) $(LDFLAGS) $(CLIOBJ) $(LIBS) -o $@ libreadwritesplit.so: -# (cd readwritesplit; touch depend.mk ; make; cp $@ ..) + (cd readwritesplit; touch depend.mk ; make; cp $@ ..) .c.o: $(CC) $(CFLAGS) $< -o $@ diff --git a/server/modules/routing/binlog/CMakeLists.txt b/server/modules/routing/binlog/CMakeLists.txt new file mode 100644 index 000000000..071901b70 --- /dev/null +++ b/server/modules/routing/binlog/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(binlogrouter SHARED blr.c blr_master.c blr_cache.c blr_slave.c blr_file.c) +set_target_properties(binlogrouter PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib) +target_link_libraries(binlogrouter ssl pthread log_manager ${EMBEDDED_LIB}) +install(TARGETS binlogrouter DESTINATION modules) diff --git a/server/modules/routing/binlog/Makefile b/server/modules/routing/binlog/Makefile index 6e9282ea1..991e86ccd 100644 --- a/server/modules/routing/binlog/Makefile +++ b/server/modules/routing/binlog/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index dec20f8b4..5f83eb5f0 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -172,6 +172,7 @@ int i; inst->low_water = DEF_LOW_WATER; inst->high_water = DEF_HIGH_WATER; + inst->initbinlog = 0; /* * We only support one server behind this router, since the server is @@ -244,6 +245,10 @@ int i; { inst->fileroot = strdup(value); } + else if (strcmp(options[i], "initialfile") == 0) + { + inst->initbinlog = atoi(value); + } else if (strcmp(options[i], "lowwater") == 0) { inst->low_water = atoi(value); @@ -450,11 +455,14 @@ ROUTER_SLAVE *slave = (ROUTER_SLAVE *)router_session; * TODO: Handle closure of master session */ LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, "Binlog router close session with master"))); + LOGFILE_ERROR, + "Binlog router close session with master server %s", + router->service->databases->unique_name))); blr_master_reconnect(router); return; } CHK_CLIENT_RSES(slave); + /** * Lock router client session for secure read and update. */ diff --git a/server/modules/routing/binlog/blr_cache.c b/server/modules/routing/binlog/blr_cache.c index 5bc46f036..a7213aa8a 100644 --- a/server/modules/routing/binlog/blr_cache.c +++ b/server/modules/routing/binlog/blr_cache.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 4f7232e64..74aacdc99 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -115,7 +115,11 @@ struct dirent *dp; if (n == 0) // No binlog files found { - sprintf(filename, BINLOG_NAMEFMT, router->fileroot, 1); + if (router->initbinlog) + sprintf(filename, BINLOG_NAMEFMT, router->fileroot, + router->initbinlog); + else + sprintf(filename, BINLOG_NAMEFMT, router->fileroot, 1); blr_file_create(router, filename); } else diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 412276e48..684b80a0b 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -55,21 +55,57 @@ #include #include +#include + /* Temporary requirement for auth data */ #include +#define SAMPLE_COUNT 10000 +CYCLES samples[10][SAMPLE_COUNT]; +int sample_index[10] = { 0, 0, 0 }; + +#define LOGD_SLAVE_CATCHUP1 0 +#define LOGD_SLAVE_CATCHUP2 1 +#define LOGD_DISTRIBUTE 2 +#define LOGD_FILE_FLUSH 3 + +SPINLOCK logspin = SPINLOCK_INIT; + +void +log_duration(int sample, CYCLES duration) +{ +char fname[100]; +int i; +FILE *fp; + + spinlock_acquire(&logspin); + samples[sample][sample_index[sample]++] = duration; + if (sample_index[sample] == SAMPLE_COUNT) + { + sprintf(fname, "binlog_profile.%d", sample); + if ((fp = fopen(fname, "a")) != NULL) + { + for (i = 0; i < SAMPLE_COUNT; i++) + fprintf(fp, "%ld\n", samples[sample][i]); + fclose(fp); + } + sample_index[sample] = 0; + } + spinlock_release(&logspin); +} + extern int lm_enabled_logfiles_bitmask; static GWBUF *blr_make_query(char *statement); static GWBUF *blr_make_registration(ROUTER_INSTANCE *router); static GWBUF *blr_make_binlog_dump(ROUTER_INSTANCE *router); -static void encode_value(unsigned char *data, unsigned int value, int len); -static void blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt); +void encode_value(unsigned char *data, unsigned int value, int len); +void blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt); static void blr_rotate_event(ROUTER_INSTANCE *router, uint8_t *pkt, REP_HEADER *hdr); -static void blr_distribute_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr); +void blr_distribute_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr); static void *CreateMySQLAuthData(char *username, char *password, char *database); -static void blr_extract_header(uint8_t *pkt, REP_HEADER *hdr); -static uint32_t extract_field(uint8_t *src, int bits); +void blr_extract_header(uint8_t *pkt, REP_HEADER *hdr); +inline uint32_t extract_field(uint8_t *src, int bits); static void blr_log_packet(logfile_id_t file, char *msg, uint8_t *ptr, int len); static int keepalive = 1; @@ -105,7 +141,8 @@ GWBUF *buf; if ((router->master = dcb_connect(router->service->databases, router->session, BLR_PROTOCOL)) == NULL) { LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR, - "Binlog router: failed to connect to master\n"))); + "Binlog router: failed to connect to master server '%s'\n", + router->service->databases->unique_name))); return; } @@ -459,7 +496,7 @@ int len = 0x1b; * @param value The value to pack * @param len Number of bits to encode value into */ -static void +void encode_value(unsigned char *data, unsigned int value, int len) { while (len > 0) @@ -477,7 +514,7 @@ encode_value(unsigned char *data, unsigned int value, int len) * @param router The router instance * @param pkt The binlog records */ -static void +void blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) { uint8_t *msg = NULL, *ptr, *pdata; @@ -765,7 +802,9 @@ static REP_HEADER phdr; { ss_dassert(pkt_length == 0); } +{ CYCLES start = rdtsc(); blr_file_flush(router); +log_duration(LOGD_FILE_FLUSH, rdtsc() - start); } } /** @@ -774,7 +813,7 @@ static REP_HEADER phdr; * @param pkt The incoming packet in a GWBUF chain * @param hdr The packet header to populate */ -static void +void blr_extract_header(uint8_t *ptr, REP_HEADER *hdr) { @@ -795,10 +834,10 @@ blr_extract_header(uint8_t *ptr, REP_HEADER *hdr) * @param src The raw packet source * @param birs The number of bits to extract (multiple of 8) */ -static uint32_t -extract_field(uint8_t *src, int bits) +inline uint32_t +extract_field(register uint8_t *src, int bits) { -uint32_t rval = 0, shift = 0; +register uint32_t rval = 0, shift = 0; while (bits > 0) { @@ -828,7 +867,7 @@ char file[BINLOG_FNAMELEN+1]; pos = extract_field(ptr+4, 32); pos <<= 32; pos |= extract_field(ptr, 32); - slen = len - 8; + slen = len - (8 + 4); // Allow for position and CRC if (slen > BINLOG_FNAMELEN) slen = BINLOG_FNAMELEN; memcpy(file, ptr + 8, slen); @@ -883,14 +922,16 @@ MYSQL_session *auth_info; * @param hdr The replication event header * @param ptr The raw replication event data */ -static void +void blr_distribute_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint8_t *ptr) { GWBUF *pkt; uint8_t *buf; ROUTER_SLAVE *slave; int action; +CYCLES entry; + entry = rdtsc(); spinlock_acquire(&router->lock); slave = router->slaves; while (slave) @@ -944,12 +985,16 @@ int action; spinlock_acquire(&slave->catch_lock); if (slave->overrun) { +CYCLES cycle_start, cycles; slave->stats.n_overrun++; slave->overrun = 0; spinlock_release(&router->lock); slave->cstate &= ~(CS_UPTODATE|CS_DIST); spinlock_release(&slave->catch_lock); +cycle_start = rdtsc(); blr_slave_catchup(router, slave); +cycles = rdtsc() - cycle_start; +log_duration(LOGD_SLAVE_CATCHUP2, cycles); spinlock_acquire(&router->lock); slave = router->slaves; if (slave) @@ -982,6 +1027,7 @@ int action; */ if (slave->cstate & CS_UPTODATE) { +CYCLES cycle_start, cycles; spinlock_release(&router->lock); LOGIF(LD, (skygw_log_write_flush(LOGFILE_DEBUG, "Force slave %d into catchup mode %s@%d\n", @@ -990,7 +1036,10 @@ int action; spinlock_acquire(&slave->catch_lock); slave->cstate &= ~(CS_UPTODATE|CS_DIST); spinlock_release(&slave->catch_lock); +cycle_start = rdtsc(); blr_slave_catchup(router, slave); +cycles = rdtsc() - cycle_start; +log_duration(LOGD_SLAVE_CATCHUP1, cycles); spinlock_acquire(&router->lock); slave = router->slaves; if (slave) @@ -1004,6 +1053,7 @@ int action; slave = slave->next; } spinlock_release(&router->lock); + log_duration(LOGD_DISTRIBUTE, rdtsc() - entry); } static void diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 176efbe4c..878c5e157 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** @@ -95,7 +95,7 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) return 0; } - atomic_add(&slave->stats.n_requests, 1); + slave->stats.n_requests++; switch (MYSQL_COMMAND(queue)) { case COM_QUERY: @@ -796,7 +796,7 @@ doitagain: slave->binlogfile))); return 0; } - atomic_add(&slave->stats.n_bursts, 1); + slave->stats.n_bursts++; spinlock_acquire(&slave->catch_lock); slave->cstate |= CS_INNERLOOP; spinlock_release(&slave->catch_lock); @@ -830,7 +830,7 @@ if (hdr.event_size > DEF_HIGH_WATER) slave->stats.n_above++; slave->binlog_pos = hdr.next_pos; } rval = written; - atomic_add(&slave->stats.n_events, 1); + slave->stats.n_events++; burst++; } if (record == NULL) @@ -843,7 +843,7 @@ if (hdr.event_size > DEF_HIGH_WATER) slave->stats.n_above++; } while (record && DCB_BELOW_LOW_WATER(slave->dcb)); if (record) { - atomic_add(&slave->stats.n_flows, 1); + slave->stats.n_flows++; spinlock_acquire(&slave->catch_lock); slave->cstate |= CS_EXPECTCB; spinlock_release(&slave->catch_lock); @@ -854,7 +854,7 @@ if (hdr.event_size > DEF_HIGH_WATER) slave->stats.n_above++; spinlock_acquire(&slave->catch_lock); if ((slave->cstate & CS_UPTODATE) == 0) { - atomic_add(&slave->stats.n_upd, 1); + slave->stats.n_upd++; slave->cstate |= CS_UPTODATE; state_change = 1; } @@ -907,7 +907,7 @@ ROUTER_INSTANCE *router = slave->router; if (slave->state == BLRS_DUMPING && slave->binlog_pos != router->binlog_position) { - atomic_add(&slave->stats.n_dcb, 1); + slave->stats.n_dcb++; blr_slave_catchup(router, slave); } } @@ -916,12 +916,12 @@ ROUTER_INSTANCE *router = slave->router; { if (slave->state == BLRS_DUMPING) { - atomic_add(&slave->stats.n_cb, 1); + slave->stats.n_cb++; blr_slave_catchup(router, slave); } else { - atomic_add(&slave->stats.n_cbna, 1); + slave->stats.n_cbna++; } } return 0; diff --git a/server/modules/routing/cli.c b/server/modules/routing/cli.c index ac525f695..eb581f4c7 100644 --- a/server/modules/routing/cli.c +++ b/server/modules/routing/cli.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ /** diff --git a/server/modules/routing/debugcli.c b/server/modules/routing/debugcli.c index aa0e82ef8..2e5a79381 100644 --- a/server/modules/routing/debugcli.c +++ b/server/modules/routing/debugcli.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** @@ -210,7 +210,7 @@ CLI_SESSION *client; session->state = SESSION_STATE_READY; client->mode = inst->mode; - dcb_printf(session->client, "Welcome the SkySQL MaxScale Debug Interface (%s).\n", + dcb_printf(session->client, "Welcome the MariaDB Corporation MaxScale Debug Interface (%s).\n", version_str); if (client->mode == CLIM_DEVELOPER) { diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index f238e16e6..8f51d531a 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index 68e2dfcef..c00a5a0a4 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ /** diff --git a/server/modules/routing/readwritesplit/CMakeLists.txt b/server/modules/routing/readwritesplit/CMakeLists.txt new file mode 100644 index 000000000..6960d4c8d --- /dev/null +++ b/server/modules/routing/readwritesplit/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(readwritesplit SHARED readwritesplit.c) +target_link_libraries(readwritesplit ssl pthread log_manager utils query_classifier) +install(TARGETS readwritesplit DESTINATION modules) +if(BUILD_TESTS) +add_subdirectory(test) +endif() diff --git a/server/modules/routing/readwritesplit/Makefile b/server/modules/routing/readwritesplit/Makefile index 80f2ec572..134a7271c 100644 --- a/server/modules/routing/readwritesplit/Makefile +++ b/server/modules/routing/readwritesplit/Makefile @@ -1,4 +1,4 @@ -# This file is distributed as part of the SkySQL Gateway. It is free +# This file is distributed as part of the MariaDB Corporation MaxScale. It is free # software: you can redistribute it and/or modify it under the terms of the # GNU General Public License as published by the Free Software Foundation, # version 2. @@ -12,7 +12,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright SkySQL Ab 2013 +# Copyright MariaDB Corporation Ab 2013 # # Revision History # Date Who Description diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 451b29742..a8ae23940 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include @@ -1282,9 +1282,10 @@ static route_target_t get_route_target ( if (hint->type == HINT_ROUTE_TO_MASTER) { target = TARGET_MASTER; /*< override */ - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, - "Hint: route to master."))); + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [get_route_target] Hint: route to master.", + pthread_self()))); break; } else if (hint->type == HINT_ROUTE_TO_NAMED_SERVER) @@ -1294,9 +1295,11 @@ static route_target_t get_route_target ( * found, the oroginal target is chosen. */ target |= TARGET_NAMED_SERVER; - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, - "Hint: route to named server : "))); + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [get_route_target] Hint: route to " + "named server : ", + pthread_self()))); } else if (hint->type == HINT_ROUTE_TO_UPTODATE_SERVER) { @@ -1334,9 +1337,11 @@ static route_target_t get_route_target ( else if (hint->type == HINT_ROUTE_TO_SLAVE) { target = TARGET_SLAVE; - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, - "Hint: route to slave."))); + LOGIF(LD, (skygw_log_write( + LOGFILE_DEBUG, + "%lu [get_route_target] Hint: route to " + "slave.", + pthread_self()))); } hint = hint->next; } /*< while (hint != NULL) */ @@ -1637,7 +1642,7 @@ void check_create_tmp_table( * * @param instance The query router instance * @param session The session associated with the client - * @param queue Gateway buffer queue with the packets received + * @param queue MaxScale buffer queue with the packets received * * @return if succeed 1, otherwise 0 * If routeQuery fails, it means that router session has failed. @@ -1653,7 +1658,6 @@ static int routeQuery( GWBUF* querybuf) { skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN; - char* querystr = NULL; mysql_server_cmd_t packet_type; uint8_t* packet; int ret = 0; @@ -1793,8 +1797,33 @@ static int routeQuery( { router_cli_ses->rses_autocommit_enabled = true; router_cli_ses->rses_transaction_active = false; - } + } + if (LOG_IS_ENABLED(LOGFILE_TRACE)) + { + uint8_t* packet = GWBUF_DATA(querybuf); + unsigned char ptype = packet[4]; + size_t len = MIN(GWBUF_LENGTH(querybuf), + MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start)-1); + char* data = (char*)&packet[5]; + char* contentstr = strndup(data, len); + char* qtypestr = skygw_get_qtype_str(qtype); + + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "> Autocommit: %s, trx is %s, cmd: %s, type: %s, " + "stmt: %s%s %s", + (router_cli_ses->rses_autocommit_enabled ? "[enabled]" : "[disabled]"), + (router_cli_ses->rses_transaction_active ? "[open]" : "[not open]"), + STRPACKETTYPE(ptype), + (qtypestr==NULL ? "N/A" : qtypestr), + contentstr, + (querybuf->hint == NULL ? "" : ", Hint:"), + (querybuf->hint == NULL ? "" : STRHINTTYPE(querybuf->hint->type))))); + + free(contentstr); + free(qtypestr); + } /** * Find out where to route the query. Result may not be clear; it is * possible to have a hint for routing to a named server which can @@ -1911,6 +1940,27 @@ static int routeQuery( btype, named_server, rlag_max); + if (!succp) + { + if (TARGET_IS_NAMED_SERVER(route_target)) + { + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Was supposed to route to named server " + "%s but couldn't find the server in a " + "suitable state.", + named_server))); + } + else if (TARGET_IS_RLAG_MAX(route_target)) + { + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Was supposed to route to server with " + "replication lag at most %d but couldn't " + "find such a slave.", + rlag_max))); + } + } } if (!succp && TARGET_IS_SLAVE(route_target)) @@ -1930,9 +1980,16 @@ static int routeQuery( NULL, rlag_max); if (succp) - { + { atomic_add(&inst->stats.n_slave, 1); } + else + { + LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, + "Was supposed to route to slave" + "but finding suitable one " + "failed."))); + } } if (!succp && TARGET_IS_MASTER(route_target)) @@ -1944,6 +2001,16 @@ static int routeQuery( BE_MASTER, NULL, MAX_RLAG_UNDEFINED); + if (!succp) + { + LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, + "Was supposed to " + "route to master " + "but couldn't find " + "master in a " + "suitable state " + "failed."))); + } } else { @@ -1951,12 +2018,38 @@ static int routeQuery( } atomic_add(&inst->stats.n_master, 1); target_dcb = master_dcb; - } - ss_dassert(succp); - + } if (succp) /*< Have DCB of the target backend */ { + backend_ref_t* bref; + sescmd_cursor_t* scur; + + bref = get_bref_from_dcb(router_cli_ses, target_dcb); + scur = &bref->bref_sescmd_cur; + + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Route query to %s\t%s:%d <", + (SERVER_IS_MASTER(bref->bref_backend->backend_server) ? + "master" : "slave"), + bref->bref_backend->backend_server->name, + bref->bref_backend->backend_server->port))); + /** + * Store current stmt if execution of previous session command + * haven't completed yet. Note that according to MySQL protocol + * there can only be one such non-sescmd stmt at the time. + */ + if (sescmd_cursor_is_active(scur)) + { + ss_dassert(bref->bref_pending_cmd == NULL); + bref->bref_pending_cmd = gwbuf_clone(querybuf); + + rses_end_locked_router_action(router_cli_ses); + ret = 1; + goto retblock; + } + if ((ret = target_dcb->func.write(target_dcb, gwbuf_clone(querybuf))) == 1) { backend_ref_t* bref; @@ -1973,8 +2066,7 @@ static int routeQuery( { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, - "Error : Routing query \"%s\" failed.", - querystr))); + "Error : Routing query failed."))); } } rses_end_locked_router_action(router_cli_ses); @@ -2295,7 +2387,34 @@ static void clientReply ( ss_dassert(succp); } - /** Unlock router session */ + else if (bref->bref_pending_cmd != NULL) /*< non-sescmd is waiting to be routed */ + { + int ret; + + CHK_GWBUF(bref->bref_pending_cmd); + + if ((ret = bref->bref_dcb->func.write(bref->bref_dcb, + gwbuf_clone(bref->bref_pending_cmd))) == 1) + { + ROUTER_INSTANCE* inst = (ROUTER_INSTANCE *)instance; + atomic_add(&inst->stats.n_queries, 1); + /** + * Add one query response waiter to backend reference + */ + bref_set_state(bref, BREF_QUERY_ACTIVE); + bref_set_state(bref, BREF_WAITING_RESULT); + } + else + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error : Routing query \"%s\" failed.", + bref->bref_pending_cmd))); + } + gwbuf_free(bref->bref_pending_cmd); + bref->bref_pending_cmd = NULL; + } + /** Unlock router session */ rses_end_locked_router_action(router_cli_ses); lock_failed: @@ -3394,12 +3513,6 @@ static bool execute_sescmd_in_backend( sescmd_cursor_clone_querybuf(scur)); break; } - LOGIF(LT, (skygw_log_write_flush( - LOGFILE_TRACE, - "%lu [execute_sescmd_in_backend] Routed %s cmd %p.", - pthread_self(), - STRPACKETTYPE(scur->scmd_cur_cmd->my_sescmd_packet_type), - scur->scmd_cur_cmd))); if (rc == 1) { @@ -3526,8 +3639,8 @@ static void tracelog_routed_query( querystr = (char *)malloc(len); memcpy(querystr, startpos, len-1); querystr[len-1] = '\0'; - LOGIF(LT, (skygw_log_write_flush( - LOGFILE_TRACE, + LOGIF(LD, (skygw_log_write_flush( + LOGFILE_DEBUG, "%lu [%s] %d bytes long buf, \"%s\" -> %s:%d %s dcb %p", pthread_self(), funcname, @@ -3548,8 +3661,8 @@ static void tracelog_routed_query( querystr = (char *)malloc(len); memcpy(querystr, startpos, len-1); querystr[len-1] = '\0'; - LOGIF(LT, (skygw_log_write_flush( - LOGFILE_TRACE, + LOGIF(LD, (skygw_log_write_flush( + LOGFILE_DEBUG, "%lu [%s] %d bytes long buf, \"%s\" -> %s:%d %s dcb %p", pthread_self(), funcname, @@ -3616,10 +3729,7 @@ static bool route_session_write( LOGIF(LT, (skygw_log_write( LOGFILE_TRACE, - "Session write, query type\t%s, packet type %s, " - "routing to all servers.", - STRQTYPE(qtype), - STRPACKETTYPE(packet_type)))); + "Session write, routing to all servers."))); backend_ref = router_cli_ses->rses_backend_ref; @@ -3646,7 +3756,19 @@ static bool route_session_write( for (i=0; irses_nbackends; i++) { - DCB* dcb = backend_ref[i].bref_dcb; + DCB* dcb = backend_ref[i].bref_dcb; + + if (LOG_IS_ENABLED(LOGFILE_TRACE)) + { + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Route query to %s\t%s:%d%s", + (SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ? + "master" : "slave"), + backend_ref[i].bref_backend->backend_server->name, + backend_ref[i].bref_backend->backend_server->port, + (i+1==router_cli_ses->rses_nbackends ? " <" : "")))); + } if (BREF_IS_IN_USE((&backend_ref[i]))) { @@ -3656,6 +3778,7 @@ static bool route_session_write( { succp = false; } + } } rses_end_locked_router_action(router_cli_ses); @@ -3685,6 +3808,18 @@ static bool route_session_write( { sescmd_cursor_t* scur; + if (LOG_IS_ENABLED(LOGFILE_TRACE)) + { + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Route query to %s\t%s:%d%s", + (SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ? + "master" : "slave"), + backend_ref[i].bref_backend->backend_server->name, + backend_ref[i].bref_backend->backend_server->port, + (i+1==router_cli_ses->rses_nbackends ? " <" : "")))); + } + scur = backend_ref_get_sescmd_cursor(&backend_ref[i]); /** @@ -3692,7 +3827,7 @@ static bool route_session_write( */ bref_set_state(get_bref_from_dcb(router_cli_ses, backend_ref[i].bref_dcb), - BREF_WAITING_RESULT); + BREF_WAITING_RESULT); /** * Start execution if cursor is not already executing. * Otherwise, cursor will execute pending commands diff --git a/server/modules/routing/readwritesplit/test/CMakeLists.txt b/server/modules/routing/readwritesplit/test/CMakeLists.txt new file mode 100644 index 000000000..b2012e789 --- /dev/null +++ b/server/modules/routing/readwritesplit/test/CMakeLists.txt @@ -0,0 +1,3 @@ +add_test(NAME ReadWriteSplitTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit.sh testrwsplit.log ${TEST_HOST} ${TEST_PORT_RW} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} ${CMAKE_CURRENT_SOURCE_DIR}) +set_tests_properties(ReadWriteSplitTest PROPERTIES DEPENDS RunExecutable) +add_subdirectory(test_hints) \ No newline at end of file diff --git a/server/modules/routing/readwritesplit/test/rwsplit.sh b/server/modules/routing/readwritesplit/test/rwsplit.sh index 6fefd8801..fcca4ac37 100755 --- a/server/modules/routing/readwritesplit/test/rwsplit.sh +++ b/server/modules/routing/readwritesplit/test/rwsplit.sh @@ -1,5 +1,5 @@ #!/bin/sh -NARGS=6 +NARGS=7 TLOG=$1 THOST=$2 TPORT=$3 @@ -7,10 +7,10 @@ TMASTER_ID=$4 TUSER=$5 TPWD=$6 -if [ $# != $NARGS ] ; +if [ $# -lt $(( NARGS - 1 )) ] ; then echo"" -echo "Wrong number of arguments, gave "$#" but "$NARGS" is required" +echo "Wrong number of arguments, gave "$#" but "$(( NARGS - 1 ))" is required" echo "" echo "Usage :" echo " rwsplit.sh " @@ -18,12 +18,20 @@ echo "" exit 1 fi +if [ "$#" == "$NARGS" ] +then + echo "CTest mode" + TDIR=$7 #this is only used by CMake + echo "Test directory is: $TDIR" +else + TDIR=. +fi RUNCMD=mysql\ --host=$THOST\ -P$TPORT\ -u$TUSER\ -p$TPWD\ --unbuffered=true\ --disable-reconnect\ --silent TINPUT=test_transaction_routing2.sql TRETVAL=0 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -32,7 +40,7 @@ fi TINPUT=test_transaction_routing2b.sql TRETVAL=0 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -41,7 +49,7 @@ fi TINPUT=test_transaction_routing3.sql TRETVAL=2 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TMASTER_ID" ]; then echo "$TINPUT FAILED, return value $a when one of the slave IDs was expected">>$TLOG; else @@ -50,7 +58,7 @@ fi TINPUT=test_transaction_routing3b.sql TRETVAL=2 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TMASTER_ID" ]; then echo "$TINPUT FAILED, return value $a when one of the slave IDs was expected">>$TLOG; else @@ -60,7 +68,7 @@ fi # test implicit transaction, that is, not started explicitly, autocommit=0 TINPUT=test_transaction_routing4.sql TRETVAL=0 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -69,7 +77,7 @@ fi TINPUT=test_transaction_routing4b.sql TRETVAL=0 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -80,7 +88,7 @@ fi TINPUT=select_for_var_set.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -90,7 +98,7 @@ fi TINPUT=test_implicit_commit1.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -99,7 +107,7 @@ fi TINPUT=test_implicit_commit2.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -108,7 +116,7 @@ fi TINPUT=test_implicit_commit3.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -117,7 +125,7 @@ fi TINPUT=test_implicit_commit4.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -126,7 +134,7 @@ fi TINPUT=test_implicit_commit5.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -135,7 +143,7 @@ fi TINPUT=test_implicit_commit6.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -144,7 +152,7 @@ fi TINPUT=test_implicit_commit7.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -153,7 +161,7 @@ fi TINPUT=test_autocommit_disabled1.sql TRETVAL=1 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -162,7 +170,7 @@ fi TINPUT=test_autocommit_disabled1b.sql TRETVAL=1 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -173,7 +181,7 @@ fi # it is again enabled. TINPUT=test_autocommit_disabled2.sql TRETVAL=1 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -181,10 +189,10 @@ else fi TINPUT=set_autocommit_disabled.sql -`$RUNCMD < ./$TINPUT` +`$RUNCMD < $TDIR/$TINPUT` TINPUT=test_after_autocommit_disabled.sql TRETVAL=$TMASTER_ID -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" = "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when it was not accetable">>$TLOG; else @@ -194,37 +202,37 @@ fi TINPUT=test_sescmd.sql TRETVAL=2 -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else @@ -232,7 +240,7 @@ else fi TINPUT=test_temporary_table.sql -a=`$RUNCMD < ./$TINPUT` +a=`$RUNCMD < $TDIR/$TINPUT` TRETVAL=1 if [ "$a" != "$TRETVAL" ]; then echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; @@ -252,7 +260,7 @@ do then printf "." fi - a=`$RUNCMD < $TINPUT 2>&1` + a=`$RUNCMD < $TDIR/$TINPUT 2>&1` if [[ "`echo "$a"|grep -i 'error'`" != "" ]] then err=`echo "$a" | grep -i error` @@ -278,7 +286,7 @@ do then printf "." fi - b=`$RUNCMD < $TINPUT 2>&1` + b=`$RUNCMD < $TDIR/$TINPUT 2>&1` if [[ "`echo "$b"|grep -i 'null\|error'`" != "" ]] then err=`echo "$b" | grep -i null\|error` @@ -292,3 +300,8 @@ else echo "Test FAILED at iteration $((j+1))" >> $TLOG fi echo "" >> $TLOG + +if [ $# -eq $NARGS ] +then + cat $TLOG +fi diff --git a/server/modules/routing/readwritesplit/test/test_hints/CMakeLists.txt b/server/modules/routing/readwritesplit/test/test_hints/CMakeLists.txt new file mode 100644 index 000000000..ed804382b --- /dev/null +++ b/server/modules/routing/readwritesplit/test/test_hints/CMakeLists.txt @@ -0,0 +1,3 @@ +add_test(NAME SimpleHintTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit_hints.sh hints.log ${TEST_HOST} ${TEST_PORT_RW_HINT} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} simple_tests ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME ComplexHintTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit_hints.sh hints.log ${TEST_HOST} ${TEST_PORT_RW_HINT} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} complex_tests ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME StackHintTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit_hints.sh hints.log ${TEST_HOST} ${TEST_PORT_RW_HINT} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} stack_tests ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/server/modules/routing/readwritesplit/test/test_hints/rwsplit_hints.sh b/server/modules/routing/readwritesplit/test/test_hints/rwsplit_hints.sh index cdbfb335b..1f751861f 100755 --- a/server/modules/routing/readwritesplit/test/test_hints/rwsplit_hints.sh +++ b/server/modules/routing/readwritesplit/test/test_hints/rwsplit_hints.sh @@ -1,5 +1,5 @@ #!/bin/bash -NARGS=7 +NARGS=8 TLOG=$1 THOST=$2 TPORT=$3 @@ -8,10 +8,10 @@ TUSER=$5 TPWD=$6 TESTINPUT=$7 -if [ $# != $NARGS ] ; +if [ $# -lt $(( NARGS - 1 )) ] ; then echo"" -echo "Wrong number of arguments, gave "$#" but "$NARGS" is required" +echo "Wrong number of arguments, gave "$#" but "$(( NARGS - 1 ))" is required" echo "" echo "Usage :" echo " rwsplit_hints.sh " @@ -19,6 +19,14 @@ echo "" exit 1 fi +if [ $# -eq $NARGS ] +then + TDIR=$8 +else + TDIR=. +fi + +TESTINPUT=$TDIR/$TESTINPUT RUNCMD=mysql\ --host=$THOST\ -P$TPORT\ -u$TUSER\ -p$TPWD\ --unbuffered=true\ --disable-reconnect\ --silent\ --comment i=0 @@ -63,3 +71,8 @@ then else echo "Test set: FAILED">>$TLOG; fi + +if [ $# -eq $NARGS ] +then + cat $TLOG +fi diff --git a/server/modules/routing/testroute.c b/server/modules/routing/testroute.c index ce2ce2ca9..47a581c5d 100644 --- a/server/modules/routing/testroute.c +++ b/server/modules/routing/testroute.c @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include #include diff --git a/server/modules/routing/webserver.c b/server/modules/routing/webserver.c index 28102dfd4..af00a4e7b 100644 --- a/server/modules/routing/webserver.c +++ b/server/modules/routing/webserver.c @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2014 + * Copyright MariaDB Corporation Ab 2014 */ #include #include diff --git a/server/test/CMakeLists.txt b/server/test/CMakeLists.txt new file mode 100644 index 000000000..22e4c1b4d --- /dev/null +++ b/server/test/CMakeLists.txt @@ -0,0 +1,7 @@ +file(COPY MaxScale_test.cnf DESTINATION ${CMAKE_BINARY_DIR}/etc) +file(RENAME ${CMAKE_BINARY_DIR}/etc/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf) +#add_test(NAME RunExecutable COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/startmaxscale.sh "${CMAKE_BINARY_DIR}/bin/" "-c ${CMAKE_BINARY_DIR}") +#set_tests_properties(RunExecutable PROPERTIES TIMEOUT 2) + +#add_test(NAME KillExecutable COMMAND killall -KILL maxscale) +#set_tests_properties(KillExecutable PROPERTIES DEPENDS StackHintTest ) #this needs to be the last test that requires a running maxscale diff --git a/server/test/startmaxscale.sh b/server/test/startmaxscale.sh new file mode 100755 index 000000000..979034476 --- /dev/null +++ b/server/test/startmaxscale.sh @@ -0,0 +1,5 @@ +#!/bin/sh +killall -KILL maxscale +sleep 1 +setsid $1/maxscale $2 +exit 0 diff --git a/table_replication_consistency/CMakeLists.txt b/table_replication_consistency/CMakeLists.txt index 11bd90c03..360471161 100644 --- a/table_replication_consistency/CMakeLists.txt +++ b/table_replication_consistency/CMakeLists.txt @@ -26,10 +26,10 @@ find_path(MySQL_INCLUDE_DIR mysql.h /usr/local/include/mysql /usr/include/mysql /usr/local/mysql/include) include_directories(${MySQL_INCLUDE_DIR}) -#SkySQL -find_path(SkySQL_INCLUDE_DIR skygw_debug.h +#MariaDB Corporation +find_path(MariaDB Corporation_INCLUDE_DIR skygw_debug.h /usr/local/include /usr/include ../utils) -include_directories(${SkySQL_INCLUDE_DIR}) +include_directories(${MariaDB Corporation_INCLUDE_DIR}) include_directories(../replication_listener) #log_manager diff --git a/table_replication_consistency/table_replication_consistency.cpp b/table_replication_consistency/table_replication_consistency.cpp index 396829ef8..e29fc0cd7 100644 --- a/table_replication_consistency/table_replication_consistency.cpp +++ b/table_replication_consistency/table_replication_consistency.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. @@ -76,7 +76,7 @@ tb_replication_consistency_init( replication_listener_t *rpl, /*!< in: Server definition. */ size_t n_servers, /*!< in: Number of servers */ - unsigned int gateway_server_id, /*!< in: Gateway slave + unsigned int gateway_server_id, /*!< in: MaxScale slave server id. */ int trace_level) /*!< in: Trace level */ { @@ -288,7 +288,7 @@ int tb_replication_consistency_reconnect( /*=================================*/ replication_listener_t* rpl, /*!< in: Server definition.*/ - unsigned int gateway_server_id) /*!< in: Gateway slave + unsigned int gateway_server_id) /*!< in: MaxScale slave server id. */ { std::string errmsg =""; diff --git a/table_replication_consistency/table_replication_consistency.h b/table_replication_consistency/table_replication_consistency.h index 92a423818..f900d1bf0 100644 --- a/table_replication_consistency/table_replication_consistency.h +++ b/table_replication_consistency/table_replication_consistency.h @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. @@ -116,7 +116,7 @@ tb_replication_consistency_init( replication_listener_t *rpl, /*!< in: Server definition. */ size_t n_servers, /*!< in: Number of servers */ - unsigned int gateway_server_id, /*!< in: Gateway slave + unsigned int gateway_server_id, /*!< in: MaxScale slave server id. */ int trace_level); /*!< in: trace level */ @@ -148,7 +148,7 @@ int tb_replication_consistency_reconnect( /*=================================*/ replication_listener_t* rpl, /*!< in: Server definition.*/ - unsigned int gateway_server_id); /*!< in: Gateway slave + unsigned int gateway_server_id); /*!< in: MaxScale slave server id. */ /***********************************************************************//** diff --git a/table_replication_consistency/table_replication_listener.cpp b/table_replication_consistency/table_replication_listener.cpp index 9db67292f..283b49984 100644 --- a/table_replication_consistency/table_replication_listener.cpp +++ b/table_replication_consistency/table_replication_listener.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/table_replication_listener.h b/table_replication_consistency/table_replication_listener.h index c207a37d0..2c1b31794 100644 --- a/table_replication_consistency/table_replication_listener.h +++ b/table_replication_consistency/table_replication_listener.h @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/table_replication_metadata.cpp b/table_replication_consistency/table_replication_metadata.cpp index fbcc425e7..b25a350ed 100644 --- a/table_replication_consistency/table_replication_metadata.cpp +++ b/table_replication_consistency/table_replication_metadata.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/table_replication_metadata.h b/table_replication_consistency/table_replication_metadata.h index 78436714f..910d63295 100644 --- a/table_replication_consistency/table_replication_metadata.h +++ b/table_replication_consistency/table_replication_metadata.h @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/table_replication_parser.cpp b/table_replication_consistency/table_replication_parser.cpp index a14f825df..999a9b083 100644 --- a/table_replication_consistency/table_replication_parser.cpp +++ b/table_replication_consistency/table_replication_parser.cpp @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/table_replication_parser.h b/table_replication_consistency/table_replication_parser.h index 0b13a6438..5a854e2f7 100644 --- a/table_replication_consistency/table_replication_parser.h +++ b/table_replication_consistency/table_replication_parser.h @@ -1,8 +1,8 @@ /* -Copyright (C) 2013, SkySQL Ab +Copyright (C) 2013-2014, MariaDB Corporation Ab -This file is distributed as part of the SkySQL Gateway. It is free +This file is distributed as part of the MariaDB Corporation MaxScale. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. diff --git a/table_replication_consistency/test/CMakeLists.txt b/table_replication_consistency/test/CMakeLists.txt index f2b461f8d..5f977310c 100644 --- a/table_replication_consistency/test/CMakeLists.txt +++ b/table_replication_consistency/test/CMakeLists.txt @@ -14,10 +14,10 @@ find_path(MySQL_INCLUDE_DIR mysql.h /usr/local/include/mysql /usr/include/mysql /usr/local/mysql/include) include_directories(${MySQL_INCLUDE_DIR}) -#SkySQL -find_path(SkySQL_INCLUDE_DIR skygw_debug.h +#MariaDB Corporation +find_path(MariaDB Corporation_INCLUDE_DIR skygw_debug.h /usr/local/include /usr/include ../../utils) -include_directories(${SkySQL_INCLUDE_DIR}) +include_directories(${MariaDB Corporation_INCLUDE_DIR}) find_path(TRC_INCLUDE_DIR table_replication_consistency.h ../ /usr/include /usr/local/include) diff --git a/test.inc b/test.inc index 7c5e5c571..5249b8159 100644 --- a/test.inc +++ b/test.inc @@ -43,4 +43,5 @@ TMASTER_ID := # Global test log where all log is gathered # TEST_MAXSCALE_LOG := $(ROOT_PATH)/test/test_maxscale.log # -TEST_MAXSCALE_LOG := +TEST_MAXSCALE_LOG := /home/mbrampton/Dropbox/skygit/MaxScale/test/testserver.log + diff --git a/unpack_rmp.sh b/unpack_rmp.sh new file mode 100755 index 000000000..4158c6a84 --- /dev/null +++ b/unpack_rmp.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +#This script unpacks the RPM to the provided directory + +unpack_to(){ + cd $2 && rpm2cpio $1 | cpio -id; +} + + +if [[ $# -lt 2 ]] +then + echo "Usage: unpack_rpm.sh " + exit 0 +fi + +SOURCE=$1 +DEST=$2 +FILES=$(ls $SOURCE |grep -i mariadb.*`uname -m`.*.rpm) + +if [[ ! -d $DEST ]] +then + mkdir -p $DEST +fi + +echo "Unpacking RPMs to: $DEST" + +for rpm in $FILES +do + echo "Unpacking $rpm..." + unpack_to $SOURCE/$rpm $DEST +done + diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 000000000..8a2cfddb6 --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(utils skygw_utils.cc) +target_link_libraries(utils stdc++) \ No newline at end of file diff --git a/utils/skygw_debug.h b/utils/skygw_debug.h index acc59bc85..1d22fbdbd 100644 --- a/utils/skygw_debug.h +++ b/utils/skygw_debug.h @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #include @@ -129,13 +129,29 @@ typedef enum skygw_chk_t { # define STRBOOL(b) ((b) ? "true" : "false") -# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \ - ((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \ - ((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \ - ((t) == QUERY_TYPE_UNKNOWN ? "QUERY_TYPE_UNKNOWN" : \ - ((t) == QUERY_TYPE_LOCAL_READ ? "QUERY_TYPE_LOCAL_READ" : \ - ((t) == QUERY_TYPE_EXEC_STMT ? "QUERY_TYPE_EXEC_STMT" : \ - "Unknown query type")))))) +# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \ + ((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \ + ((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \ + ((t) == QUERY_TYPE_UNKNOWN ? "QUERY_TYPE_UNKNOWN" : \ + ((t) == QUERY_TYPE_LOCAL_READ ? "QUERY_TYPE_LOCAL_READ" : \ + ((t) == QUERY_TYPE_MASTER_READ ? "QUERY_TYPE_MASTER_READ" : \ + ((t) == QUERY_TYPE_USERVAR_READ ? "QUERY_TYPE_USERVAR_READ" : \ + ((t) == QUERY_TYPE_SYSVAR_READ ? "QUERY_TYPE_SYSVAR_READ" : \ + ((t) == QUERY_TYPE_GSYSVAR_READ ? "QUERY_TYPE_GSYSVAR_READ" : \ + ((t) == QUERY_TYPE_GSYSVAR_WRITE ? "QUERY_TYPE_GSYSVAR_WRITE" : \ + ((t) == QUERY_TYPE_BEGIN_TRX ? "QUERY_TYPE_BEGIN_TRX" : \ + ((t) == QUERY_TYPE_ENABLE_AUTOCOMMIT ? "QUERY_TYPE_ENABLE_AUTOCOMMIT" : \ + ((t) == QUERY_TYPE_DISABLE_AUTOCOMMIT ? "QUERY_TYPE_DISABLE_AUTOCOMMIT" : \ + ((t) == QUERY_TYPE_ROLLBACK ? "QUERY_TYPE_ROLLBACK" : \ + ((t) == QUERY_TYPE_COMMIT ? "QUERY_TYPE_COMMIT" : \ + ((t) == QUERY_TYPE_PREPARE_NAMED_STMT ? "QUERY_TYPE_PREPARE_NAMED_STMT" : \ + ((t) == QUERY_TYPE_PREPARE_STMT ? "QUERY_TYPE_PREPARE_STMT" : \ + ((t) == QUERY_TYPE_EXEC_STMT ? "QUERY_TYPE_EXEC_STMT" : \ + ((t) == QUERY_TYPE_CREATE_TMP_TABLE ? "QUERY_TYPE_CREATE_TMP_TABLE" : \ + ((t) == QUERY_TYPE_READ_TMP_TABLE ? "QUERY_TYPE_READ_TMP_TABLE" : \ + ((t) == QUERY_TYPE_SHOW_DATABASES ? "QUERY_TYPE_SHOW_DATABASES" : \ + ((t) == QUERY_TYPE_SHOW_TABLES ? "QUERY_TYPE_SHOW_TABLES" : \ + "Unknown query type")))))))))))))))))))))) #define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \ ((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \ @@ -247,6 +263,14 @@ typedef enum skygw_chk_t { (SERVER_IS_RELAY_SERVER(s) ? "RUNNING RELAY" : \ (SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS"))))))) +#define STRHINTTYPE(t) (t == HINT_ROUTE_TO_MASTER ? "HINT_ROUTE_TO_MASTER" : \ + ((t) == HINT_ROUTE_TO_SLAVE ? "HINT_ROUTE_TO_SLAVE" : \ + ((t) == HINT_ROUTE_TO_NAMED_SERVER ? "HINT_ROUTE_TO_NAMED_SERVER" : \ + ((t) == HINT_ROUTE_TO_UPTODATE_SERVER ? "HINT_ROUTE_TO_UPTODATE_SERVER" : \ + ((t) == HINT_ROUTE_TO_ALL ? "HINT_ROUTE_TO_ALL" : \ + ((t) == HINT_PARAMETER ? "HINT_PARAMETER" : "UNKNOWN HINT TYPE")))))) + + #define CHK_MLIST(l) { \ ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \ l->mlist_chk_tail == CHK_NUM_MLIST), \ @@ -450,7 +474,7 @@ typedef enum skygw_chk_t { } #define CHK_GWBUF(b) { \ - ss_info_dassert(((b)->start <= (b)->end), \ + ss_info_dassert(((char *)(b)->start <= (char *)(b)->end), \ "gwbuf start has passed the endpoint"); \ } diff --git a/utils/skygw_types.h b/utils/skygw_types.h index a82db80ab..4410cc23a 100644 --- a/utils/skygw_types.h +++ b/utils/skygw_types.h @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ #if !defined(SKYGW_TYPES_H) #define SKYGW_TYPES_H diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 4845c73a2..7e8407ba7 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -1,5 +1,5 @@ /* - * This file is distributed as part of the SkySQL Gateway. It is free + * This file is distributed as part of the MariaDB Corporation MaxScale. It is free * software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * version 2. @@ -13,7 +13,7 @@ * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright SkySQL Ab 2013 + * Copyright MariaDB Corporation Ab 2013-2014 */ @@ -119,15 +119,16 @@ static void slist_add_node( slist_t* list, slist_node_t* node); +#if defined(NOT_USED) static slist_node_t* slist_node_get_next( slist_node_t* curr_node); static slist_node_t* slist_get_first( slist_t* list); - static slist_cursor_t* slist_get_cursor( slist_t* list); - +#endif /*< NOT_USED */ + static bool file_write_header(skygw_file_t* file); static void simple_mutex_free_memory(simple_mutex_t* sm); static void mlist_free_memory(mlist_t* ml, char* name); @@ -740,7 +741,7 @@ static void slist_add_node( } - +#if defined(NOT_USED) static slist_node_t* slist_node_get_next( slist_node_t* curr_node) { @@ -766,7 +767,6 @@ static slist_node_t* slist_get_first( return NULL; } - static slist_cursor_t* slist_get_cursor( slist_t* list) { @@ -777,7 +777,7 @@ static slist_cursor_t* slist_get_cursor( c = slist_cursor_init(list); return c; } - +#endif /*< NOT_USED */ static slist_cursor_t* slist_cursor_init( slist_t* list) @@ -1600,7 +1600,7 @@ static bool file_write_header( *tm = *localtime(t); CHK_FILE(file); - header_buf1 = "\n\nSkySQL MaxScale\t"; + header_buf1 = "\n\nMariaDB Corporation MaxScale\t"; header_buf2 = (char *)calloc(1, strlen(file->sf_fname)+2); snprintf(header_buf2, strlen(file->sf_fname)+2, "%s ", file->sf_fname); header_buf3 = strdup(asctime(tm)); @@ -1955,7 +1955,19 @@ retblock: return newstr; } - +/** + * Calculate the number of decimal numbers from a size_t value. + * + * @param value value + * + * @return number of decimal numbers of which the value consists of + * value==123 returns 3, for example. + */ +size_t get_decimal_len( + size_t value) +{ + return value > 0 ? (size_t) log10 ((double) value) + 1 : 1; +} diff --git a/utils/skygw_utils.h b/utils/skygw_utils.h index a54859392..309b9019f 100644 --- a/utils/skygw_utils.h +++ b/utils/skygw_utils.h @@ -195,6 +195,8 @@ int atomic_add(int *variable, int value); EXTERN_C_BLOCK_BEGIN +size_t get_decimal_len(size_t s); + char* replace_literal(char* haystack, const char* needle, const char* replacement);