More functions moved to Base_Thread()

* check_timing_out_session()
* check_for_invalid_fd()
v2.x_pg_PrepStmtBase_240714
René Cannaò 2 years ago
parent 77de8c1a97
commit 8389f76413

@ -48,6 +48,10 @@ class Base_Thread {
S create_new_session_and_client_data_stream(int _fd);
template<typename T, typename S>
void register_session(T, S, bool up_start = true);
template<typename T>
void check_timing_out_session(unsigned int n);
template<typename T>
void check_for_invalid_fd(unsigned int n);
};
#endif // CLASS_BASE_THREAD_H

@ -128,8 +128,8 @@ class __attribute__((aligned(64))) MySQL_Thread : public Base_Thread
bool set_backend_to_be_skipped_if_frontend_is_slow(MySQL_Data_Stream *myds, unsigned int n);
void handle_mirror_queue_mysql_sessions();
void handle_kill_queues();
void check_timing_out_session(unsigned int n);
void check_for_invalid_fd(unsigned int n);
//void check_timing_out_session(unsigned int n);
//void check_for_invalid_fd(unsigned int n);
void read_one_byte_from_pipe(unsigned int n);
void tune_timeout_for_myds_needs_pause(MySQL_Data_Stream *myds);
void tune_timeout_for_session_needs_pause(MySQL_Data_Stream *myds);

@ -148,8 +148,8 @@ private:
bool set_backend_to_be_skipped_if_frontend_is_slow(PgSQL_Data_Stream * myds, unsigned int n);
void handle_mirror_queue_mysql_sessions();
void handle_kill_queues();
void check_timing_out_session(unsigned int n);
void check_for_invalid_fd(unsigned int n);
//void check_timing_out_session(unsigned int n);
//void check_for_invalid_fd(unsigned int n);
void read_one_byte_from_pipe(unsigned int n);
void tune_timeout_for_myds_needs_pause(PgSQL_Data_Stream * myds);
void tune_timeout_for_session_needs_pause(PgSQL_Data_Stream * myds);

@ -11,6 +11,10 @@
// Explicitly instantiate the required template class and member functions
template MySQL_Session* Base_Thread::create_new_session_and_client_data_stream<MySQL_Thread, MySQL_Session*>(int);
template PgSQL_Session* Base_Thread::create_new_session_and_client_data_stream<PgSQL_Thread, PgSQL_Session*>(int);
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);
Base_Thread::Base_Thread() {
};
@ -132,3 +136,64 @@ S Base_Thread::create_new_session_and_client_data_stream(int _fd) {
}
return sess;
}
/**
* @brief Checks for timing out session and marks them for processing.
*
* This function checks for timing out sessions and marks them for processing. Although the logic for managing connection timeout
* was removed due to the addition of the MariaDB client library, this function remains as a placeholder. It checks if the session
* has reached its wait_until or pause_until time, and if so, marks the session for processing.
*
* @param n The index of the session in the MySQL_Data_Stream array.
*/
template<typename T>
void Base_Thread::check_timing_out_session(unsigned int n) {
// FIXME: this logic was removed completely because we added mariadb client library. Yet, we need to implement a way to manage connection timeout
// check for timeout
// no events. This section is copied from process_data_on_data_stream()
T* thr = static_cast<T*>(this);
auto * _myds = thr->mypolls.myds[n];
if (_myds && _myds->sess) {
if (_myds->wait_until && curtime > _myds->wait_until) {
// timeout
_myds->sess->to_process=1;
} else {
if (_myds->sess->pause_until && curtime > _myds->sess->pause_until) {
// timeout
_myds->sess->to_process=1;
}
}
}
}
/**
* @brief Checks for an invalid file descriptor (FD) and raises an error if found.
*
* This function checks if the file descriptor (FD) at the specified index in the `mypolls.fds` array is invalid (`POLLNVAL`).
* If an invalid FD is found, it raises an error and asserts to ensure that the program does not proceed with an invalid FD.
*
* @param n The index of the file descriptor in the `mypolls.fds` array.
*/
template<typename T>
void Base_Thread::check_for_invalid_fd(unsigned int n) {
// check if the FD is valid
T* thr = static_cast<T*>(this);
if (thr->mypolls.fds[n].revents==POLLNVAL) {
// debugging output before assert
auto *_myds=thr->mypolls.myds[n];
if (_myds) {
if (_myds->myconn) {
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d, MyConnFD=%d\n", thr->mypolls.fds[n].fd, thr->mypolls.fds[n].events, _myds->fd, _myds->myconn->fd);
assert(thr->mypolls.fds[n].revents!=POLLNVAL);
}
}
// if we reached her, we didn't assert() yet
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d\n", thr->mypolls.fds[n].fd, thr->mypolls.fds[n].events, _myds->fd);
assert(thr->mypolls.fds[n].revents!=POLLNVAL);
}
}

