From 4eddec7989d4254cd20b696e92e5d2671068c90b Mon Sep 17 00:00:00 2001 From: Sriram Patil Date: Wed, 20 May 2015 17:47:58 +0530 Subject: [PATCH 1/8] Fixed MXS - 165: Concurrency issue while incrementing sessions in qlafilter --- server/modules/filter/qlafilter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/modules/filter/qlafilter.c b/server/modules/filter/qlafilter.c index 5362cf61e..3c358cda1 100644 --- a/server/modules/filter/qlafilter.c +++ b/server/modules/filter/qlafilter.c @@ -50,6 +50,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -304,7 +305,9 @@ char *remote, *userName; sprintf(my_session->filename, "%s.%d", my_instance->filebase, my_instance->sessions); - my_instance->sessions++; + + // Multiple sessions can try to update my_instance->sessions simultaneously + atomic_add(&(my_instance->sessions), 1); if (my_session->active) { From f24da8712b4c4cbf5c1bf731a6133cae39d62245 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 11 Jun 2015 18:25:42 +0300 Subject: [PATCH 2/8] Fixed a segfault and disabled syslog by default. --- server/core/gateway.c | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index 9845713e1..9d0e6f908 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -935,7 +935,7 @@ int main(int argc, char **argv) char* tmp_var; int option_index; int logtofile = 0; /* Use shared memory or file */ - int syslog_enabled = 1; /** Log to syslog */ + int syslog_enabled = 0; /** Log to syslog */ int maxscalelog_enabled = 1; /** Log with MaxScale */ ssize_t log_flush_timeout_ms = 0; sigset_t sigset; @@ -1078,26 +1078,34 @@ int main(int argc, char **argv) } break; case 'S': - if(strstr(optarg,"=")) - { - strtok(optarg,"= "); - maxscalelog_enabled = config_truth_value(strtok(NULL,"= ")); - } - else - { - maxscalelog_enabled = config_truth_value(optarg); - } + { + char* tok = strstr(optarg,"="); + if(tok) + { + tok++; + if(tok) + maxscalelog_enabled = config_truth_value(tok); + } + else + { + maxscalelog_enabled = config_truth_value(optarg); + } + } break; case 's': - if(strstr(optarg,"=")) - { - strtok(optarg,"= "); - syslog_enabled = config_truth_value(strtok(NULL,"= ")); - } - else - { - syslog_enabled = config_truth_value(optarg); - } + { + char* tok = strstr(optarg,"="); + if(tok) + { + tok++; + if(tok) + syslog_enabled = config_truth_value(tok); + } + else + { + syslog_enabled = config_truth_value(optarg); + } + } break; case 'U': if(set_user(optarg) != 0) From 2b2e81feb26665b938eb4acb8a60adb124bb6fdc Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 11 Jun 2015 19:05:05 +0300 Subject: [PATCH 3/8] Fix to MXS-181: https://mariadb.atlassian.net/browse/MXS-181 Added TCP_NODELAY to socket options. --- server/modules/protocol/mysql_client.c | 4 ++++ server/modules/protocol/mysql_common.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index abdb4422c..ea0b05b79 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -46,6 +46,7 @@ #include #include #include +#include MODULE_INFO info = { MODULE_API_PROTOCOL, @@ -1064,6 +1065,9 @@ int gw_MySQLListener( LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); } + if((syseno = setsockopt(l_so, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one))) != 0){ + LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,"Error: Failed to set socket options. Error %d: %s",errno,strerror(errno)))); + } // set NONBLOCKING mode setnonblocking(l_so); diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index ffd72c034..0a7f22f5e 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -44,6 +44,7 @@ #include #include #include +#include /** Defined in log_manager.cc */ extern int lm_enabled_logfiles_bitmask; @@ -812,6 +813,23 @@ int gw_do_connect_to_backend( goto close_so; } + int one = 1; + if(setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0) + { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: Failed to set socket options " + "%s:%d failed.\n\t\t Socket configuration failed " + "due %d, %s.", + host, + port, + errno, + strerror(errno)))); + rv = -1; + /** Close socket */ + goto close_so; + } + /* set socket to as non-blocking here */ setnonblocking(so); rv = connect(so, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); From 6f0e3937eba9e4466a9b4645deca9064c76cde47 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 11 Jun 2015 19:43:22 +0300 Subject: [PATCH 4/8] Added missing include to gwdirs.h. --- server/include/gwdirs.h.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/include/gwdirs.h.in b/server/include/gwdirs.h.in index cf1f47987..fe911c71b 100644 --- a/server/include/gwdirs.h.in +++ b/server/include/gwdirs.h.in @@ -18,9 +18,11 @@ * * Copyright MariaDB Corporation Ab 2015 */ - +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif #include - +#include /** Default file locations, configured by CMake */ static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = "/etc/"; From fe2062b5b09d18f4bfb078f646fd941bdd09338b Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 11 Jun 2015 19:50:51 +0300 Subject: [PATCH 5/8] Fixed a regression in mysql_mon.c which caused a memory leak --- server/modules/monitor/mysql_mon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index 2e16afc7b..e310e2ede 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -323,6 +323,8 @@ char *server_string; int read_timeout = mon->read_timeout; int write_timeout = mon->write_timeout; + if(database->con) + mysql_close(database->con); database->con = mysql_init(NULL); mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&connect_timeout); From 68d5054afe3977717af708834b1fa15d50c44963 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 11 Jun 2015 20:58:27 +0300 Subject: [PATCH 6/8] dcb_alloc now explicitly sets the server and service pointers to NULL. --- server/core/dcb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 6717aea41..128ffed21 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -193,7 +193,8 @@ DCB *rval; rval->polloutbusy = 0; rval->writecheck = 0; rval->fd = DCBFD_CLOSED; - + rval->server = NULL; + rval->service = NULL; rval->evq.next = NULL; rval->evq.prev = NULL; rval->evq.pending_events = 0; From 521e1aaf3b9126a7c21c31219871f3eb25f959e8 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 12 Jun 2015 02:44:43 +0300 Subject: [PATCH 7/8] Added man page for maxscale. --- CMakeLists.txt | 1 + Documentation/maxscale.1 | 69 ++++++++++++++++++++++++++++++++++++++++ etc/postinst.in | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Documentation/maxscale.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f35031d8..a21e9c745 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,7 @@ install(FILES ${ERRMSG} DESTINATION ${MAXSCALE_VARDIR}/lib/maxscale install(FILES ${CMAKE_SOURCE_DIR}/COPYRIGHT DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/README DESTINATION ${MAXSCALE_SHAREDIR}) install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${MAXSCALE_SHAREDIR}) +install(FILES Documentation/maxscale.1 DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1) # Install startup scripts and ldconfig files if(WITH_SCRIPTS) diff --git a/Documentation/maxscale.1 b/Documentation/maxscale.1 new file mode 100644 index 000000000..104eaa235 --- /dev/null +++ b/Documentation/maxscale.1 @@ -0,0 +1,69 @@ +.TH maxscale 1 +.SH NAME +maxscale - The intelligent proxy +.SH SYNOPSIS +.B maxscale +[\fIOPTIONS...\fR] +.SH DESCRIPTION +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. + +MaxScale is designed to provide load balancing and high availability +functionality transparently to the applications. In addition it provides +a highly scalable and flexible architecture, with plugin components to +support different protocols and routing decisions. + +.SH OPTIONS +.TP +.BR "-d, --nodaemon" +Run MaxScale in the terminal process +.TP +.BR -f " \fIFILE\fB, --config=\fIFILE\fR" +Relative or absolute pathname of MaxScale configuration file to load. +.TP +.BR -l "[\fIfile|shm\fB], --log=[\fIfile|shm\fB]" +Log trace and debug logs to file or shared memory. The debug and trace logs are disabled by default and if enabled, will log to shared memory. +.TP +.BR -L " \fIPATH\fB, --logdir=\fIPATH\fB" +Path to log file directory. +.TP +.BR -D " \fIPATH\fB, --datadir=\fIPATH\fB" +Path to data directory. This is where the embedded mysql tables are stored in addition to other MaxScale specific data. +.TP +.BR -C " \fIPATH\fB, --configdir=\fIPATH\fB" +Path to configuration file directory. MaxScale will look for the \fImaxscale.cnf\fR file from this folder. +.TP +.BR -B " \fIPATH\fB, --libdir=\fIPATH\fB" +Path to module directory. Modules are only searched from this folder. +.TP +.BR -A " \fIPATH\fB, --cachedir=\fIPATH\fB" +Path to cache directory. This is where MaxScale stores cached authentication data. +.TP +.BR -P " \fIPATH\fB, --piddir=\fIPATH\fB" +Location of MaxScale's PID file. +.TP +.BR -U " \fIUSER\fB, --user=\fIUSER\fB" +Run MaxScale as another user. The user ID and group ID of this user are used to run MaxScale. +.TP +.BR -s " [\fIyes\fB|\fIno\fB], --syslog=[\fIyes\fB|\fIno\fB]" +Log messages to syslog. +.TP +.BR -S " [\fIyes\fB|\fIno\fB], \fB--maxscalelog=[\fIyes\fB|\fIno\fB]" +Log messages to MaxScale's own log files. +.TP +.BR "-v, --version" +Print version information and exit. +.TP +.BR "-?, --help" +Show the help information for MaxScale and exit. + +.SH EXAMPLES +Tutorials on GitHub: +.UR https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Documentation-Contents.md#tutorials +.UE +.SH SEE ALSO +The MaxScale documentation on GitHub: +.UR https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Documentation-Contents.md +.UE diff --git a/etc/postinst.in b/etc/postinst.in index 1a2c68ca3..e1d3dc8ad 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -38,7 +38,7 @@ then cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.service /usr/lib/systemd/system fi /sbin/ldconfig - +mandb cat <& 2 ********** Notice: MaxScale 1.2 Changes ************** From d3cc9be52ec445602180abcfb78ccaf226ef4b5d Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 12 Jun 2015 10:05:50 +0300 Subject: [PATCH 8/8] Added libcurl-devel and pcre-devel to build dependencies. --- .../Getting-Started/Building-MaxScale-from-Source-Code.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md index f83a6e3ae..95236ed7e 100644 --- a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md +++ b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md @@ -28,7 +28,7 @@ You will need to install all of the following packages for all versions of RHEL, ``` gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool -openssl-devel libaio libaio-devel librabbitmq-devel +openssl-devel libaio libaio-devel librabbitmq-devel libcurl-devel pcre-devel ``` In addition, if you wish to to build an RPM package include: @@ -68,7 +68,7 @@ These packages are required on all versions of Ubuntu and Debian. ``` build-essential libssl-dev libaio-dev ncurses-dev bison - cmake perl libtool librabbitmq-dev + cmake perl libtool librabbitmq-dev libcurl-dev libpcre3-dev ``` If you want to build a DEB package, you will also need: