From d355e07e2de580c4627baf51d5c4e9c733331f52 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Mon, 18 Aug 2014 09:39:29 +0000 Subject: [PATCH 01/12] gitignore cleanup * ignore typical backup files created by common editors * move general ignore rules like "*.o" or "depend.mk" to top level gitignore * ignore executables and test directories in target dir gitignore as these are local and there's no general catch-all pattern for them --- .gitignore | 36 ++++++++++++++++--- client/.gitignore | 2 ++ log_manager/.gitignore | 5 --- log_manager/test/.gitignore | 2 ++ query_classifier/.gitignore | 5 --- query_classifier/test/.gitignore | 2 ++ server/core/.gitignore | 5 +-- server/core/test/.gitignore | 2 ++ server/modules/monitor/.gitignore | 3 -- server/modules/protocol/.gitignore | 3 -- server/modules/routing/.gitignore | 3 -- .../modules/routing/readwritesplit/.gitignore | 3 -- server/test/.gitignore | 7 ++++ utils/.gitignore | 1 - 14 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 client/.gitignore delete mode 100644 log_manager/.gitignore create mode 100644 log_manager/test/.gitignore delete mode 100644 query_classifier/.gitignore create mode 100644 query_classifier/test/.gitignore create mode 100644 server/core/test/.gitignore delete mode 100644 server/modules/monitor/.gitignore delete mode 100644 server/modules/protocol/.gitignore delete mode 100644 server/modules/routing/.gitignore delete mode 100644 server/modules/routing/readwritesplit/.gitignore create mode 100644 server/test/.gitignore delete mode 100644 utils/.gitignore diff --git a/.gitignore b/.gitignore index b680e25df..64e460020 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,32 @@ -server/core/tags -server/core/maxscale -server/core/maxkeys -server/core/maxpasswd +# Object files +*.o +*.ko +*.lo + +# Libraries +*.lib +*.a +*.la + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app + +# log files (from testing etc.) +*.log + +# "make depend" generated stuff +depend +depend.mk + +# various auto-backup stuff +*~ +*# +.#* diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 000000000..0e7ae0f51 --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,2 @@ +# binaries generated here +maxadmin diff --git a/log_manager/.gitignore b/log_manager/.gitignore deleted file mode 100644 index d5a8be98b..000000000 --- a/log_manager/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.o -*.so -*.so.* -depend.mk - diff --git a/log_manager/test/.gitignore b/log_manager/test/.gitignore new file mode 100644 index 000000000..c6172ea0a --- /dev/null +++ b/log_manager/test/.gitignore @@ -0,0 +1,2 @@ +# binaries generated here +testlog diff --git a/query_classifier/.gitignore b/query_classifier/.gitignore deleted file mode 100644 index d5a8be98b..000000000 --- a/query_classifier/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.o -*.so -*.so.* -depend.mk - diff --git a/query_classifier/test/.gitignore b/query_classifier/test/.gitignore new file mode 100644 index 000000000..670ee3e79 --- /dev/null +++ b/query_classifier/test/.gitignore @@ -0,0 +1,2 @@ +# binaries generated here +testmain diff --git a/server/core/.gitignore b/server/core/.gitignore index 84590451f..e9b574d3e 100644 --- a/server/core/.gitignore +++ b/server/core/.gitignore @@ -1,3 +1,4 @@ -*.o +# binaries generated here maxscale -depend.mk +maxkeys +maxpasswd diff --git a/server/core/test/.gitignore b/server/core/test/.gitignore new file mode 100644 index 000000000..ebadda641 --- /dev/null +++ b/server/core/test/.gitignore @@ -0,0 +1,2 @@ +#binaries generated here +testhash diff --git a/server/modules/monitor/.gitignore b/server/modules/monitor/.gitignore deleted file mode 100644 index 1f1cd4c04..000000000 --- a/server/modules/monitor/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -depend.mk diff --git a/server/modules/protocol/.gitignore b/server/modules/protocol/.gitignore deleted file mode 100644 index 1f1cd4c04..000000000 --- a/server/modules/protocol/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -depend.mk diff --git a/server/modules/routing/.gitignore b/server/modules/routing/.gitignore deleted file mode 100644 index 1f1cd4c04..000000000 --- a/server/modules/routing/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -depend.mk diff --git a/server/modules/routing/readwritesplit/.gitignore b/server/modules/routing/readwritesplit/.gitignore deleted file mode 100644 index 1f1cd4c04..000000000 --- a/server/modules/routing/readwritesplit/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -depend.mk diff --git a/server/test/.gitignore b/server/test/.gitignore new file mode 100644 index 000000000..b8ca24c40 --- /dev/null +++ b/server/test/.gitignore @@ -0,0 +1,7 @@ +bin/ +Documentation/ +etc/ +lib/ +log/ +modules/ +mysql/ diff --git a/utils/.gitignore b/utils/.gitignore deleted file mode 100644 index 5761abcfd..000000000 --- a/utils/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.o From 13b79d4124ac46d75b9d90c2d81ad8e622e38a88 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Mon, 18 Aug 2014 09:43:38 +0000 Subject: [PATCH 02/12] comment header --- server/test/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/server/test/.gitignore b/server/test/.gitignore index b8ca24c40..184d7f57f 100644 --- a/server/test/.gitignore +++ b/server/test/.gitignore @@ -1,3 +1,4 @@ +# directories generated/filled by "make testall" bin/ Documentation/ etc/ From 066b58afb0a50a049f10cfb6ded87cfee5b79401 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 15 Sep 2014 08:05:47 +0100 Subject: [PATCH 03/12] Turn off spinlock profiling --- server/include/spinlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/include/spinlock.h b/server/include/spinlock.h index 43192da3f..e5f938815 100644 --- a/server/include/spinlock.h +++ b/server/include/spinlock.h @@ -31,7 +31,7 @@ #include #include -#define SPINLOCK_PROFILE 1 +#define SPINLOCK_PROFILE 0 /** * The spinlock structure. From c7bf6b66bf5f843e02057afc18852c9524f898e1 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 10:34:42 +0300 Subject: [PATCH 04/12] Fix to #492, http://bugs.skysql.com/show_bug.cgi?id=492 Added comments --- server/core/dcb.c | 95 ++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 001989c07..deccdb0a5 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -1560,77 +1560,80 @@ static bool dcb_set_state_nomutex( case DCB_STATE_ALLOC: switch (new_state) { - case DCB_STATE_POLLING: /*< for client requests */ - case DCB_STATE_LISTENING: /*< for connect listeners */ - case DCB_STATE_DISCONNECTED: /*< for failed connections */ - dcb->state = new_state; - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + /** fall through, for client requests */ + case DCB_STATE_POLLING: + /** fall through, for connect listeners */ + case DCB_STATE_LISTENING: + /** for failed connections */ + case DCB_STATE_DISCONNECTED: + dcb->state = new_state; + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; case DCB_STATE_POLLING: switch(new_state) { - case DCB_STATE_NOPOLLING: - dcb->state = new_state; - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + case DCB_STATE_NOPOLLING: + dcb->state = new_state; + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; case DCB_STATE_LISTENING: switch(new_state) { - case DCB_STATE_NOPOLLING: - dcb->state = new_state; - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + case DCB_STATE_NOPOLLING: + dcb->state = new_state; + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; case DCB_STATE_NOPOLLING: switch (new_state) { - case DCB_STATE_ZOMBIE: - dcb->state = new_state; - case DCB_STATE_POLLING: /*< ok to try but state can't change */ - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + case DCB_STATE_ZOMBIE: /*< fall through */ + dcb->state = new_state; + case DCB_STATE_POLLING: /*< ok to try but state can't change */ + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; case DCB_STATE_ZOMBIE: switch (new_state) { - case DCB_STATE_DISCONNECTED: - dcb->state = new_state; - case DCB_STATE_POLLING: /*< ok to try but state can't change */ - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + case DCB_STATE_DISCONNECTED: /*< fall through */ + dcb->state = new_state; + case DCB_STATE_POLLING: /*< ok to try but state can't change */ + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; case DCB_STATE_DISCONNECTED: switch (new_state) { - case DCB_STATE_FREED: - dcb->state = new_state; - succp = true; - break; - default: - ss_dassert(old_state != NULL); - break; + case DCB_STATE_FREED: + dcb->state = new_state; + succp = true; + break; + default: + ss_dassert(old_state != NULL); + break; } break; From bc320d151498a25734f17729afed26a109cb298b Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 11:09:12 +0300 Subject: [PATCH 05/12] Cannot compile --- server/core/spinlock.c | 14 +++++++------- server/include/spinlock.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/core/spinlock.c b/server/core/spinlock.c index 7b35163f3..2e112e0b9 100644 --- a/server/core/spinlock.c +++ b/server/core/spinlock.c @@ -40,7 +40,7 @@ void spinlock_init(SPINLOCK *lock) { lock->lock = 0; -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) lock->spins = 0; lock->acquired = 0; lock->waiting = 0; @@ -57,7 +57,7 @@ spinlock_init(SPINLOCK *lock) void spinlock_acquire(SPINLOCK *lock) { -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) int spins = 0; atomic_add(&(lock->waiting), 1); @@ -65,12 +65,12 @@ int spins = 0; while (atomic_add(&(lock->lock), 1) != 0) { atomic_add(&(lock->lock), -1); -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) atomic_add(&(lock->spins), 1); spins++; #endif } -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) if (spins) { lock->contended++; @@ -97,7 +97,7 @@ spinlock_acquire_nowait(SPINLOCK *lock) atomic_add(&(lock->lock), -1); return FALSE; } -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) lock->acquired++; lock->owner = THREAD_SHELF(); #endif @@ -112,7 +112,7 @@ spinlock_acquire_nowait(SPINLOCK *lock) void spinlock_release(SPINLOCK *lock) { -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) if (lock->waiting > lock->max_waiting) lock->max_waiting = lock->waiting; #endif @@ -135,7 +135,7 @@ spinlock_release(SPINLOCK *lock) void spinlock_stats(SPINLOCK *lock, void (*reporter)(void *, char *, int), void *hdl) { -#ifdef SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) reporter(hdl, "Spinlock acquired", lock->acquired); if (lock->acquired) { diff --git a/server/include/spinlock.h b/server/include/spinlock.h index e5f938815..41b92769c 100644 --- a/server/include/spinlock.h +++ b/server/include/spinlock.h @@ -45,7 +45,7 @@ */ typedef struct spinlock { int lock; /*< Is the lock held? */ -#if SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) int spins; /*< Number of spins on this lock */ int maxspins; /*< Max no of spins to acquire lock */ int acquired; /*< No. of times lock was acquired */ @@ -63,7 +63,7 @@ typedef struct spinlock { #define FALSE false #endif -#if SPINLOCK_PROFILE +#if defined(SPINLOCK_PROFILE) #define SPINLOCK_INIT { 0, 0, 0, 0, 0, 0, 0, 0 } #else #define SPINLOCK_INIT { 0 } From fb4f74ed61ddc7fc1152ac052c5f85a3d364cc09 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 15 Sep 2014 09:38:58 +0100 Subject: [PATCH 06/12] Changed SPINLOCK_PROFILE back to #if so that defining SPINLOC_PROFILE 0 turns off the profilign of spinlocks --- server/core/spinlock.c | 14 +++++++------- server/include/spinlock.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/core/spinlock.c b/server/core/spinlock.c index 2e112e0b9..ce64042e3 100644 --- a/server/core/spinlock.c +++ b/server/core/spinlock.c @@ -40,7 +40,7 @@ void spinlock_init(SPINLOCK *lock) { lock->lock = 0; -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE lock->spins = 0; lock->acquired = 0; lock->waiting = 0; @@ -57,7 +57,7 @@ spinlock_init(SPINLOCK *lock) void spinlock_acquire(SPINLOCK *lock) { -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE int spins = 0; atomic_add(&(lock->waiting), 1); @@ -65,12 +65,12 @@ int spins = 0; while (atomic_add(&(lock->lock), 1) != 0) { atomic_add(&(lock->lock), -1); -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE atomic_add(&(lock->spins), 1); spins++; #endif } -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE if (spins) { lock->contended++; @@ -97,7 +97,7 @@ spinlock_acquire_nowait(SPINLOCK *lock) atomic_add(&(lock->lock), -1); return FALSE; } -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE lock->acquired++; lock->owner = THREAD_SHELF(); #endif @@ -112,7 +112,7 @@ spinlock_acquire_nowait(SPINLOCK *lock) void spinlock_release(SPINLOCK *lock) { -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE if (lock->waiting > lock->max_waiting) lock->max_waiting = lock->waiting; #endif @@ -135,7 +135,7 @@ spinlock_release(SPINLOCK *lock) void spinlock_stats(SPINLOCK *lock, void (*reporter)(void *, char *, int), void *hdl) { -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE reporter(hdl, "Spinlock acquired", lock->acquired); if (lock->acquired) { diff --git a/server/include/spinlock.h b/server/include/spinlock.h index 41b92769c..e5f938815 100644 --- a/server/include/spinlock.h +++ b/server/include/spinlock.h @@ -45,7 +45,7 @@ */ typedef struct spinlock { int lock; /*< Is the lock held? */ -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE int spins; /*< Number of spins on this lock */ int maxspins; /*< Max no of spins to acquire lock */ int acquired; /*< No. of times lock was acquired */ @@ -63,7 +63,7 @@ typedef struct spinlock { #define FALSE false #endif -#if defined(SPINLOCK_PROFILE) +#if SPINLOCK_PROFILE #define SPINLOCK_INIT { 0, 0, 0, 0, 0, 0, 0, 0 } #else #define SPINLOCK_INIT { 0 } From 68f8e32f588aaf1b4eb872a62222f0cbb99678d2 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 13:38:47 +0300 Subject: [PATCH 07/12] Added physical log paths to message which is printed on the start screen. Refers to bug #506, http://bugs.skysql.com/show_bug.cgi?id=506 --- log_manager/log_manager.cc | 16 +++++++++++++--- utils/skygw_debug.h | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 6c40190be..9bfc9dd41 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -1603,7 +1603,7 @@ static bool fnames_conf_init( ss_dfprintf(stderr, "%s ", argv[i]); } ss_dfprintf(stderr, "\n");*/ - +#if defined(NOT_USED) fprintf(stderr, "Error log :\t%s/%s1%s\n" "Message log :\t%s/%s1%s\n" @@ -1621,7 +1621,7 @@ static bool fnames_conf_init( fn->fn_logpath, fn->fn_debug_prefix, fn->fn_debug_suffix); - +#endif succp = true; fn->fn_state = RUN; CHK_FNAMES_CONF(fn); @@ -2092,8 +2092,18 @@ static bool logfile_init( logfile->lf_full_link_name = form_full_file_name(strparts, logfile->lf_name_seqno, - 2); + 2); + fprintf(stderr, "%s\t: %s->%s\n", + STRLOGNAME(logfile_id), + logfile->lf_full_link_name, + logfile->lf_full_file_name); } + else + { + fprintf(stderr, "%s\t: %s\n", + STRLOGNAME(logfile_id), + logfile->lf_full_file_name); + } /** * At least one of the files couldn't be created. Increase * sequence number and retry until succeeds. diff --git a/utils/skygw_debug.h b/utils/skygw_debug.h index 352d736f9..acc59bc85 100644 --- a/utils/skygw_debug.h +++ b/utils/skygw_debug.h @@ -142,6 +142,12 @@ typedef enum skygw_chk_t { ((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \ ((i) == LOGFILE_DEBUG ? "LOGFILE_DEBUG" : \ "Unknown logfile type")))) + +#define STRLOGNAME(n) ((n) == LOGFILE_TRACE ? "Trace log" : \ + ((n) == LOGFILE_MESSAGE ? "Message log" : \ + ((n) == LOGFILE_ERROR ? "Error log" : \ + ((n) == LOGFILE_DEBUG ? "Debug log" : \ + "Unknown log file type")))) #define STRPACKETTYPE(p) ((p) == MYSQL_COM_INIT_DB ? "COM_INIT_DB" : \ ((p) == MYSQL_COM_CREATE_DB ? "COM_CREATE_DB" : \ From 7225804c421ec5f53284b9de6682ab2d28e99cee Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 15 Sep 2014 13:23:58 +0100 Subject: [PATCH 08/12] Add vi swap files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 64e460020..6e659cc6b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ depend.mk *~ *# .#* + +# Vi swap files +.*.swp From d5e2410fe6768be65292413ced9a771cec397a6f Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Mon, 15 Sep 2014 14:53:08 +0100 Subject: [PATCH 09/12] Fix for zero wieght in readconnrouter --- server/modules/routing/readconnroute.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/modules/routing/readconnroute.c b/server/modules/routing/readconnroute.c index a5c648c67..68e2dfcef 100644 --- a/server/modules/routing/readconnroute.c +++ b/server/modules/routing/readconnroute.c @@ -264,11 +264,11 @@ char *weightby; { for (n = 0; inst->servers[n]; n++) { - int perc; + int perc, wght; backend = inst->servers[n]; - perc = (atoi(serverGetParameter(backend->server, - weightby)) * 1000) / total; - if (perc == 0) + perc = ((wght = atoi(serverGetParameter(backend->server, + weightby))) * 1000) / total; + if (perc == 0 && wght != 0) perc = 1; backend->weight = perc; if (perc == 0) @@ -279,7 +279,7 @@ char *weightby; "for weighting parameter '%s', " "no queries will be routed to " "this server.\n", - server->unique_name, + inst->servers[n]->server->unique_name, weightby))); } @@ -418,6 +418,9 @@ BACKEND *master_host = NULL; if (SERVER_IN_MAINT(inst->servers[i]->server)) continue; + if (inst->servers[i]->weight == 0) + continue; + /* Check server status bits against bitvalue from router_options */ if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server) && From 4e88833d3ec8f34e9f2918891e8faa4a365fb495 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 15 Sep 2014 15:53:09 +0200 Subject: [PATCH 10/12] Fixed memory leak in getUsers bug 439 Fixed memory leak in getUsers bug 439 --- server/core/dbusers.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/core/dbusers.c b/server/core/dbusers.c index d318fd5f2..4f8de392b 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -359,10 +359,10 @@ getUsers(SERVICE *service, struct users *users) row[0], row[1], rc == NULL ? "NULL" : ret_ip))); - - continue; } + free(key.user); + } else { /* setipaddress() failed, skip user add and log this*/ LOGIF(LE, (skygw_log_write_flush( @@ -380,7 +380,6 @@ getUsers(SERVICE *service, struct users *users) memcpy(users->cksum, hash, SHA_DIGEST_LENGTH); free(users_data); - free(key.user); mysql_free_result(result); mysql_close(con); From a41a8d6060c7b60e09686bea8124803f047d85ad Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 19:01:04 +0300 Subject: [PATCH 11/12] Fix to bug #543, http://bugs.skysql.com/show_bug.cgi?id=543 All counters are now updated in routeQuery Fix to bug #545, http://bugs.skysql.com/show_bug.cgi?id=545 All sql variable and session modification statements, such as autocommit-, and set commands are routed to all nodes. --- query_classifier/query_classifier.cc | 11 +++++-- .../routing/readwritesplit/readwritesplit.c | 32 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index 02d693ac1..f034d770f 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -454,7 +454,7 @@ static skygw_query_type_t resolve_query_type( /** SELECT ..INTO variable|OUTFILE|DUMPFILE */ if (lex->result != NULL) { - type = QUERY_TYPE_SESSION_WRITE; + type = QUERY_TYPE_GSYSVAR_WRITE; goto return_qtype; } @@ -543,7 +543,7 @@ static skygw_query_type_t resolve_query_type( else if (lex->sql_command == SQLCOM_SET_OPTION) { /** Either user- or system variable write */ - type |= QUERY_TYPE_SESSION_WRITE; + type |= QUERY_TYPE_GSYSVAR_WRITE; } goto return_qtype; } @@ -759,7 +759,12 @@ static skygw_query_type_t resolve_query_type( break; /** User-defined variable modification */ case Item_func::SUSERVAR_FUNC: - func_qtype |= QUERY_TYPE_SESSION_WRITE; + /** + * Really it is user variable but we + * don't separate sql variables atm. + * 15.9.14 + */ + func_qtype |= QUERY_TYPE_GSYSVAR_WRITE; LOGIF(LD, (skygw_log_write( LOGFILE_DEBUG, "%lu [resolve_query_type] " diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index d7ba011bc..1e2b68517 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1209,13 +1209,15 @@ static route_target_t get_route_target ( /** * These queries are not affected by hints */ - if (!trx_active && - (QUERY_IS_TYPE(qtype, QUERY_TYPE_PREPARE_STMT) || + if (QUERY_IS_TYPE(qtype, QUERY_TYPE_SESSION_WRITE) || + QUERY_IS_TYPE(qtype, QUERY_TYPE_PREPARE_STMT) || QUERY_IS_TYPE(qtype, QUERY_TYPE_PREPARE_NAMED_STMT) || /** Configured to allow writing variables to all nodes */ (use_sql_variables_in == TYPE_ALL && - (QUERY_IS_TYPE(qtype, QUERY_TYPE_SESSION_WRITE) || - QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_WRITE))))) + QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_WRITE)) || + /** enable or disable autocommit are always routed to all */ + QUERY_IS_TYPE(qtype, QUERY_TYPE_ENABLE_AUTOCOMMIT) || + QUERY_IS_TYPE(qtype, QUERY_TYPE_DISABLE_AUTOCOMMIT)) { /** hints don't affect on routing */ target = TARGET_ALL; @@ -1678,8 +1680,6 @@ static int routeQuery( } goto retblock; } - inst->stats.n_queries++; - master_dcb = router_cli_ses->rses_master_ref->bref_dcb; CHK_DCB(master_dcb); @@ -1808,6 +1808,7 @@ static int routeQuery( if (succp) { + atomic_add(&inst->stats.n_all, 1); ret = 1; } goto retblock; @@ -1904,6 +1905,10 @@ static int routeQuery( BE_SLAVE, NULL, rlag_max); + if (succp) + { + atomic_add(&inst->stats.n_slave, 1); + } } if (!succp && TARGET_IS_MASTER(route_target)) @@ -1920,21 +1925,22 @@ static int routeQuery( { succp = true; } + atomic_add(&inst->stats.n_master, 1); target_dcb = master_dcb; } ss_dassert(succp); if (succp) /*< Have DCB of the target backend */ - { + { if ((ret = target_dcb->func.write(target_dcb, gwbuf_clone(querybuf))) == 1) { backend_ref_t* bref; - atomic_add(&inst->stats.n_slave, 1); - /** - * Add one query response waiter to backend reference - */ + atomic_add(&inst->stats.n_queries, 1); + /** + * Add one query response waiter to backend reference + */ bref = get_bref_from_dcb(router_cli_ses, target_dcb); bref_set_state(bref, BREF_QUERY_ACTIVE); bref_set_state(bref, BREF_WAITING_RESULT); @@ -3677,9 +3683,7 @@ static bool route_session_write( } /** Unlock router session */ rses_end_locked_router_action(router_cli_ses); - - atomic_add(&inst->stats.n_all, 1); - + return_succp: return succp; } From 3dc44ff6fd37c149ff7e8c6d08b4e14a4a489efe Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 21:03:11 +0300 Subject: [PATCH 12/12] Fix to bug #544, http://bugs.skysql.com/show_bug.cgi?id=544 Changes to readwritesplit router. --- .../routing/readwritesplit/readwritesplit.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 1e2b68517..e239b72ab 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -613,25 +613,29 @@ createInstance(SERVICE *service, char **options) for (n = 0; router->servers[n]; n++) { int perc; + int wght; backend = router->servers[n]; - perc = (atoi(serverGetParameter( - backend->backend_server, - weightby)) * 1000) / total; - if (perc == 0) + wght = atoi(serverGetParameter(backend->backend_server, + weightby)); + perc = (wght*1000) / total; + + if (perc == 0 && wght != 0) + { perc = 1; + } backend->weight = perc; + if (perc == 0) { LOGIF(LE, (skygw_log_write( - LOGFILE_ERROR, + LOGFILE_ERROR, "Server '%s' has no value " "for weighting parameter '%s', " "no queries will be routed to " "this server.\n", - server->unique_name, + router->servers[n]->backend_server->unique_name, weightby))); } - } } } @@ -2452,7 +2456,10 @@ static bool select_connect_backend_servers( master_found = true; master_connected = true; /* assert with master_host */ - ss_dassert(master_host && ((*p_master_ref)->bref_backend->backend_server == master_host->backend_server) && SERVER_MASTER); + ss_dassert(master_host && + ((*p_master_ref)->bref_backend->backend_server == + master_host->backend_server) && + SERVER_MASTER); } /** New session or master failure case */ else @@ -2574,11 +2581,17 @@ static bool select_connect_backend_servers( * servers from the sorted list. First master found is selected. */ for (i=0; - iservers[i]->weight == 0) + { + continue; + } + if (SERVER_IS_RUNNING(b->backend_server) && ((b->backend_server->status & router->bitmask) == router->bitvalue))