diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 0ade2e54a..92eaaff0f 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -729,10 +729,10 @@ static int logmanager_write_log( /** Length of session id */ int sesid_str_len; - /** 2 braces and 2 spaces */ + /** 2 braces, 2 spaces and terminating char */ if (id == LOGFILE_TRACE && tls_log_info.li_sesid != 0) { - sesid_str_len = 2+2+get_decimal_len(tls_log_info.li_sesid); + sesid_str_len = 2+2+get_decimal_len(tls_log_info.li_sesid)+1; } else { @@ -741,13 +741,13 @@ static int logmanager_write_log( timestamp_len = get_timestamp_len(); /** Find out how much can be safely written with current block size */ - if (timestamp_len-1+sesid_str_len+str_len > lf->lf_buf_size) + if (timestamp_len-1+MAX(sesid_str_len-1,0)+str_len > lf->lf_buf_size) { safe_str_len = lf->lf_buf_size; } else { - safe_str_len = timestamp_len-1+sesid_str_len+str_len; + safe_str_len = timestamp_len-1+MAX(sesid_str_len-1,0)+str_len; } /** * Seek write position and register to block buffer. @@ -809,6 +809,7 @@ static int logmanager_write_log( sesid_str_len, "[%lu] ", tls_log_info.li_sesid); + sesid_str_len -= 1; /*< don't calculate terminating char anymore */ } /** * Write next string to overwrite terminating null character diff --git a/server/core/service.c b/server/core/service.c index 1263c0ee1..708789f32 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -1232,19 +1232,18 @@ bool service_set_param_value ( /* * Function to find a string in typelib_t * (similar to find_type() of mysys/typelib.c) - * - * SYNOPSIS - * find_type() - * lib typelib_t - * find String to find - * length Length of string to find - * part_match Allow part matching of value - * - * RETURN - * 0 error - * > 0 position in TYPELIB->type_names +1 + * + * SYNOPSIS + * find_type() + * lib typelib_t + * find String to find + * length Length of string to find + * part_match Allow part matching of value + * + * RETURN + * 0 error + * > 0 position in TYPELIB->type_names +1 */ - static int find_type( typelib_t* tl, const char* needle, diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index 0dcec1b70..97121cf4f 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -552,7 +552,7 @@ static int gw_read_backend_event(DCB *dcb) { { client_protocol = SESSION_PROTOCOL(dcb->session, MySQLProtocol); - if (client_protocol != NULL) + if (client_protocol != NULL) { CHK_PROTOCOL(client_protocol); @@ -1065,18 +1065,21 @@ gw_backend_hangup(DCB *dcb) if (ses_state != SESSION_STATE_ROUTER_READY) { - int error, len; - char buf[100]; + int error, len; + char buf[100]; len = sizeof(error); if (getsockopt(dcb->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0) { - strerror_r(error, buf, 100); - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Hangup in session that is not ready for routing, " - "Error reported is '%s'.", - buf))); + if (error != 0) + { + strerror_r(error, buf, 100); + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Hangup in session that is not ready for routing, " + "Error reported is '%s'.", + buf))); + } } gwbuf_free(errbuf); goto retblock; diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index b86db4dde..c21ecf26b 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1212,9 +1212,10 @@ static bool get_dcb( * backend and update assign it to new candidate if * necessary. */ - else if (max_rlag == MAX_RLAG_UNDEFINED || + else if (SERVER_IS_SLAVE(b->backend_server) && + (max_rlag == MAX_RLAG_UNDEFINED || (b->backend_server->rlag != MAX_RLAG_NOT_AVAILABLE && - b->backend_server->rlag <= max_rlag)) + b->backend_server->rlag <= max_rlag))) { candidate_bref = check_candidate_bref( candidate_bref, @@ -1473,6 +1474,12 @@ static route_target_t get_route_target ( QUERY_IS_TYPE(qtype, QUERY_TYPE_UNKNOWN))); target = TARGET_MASTER; } +#if defined(SS_DEBUG) + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Selected target \"%s\"", + STRTARGET(target)))); +#endif return target; } @@ -2106,7 +2113,7 @@ static int routeQuery( rlag_max))); } } - } + } else if (TARGET_IS_SLAVE(route_target)) { btype = BE_SLAVE; @@ -2125,6 +2132,14 @@ static int routeQuery( rlag_max); if (succp) { +#if defined(SS_DEBUG) + LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, + "Found DCB for slave."))); + ss_dassert(get_bref_from_dcb(router_cli_ses, target_dcb) != + router_cli_ses->rses_master_ref); + ss_dassert(get_root_master_bref(router_cli_ses) == + router_cli_ses->rses_master_ref); +#endif atomic_add(&inst->stats.n_slave, 1); } else diff --git a/utils/skygw_debug.h b/utils/skygw_debug.h index 7294a7ba6..1ade113a3 100644 --- a/utils/skygw_debug.h +++ b/utils/skygw_debug.h @@ -262,6 +262,12 @@ typedef enum skygw_chk_t { (SERVER_IS_RELAY_SERVER(s) ? "RUNNING RELAY" : \ (SERVER_IS_RUNNING(s) ? "RUNNING (only)" : "NO STATUS"))))))) +#define STRTARGET(t) (t == TARGET_ALL ? "TARGET_ALL" : \ + (t == TARGET_MASTER ? "TARGET_MASTER" : \ + (t == TARGET_SLAVE ? "TARGET_SLAVE" : \ + (t == TARGET_UNDEFINED ? "TARGET_UNDEFINED" : \ + "Unknown target value")))) + #define BREFSRV(b) (b->bref_backend->backend_server)