From e0a584a6263abb589a32cb69a0b6d133579bc744 Mon Sep 17 00:00:00 2001 From: Timofey Turenko Date: Wed, 3 Jan 2018 14:12:43 +0200 Subject: [PATCH 01/14] add ulimit setting for tests --- maxscale-system-test/mdbci/run_test.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/maxscale-system-test/mdbci/run_test.sh b/maxscale-system-test/mdbci/run_test.sh index b34962aad..c74ab8dc9 100755 --- a/maxscale-system-test/mdbci/run_test.sh +++ b/maxscale-system-test/mdbci/run_test.sh @@ -6,34 +6,34 @@ # see lists of supported boxes # https://github.com/mariadb-corporation/mdbci/tree/integration/BOXES -# $template - name of MDBCI json template file +# $template - name of MDBCI json template file # Template file have to be in ./templates/, file name # have to be '$template.json.template # Template file can contain references to any variables - # all ${variable_name} will be replaced with values # $name - name of test run. It can be any string of leytters or digits -# If it is not defined, name will be automatically genereted +# If it is not defined, name will be automatically genereted # using $box and current date and time -# $ci_url - URL to Maxscale CI repository +# $ci_url - URL to Maxscale CI repository # (default "http://max-tst-01.mariadb.com/ci-repository/") # if build is done also locally and binaries are not uploaded to # max-tst-01.mariadb.com $ci_url should toint to local web server -# e.g. http://192.168.122.1/repository (IP should be a host IP in the +# e.g. http://192.168.122.1/repository (IP should be a host IP in the # virtual network (not 127.0.0.1)) # $product - 'mariadb' or 'mysql' # $version - version of backend DB (e.g. '10.1', '10.2') -# $galera_version - version of Galera backend DB -# same as $version by default +# $galera_version - version of Galera backend DB +# same as $version by default -# $target - name of binary repository +# $target - name of binary repository # (name of subdirectroy http://max-tst-01.mariadb.com/ci-repository/) -# $team_keys - path to the file with open ssh keys to be +# $team_keys - path to the file with open ssh keys to be # installed on all VMs (default ${HOME}/team_keys) # $don_not_destroy_vm - if 'yes' VM won't be destored afther the test @@ -61,6 +61,7 @@ export name=`echo $name | sed "s/?//g"` ${script_dir}/create_config.sh res=$? +ulimit -c unlimited if [ $res == 0 ] ; then # . ${script_dir}/configure_backend.sh . ${script_dir}/set_env.sh $name @@ -75,7 +76,7 @@ if [ $res == 0 ] ; then if [ $? != 0 ]; then echo "Backend broken!" if [ "${do_not_destroy_vm}" != "yes" ] ; then - ${script_dir}/destroy.sh + ${script_dir}/destroy.sh fi rm ~/vagrant_lock exit 1 @@ -83,9 +84,9 @@ if [ $res == 0 ] ; then ${mdbci_dir}/mdbci snapshot take --path-to-nodes $name --snapshot-name clean ctest -VV -D Nightly ${test_set} fi - - cd $dir + cp core.* ${logs_publish_dir} ${script_dir}/copy_logs.sh + cd $dir else echo "Failed to create VMs, exiting" if [ "${do_not_destroy_vm}" != "yes" ] ; then @@ -99,4 +100,3 @@ if [ "${do_not_destroy_vm}" != "yes" ] ; then ${script_dir}/destroy.sh echo "clean up done!" fi - From df0def9c973c6d9b74e9b2114778598ac1681bfe Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 3 Jan 2018 13:29:00 +0200 Subject: [PATCH 02/14] Remove unused skygw_-functions --- server/core/internal/skygw_utils.h | 14 ---- server/core/skygw_utils.cc | 111 ----------------------------- 2 files changed, 125 deletions(-) diff --git a/server/core/internal/skygw_utils.h b/server/core/internal/skygw_utils.h index d752950e5..cceabf6eb 100644 --- a/server/core/internal/skygw_utils.h +++ b/server/core/internal/skygw_utils.h @@ -40,15 +40,6 @@ typedef struct simple_mutex_st skygw_chk_t sm_chk_tail; } simple_mutex_t; -typedef struct skygw_rwlock_st -{ - skygw_chk_t srw_chk_top; - pthread_rwlock_t* srw_rwlock; - pthread_t srw_rwlock_thr; - skygw_chk_t srw_chk_tail; -} skygw_rwlock_t; - - typedef enum { THR_INIT, THR_RUNNING, THR_STOPPED, THR_DONE } skygw_thr_state_t; typedef enum { MES_RC_FAIL, MES_RC_SUCCESS, MES_RC_TIMEOUT } skygw_mes_rc_t; @@ -158,11 +149,6 @@ void skygw_message_reset(skygw_message_t* mes); /** Skygw message routines */ -int skygw_rwlock_wrlock(skygw_rwlock_t* rwlock); -int skygw_rwlock_rdlock(skygw_rwlock_t* rwlock); -int skygw_rwlock_unlock(skygw_rwlock_t* rwlock); -int skygw_rwlock_init(skygw_rwlock_t** rwlock); - size_t get_decimal_len(size_t s); MXS_END_DECLS diff --git a/server/core/skygw_utils.cc b/server/core/skygw_utils.cc index 262db6889..baa18a184 100644 --- a/server/core/skygw_utils.cc +++ b/server/core/skygw_utils.cc @@ -43,117 +43,6 @@ static void simple_mutex_free_memory(simple_mutex_t* sm); static void thread_free_memory(skygw_thread_t* th, char* name); /** End of static function declarations */ - -int skygw_rwlock_rdlock(skygw_rwlock_t* rwlock) -{ - int err = pthread_rwlock_rdlock(rwlock->srw_rwlock); - - if (err == 0) - { - rwlock->srw_rwlock_thr = pthread_self(); - } - else - { - rwlock->srw_rwlock_thr = 0; - ss_dfprintf(stderr, - "* pthread_rwlock_rdlock : %s\n", - mxs_strerror(err)); - } - return err; -} - -int skygw_rwlock_wrlock(skygw_rwlock_t* rwlock) -{ - int err = pthread_rwlock_wrlock(rwlock->srw_rwlock); - - if (err == 0) - { - rwlock->srw_rwlock_thr = pthread_self(); - } - else - { - rwlock->srw_rwlock_thr = 0; - ss_dfprintf(stderr, - "* pthread_rwlock_wrlock : %s\n", - mxs_strerror(err)); - } - return err; -} - -int skygw_rwlock_unlock(skygw_rwlock_t* rwlock) -{ - int err = pthread_rwlock_rdlock(rwlock->srw_rwlock); - - if (err == 0) - { - rwlock->srw_rwlock_thr = 0; - } - else - { - ss_dfprintf(stderr, "* pthread_rwlock_unlock : %s\n", - mxs_strerror(err)); - } - return err; -} - -int skygw_rwlock_destroy(skygw_rwlock_t* rwlock) -{ - int err; - /** Lock */ - if ((err = pthread_rwlock_wrlock(rwlock->srw_rwlock)) != 0) - { - fprintf(stderr, "* Error : pthread_rwlock_wrlock failed due to %d, %s.\n", - err, mxs_strerror(err)); - goto retblock; - } - /** Clean the struct */ - rwlock->srw_rwlock_thr = 0; - /** Unlock */ - pthread_rwlock_unlock(rwlock->srw_rwlock); - /** Destroy */ - if ((err = pthread_rwlock_destroy(rwlock->srw_rwlock)) != 0) - { - fprintf(stderr, "* Error : pthread_rwlock_destroy failed due to %d,%s\n", - err, mxs_strerror(err)); - } - else - { - rwlock->srw_rwlock = NULL; - } -retblock: - return err; -} - -int skygw_rwlock_init(skygw_rwlock_t** rwlock) -{ - skygw_rwlock_t* rwl; - int err; - - rwl = (skygw_rwlock_t *) calloc(1, sizeof (skygw_rwlock_t)); - - if (rwl == NULL) - { - err = 1; - goto return_err; - } - rwl->srw_chk_top = CHK_NUM_RWLOCK; - rwl->srw_chk_tail = CHK_NUM_RWLOCK; - err = pthread_rwlock_init(rwl->srw_rwlock, NULL); - ss_dassert(err == 0); - - if (err != 0) - { - free(rwl); - ss_dfprintf(stderr, "* Creating pthread_rwlock failed : %s\n", - mxs_strerror(err)); - goto return_err; - } - *rwlock = rwl; - -return_err: - return err; -} - size_t get_timestamp_len(void) { return timestamp_len; From 289ae983df4a6859bc00a3dc366bed1115036966 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 3 Jan 2018 13:50:00 +0200 Subject: [PATCH 03/14] Replace log custom spinlocks with SPINLOCK --- server/core/internal/skygw_utils.h | 3 --- server/core/log_manager.cc | 42 +++++++++++++++--------------- server/core/skygw_utils.cc | 23 ---------------- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/server/core/internal/skygw_utils.h b/server/core/internal/skygw_utils.h index cceabf6eb..1c4b6e85c 100644 --- a/server/core/internal/skygw_utils.h +++ b/server/core/internal/skygw_utils.h @@ -131,9 +131,6 @@ int skygw_file_write(skygw_file_t* file, bool flush); /** Skygw file routines */ -void acquire_lock(int* l); -void release_lock(int* l); - simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, const char* name); int simple_mutex_done(simple_mutex_t* sm); int simple_mutex_lock(simple_mutex_t* sm, bool block); diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index 48392306a..45ae89d9c 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -154,7 +154,7 @@ typedef struct logmanager logmanager_t; * Global log manager pointer and lock variable. * lmlock protects logmanager access. */ -static int lmlock; +static SPINLOCK lmlock = SPINLOCK_INIT; static logmanager_t* lm; static bool flushall_flag; static bool flushall_started_flag; @@ -370,7 +370,7 @@ struct logfile size_t lf_buf_size; bool lf_flushflag; bool lf_rotateflag; - int lf_spinlock; /**< lf_flushflag & lf_rotateflag */ + SPINLOCK lf_spinlock; /**< lf_flushflag & lf_rotateflag */ #if defined(SS_DEBUG) skygw_chk_t lf_chk_tail; #endif @@ -599,7 +599,7 @@ bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target { bool succ = false; - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); if (!lm) { @@ -634,7 +634,7 @@ bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target succ = true; } - release_lock(&lmlock); + spinlock_release(&lmlock); return succ; } @@ -693,7 +693,7 @@ static void logmanager_done_nomutex(void) */ void mxs_log_finish(void) { - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); if (lm) { @@ -706,9 +706,9 @@ void mxs_log_finish(void) */ while (lm != NULL && lm->lm_nlinks != 0) { - release_lock(&lmlock); + spinlock_release(&lmlock); sched_yield(); - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); } /** Shut down if not already shutted down. */ @@ -719,7 +719,7 @@ void mxs_log_finish(void) } } - release_lock(&lmlock); + spinlock_release(&lmlock); } static logfile_t* logmanager_get_logfile(logmanager_t* lmgr) @@ -1330,7 +1330,7 @@ static bool logmanager_register(bool writep) { bool succ = true; - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); if (lm == NULL || !lm->lm_enabled) { @@ -1355,9 +1355,9 @@ static bool logmanager_register(bool writep) */ while (lm != NULL && !lm->lm_enabled) { - release_lock(&lmlock); + spinlock_release(&lmlock); sched_yield(); - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); } if (lm == NULL) @@ -1380,7 +1380,7 @@ return_succ: { fatal_error = true; } - release_lock(&lmlock); + spinlock_release(&lmlock); return succ; } @@ -1399,12 +1399,12 @@ return_succ: */ static void logmanager_unregister(void) { - acquire_lock(&lmlock); + spinlock_acquire(&lmlock); lm->lm_nlinks -= 1; ss_dassert(lm->lm_nlinks >= 0); - release_lock(&lmlock); + spinlock_release(&lmlock); } @@ -1461,9 +1461,9 @@ static bool fnames_conf_init(fnames_conf_t* fn, const char* logdir) static void logfile_flush(logfile_t* lf) { CHK_LOGFILE(lf); - acquire_lock(&lf->lf_spinlock); + spinlock_acquire(&lf->lf_spinlock); lf->lf_flushflag = true; - release_lock(&lf->lf_spinlock); + spinlock_release(&lf->lf_spinlock); skygw_message_send(lf->lf_logmes); } @@ -1476,9 +1476,9 @@ static void logfile_flush(logfile_t* lf) static void logfile_rotate(logfile_t* lf) { CHK_LOGFILE(lf); - acquire_lock(&lf->lf_spinlock); + spinlock_acquire(&lf->lf_spinlock); lf->lf_rotateflag = true; - release_lock(&lf->lf_spinlock); + spinlock_release(&lf->lf_spinlock); skygw_message_send(lf->lf_logmes); } @@ -1867,7 +1867,7 @@ static bool logfile_init(logfile_t* logfile, logfile->lf_lmgr = logmanager; logfile->lf_flushflag = false; logfile->lf_rotateflag = false; - logfile->lf_spinlock = 0; + logfile->lf_spinlock = SPINLOCK_INIT; logfile->lf_store_shmem = store_shmem; logfile->lf_buf_size = MAX_LOGSTRLEN; /** @@ -2126,12 +2126,12 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr) /** * read and reset logfile's flush- and rotateflag */ - acquire_lock(&lf->lf_spinlock); + spinlock_acquire(&lf->lf_spinlock); bool flush_logfile = lf->lf_flushflag; bool rotate_logfile = lf->lf_rotateflag; lf->lf_flushflag = false; lf->lf_rotateflag = false; - release_lock(&lf->lf_spinlock); + spinlock_release(&lf->lf_spinlock); // fwr->fwr_file may be NULL if an earlier log-rotation failed. if (rotate_logfile || !fwr->fwr_file) diff --git a/server/core/skygw_utils.cc b/server/core/skygw_utils.cc index baa18a184..4292e2dd3 100644 --- a/server/core/skygw_utils.cc +++ b/server/core/skygw_utils.cc @@ -336,29 +336,6 @@ bool skygw_thread_must_exit(skygw_thread_t* thr) return thr->sth_must_exit; } -void acquire_lock(int* l) -{ - register int misscount = 0; - struct timespec ts1; - ts1.tv_sec = 0; - - while (atomic_add(l, 1) != 0) - { - atomic_add(l, -1); - misscount += 1; - if (misscount > 10) - { - ts1.tv_nsec = misscount * 1000000; - nanosleep(&ts1, NULL); - } - } -} - -void release_lock(int* l) -{ - atomic_add(l, -1); -} - /** * @node Create a simple_mutex structure which encapsulates pthread_mutex. * From 224f9188450ff4a56f67f08d69b7f9ed218d6414 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 3 Jan 2018 11:06:17 +0200 Subject: [PATCH 04/14] MXS-1592 Make all modules lowercase Make all modules lowercase and make module loading case insensitive. Further, make command invocation case insensitive, as far as the module name is conserned. --- server/core/load_utils.cc | 10 ++++++++-- server/core/modulecmd.cc | 4 ++-- .../modules/authenticator/CDCPlainAuth/CMakeLists.txt | 8 ++++---- .../authenticator/GSSAPI/GSSAPIAuth/CMakeLists.txt | 8 ++++---- .../GSSAPI/GSSAPIBackendAuth/CMakeLists.txt | 8 ++++---- server/modules/authenticator/HTTPAuth/CMakeLists.txt | 8 ++++---- .../modules/authenticator/MaxAdminAuth/CMakeLists.txt | 8 ++++---- server/modules/authenticator/MySQLAuth/CMakeLists.txt | 8 ++++---- .../authenticator/MySQLBackendAuth/CMakeLists.txt | 8 ++++---- .../modules/authenticator/NullAuthAllow/CMakeLists.txt | 8 ++++---- .../modules/authenticator/NullAuthDeny/CMakeLists.txt | 8 ++++---- .../modules/authenticator/PAM/PAMAuth/CMakeLists.txt | 8 ++++---- .../authenticator/PAM/PAMBackendAuth/CMakeLists.txt | 8 ++++---- server/modules/filter/cache/CMakeLists.txt | 2 +- server/modules/filter/dbfwfilter/CMakeLists.txt | 4 ++-- server/modules/filter/insertstream/CMakeLists.txt | 2 +- server/modules/filter/tee/CMakeLists.txt | 2 +- server/modules/protocol/CDC/CMakeLists.txt | 8 ++++---- server/modules/protocol/MySQL/CMakeLists.txt | 8 ++++---- .../modules/protocol/MySQL/MySQLBackend/CMakeLists.txt | 8 ++++---- .../modules/protocol/MySQL/MySQLClient/CMakeLists.txt | 8 ++++---- server/modules/protocol/MySQL/test/CMakeLists.txt | 2 +- server/modules/routing/readwritesplit/CMakeLists.txt | 2 +- server/modules/routing/schemarouter/CMakeLists.txt | 2 +- 24 files changed, 78 insertions(+), 72 deletions(-) diff --git a/server/core/load_utils.cc b/server/core/load_utils.cc index 0ea413225..b313d68a9 100644 --- a/server/core/load_utils.cc +++ b/server/core/load_utils.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -139,9 +140,14 @@ void *load_module(const char *module, const char *type) if ((mod = find_module(module)) == NULL) { + size_t len = strlen(module); + char lc_module[len + 1]; + lc_module[len] = 0; + std::transform(module, module + len, lc_module, tolower); + /** The module is not already loaded, search for the shared object */ char fname[MAXPATHLEN + 1]; - snprintf(fname, MAXPATHLEN + 1, "%s/lib%s.so", get_libdir(), module); + snprintf(fname, MAXPATHLEN + 1, "%s/lib%s.so", get_libdir(), lc_module); if (access(fname, F_OK) == -1) { @@ -219,7 +225,7 @@ find_module(const char *module) { while (mod) { - if (strcmp(mod->module, module) == 0) + if (strcasecmp(mod->module, module) == 0) { return mod; } diff --git a/server/core/modulecmd.cc b/server/core/modulecmd.cc index 68290fb3f..717fd19e1 100644 --- a/server/core/modulecmd.cc +++ b/server/core/modulecmd.cc @@ -323,7 +323,7 @@ static bool process_argument(const MODULECMD *cmd, modulecmd_arg_type_t *type, c if ((arg->value.monitor = monitor_find((char*)value))) { const char* eff_name = mxs_module_get_effective_name(arg->value.monitor->module_name); - if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcmp(cmd->domain, eff_name) == 0) + if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcasecmp(cmd->domain, eff_name) == 0) { arg->type.type = MODULECMD_ARG_MONITOR; rval = true; @@ -343,7 +343,7 @@ static bool process_argument(const MODULECMD *cmd, modulecmd_arg_type_t *type, c if ((arg->value.filter = filter_def_find((char*)value))) { const char* eff_name = mxs_module_get_effective_name(arg->value.filter->module); - if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcmp(cmd->domain, eff_name) == 0) + if (MODULECMD_ALLOW_NAME_MISMATCH(type) || strcasecmp(cmd->domain, eff_name) == 0) { arg->type.type = MODULECMD_ARG_FILTER; rval = true; diff --git a/server/modules/authenticator/CDCPlainAuth/CMakeLists.txt b/server/modules/authenticator/CDCPlainAuth/CMakeLists.txt index f729f9979..457c87044 100644 --- a/server/modules/authenticator/CDCPlainAuth/CMakeLists.txt +++ b/server/modules/authenticator/CDCPlainAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(CDCPlainAuth SHARED cdc_plain_auth.c) -target_link_libraries(CDCPlainAuth maxscale-common) -set_target_properties(CDCPlainAuth PROPERTIES VERSION "1.0.0") -install_module(CDCPlainAuth core) +add_library(cdcplainauth SHARED cdc_plain_auth.c) +target_link_libraries(cdcplainauth maxscale-common) +set_target_properties(cdcplainauth PROPERTIES VERSION "1.0.0") +install_module(cdcplainauth core) diff --git a/server/modules/authenticator/GSSAPI/GSSAPIAuth/CMakeLists.txt b/server/modules/authenticator/GSSAPI/GSSAPIAuth/CMakeLists.txt index 7dd3034a9..a94d9d8f5 100644 --- a/server/modules/authenticator/GSSAPI/GSSAPIAuth/CMakeLists.txt +++ b/server/modules/authenticator/GSSAPI/GSSAPIAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(GSSAPIAuth SHARED gssapi_auth.c ../gssapi_auth_common.c) -target_link_libraries(GSSAPIAuth maxscale-common ${GSSAPI_LIBS} ${SQLITE_LIBRARIES} MySQLCommon) -set_target_properties(GSSAPIAuth PROPERTIES VERSION "1.0.0") -install_module(GSSAPIAuth core) +add_library(gssapiauth SHARED gssapi_auth.c ../gssapi_auth_common.c) +target_link_libraries(gssapiauth maxscale-common ${GSSAPI_LIBS} ${SQLITE_LIBRARIES} mysqlcommon) +set_target_properties(gssapiauth PROPERTIES VERSION "1.0.0") +install_module(gssapiauth core) diff --git a/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/CMakeLists.txt b/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/CMakeLists.txt index fc61e8e9d..98b1a81e0 100644 --- a/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/CMakeLists.txt +++ b/server/modules/authenticator/GSSAPI/GSSAPIBackendAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(GSSAPIBackendAuth SHARED gssapi_backend_auth.c ../gssapi_auth_common.c) -target_link_libraries(GSSAPIBackendAuth maxscale-common ${GSSAPI_LIBS} MySQLCommon) -set_target_properties(GSSAPIBackendAuth PROPERTIES VERSION "1.0.0") -install_module(GSSAPIBackendAuth core) +add_library(gssapibackendauth SHARED gssapi_backend_auth.c ../gssapi_auth_common.c) +target_link_libraries(gssapibackendauth maxscale-common ${GSSAPI_LIBS} mysqlcommon) +set_target_properties(gssapibackendauth PROPERTIES VERSION "1.0.0") +install_module(gssapibackendauth core) diff --git a/server/modules/authenticator/HTTPAuth/CMakeLists.txt b/server/modules/authenticator/HTTPAuth/CMakeLists.txt index 31e72afac..8bfcfe844 100644 --- a/server/modules/authenticator/HTTPAuth/CMakeLists.txt +++ b/server/modules/authenticator/HTTPAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(HTTPAuth SHARED http_auth.c) -target_link_libraries(HTTPAuth maxscale-common) -set_target_properties(HTTPAuth PROPERTIES VERSION "1.0.0") -install_module(HTTPAuth core) +add_library(httpauth SHARED http_auth.c) +target_link_libraries(httpauth maxscale-common) +set_target_properties(httpauth PROPERTIES VERSION "1.0.0") +install_module(httpauth core) diff --git a/server/modules/authenticator/MaxAdminAuth/CMakeLists.txt b/server/modules/authenticator/MaxAdminAuth/CMakeLists.txt index 7de926fb2..6ea6328dc 100644 --- a/server/modules/authenticator/MaxAdminAuth/CMakeLists.txt +++ b/server/modules/authenticator/MaxAdminAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(MaxAdminAuth SHARED max_admin_auth.c) -target_link_libraries(MaxAdminAuth maxscale-common) -set_target_properties(MaxAdminAuth PROPERTIES VERSION "1.0.0") -install_module(MaxAdminAuth core) +add_library(maxadminauth SHARED max_admin_auth.c) +target_link_libraries(maxadminauth maxscale-common) +set_target_properties(maxadminauth PROPERTIES VERSION "1.0.0") +install_module(maxadminauth core) diff --git a/server/modules/authenticator/MySQLAuth/CMakeLists.txt b/server/modules/authenticator/MySQLAuth/CMakeLists.txt index 9828e34b6..a4aa424f1 100644 --- a/server/modules/authenticator/MySQLAuth/CMakeLists.txt +++ b/server/modules/authenticator/MySQLAuth/CMakeLists.txt @@ -1,8 +1,8 @@ if(SQLITE_VERSION VERSION_LESS 3.3) message(FATAL_ERROR "SQLite version 3.3 or higher is required") else() - add_library(MySQLAuth SHARED mysql_auth.c dbusers.c) - target_link_libraries(MySQLAuth maxscale-common MySQLCommon sqlite3) - set_target_properties(MySQLAuth PROPERTIES VERSION "1.0.0") - install_module(MySQLAuth core) + add_library(mysqlauth SHARED mysql_auth.c dbusers.c) + target_link_libraries(mysqlauth maxscale-common mysqlcommon sqlite3) + set_target_properties(mysqlauth PROPERTIES VERSION "1.0.0") + install_module(mysqlauth core) endif() diff --git a/server/modules/authenticator/MySQLBackendAuth/CMakeLists.txt b/server/modules/authenticator/MySQLBackendAuth/CMakeLists.txt index 65582f6ca..26880ed36 100644 --- a/server/modules/authenticator/MySQLBackendAuth/CMakeLists.txt +++ b/server/modules/authenticator/MySQLBackendAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(MySQLBackendAuth SHARED mysql_backend_auth.c) -target_link_libraries(MySQLBackendAuth maxscale-common MySQLCommon) -set_target_properties(MySQLBackendAuth PROPERTIES VERSION "1.0.0") -install_module(MySQLBackendAuth core) +add_library(mysqlbackendauth SHARED mysql_backend_auth.c) +target_link_libraries(mysqlbackendauth maxscale-common mysqlcommon) +set_target_properties(mysqlbackendauth PROPERTIES VERSION "1.0.0") +install_module(mysqlbackendauth core) diff --git a/server/modules/authenticator/NullAuthAllow/CMakeLists.txt b/server/modules/authenticator/NullAuthAllow/CMakeLists.txt index 23be1cb3e..fb1ee7e2f 100644 --- a/server/modules/authenticator/NullAuthAllow/CMakeLists.txt +++ b/server/modules/authenticator/NullAuthAllow/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(NullAuthAllow SHARED null_auth_allow.c) -target_link_libraries(NullAuthAllow maxscale-common MySQLCommon) -set_target_properties(NullAuthAllow PROPERTIES VERSION "1.0.0") -install_module(NullAuthAllow core) +add_library(nullauthallow SHARED null_auth_allow.c) +target_link_libraries(nullauthallow maxscale-common mysqlcommon) +set_target_properties(nullauthallow PROPERTIES VERSION "1.0.0") +install_module(nullauthallow core) diff --git a/server/modules/authenticator/NullAuthDeny/CMakeLists.txt b/server/modules/authenticator/NullAuthDeny/CMakeLists.txt index bedb90cee..d3650588c 100644 --- a/server/modules/authenticator/NullAuthDeny/CMakeLists.txt +++ b/server/modules/authenticator/NullAuthDeny/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(NullAuthDeny SHARED null_auth_deny.c) -target_link_libraries(NullAuthDeny maxscale-common) -set_target_properties(NullAuthDeny PROPERTIES VERSION "1.0.0") -install_module(NullAuthDeny core) +add_library(nullauthdeny SHARED null_auth_deny.c) +target_link_libraries(nullauthdeny maxscale-common) +set_target_properties(nullauthdeny PROPERTIES VERSION "1.0.0") +install_module(nullauthdeny core) diff --git a/server/modules/authenticator/PAM/PAMAuth/CMakeLists.txt b/server/modules/authenticator/PAM/PAMAuth/CMakeLists.txt index 468be540b..aaf7de9ca 100644 --- a/server/modules/authenticator/PAM/PAMAuth/CMakeLists.txt +++ b/server/modules/authenticator/PAM/PAMAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(PAMAuth SHARED pam_auth.cc ../pam_auth_common.cc pam_client_session.cc pam_instance.cc) -target_link_libraries(PAMAuth maxscale-common ${PAM_LIBRARIES} ${SQLITE_LIBRARIES} MySQLCommon) -set_target_properties(PAMAuth PROPERTIES VERSION "1.0.0") -install_module(PAMAuth core) +add_library(pamauth SHARED pam_auth.cc ../pam_auth_common.cc pam_client_session.cc pam_instance.cc) +target_link_libraries(pamauth maxscale-common ${PAM_LIBRARIES} ${SQLITE_LIBRARIES} mysqlcommon) +set_target_properties(pamauth PROPERTIES VERSION "1.0.0") +install_module(pamauth core) diff --git a/server/modules/authenticator/PAM/PAMBackendAuth/CMakeLists.txt b/server/modules/authenticator/PAM/PAMBackendAuth/CMakeLists.txt index fb9fb4539..c1a1b41e0 100644 --- a/server/modules/authenticator/PAM/PAMBackendAuth/CMakeLists.txt +++ b/server/modules/authenticator/PAM/PAMBackendAuth/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(PAMBackendAuth SHARED pam_backend_auth.cc ../pam_auth_common.cc pam_backend_session.cc) -target_link_libraries(PAMBackendAuth maxscale-common MySQLCommon ${SQLITE_LIBRARIES}) -set_target_properties(PAMBackendAuth PROPERTIES VERSION "1.0.0") -install_module(PAMBackendAuth core) +add_library(pambackendauth SHARED pam_backend_auth.cc ../pam_auth_common.cc pam_backend_session.cc) +target_link_libraries(pambackendauth maxscale-common mysqlcommon ${SQLITE_LIBRARIES}) +set_target_properties(pambackendauth PROPERTIES VERSION "1.0.0") +install_module(pambackendauth core) diff --git a/server/modules/filter/cache/CMakeLists.txt b/server/modules/filter/cache/CMakeLists.txt index 83a04bb9a..56b4de875 100644 --- a/server/modules/filter/cache/CMakeLists.txt +++ b/server/modules/filter/cache/CMakeLists.txt @@ -17,7 +17,7 @@ if (JANSSON_FOUND) storagefactory.cc storagereal.cc ) - target_link_libraries(cache maxscale-common ${JANSSON_LIBRARIES} MySQLCommon) + target_link_libraries(cache maxscale-common ${JANSSON_LIBRARIES} mysqlcommon) set_target_properties(cache PROPERTIES VERSION "1.0.0") set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) install_module(cache core) diff --git a/server/modules/filter/dbfwfilter/CMakeLists.txt b/server/modules/filter/dbfwfilter/CMakeLists.txt index fe0da8da0..4d0802d31 100644 --- a/server/modules/filter/dbfwfilter/CMakeLists.txt +++ b/server/modules/filter/dbfwfilter/CMakeLists.txt @@ -12,13 +12,13 @@ if(BISON_FOUND AND FLEX_FOUND) add_dependencies(dbfwfilter-core pcre2 connector-c) add_library(dbfwfilter SHARED dbfwfilter.cc) - target_link_libraries(dbfwfilter maxscale-common MySQLCommon dbfwfilter-core) + target_link_libraries(dbfwfilter maxscale-common mysqlcommon dbfwfilter-core) set_target_properties(dbfwfilter PROPERTIES VERSION "1.0.0") install_module(dbfwfilter core) # The offline rule check utility add_executable(dbfwchk dbfw_rule_check.cc) - target_link_libraries(dbfwchk maxscale-common MySQLCommon dbfwfilter-core) + target_link_libraries(dbfwchk maxscale-common mysqlcommon dbfwfilter-core) install_executable(dbfwchk core) if(BUILD_TESTS) diff --git a/server/modules/filter/insertstream/CMakeLists.txt b/server/modules/filter/insertstream/CMakeLists.txt index 845821e8c..54dd18349 100644 --- a/server/modules/filter/insertstream/CMakeLists.txt +++ b/server/modules/filter/insertstream/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(insertstream SHARED insertstream.c) -target_link_libraries(insertstream maxscale-common MySQLCommon) +target_link_libraries(insertstream maxscale-common mysqlcommon) set_target_properties(insertstream PROPERTIES VERSION "1.0.0") install_module(insertstream core) diff --git a/server/modules/filter/tee/CMakeLists.txt b/server/modules/filter/tee/CMakeLists.txt index e9ebabb27..77da7e78f 100644 --- a/server/modules/filter/tee/CMakeLists.txt +++ b/server/modules/filter/tee/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(tee SHARED tee.cc teesession.cc) -target_link_libraries(tee maxscale-common MySQLCommon) +target_link_libraries(tee maxscale-common mysqlcommon) set_target_properties(tee PROPERTIES VERSION "1.0.0") install_module(tee core) diff --git a/server/modules/protocol/CDC/CMakeLists.txt b/server/modules/protocol/CDC/CMakeLists.txt index 4d6d2deb8..272891a99 100644 --- a/server/modules/protocol/CDC/CMakeLists.txt +++ b/server/modules/protocol/CDC/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(CDC SHARED cdc.c) -target_link_libraries(CDC maxscale-common) -set_target_properties(CDC PROPERTIES VERSION "1.0.1") -install_module(CDC core) +add_library(cdc SHARED cdc.c) +target_link_libraries(cdc maxscale-common) +set_target_properties(cdc PROPERTIES VERSION "1.0.1") +install_module(cdc core) diff --git a/server/modules/protocol/MySQL/CMakeLists.txt b/server/modules/protocol/MySQL/CMakeLists.txt index 24e09dcbb..75471c144 100644 --- a/server/modules/protocol/MySQL/CMakeLists.txt +++ b/server/modules/protocol/MySQL/CMakeLists.txt @@ -1,7 +1,7 @@ -add_library(MySQLCommon SHARED mysql_common.cc mariadb_client.cc) -target_link_libraries(MySQLCommon maxscale-common) -set_target_properties(MySQLCommon PROPERTIES VERSION "2.0.0") -install_module(MySQLCommon core) +add_library(mysqlcommon SHARED mysql_common.cc mariadb_client.cc) +target_link_libraries(mysqlcommon maxscale-common) +set_target_properties(mysqlcommon PROPERTIES VERSION "2.0.0") +install_module(mysqlcommon core) add_subdirectory(MySQLBackend) add_subdirectory(MySQLClient) diff --git a/server/modules/protocol/MySQL/MySQLBackend/CMakeLists.txt b/server/modules/protocol/MySQL/MySQLBackend/CMakeLists.txt index 3dc29a6e7..1da92086b 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/CMakeLists.txt +++ b/server/modules/protocol/MySQL/MySQLBackend/CMakeLists.txt @@ -1,7 +1,7 @@ -add_library(MySQLBackend SHARED mysql_backend.c) +add_library(mysqlbackend SHARED mysql_backend.c) # TODO: Refactor MySQLBackend so that COM_CHANGE_USER processing is # transparent to the protocol module. After this change, we don't need to # link against MySQLAuth. -target_link_libraries(MySQLBackend maxscale-common MySQLCommon MySQLAuth) -set_target_properties(MySQLBackend PROPERTIES VERSION "2.0.0") -install_module(MySQLBackend core) +target_link_libraries(mysqlbackend maxscale-common mysqlcommon mysqlauth) +set_target_properties(mysqlbackend PROPERTIES VERSION "2.0.0") +install_module(mysqlbackend core) diff --git a/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt b/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt index 00d2bbf06..5d2c56b7b 100644 --- a/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt +++ b/server/modules/protocol/MySQL/MySQLClient/CMakeLists.txt @@ -1,7 +1,7 @@ -add_library(MySQLClient SHARED mysql_client.cc) -target_link_libraries(MySQLClient maxscale-common MySQLCommon) -set_target_properties(MySQLClient PROPERTIES VERSION "1.0.0") -install_module(MySQLClient core) +add_library(mysqlclient SHARED mysql_client.cc) +target_link_libraries(mysqlclient maxscale-common mysqlcommon) +set_target_properties(mysqlclient PROPERTIES VERSION "1.0.0") +install_module(mysqlclient core) if(BUILD_TESTS) add_subdirectory(test) diff --git a/server/modules/protocol/MySQL/test/CMakeLists.txt b/server/modules/protocol/MySQL/test/CMakeLists.txt index 0723e3acc..a5f8e6c27 100644 --- a/server/modules/protocol/MySQL/test/CMakeLists.txt +++ b/server/modules/protocol/MySQL/test/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(test_parse_kill test_parse_kill.cc) -target_link_libraries(test_parse_kill maxscale-common MySQLCommon) +target_link_libraries(test_parse_kill maxscale-common mysqlcommon) add_test(test_parse_kill test_parse_kill) diff --git a/server/modules/routing/readwritesplit/CMakeLists.txt b/server/modules/routing/readwritesplit/CMakeLists.txt index 73ba0f832..dcea0c070 100644 --- a/server/modules/routing/readwritesplit/CMakeLists.txt +++ b/server/modules/routing/readwritesplit/CMakeLists.txt @@ -7,6 +7,6 @@ rwsplit_select_backends.cc rwsplit_session_cmd.cc rwsplit_tmp_table_multi.cc rwsplit_ps.cc) -target_link_libraries(readwritesplit maxscale-common MySQLCommon) +target_link_libraries(readwritesplit maxscale-common mysqlcommon) set_target_properties(readwritesplit PROPERTIES VERSION "1.0.2") install_module(readwritesplit core) diff --git a/server/modules/routing/schemarouter/CMakeLists.txt b/server/modules/routing/schemarouter/CMakeLists.txt index c2d3dd5d6..71ec116f1 100644 --- a/server/modules/routing/schemarouter/CMakeLists.txt +++ b/server/modules/routing/schemarouter/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(schemarouter SHARED schemarouter.cc schemarouterinstance.cc schemaroutersession.cc shard_map.cc) -target_link_libraries(schemarouter maxscale-common MySQLCommon) +target_link_libraries(schemarouter maxscale-common mysqlcommon) add_dependencies(schemarouter pcre2) set_target_properties(schemarouter PROPERTIES VERSION "1.0.0") install_module(schemarouter core) From c31881914b3bc8497a2bfb49a497af538d3b33a9 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 20 Dec 2017 10:55:11 +0200 Subject: [PATCH 05/14] MXS-1584 Correctly classify "SELECT NEXT VALUE FOR seq" --- query_classifier/qc_sqlite/qc_sqlite.cc | 16 ++++++++++------ .../qc_sqlite/sqlite-src-3110100/src/parse.y | 10 +++++++++- .../sqlite-src-3110100/tool/mkkeywordhash.c | 7 +++++++ query_classifier/test/CMakeLists.txt | 4 +++- query_classifier/test/classify.c | 5 +++++ query_classifier/test/expected.sql | 3 +++ query_classifier/test/input.sql | 3 +++ 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index 5845bff22..3e982e120 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -156,12 +156,15 @@ static thread_local struct sqlite3* pDb; // Thread specific database handle. qc_sql_mode_t sql_mode; // What sql_mode is used. QcSqliteInfo* pInfo; // The information for the current statement being classified. + uint64_t version; // Encoded version number uint32_t version_major; uint32_t version_minor; uint32_t version_patch; QC_NAME_MAPPING* pFunction_name_mappings; // How function names should be mapped. } this_thread; +const uint64_t VERSION_103 = 10 * 10000 + 3 * 100; + /** * HELPERS */ @@ -492,7 +495,10 @@ public: */ bool must_check_sequence_related_functions() const { - return (m_sql_mode == QC_SQL_MODE_ORACLE) || (this_unit.parse_as == QC_PARSE_AS_103); + return + (m_sql_mode == QC_SQL_MODE_ORACLE) || + (this_unit.parse_as == QC_PARSE_AS_103) || + (this_thread.version >= VERSION_103); } /** @@ -530,7 +536,7 @@ public: } } - if (!rv && (this_unit.parse_as == QC_PARSE_AS_103)) + if (!rv && ((this_unit.parse_as == QC_PARSE_AS_103) || (this_thread.version >= VERSION_103))) { if ((strcasecmp(zFunc_name, "lastval") == 0) || (strcasecmp(zFunc_name, "nextval") == 0)) @@ -4942,6 +4948,7 @@ static void qc_sqlite_set_server_version(uint64_t version) uint32_t minor = (version - major * 10000) / 100; uint32_t patch = version - major * 10000 - minor * 100; + this_thread.version = version; this_thread.version_major = major; this_thread.version_minor = minor; this_thread.version_patch = patch; @@ -4951,10 +4958,7 @@ static void qc_sqlite_get_server_version(uint64_t* pVersion) { QC_TRACE(); - *pVersion = - this_thread.version_major * 10000 + - this_thread.version_minor * 100 + - this_thread.version_patch; + *pVersion = this_thread.version; } diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y index e5e9de952..66a474d8b 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y @@ -623,7 +623,7 @@ columnid(A) ::= nm(X). { /*KEY*/ /*LIKE_KW*/ MASTER /*MATCH*/ MERGE - NAMES + NAMES NEXT NO OF OFFSET OPEN QUICK @@ -1207,6 +1207,14 @@ selcollist(A) ::= sclp(P) nm(X) DOT STAR(Y). { A = sqlite3ExprListAppend(pParse,P, pDot); } %ifdef MAXSCALE +selcollist(A) ::= sclp(P) NEXT VALUE FOR nm(X) as(Y). { + Expr* pSeq = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); + ExprList* pArgs = sqlite3ExprListAppend(pParse, NULL, pSeq); + Token nextval = { "nextval", 7 }; + Expr* pFunc = sqlite3ExprFunction(pParse, pArgs, &nextval); + if( Y.n>0 ) sqlite3ExprListSetName(pParse, A, &Y, 1); + A = sqlite3ExprListAppend(pParse, P, pFunc); +} selcollist(A) ::= sclp(P) DEFAULT LP nm RP as. { A = P; } diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/tool/mkkeywordhash.c b/query_classifier/qc_sqlite/sqlite-src-3110100/tool/mkkeywordhash.c index b30bb9b07..d8723ea16 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/tool/mkkeywordhash.c +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/tool/mkkeywordhash.c @@ -269,7 +269,11 @@ static Keyword aKeywordTable[] = { { "FLUSH", "TK_FLUSH", ALWAYS }, { "FOLLOWING", "TK_FOLLOWING", ALWAYS }, #endif +#ifdef MAXSCALE + { "FOR", "TK_FOR", ALWAYS }, +#else { "FOR", "TK_FOR", TRIGGER }, +#endif #ifdef MAXSCALE { "FORCE", "TK_FORCE", ALWAYS }, #endif @@ -342,6 +346,9 @@ static Keyword aKeywordTable[] = { { "NAMES", "TK_NAMES", ALWAYS }, #endif { "NATURAL", "TK_JOIN_KW", ALWAYS }, +#ifdef MAXSCALE + { "NEXT", "TK_NEXT", ALWAYS }, +#endif { "NO", "TK_NO", FKEY }, { "NOT", "TK_NOT", ALWAYS }, { "NOTNULL", "TK_NOTNULL", ALWAYS }, diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt index 4d72b4abe..d66cd160a 100644 --- a/query_classifier/test/CMakeLists.txt +++ b/query_classifier/test/CMakeLists.txt @@ -32,7 +32,9 @@ if (BUILD_QC_MYSQLEMBEDDED) add_test(TestQC_Crash_qcsqlite crash_qc_sqlite) - add_test(TestQC_MySQLEmbedded classify qc_mysqlembedded ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql) + # TestQC_MySQLEmbedded excluded, classify is now solely used for verifying the + # functionality of qc_sqlite. + #add_test(TestQC_MySQLEmbedded classify qc_mysqlembedded ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql) add_test(TestQC_SqLite classify qc_sqlite ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql) add_test(TestQC_CompareCreate compare -v 2 ${CMAKE_CURRENT_SOURCE_DIR}/create.test) diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index cb2cd2080..7e977803a 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -317,6 +317,11 @@ int main(int argc, char** argv) qc_process_init(QC_INIT_BOTH) && qc_thread_init(QC_INIT_BOTH)) { + // Version encoded as MariaDB encodes the version, i.e.: + // version = major * 10000 + minor * 100 + patch + uint64_t version = 10 * 10000 + 3 * 100; + + qc_set_server_version(version); rc = run(input_name, expected_name); qc_process_end(QC_INIT_BOTH); } diff --git a/query_classifier/test/expected.sql b/query_classifier/test/expected.sql index 35ef67a02..dbff01229 100644 --- a/query_classifier/test/expected.sql +++ b/query_classifier/test/expected.sql @@ -16,3 +16,6 @@ QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ QUERY_TYPE_READ|QUERY_TYPE_SYSVAR_READ +QUERY_TYPE_READ|QUERY_TYPE_WRITE +QUERY_TYPE_READ|QUERY_TYPE_WRITE +QUERY_TYPE_READ|QUERY_TYPE_WRITE diff --git a/query_classifier/test/input.sql b/query_classifier/test/input.sql index cbd63c3ce..48c5d6276 100644 --- a/query_classifier/test/input.sql +++ b/query_classifier/test/input.sql @@ -16,3 +16,6 @@ select last_insert_id(); select @@last_insert_id; select @@identity; select if(@@hostname='box02','prod_mariadb02','n'); +select next value for seq1; +select nextval(seq1); +select seq1.nextval; From 632f9f2864f9b24a41bf7b47cca87e9328f762b1 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 3 Jan 2018 15:58:57 +0200 Subject: [PATCH 06/14] Fix typo in help message --- server/core/gateway.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/gateway.cc b/server/core/gateway.cc index bfb3a1c3a..850d1b7bc 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -204,7 +204,7 @@ const DEBUG_ARGUMENT debug_arguments[] = { "disable-module-unloading", disable_module_unloading, "disable module unloading at exit. Will produce better\n" - SPACER "Valgring leak reports if leaked memory was allocated in\n" + SPACER "Valgrind leak reports if leaked memory was allocated in\n" SPACER "a shared library" }, { From e9fceff8cefa9ebedbd7fea1a869474d87cdd4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 3 Jan 2018 16:07:21 +0200 Subject: [PATCH 07/14] Fix log manager race condition The log manager could send two messages if a log message was posted soon before the log manager was stopped. This caused a debug assertion which then manifested as a deadlock inside the log manager. --- server/core/log_manager.cc | 17 ++++++++++++++--- server/core/skygw_utils.cc | 2 ++ server/core/test/testlog.c | 2 -- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index 4528813e5..f9781d171 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -2321,7 +2321,9 @@ static void* thr_filewriter_fun(void* data) /** Inform log manager about the state. */ skygw_message_send(fwr->fwr_clientmes); - while (!skygw_thread_must_exit(thr)) + bool running = true; + + do { /** * Wait until new log arrival message appears. @@ -2347,14 +2349,23 @@ static void* thr_filewriter_fun(void* data) } } + bool send_message = false; + if (flushall_done_flag) { flushall_done_flag = false; flushall_logfiles(false); - skygw_message_send(fwr->fwr_clientmes); + send_message = true; } - } /* while (!skygw_thread_must_exit) */ + running = !skygw_thread_must_exit(thr); + + if (running && send_message) + { + skygw_message_send(fwr->fwr_clientmes); + } + } + while (running); ss_debug(skygw_thread_set_state(thr, THR_STOPPED)); /** Inform log manager that file writer thread has stopped. */ diff --git a/server/core/skygw_utils.cc b/server/core/skygw_utils.cc index 9ef3bac56..7afd5a60e 100644 --- a/server/core/skygw_utils.cc +++ b/server/core/skygw_utils.cc @@ -436,7 +436,9 @@ bool skygw_thread_set_exitflag(skygw_thread_t* thr, skygw_message_t* sendmes, skygw_message_wait(recmes); } + ss_dassert(simple_mutex_lock(thr->sth_mutex, true) == 0); ss_dassert(thr->sth_state == THR_STOPPED); + ss_dassert(simple_mutex_unlock(thr->sth_mutex) == 0); return_succp: return succp; diff --git a/server/core/test/testlog.c b/server/core/test/testlog.c index f4d713df7..7e4fd8237 100644 --- a/server/core/test/testlog.c +++ b/server/core/test/testlog.c @@ -221,8 +221,6 @@ int main(int argc, char* argv[]) err = MXS_NOTICE("%s", logstr); ss_dassert(err == 0); - succp = mxs_log_init(NULL, "/tmp", MXS_LOG_TARGET_FS); - ss_dassert(succp); skygw_log_enable(LOG_INFO); logstr = ("6.\tWrite to ERROR and thus also to MESSAGE and TRACE logs."); err = MXS_ERROR("%s", logstr); From a6914ebefec4bc2cbe4c1db2ceaed1ba3542ac74 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 3 Jan 2018 12:38:03 +0200 Subject: [PATCH 08/14] MXS-1565: Test for invalid old master rejoin The test uses standard setup (1xMaster, 3xSlaves). 1. Shutdown master (server 1), check that autofailover promotes a new master. 2. Stop MaxScale. 3. Start server 1 and add some events to it so it can no longer rejoin cluster. 4. Start MaxScale, check that server 1 does not join. 5. Set current master to replicate from server 1, turning it to a relay master. 6. Check that server 1 is master, all others are slaves (due to auto-rejoin). --- maxscale-system-test/.gitignore | 1 + maxscale-system-test/CMakeLists.txt | 3 + maxscale-system-test/mysqlmon_rejoin_bad2.cpp | 151 ++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 maxscale-system-test/mysqlmon_rejoin_bad2.cpp diff --git a/maxscale-system-test/.gitignore b/maxscale-system-test/.gitignore index b33e105e0..51da6f12a 100644 --- a/maxscale-system-test/.gitignore +++ b/maxscale-system-test/.gitignore @@ -180,6 +180,7 @@ mysqlmon_failover_auto mysqlmon_failover_manual mysqlmon_rejoin_good mysqlmon_rejoin_bad +mysqlmon_rejoin_bad2 namedserverfilter no_password non_native_setup diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 22283e486..01ddb4f32 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -278,6 +278,9 @@ add_test_executable(mysqlmon_rejoin_good.cpp mysqlmon_rejoin_good mysqlmon_rejoi # MySQL Monitor Rejoin (bad) Test, use template for Rejoin (good) add_test_executable(mysqlmon_rejoin_bad.cpp mysqlmon_rejoin_bad mysqlmon_rejoin_good LABELS mysqlmon REPL_BACKEND) +# MySQL Monitor Rejoin (bad2) Test, use template for Rejoin (good) +add_test_executable(mysqlmon_rejoin_bad2.cpp mysqlmon_rejoin_bad2 mysqlmon_rejoin_good LABELS mysqlmon REPL_BACKEND) + # MySQL Monitor rolling master add_test_executable(mysqlmon_failover_rolling_master.cpp mysqlmon_failover_rolling_master mysqlmon_failover_rolling_master LABELS mysqlmon REPL_BACKEND) diff --git a/maxscale-system-test/mysqlmon_rejoin_bad2.cpp b/maxscale-system-test/mysqlmon_rejoin_bad2.cpp new file mode 100644 index 000000000..27837696b --- /dev/null +++ b/maxscale-system-test/mysqlmon_rejoin_bad2.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2020-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include +#include +#include + +#include "testconnections.h" +#include "fail_switch_rejoin_common.cpp" + +using std::string; +using std::cout; +using std::endl; + +static void expect(TestConnections& test, const char* zServer, const StringSet& expected) +{ + StringSet found = test.get_server_status(zServer); + + std::ostream_iterator oi(cout, ", "); + + cout << zServer + << ", expected states: "; + std::copy(expected.begin(), expected.end(), oi); + cout << endl; + + cout << zServer + << ", found states : "; + std::copy(found.begin(), found.end(), oi); + cout << endl; + + if (found != expected) + { + cout << "ERROR, found states are not the same as the expected ones." << endl; + ++test.global_result; + } + + cout << endl; +} + +static void expect(TestConnections& test, const char* zServer, const char* zState) +{ + StringSet s; + s.insert(zState); + + expect(test, zServer, s); +} + +static void expect(TestConnections& test, const char* zServer, const char* zState1, const char* zState2) +{ + StringSet s; + s.insert(zState1); + s.insert(zState2); + + expect(test, zServer, s); +} + +int main(int argc, char** argv) +{ + char result_tmp[bufsize]; + interactive = strcmp(argv[argc - 1], "interactive") == 0; + Mariadb_nodes::require_gtid(true); + TestConnections test(argc, argv); + MYSQL* maxconn = test.maxscales->open_rwsplit_connection(0); + + // Set up test table + basic_test(test); + // Delete binlogs to sync gtid:s + delete_slave_binlogs(test); + // Advance gtid:s a bit to so gtid variables are updated. + generate_traffic_and_check(test, maxconn, 5); + test.repl->sync_slaves(0); + get_output(test); + + print_gtids(test); + get_input(); + mysql_close(maxconn); + + // Stop master, wait for failover + cout << "Stopping master, should auto-failover." << endl; + int master_id_old = get_master_server_id(test); + test.repl->stop_node(0); + sleep(5); + get_output(test); + int master_id_new = get_master_server_id(test); + cout << "Master server id is " << master_id_new << endl; + test.assert(master_id_new > 0 && master_id_new != master_id_old, + "Failover did not promote a new master."); + if (test.global_result != 0) + { + return test.global_result; + } + + // Stop maxscale to prevent an unintended rejoin. + if (test.stop_maxscale(0)) + { + test.assert(false, "Could not stop MaxScale."); + return test.global_result; + } + // Restart old master. Then add some events to it. + test.repl->start_node(0, (char*)""); + sleep(3); + test.repl->connect(); + cout << "Adding more events to node 0. It should not join the cluster." << endl; + generate_traffic_and_check(test, test.repl->nodes[0], 5); + print_gtids(test); + // Restart maxscale. Should not rejoin old master. + if (test.start_maxscale(0)) + { + test.assert(false, "Could not start MaxScale."); + return test.global_result; + } + sleep(5); + get_output(test); + + expect(test, "server1", "Running"); + if (test.global_result != 0) + { + cout << "Old master is a member or the cluster when it should not be." << endl; + return test.global_result; + } + + // Manually set current master to replicate from the old master to quickly fix the cluster. + cout << "Setting server " << master_id_new << " to replicate from server 1. Auto-rejoin should redirect " + "servers so that in the end server 1 is master and all others are slaves." << endl; + const char CHANGE_CMD_FMT[] = "CHANGE MASTER TO MASTER_HOST = '%s', MASTER_PORT = %d, " + "MASTER_USE_GTID = current_pos, MASTER_USER='repl', MASTER_PASSWORD = 'repl';"; + char cmd[256]; + int ind = master_id_new - 1; + snprintf(cmd, sizeof(cmd), CHANGE_CMD_FMT, test.repl->IP[0], test.repl->port[0]); + MYSQL** nodes = test.repl->nodes; + mysql_query(nodes[ind], cmd); + mysql_query(nodes[ind], "START SLAVE;"); + sleep(5); + get_output(test); + + expect(test, "server1", "Master", "Running"); + expect(test, "server2", "Slave", "Running"); + expect(test, "server3", "Slave", "Running"); + expect(test, "server4", "Slave", "Running"); + return test.global_result; +} From c45a8abc2060e15335cda3fa9e54e5fb2715e188 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 3 Jan 2018 14:35:19 +0200 Subject: [PATCH 09/14] Use SQLITE_OPEN_NOMUTEX for session specific sqlite3 handles in PAM auth --- .../modules/authenticator/PAM/PAMAuth/pam_client_session.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/modules/authenticator/PAM/PAMAuth/pam_client_session.cc b/server/modules/authenticator/PAM/PAMAuth/pam_client_session.cc index 38c713b3a..5e6431d01 100644 --- a/server/modules/authenticator/PAM/PAMAuth/pam_client_session.cc +++ b/server/modules/authenticator/PAM/PAMAuth/pam_client_session.cc @@ -203,9 +203,9 @@ PamClientSession:: ~PamClientSession() PamClientSession* PamClientSession::create(const PamInstance& inst) { - int db_flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_SHAREDCACHE; + // This handle is only used from one thread, can define no_mutex. sqlite3* dbhandle = NULL; - // This handle is only used from one thread + int db_flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_NOMUTEX; if (sqlite3_open_v2(inst.m_dbname.c_str(), &dbhandle, db_flags, NULL) == SQLITE_OK) { sqlite3_busy_timeout(dbhandle, 1000); From 5fa1036a48353b4b96b369406c79459cab882563 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 3 Jan 2018 15:21:18 +0200 Subject: [PATCH 10/14] Only print PCRE2 error log message if error log is enabled Also, change the static buffer size to big enough for all error messages according to PCRE2 manual. --- server/core/maxscale_pcre2.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/server/core/maxscale_pcre2.cc b/server/core/maxscale_pcre2.cc index ec0b3d640..92404e55d 100644 --- a/server/core/maxscale_pcre2.cc +++ b/server/core/maxscale_pcre2.cc @@ -143,18 +143,14 @@ void mxs_pcre2_print_error(int errorcode, const char *module_name, const char *f { ss_dassert(filename); ss_dassert(func_name); - - char errorbuf[100]; - int err_msg_rval = pcre2_get_error_message(errorcode, (PCRE2_UCHAR*)errorbuf, - sizeof(errorbuf)); - - mxs_log_message(LOG_ERR, module_name, filename, line_num, func_name, - "PCRE2 Error message: '%s'.", errorbuf); - if (err_msg_rval == PCRE2_ERROR_NOMEMORY) + if (mxs_log_priority_is_enabled(LOG_ERR)) { + // 120 should be enough to contain any error message according to pcre2 manual. + const PCRE2_SIZE errbuf_len = 120; + PCRE2_UCHAR errorbuf[errbuf_len]; + pcre2_get_error_message(errorcode, errorbuf, errbuf_len); mxs_log_message(LOG_ERR, module_name, filename, line_num, func_name, - "PCRE2 error buffer was too small to contain the complete" - "message."); + "PCRE2 Error message: '%s'.", errorbuf); } } From 5c8c20abe46628e70b05c5fe3944bc264fc3d060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 3 Jan 2018 14:23:04 +0200 Subject: [PATCH 11/14] MXS-1539: Also synchronize rate limitations If a synchronous authenticator is used, the rate limitations are also synchronous. --- server/core/service.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/core/service.cc b/server/core/service.cc index 105fa052b..68ff8fc1c 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -1624,6 +1624,9 @@ int service_refresh_users(SERVICE *service) if ((service->capabilities & ACAP_TYPE_ASYNC) == 0) { spinlock_acquire(&service->spin); + // Use only one rate limitation for synchronous authenticators to keep + // rate limitations synchronous as well + self = 0; } /* Check if refresh rate limit has been exceeded */ From a91b857a431ec7fc9ddba3c21a94eb52701f4378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 3 Jan 2018 23:24:43 +0200 Subject: [PATCH 12/14] MXS-1593: Don't display stale status As the stale status is not a real status bit and it's used to retain the history of a master, there is no need to print it in any output. This output will only confuse users now that the stale status will not be cleared from masters that go down. --- server/core/server.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/core/server.cc b/server/core/server.cc index 95b17b612..45336d6de 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -706,10 +706,6 @@ server_status(const SERVER *server) { strcat(status, "Slave of External Server, "); } - if (server_status & SERVER_STALE_STATUS) - { - strcat(status, "Stale Status, "); - } if (server_status & SERVER_MASTER_STICKINESS) { strcat(status, "Master Stickiness, "); From 1bd20cd2eb87c026377ba23cad95afb6c7294635 Mon Sep 17 00:00:00 2001 From: Timofey Turenko Date: Fri, 5 Jan 2018 09:40:41 +0200 Subject: [PATCH 13/14] temopary disable snapshot revert due to Galera failures --- maxscale-system-test/testconnections.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 1800250d2..7023bf08b 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -306,6 +306,7 @@ TestConnections::~TestConnections() copy_all_logs(); + /* Temporary disable snapshot revert due to Galera failures if (global_result != 0 ) { if (no_vm_revert) @@ -318,6 +319,7 @@ TestConnections::~TestConnections() revert_snapshot((char*) "clean"); } } + */ delete repl; if (!no_galera) From 87d729a4f9d3772d453bda385ac3144c93a3d390 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 5 Jan 2018 09:33:00 +0200 Subject: [PATCH 14/14] Update 2.1.13 release date --- Documentation/Release-Notes/MaxScale-2.1.13-Release-Notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Release-Notes/MaxScale-2.1.13-Release-Notes.md b/Documentation/Release-Notes/MaxScale-2.1.13-Release-Notes.md index a6e6acd1b..24a144e33 100644 --- a/Documentation/Release-Notes/MaxScale-2.1.13-Release-Notes.md +++ b/Documentation/Release-Notes/MaxScale-2.1.13-Release-Notes.md @@ -1,4 +1,4 @@ -# MariaDB MaxScale 2.1.13 Release Notes +# MariaDB MaxScale 2.1.13 Release Notes -- 2017-01-05 Release 2.1.13 is a GA release.