@ -3075,10 +3075,10 @@ void MySQL_Thread::ProcessAllMyDS_AfterPoll() {
}
if (mypolls.fds[n].revents==0) {
if (poll_timeout_bool) {
check_timing_out_session(n);
check_timing_out_session<MySQL_Thread>(n);
}
} else {
check_for_invalid_fd(n); // this is designed to assert in case of failure
check_for_invalid_fd<MySQL_Thread>(n); // this is designed to assert in case of failure
switch(myds->myds_type) {
// Note: this logic that was here was removed completely because we added mariadb client library.
case MYDS_LISTENER:
@ -5961,59 +5961,6 @@ void MySQL_Thread::handle_kill_queues() {
}
/**
* @brief Checks for timing out session and marks them for processing.
*
* This function checks for timing out sessions and marks them for processing. Although the logic for managing connection timeout
* was removed due to the addition of the MariaDB client library, this function remains as a placeholder. It checks if the session
* has reached its wait_until or pause_until time, and if so, marks the session for processing.
*
* @param n The index of the session in the MySQL_Data_Stream array.
*/
void MySQL_Thread::check_timing_out_session(unsigned int n) {
// FIXME: this logic was removed completely because we added mariadb client library. Yet, we need to implement a way to manage connection timeout
// check for timeout
// no events. This section is copied from process_data_on_data_stream()
MySQL_Data_Stream *_myds=mypolls.myds[n];
if (_myds && _myds->sess) {
if (_myds->wait_until && curtime > _myds->wait_until) {
// timeout
_myds->sess->to_process=1;
} else {
if (_myds->sess->pause_until && curtime > _myds->sess->pause_until) {
// timeout
_myds->sess->to_process=1;
}
}
}
}
/**
* @brief Checks for an invalid file descriptor (FD) and raises an error if found.
*
* This function checks if the file descriptor (FD) at the specified index in the `mypolls.fds` array is invalid (`POLLNVAL`).
* If an invalid FD is found, it raises an error and asserts to ensure that the program does not proceed with an invalid FD.
*
* @param n The index of the file descriptor in the `mypolls.fds` array.
*/
void MySQL_Thread::check_for_invalid_fd(unsigned int n) {
// check if the FD is valid
if (mypolls.fds[n].revents==POLLNVAL) {
// debugging output before assert
MySQL_Data_Stream *_myds=mypolls.myds[n];
if (_myds) {
if (_myds->myconn) {
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d, MyConnFD=%d\n", mypolls.fds[n].fd, mypolls.fds[n].events, _myds->fd, _myds->myconn->fd);
assert(mypolls.fds[n].revents!=POLLNVAL);
}
}
// if we reached her, we didn't assert() yet
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d\n", mypolls.fds[n].fd, mypolls.fds[n].events, _myds->fd);
assert(mypolls.fds[n].revents!=POLLNVAL);
}
}
void MySQL_Thread::read_one_byte_from_pipe(unsigned int n) {
if (mypolls.fds[n].revents) {
unsigned char c;

@ -2917,11 +2917,11 @@ void PgSQL_Thread::ProcessAllMyDS_AfterPoll() {
}
if (mypolls.fds[n].revents == 0) {
if (poll_timeout_bool) {
check_timing_out_session(n);
check_timing_out_session<PgSQL_Thread>(n);
}
}
else {
check_for_invalid_fd(n); // this is designed to assert in case of failure
check_for_invalid_fd<PgSQL_Thread>(n); // this is designed to assert in case of failure
switch (myds->myds_type) {
// Note: this logic that was here was removed completely because we added mariadb client library.
case MYDS_LISTENER:
@ -5553,42 +5553,6 @@ void PgSQL_Thread::handle_kill_queues() {
pthread_mutex_unlock(&kq.m);
}
void PgSQL_Thread::check_timing_out_session(unsigned int n) {
// FIXME: this logic was removed completely because we added mariadb client library. Yet, we need to implement a way to manage connection timeout
// check for timeout
// no events. This section is copied from process_data_on_data_stream()
PgSQL_Data_Stream* _myds = mypolls.myds[n];
if (_myds && _myds->sess) {
if (_myds->wait_until && curtime > _myds->wait_until) {
// timeout
_myds->sess->to_process = 1;
}
else {
if (_myds->sess->pause_until && curtime > _myds->sess->pause_until) {
// timeout
_myds->sess->to_process = 1;
}
}
}
}
void PgSQL_Thread::check_for_invalid_fd(unsigned int n) {
// check if the FD is valid
if (mypolls.fds[n].revents == POLLNVAL) {
// debugging output before assert
PgSQL_Data_Stream* _myds = mypolls.myds[n];
if (_myds) {
if (_myds->myconn) {
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d, MyConnFD=%d\n", mypolls.fds[n].fd, mypolls.fds[n].events, _myds->fd, _myds->myconn->fd);
assert(mypolls.fds[n].revents != POLLNVAL);
}
}
// if we reached her, we didn't assert() yet
proxy_error("revents==POLLNVAL for FD=%d, events=%d, MyDSFD=%d\n", mypolls.fds[n].fd, mypolls.fds[n].events, _myds->fd);
assert(mypolls.fds[n].revents != POLLNVAL);
}
}
void PgSQL_Thread::read_one_byte_from_pipe(unsigned int n) {
if (mypolls.fds[n].revents) {
unsigned char c;

Loading…
Cancel
Save