From a41a8d6060c7b60e09686bea8124803f047d85ad Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 15 Sep 2014 19:01:04 +0300 Subject: [PATCH] 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; }