diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 9d8cfc04b..b438b74cc 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -4691,12 +4691,6 @@ int MySQL_Session::handler() { //unsigned int j; //unsigned char c; - if (active_transactions == 0) { - active_transactions=NumActiveTransactions(); - if (active_transactions > 0) { - transaction_started_at = thread->curtime; - } - } // FIXME: Sessions without frontend are an ugly hack if (session_fast_forward==false) { if (client_myds==NULL) { @@ -4968,6 +4962,15 @@ handler_again: gtid_hid = -1; if (rc==0) { + if (active_transactions != 0) { // run this only if currently we think there is a transaction + // Redundant? + //if ((myconn->mysql->server_status & SERVER_STATUS_IN_TRANS) == 0) { // there is no transaction on the backend connection + active_transactions = NumActiveTransactions(); // we check all the hostgroups/backends + if (active_transactions == 0) + transaction_started_at = 0; // reset it + //} + } + handler_rc0_Process_GTID(myconn); // if we are locked on hostgroup, the value of autocommit is copied from the backend connection @@ -5075,6 +5078,12 @@ handler_again: handler_minus1_HandleBackendConnection(myds, myconn); } } else { + if (active_transactions == 0) { + active_transactions=NumActiveTransactions(); + if (active_transactions > 0) { + transaction_started_at = thread->curtime; + } + } switch (rc) { // rc==1 , query is still running // start sending to frontend if mysql_thread___threshold_resultset_size is reached @@ -7206,8 +7215,7 @@ void MySQL_Session::MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *My int myerrno=mysql_errno(mysql); if (myerrno==0) { unsigned int num_rows = mysql_affected_rows(mysql); - unsigned int nTrx=NumActiveTransactions(); - uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 ); + uint16_t setStatus = (active_transactions ? SERVER_STATUS_IN_TRANS : 0); if (autocommit) setStatus |= SERVER_STATUS_AUTOCOMMIT; if (mysql->server_status & SERVER_MORE_RESULTS_EXIST) setStatus |= SERVER_MORE_RESULTS_EXIST; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 800438f28..f4df74679 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -3746,18 +3746,6 @@ void MySQL_Thread::ProcessAllSessions_CompletedMirrorSession(unsigned int& n, My // this function was inline in MySQL_Thread::process_all_sessions() void MySQL_Thread::ProcessAllSessions_MaintenanceLoop(MySQL_Session *sess, unsigned long long sess_time, unsigned int& total_active_transactions_) { unsigned int numTrx=0; - sess->active_transactions=sess->NumActiveTransactions(); - { - sess->active_transactions=sess->NumActiveTransactions(); - // in case we detected a new transaction just now - if (sess->active_transactions == 0) { - sess->transaction_started_at = 0; - } else { - if (sess->transaction_started_at == 0) { - sess->transaction_started_at = curtime; - } - } - } total_active_transactions_ += sess->active_transactions; sess->to_process=1; if ( (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_idle_time) || (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) {