diff --git a/include/Base_Thread.h b/include/Base_Thread.h index 078e9ecb4..bc6306e6b 100644 --- a/include/Base_Thread.h +++ b/include/Base_Thread.h @@ -52,6 +52,8 @@ class Base_Thread { void check_timing_out_session(unsigned int n); template void check_for_invalid_fd(unsigned int n); + template + void ProcessAllSessions_SortingSessions(); }; #endif // CLASS_BASE_THREAD_H diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index a9fc1766a..0cee4d26e 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -209,7 +209,7 @@ class __attribute__((aligned(64))) MySQL_Thread : public Base_Thread void unregister_session(int); struct pollfd * get_pollfd(unsigned int i); bool process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n); - void ProcessAllSessions_SortingSessions(); + //void ProcessAllSessions_SortingSessions(); void ProcessAllSessions_CompletedMirrorSession(unsigned int& n, MySQL_Session *sess); void ProcessAllSessions_MaintenanceLoop(MySQL_Session *sess, unsigned long long sess_time, unsigned int& total_active_transactions_); void ProcessAllSessions_Healthy0(MySQL_Session *sess, unsigned int& n); diff --git a/include/PgSQL_Thread.h b/include/PgSQL_Thread.h index 537933e92..d8fb45781 100644 --- a/include/PgSQL_Thread.h +++ b/include/PgSQL_Thread.h @@ -220,7 +220,7 @@ public: void unregister_session(int); struct pollfd* get_pollfd(unsigned int i); bool process_data_on_data_stream(PgSQL_Data_Stream * myds, unsigned int n); - void ProcessAllSessions_SortingSessions(); + //void ProcessAllSessions_SortingSessions(); void ProcessAllSessions_CompletedMirrorSession(unsigned int& n, PgSQL_Session * sess); void ProcessAllSessions_MaintenanceLoop(PgSQL_Session * sess, unsigned long long sess_time, unsigned int& total_active_transactions_); void process_all_sessions(); diff --git a/lib/Base_Thread.cpp b/lib/Base_Thread.cpp index 6b1c86d66..bbd6c5652 100644 --- a/lib/Base_Thread.cpp +++ b/lib/Base_Thread.cpp @@ -15,6 +15,9 @@ template void Base_Thread::check_timing_out_session(unsigned int); template void Base_Thread::check_timing_out_session(unsigned int); template void Base_Thread::check_for_invalid_fd(unsigned int); template void Base_Thread::check_for_invalid_fd(unsigned int); +template void Base_Thread::ProcessAllSessions_SortingSessions(); +template void Base_Thread::ProcessAllSessions_SortingSessions(); + Base_Thread::Base_Thread() { }; @@ -197,3 +200,35 @@ void Base_Thread::check_for_invalid_fd(unsigned int n) { } } +// this function was inline in MySQL_Thread::process_all_sessions() +/** + * @brief Sort all sessions based on maximum connection time. + * + * This function iterates through all MySQL sessions and sorts them based on their maximum connection time. + * Sessions with a valid maximum connection time are compared, and if one session has a greater maximum connection + * time than another, their positions in the session list are swapped. The sorting is performed in-place. + * + * @note This function assumes that MySQL sessions and their associated data structures have been initialized + * and are accessible within the MySQL Thread. + */ +template +void Base_Thread::ProcessAllSessions_SortingSessions() { + unsigned int a=0; + for (unsigned int n=0; nlen; n++) { + S *sess=(S *)mysql_sessions->index(n); + if (sess->mybe && sess->mybe->server_myds) { + if (sess->mybe->server_myds->max_connect_time) { + S *sess2=(S *)mysql_sessions->index(a); + if (sess2->mybe && sess2->mybe->server_myds && sess2->mybe->server_myds->max_connect_time && sess2->mybe->server_myds->max_connect_time <= sess->mybe->server_myds->max_connect_time) { + // do nothing + } else { + void *p=mysql_sessions->pdata[a]; + mysql_sessions->pdata[a]=mysql_sessions->pdata[n]; + mysql_sessions->pdata[n]=p; + a++; + } + } + } + } +} + diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 0ac2d1379..c6f1500b5 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -3797,38 +3797,6 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned } - -// this function was inline in MySQL_Thread::process_all_sessions() -/** - * @brief Sort all sessions based on maximum connection time. - * - * This function iterates through all MySQL sessions and sorts them based on their maximum connection time. - * Sessions with a valid maximum connection time are compared, and if one session has a greater maximum connection - * time than another, their positions in the session list are swapped. The sorting is performed in-place. - * - * @note This function assumes that MySQL sessions and their associated data structures have been initialized - * and are accessible within the MySQL Thread. - */ -void MySQL_Thread::ProcessAllSessions_SortingSessions() { - unsigned int a=0; - for (unsigned int n=0; nlen; n++) { - MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); - if (sess->mybe && sess->mybe->server_myds) { - if (sess->mybe->server_myds->max_connect_time) { - MySQL_Session *sess2=(MySQL_Session *)mysql_sessions->index(a); - if (sess2->mybe && sess2->mybe->server_myds && sess2->mybe->server_myds->max_connect_time && sess2->mybe->server_myds->max_connect_time <= sess->mybe->server_myds->max_connect_time) { - // do nothing - } else { - void *p=mysql_sessions->pdata[a]; - mysql_sessions->pdata[a]=mysql_sessions->pdata[n]; - mysql_sessions->pdata[n]=p; - a++; - } - } - } - } -} - // this function was inline in MySQL_Thread::process_all_sessions() void MySQL_Thread::ProcessAllSessions_CompletedMirrorSession(unsigned int& n, MySQL_Session *sess) { unregister_session(n); @@ -4052,7 +4020,7 @@ void MySQL_Thread::process_all_sessions() { } #endif // IDLE_THREADS if (sess_sort && mysql_sessions->len > 3) { - ProcessAllSessions_SortingSessions(); + ProcessAllSessions_SortingSessions(); } for (n=0; nlen; n++) { MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index fb60ab11a..9b12e0262 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -3550,29 +3550,6 @@ bool PgSQL_Thread::process_data_on_data_stream(PgSQL_Data_Stream * myds, unsigne } - -// this function was inline in PgSQL_Thread::process_all_sessions() -void PgSQL_Thread::ProcessAllSessions_SortingSessions() { - unsigned int a = 0; - for (unsigned int n = 0; n < mysql_sessions->len; n++) { - PgSQL_Session* sess = (PgSQL_Session*)mysql_sessions->index(n); - if (sess->mybe && sess->mybe->server_myds) { - if (sess->mybe->server_myds->max_connect_time) { - PgSQL_Session* sess2 = (PgSQL_Session*)mysql_sessions->index(a); - if (sess2->mybe && sess2->mybe->server_myds && sess2->mybe->server_myds->max_connect_time && sess2->mybe->server_myds->max_connect_time <= sess->mybe->server_myds->max_connect_time) { - // do nothing - } - else { - void* p = mysql_sessions->pdata[a]; - mysql_sessions->pdata[a] = mysql_sessions->pdata[n]; - mysql_sessions->pdata[n] = p; - a++; - } - } - } - } -} - // this function was inline in PgSQL_Thread::process_all_sessions() void PgSQL_Thread::ProcessAllSessions_CompletedMirrorSession(unsigned int& n, PgSQL_Session * sess) { unregister_session(n); @@ -3700,7 +3677,7 @@ void PgSQL_Thread::process_all_sessions() { } #endif // IDLE_THREADS if (sess_sort && mysql_sessions->len > 3) { - ProcessAllSessions_SortingSessions(); + ProcessAllSessions_SortingSessions(); } for (n = 0; n < mysql_sessions->len; n++) { PgSQL_Session* sess = (PgSQL_Session*)mysql_sessions->index(n);