Moved ProcessAllSessions_SortingSessions to Base_Thread

v2.x_pg_PrepStmtBase_240714
René Cannaò 2 years ago
parent 8389f76413
commit db6cb93fb9

@ -52,6 +52,8 @@ class Base_Thread {
void check_timing_out_session(unsigned int n);
template<typename T>
void check_for_invalid_fd(unsigned int n);
template<typename S>
void ProcessAllSessions_SortingSessions();
};
#endif // CLASS_BASE_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);

@ -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();

@ -15,6 +15,9 @@ template void Base_Thread::check_timing_out_session<MySQL_Thread>(unsigned int);
template void Base_Thread::check_timing_out_session<PgSQL_Thread>(unsigned int);
template void Base_Thread::check_for_invalid_fd<MySQL_Thread>(unsigned int);
template void Base_Thread::check_for_invalid_fd<PgSQL_Thread>(unsigned int);
template void Base_Thread::ProcessAllSessions_SortingSessions<MySQL_Session>();
template void Base_Thread::ProcessAllSessions_SortingSessions<PgSQL_Session>();
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<typename S>
void Base_Thread::ProcessAllSessions_SortingSessions() {
unsigned int a=0;
for (unsigned int n=0; n<mysql_sessions->len; 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++;
}
}
}
}
}

@ -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; n<mysql_sessions->len; 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<MySQL_Session>();
}
for (n=0; n<mysql_sessions->len; n++) {
MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n);

@ -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<PgSQL_Session>();
}
for (n = 0; n < mysql_sessions->len; n++) {
PgSQL_Session* sess = (PgSQL_Session*)mysql_sessions->index(n);

Loading…
Cancel
Save