From 115eef2ea3f2d1daa0b12315574bc33414c9d7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 16 Sep 2024 16:47:22 +0000 Subject: [PATCH] Some code cleanup --- include/PgSQL_Connection.h | 10 +++++++++- include/PgSQL_Session.h | 12 +++++++++++- include/PgSQL_Variables.h | 2 ++ lib/PgSQL_Connection.cpp | 11 ++++++++++- lib/PgSQL_Session.cpp | 36 +++++++++++++++++++++++++----------- lib/PgSQL_Variables.cpp | 7 ++++--- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/include/PgSQL_Connection.h b/include/PgSQL_Connection.h index 0cc2464b7..9bcf0dba6 100644 --- a/include/PgSQL_Connection.h +++ b/include/PgSQL_Connection.h @@ -399,21 +399,25 @@ class PgSQL_Connection_Placeholder { unsigned int set_charset(unsigned int, enum pgsql_charset_action); void set_status(bool set, uint32_t status_flag); - void set_status_sql_log_bin0(bool); bool get_status(uint32_t status_flag); +#if 0 + void set_status_sql_log_bin0(bool); bool get_status_sql_log_bin0(); void set_autocommit_start(); void set_autocommit_cont(short event); +#endif // 0 void set_names_start(); void set_names_cont(short event); #ifndef PROXYSQL_USE_RESULT void store_result_start(); void store_result_cont(short event); #endif // PROXYSQL_USE_RESULT +#if 0 void initdb_start(); void initdb_cont(short event); void set_option_start(); void set_option_cont(short event); +#endif // 0 void set_query(char *stmt, unsigned long length); int async_set_autocommit(short event, bool); @@ -429,6 +433,7 @@ class PgSQL_Connection_Placeholder { void stmt_execute_store_result_start(); void stmt_execute_store_result_cont(short event); +#if 0 /** * @brief Process the rows returned by 'async_stmt_execute_store_result'. Extracts all the received * rows from 'query.stmt->result.data' but the last one, adds them to 'MyRS', frees the buffer @@ -438,6 +443,7 @@ class PgSQL_Connection_Placeholder { * that are being read and added to 'MyRS'. */ void process_rows_in_ASYNC_STMT_EXECUTE_STORE_RESULT_CONT(unsigned long long& processed_bytes); +#endif // 0 void async_free_result(); @@ -491,7 +497,9 @@ public: void reset_session_cont(short event); int async_connect(short event); +#if 0 int async_set_autocommit(short event, bool ac); +#endif // 0 int async_query(short event, char* stmt, unsigned long length, MYSQL_STMT** _stmt = NULL, stmt_execute_metadata_t* _stmt_meta = NULL); int async_ping(short event); int async_reset_session(short event); diff --git a/include/PgSQL_Session.h b/include/PgSQL_Session.h index 55db98f5a..c9d6873a3 100644 --- a/include/PgSQL_Session.h +++ b/include/PgSQL_Session.h @@ -187,21 +187,29 @@ private: void handler_again___new_thread_to_kill_connection(); bool handler_again___verify_init_connect(); +#if 0 bool handler_again___verify_ldap_user_variable(); - //bool handler_again___verify_backend_autocommit(); + bool handler_again___verify_backend_autocommit(); bool handler_again___verify_backend_session_track_gtids(); bool handler_again___verify_backend_multi_statement(); +#endif // 0 bool handler_again___verify_backend_user_db(); bool handler_again___status_SETTING_INIT_CONNECT(int*); +#if 0 bool handler_again___status_SETTING_LDAP_USER_VARIABLE(int*); bool handler_again___status_SETTING_SQL_MODE(int*); bool handler_again___status_SETTING_SESSION_TRACK_GTIDS(int*); +#endif // 0 bool handler_again___status_CHANGING_CHARSET(int* _rc); +#if 0 bool handler_again___status_CHANGING_SCHEMA(int*); +#endif // 0 bool handler_again___status_CONNECTING_SERVER(int*); bool handler_again___status_RESETTING_CONNECTION(int*); //bool handler_again___status_CHANGING_AUTOCOMMIT(int*); +#if 0 bool handler_again___status_SETTING_MULTI_STMT(int* _rc); +#endif // 0 bool handler_again___multiple_statuses(int* rc); //void init(); void reset(); @@ -248,7 +256,9 @@ private: public: bool handler_again___status_SETTING_GENERIC_VARIABLE(int* _rc, const char* var_name, const char* var_value, bool no_quote = false, bool set_transaction = false); +#if 0 bool handler_again___status_SETTING_SQL_LOG_BIN(int*); +#endif // 0 std::stack previous_status; PgSQL_Query_Info CurrentQuery; diff --git a/include/PgSQL_Variables.h b/include/PgSQL_Variables.h index aa54c02ec..d8a5ccbef 100644 --- a/include/PgSQL_Variables.h +++ b/include/PgSQL_Variables.h @@ -19,7 +19,9 @@ bool validate_charset(PgSQL_Session* session, int idx, int &_rc); bool update_server_variable(PgSQL_Session* session, int idx, int &_rc); bool verify_server_variable(PgSQL_Session* session, int idx, uint32_t client_hash, uint32_t server_hash); bool verify_set_names(PgSQL_Session* session); +#if 0 bool logbin_update_server_variable(PgSQL_Session* session, int idx, int &_rc); +#endif // 0 class PgSQL_Variables { static pgsql_verify_var verifiers[SQL_NAME_LAST_HIGH_WM]; diff --git a/lib/PgSQL_Connection.cpp b/lib/PgSQL_Connection.cpp index 3858439ad..2662ef9e9 100644 --- a/lib/PgSQL_Connection.cpp +++ b/lib/PgSQL_Connection.cpp @@ -15,7 +15,7 @@ using json = nlohmann::json; #include "MySQL_Variables.h" - +#if 0 // some of the code that follows is from mariadb client library memory allocator typedef int myf; // Type of MyFlags in my_funcs #define MYF(v) (myf) (v) @@ -109,6 +109,7 @@ static void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) root->free->next=0; } } +#endif // 0 extern char * binary_sha1; @@ -602,6 +603,7 @@ bool PgSQL_Connection_Placeholder::get_status(uint32_t status_flag) { return this->status_flags & status_flag; } +#if 0 void PgSQL_Connection_Placeholder::set_status_sql_log_bin0(bool v) { if (v) { status_flags |= STATUS_MYSQL_CONNECTION_SQL_LOG_BIN0; @@ -613,6 +615,7 @@ void PgSQL_Connection_Placeholder::set_status_sql_log_bin0(bool v) { bool PgSQL_Connection_Placeholder::get_status_sql_log_bin0() { return status_flags & STATUS_MYSQL_CONNECTION_SQL_LOG_BIN0; } +#endif // 0 unsigned int PgSQL_Connection_Placeholder::reorder_dynamic_variables_idx() { dynamic_variables_idx.clear(); @@ -660,6 +663,7 @@ unsigned int PgSQL_Connection_Placeholder::number_of_matching_session_variables( return ret; } +#if 0 void PgSQL_Connection_Placeholder::initdb_start() { PROXY_TRACE(); PgSQL_Connection_userinfo *client_ui=myds->sess->client_myds->myconn->userinfo; @@ -693,6 +697,7 @@ void PgSQL_Connection_Placeholder::set_autocommit_cont(short event) { proxy_debug(PROXY_DEBUG_MYSQL_PROTOCOL, 6,"event=%d\n", event); async_exit_status = mysql_autocommit_cont(&ret_bool, pgsql, mysql_status(event, true)); } +#endif // 0 void PgSQL_Connection_Placeholder::set_names_start() { PROXY_TRACE(); @@ -785,6 +790,7 @@ void PgSQL_Connection_Placeholder::set_is_client() { #define NEXT_IMMEDIATE(new_st) do { async_state_machine = new_st; goto handler_again; } while (0) +#if 0 void PgSQL_Connection_Placeholder::process_rows_in_ASYNC_STMT_EXECUTE_STORE_RESULT_CONT(unsigned long long& processed_bytes) { PROXY_TRACE2(); // there is more than 1 row @@ -893,6 +899,7 @@ int PgSQL_Connection_Placeholder::async_set_autocommit(short event, bool ac) { } return 1; } +#endif // 0 int PgSQL_Connection_Placeholder::async_set_names(short event, unsigned int c) { PROXY_TRACE(); @@ -2338,6 +2345,7 @@ void PgSQL_Connection::async_free_result() { new_result = false; } +#if 0 int PgSQL_Connection::async_set_autocommit(short event, bool ac) { PROXY_TRACE(); assert(pgsql_conn); @@ -2379,6 +2387,7 @@ int PgSQL_Connection::async_set_autocommit(short event, bool ac) { } return 1; } +#endif // 0 bool PgSQL_Connection::IsAutoCommit() { bool ret = true; diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index 71935d045..185b1d6f2 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -1535,6 +1535,7 @@ void PgSQL_Session::handler_again___new_thread_to_kill_connection() { // true should jump to handler_again #define NEXT_IMMEDIATE_NEW(new_st) do { set_status(new_st); return true; } while (0) +#if 0 bool PgSQL_Session::handler_again___verify_backend_multi_statement() { if ((client_myds->myconn->options.client_flag & CLIENT_MULTI_STATEMENTS) != (mybe->server_myds->myconn->options.client_flag & CLIENT_MULTI_STATEMENTS)) { @@ -1563,6 +1564,7 @@ bool PgSQL_Session::handler_again___verify_backend_multi_statement() { } return false; } +#endif // 0 bool PgSQL_Session::handler_again___verify_init_connect() { if (mybe->server_myds->myconn->options.init_connect_sent == false) { @@ -1585,6 +1587,7 @@ bool PgSQL_Session::handler_again___verify_init_connect() { return false; } +#if 0 bool PgSQL_Session::handler_again___verify_backend_session_track_gtids() { bool ret = false; proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Session %p , client: %s , backend: %s\n", this, client_myds->myconn->options.session_track_gtids, mybe->server_myds->myconn->options.session_track_gtids); @@ -1693,6 +1696,7 @@ bool PgSQL_Session::handler_again___verify_ldap_user_variable() { } return false; } +#endif // 0 bool PgSQL_Session::handler_again___verify_backend_user_db() { PgSQL_Data_Stream* myds = mybe->server_myds; @@ -1793,6 +1797,7 @@ bool PgSQL_Session::handler_again___status_SETTING_INIT_CONNECT(int* _rc) { return ret; } +#if 0 bool PgSQL_Session::handler_again___status_SETTING_LDAP_USER_VARIABLE(int* _rc) { bool ret = false; assert(mybe->server_myds->myconn); @@ -1977,6 +1982,7 @@ bool PgSQL_Session::handler_again___status_SETTING_SQL_LOG_BIN(int* _rc) { } return ret; } +#endif // 0 bool PgSQL_Session::handler_again___status_CHANGING_CHARSET(int* _rc) { assert(mybe->server_myds->myconn); @@ -2259,6 +2265,7 @@ bool PgSQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int* _rc, co return ret; } +#if 0 bool PgSQL_Session::handler_again___status_SETTING_MULTI_STMT(int* _rc) { assert(mybe->server_myds->myconn); PgSQL_Data_Stream* myds = mybe->server_myds; @@ -2398,7 +2405,7 @@ bool PgSQL_Session::handler_again___status_CHANGING_SCHEMA(int* _rc) { } return false; } - +#endif // 0 bool PgSQL_Session::handler_again___status_CONNECTING_SERVER(int* _rc) { //fprintf(stderr,"CONNECTING_SERVER\n"); @@ -4483,24 +4490,27 @@ handler_again: if (handler_again___verify_init_connect()) { goto handler_again; } +#if 0 if (use_ldap_auth) { if (handler_again___verify_ldap_user_variable()) { goto handler_again; } } - //if (handler_again___verify_backend_autocommit()) { - // goto handler_again; - //} + if (handler_again___verify_backend_autocommit()) { + goto handler_again; + } +#endif // 0 if (locked_on_hostgroup == -1 || locked_on_hostgroup_and_all_variables_set == false) { +#if 0 if (handler_again___verify_backend_multi_statement()) { goto handler_again; } - //if (handler_again___verify_backend_session_track_gtids()) { - // goto handler_again; - //} - + if (handler_again___verify_backend_session_track_gtids()) { + goto handler_again; + } +#endif // 0 // Optimize network traffic when we can use 'SET NAMES' //if (verify_set_names(this)) { // goto handler_again; @@ -4870,24 +4880,28 @@ bool PgSQL_Session::handler_again___multiple_statuses(int* rc) { case RESETTING_CONNECTION_V2: ret = handler_again___status_RESETTING_CONNECTION(rc); break; -// case CHANGING_AUTOCOMMIT: -// ret = handler_again___status_CHANGING_AUTOCOMMIT(rc); -// break; +#if 0 + case CHANGING_AUTOCOMMIT: + ret = handler_again___status_CHANGING_AUTOCOMMIT(rc); + break; case CHANGING_SCHEMA: ret = handler_again___status_CHANGING_SCHEMA(rc); break; case SETTING_LDAP_USER_VARIABLE: ret = handler_again___status_SETTING_LDAP_USER_VARIABLE(rc); break; +#endif // 0 case SETTING_INIT_CONNECT: ret = handler_again___status_SETTING_INIT_CONNECT(rc); break; +#if 0 case SETTING_MULTI_STMT: ret = handler_again___status_SETTING_MULTI_STMT(rc); break; case SETTING_SESSION_TRACK_GTIDS: ret = handler_again___status_SETTING_SESSION_TRACK_GTIDS(rc); break; +#endif // 0 case SETTING_SET_NAMES: ret = handler_again___status_CHANGING_CHARSET(rc); break; diff --git a/lib/PgSQL_Variables.cpp b/lib/PgSQL_Variables.cpp index c3e689b2f..4a9a89dab 100644 --- a/lib/PgSQL_Variables.cpp +++ b/lib/PgSQL_Variables.cpp @@ -61,8 +61,8 @@ PgSQL_Variables::PgSQL_Variables() { PgSQL_Variables::verifiers[i] = NULL; } else if (i == SQL_SQL_LOG_BIN) { - PgSQL_Variables::verifiers[i] = verify_server_variable; - PgSQL_Variables::updaters[i] = logbin_update_server_variable; +// PgSQL_Variables::verifiers[i] = verify_server_variable; +// PgSQL_Variables::updaters[i] = logbin_update_server_variable; } else { PgSQL_Variables::verifiers[i] = verify_server_variable; PgSQL_Variables::updaters[i] = update_server_variable; @@ -559,10 +559,11 @@ inline bool verify_server_variable(PgSQL_Session* session, int idx, uint32_t cli return false; } +#if 0 bool logbin_update_server_variable(PgSQL_Session* session, int idx, int &_rc) { return session->handler_again___status_SETTING_SQL_LOG_BIN(&_rc); } - +#endif // 0 bool PgSQL_Variables::parse_variable_boolean(PgSQL_Session *sess, int idx, string& value1, bool * lock_hostgroup) { proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Processing SET %s value %s\n", mysql_tracked_variables[idx].set_variable_name, value1.c_str());