From 6aac86bebcc00ad3caa22f8260545a154f875c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 22 Mar 2019 00:23:50 +1100 Subject: [PATCH] Changed the way max_lag_ms in query is computed It now remembers if the query is waiting for long time --- include/query_processor.h | 2 +- lib/MySQL_Session.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/query_processor.h b/include/query_processor.h index 3940f224b..a2748c322 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -72,7 +72,7 @@ class Query_Processor_Output { int sticky_conn; int multiplex; int gtid_from_hostgroup; - int max_lag_ms; + long long max_lag_ms; int log; char *comment; // #643 std::string *new_query; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index acb9032d7..adbed28ef 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -4491,6 +4491,19 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED MySQL_Backend * _gtid_from_backend = NULL; char uuid[64]; uint64_t trxid = 0; + unsigned long long now_us = 0; + if (qpo->max_lag_ms >= 0) { + if (qpo->max_lag_ms > 360000) { // this is an absolute time, we convert it to relative + if (now_us == 0) { + now_us = realtime_time(); + } + long long now_ms = now_us/1000; + qpo->max_lag_ms -= now_ms; + if (qpo->max_lag_ms < 0) { + qpo->max_lag_ms = -1; // time expired + } + } + } if (session_fast_forward == false) { if (qpo->gtid_from_hostgroup >= 0) { _gtid_from_backend = find_backend(qpo->gtid_from_hostgroup); @@ -4514,14 +4527,14 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED uuid[n]='\0'; mc=thread->get_MyConn_local(mybe->hostgroup_id, this, uuid, trxid, -1); } else { - mc=thread->get_MyConn_local(mybe->hostgroup_id, this, NULL, 0, qpo->max_lag_ms); + mc=thread->get_MyConn_local(mybe->hostgroup_id, this, NULL, 0, (int)qpo->max_lag_ms); } } if (mc==NULL) { if (trxid) { - mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id, this, session_fast_forward, uuid, trxid, qpo->max_lag_ms); + mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id, this, session_fast_forward, uuid, trxid, -1); } else { - mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id, this, session_fast_forward, NULL, 0, qpo->max_lag_ms); + mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id, this, session_fast_forward, NULL, 0, (int)qpo->max_lag_ms); } } else { thread->status_variables.ConnPool_get_conn_immediate++; @@ -4532,6 +4545,15 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED } else { thread->status_variables.ConnPool_get_conn_failure++; } + if (qpo->max_lag_ms >= 0) { + if (qpo->max_lag_ms <= 360000) { // this is a relative time , we convert it to absolute + if (now_us == 0) { + now_us = realtime_time(); + } + long long now_ms = now_us/1000; + qpo->max_lag_ms += now_ms; + } + } proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- server_myds=%p -- MySQL_Connection %p\n", this, mybe->server_myds, mybe->server_myds->myconn); if (mybe->server_myds->myconn==NULL) { // we couldn't get a connection for whatever reason, ex: no backends, or too busy