Skip to content

Commit

Permalink
Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
rahim-kanji committed May 8, 2024
2 parents c7cf5ba + cdbe983 commit ca93da5
Show file tree
Hide file tree
Showing 20 changed files with 1,915 additions and 1,426 deletions.
70 changes: 70 additions & 0 deletions doc/internal/MySQL_Connection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
### Flowchart of `MySQL_Connection::async_query()`

This function asynchronously executes a query on the MySQL connection.
It handles various states of the asynchronous query execution process and returns appropriate status codes indicating the result of the execution.

Returns an integer status code indicating the result of the query execution:
- 0: Query execution completed successfully.
- -1: Query execution failed.
- 1: Query execution in progress.
- 2: Processing a multi-statement query, control needs to be transferred to MySQL_Session.
- 3: In the middle of processing a multi-statement query.


```mermaid
---
title: MySQL_Connection::async_query()
---
flowchart TD
Assert["assert()"]
ValidConnection{Valid Connection}
ValidConnection -- no --> Assert
IsServerOffline{"IsServerOffline()"}
ValidConnection -- yes --> IsServerOffline
IsServerOffline -- yes --> ReturnMinus1
asyncStateMachine1{async_state_machine}
asyncStateMachine2{async_state_machine}
IsServerOffline -- no --> asyncStateMachine1
asyncStateMachine1 -- ASYNC_QUERY_END --> Return0
handler["handler()"]
asyncStateMachine1 --> handler
handler --> asyncStateMachine2
asyncStateMachine2 -- ASYNC_QUERY_END --> mysql_error{"mysql_error"}
asyncStateMachine2 -- ASYNC_STMT_EXECUTE_END --> mysql_error
asyncStateMachine2 -- ASYNC_STMT_PREPARE_FAILED --> ReturnMinus1
asyncStateMachine2 -- ASYNC_STMT_PREPARE_SUCCESSFUL --> Return0
mysql_error -- yes --> ReturnMinus1
mysql_error -- no --> Return0
asyncStateMachine2 -- ASYNC_NEXT_RESULT_START --> Return2
processing_multi_statement{"processing_multi_statement"}
asyncStateMachine2 --> processing_multi_statement
processing_multi_statement -- yes --> Return3
processing_multi_statement -- no --> Return1
ReturnMinus1["return -1"]
Return0["return 0"]
Return1["return 1"]
Return2["return 2"]
Return3["return 3"]
```

### Flowchart of `MySQL_Connection::IsServerOffline()`

```mermaid
---
title: MySQL_Connection::IsServerOffline()
---
flowchart TD
True[true]
False[false]
SS1{"server_status"}
SA{"shunned_automatic"}
SB{"shunned_and_kill_all_connections"}
SS1 -- OFFLINE_HARD --> True
SS1 -- REPLICATION_LAG --> True
SS1 -- SHUNNED --> SA
SA -- yes --> SB
SB -- yes --> True
SA -- no --> False
SB -- no --> False
SS1 --> False
```
68 changes: 68 additions & 0 deletions doc/internal/MySQL_Session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
### Flowchart of `MySQL_Session::RunQuery()`

This function mostly calls `MySQL_Connection::async_query()` with the right arguments.
Returns an integer status code indicating the result of the query execution:
- 0: Query execution completed successfully.
- -1: Query execution failed.
- 1: Query execution in progress.
- 2: Processing a multi-statement query, control needs to be transferred to MySQL_Session.
- 3: In the middle of processing a multi-statement query.

```mermaid
---
title: MySQL_Session::RunQuery()
---
flowchart TD
RQ["MySQL_Connection::async_query()"]
BEGIN --> RQ
RQ --> END
```

### Flowchart of `MySQL_Session::handler()`

WORK IN PROGRESS

```mermaid
---
title: MySQL_Session::handler()
---
flowchart TD
RQ["rc = RunQuery()"]
RC{rc}
CBCS["rc1 = handler_ProcessingQueryError_CheckBackendConnectionStatus()"]
RC1{rc1}
RQ --> RC
RC -- 0 --> OK
RC -- -1 --> CBCS
CBCS --> RC1
CS["CONNECTING_SERVER"]
ReturnMinus1["return -1"]
RC1 -- -1 --> ReturnMinus1
RC1 -- 1 --> CS
HM1CLE1["handler_minus1_ClientLibraryError()"]
HM1CLE2["handler_minus1_ClientLibraryError()"]
myerr1{"myerr >= 2000
&&
myerr < 3000"}
RC1 --> myerr1
myerr1 -- yes --> HM1CLE1
HM1CLE1 -- true --> CS
HM1CLE1 -- false --> ReturnMinus1
HM1LEDQ1["handler_minus1_LogErrorDuringQuery()"]
myerr1 -- no --> HM1LEDQ1
HM1HEC1["handler_minus1_HandleErrorCodes()"]
HM1LEDQ1 --> HM1HEC1
HM1HEC1 -- true --> HR1{"handler_ret"}
HR1 -- 0 --> CS
HR1 --> RHR1["return handler_ret"]
HM1GEM1["handler_minus1_GenerateErrorMessage()"]
HM1HEC1 -- false --> HM1GEM1
RE["RequestEnd()"]
HM1HBC1["handler_minus1_HandleBackendConnection()"]
HM1GEM1 --> RE
RE --> HM1HBC1
```


### Flowchart of `MySQL_Session::handler_ProcessingQueryError_CheckBackendConnectionStatus()`
TODO
2 changes: 2 additions & 0 deletions include/MySQL_Data_Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,7 @@ class MySQL_Data_Stream
void destroy_queues();

bool data_in_rbio();

void get_client_myds_info_json(json&);
};
#endif /* __CLASS_MYSQL_DATA_STREAM_H */
16 changes: 16 additions & 0 deletions include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MySQL_Session
private:
//int handler_ret;
void handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(PtrSize_t *, bool *);
void handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE_WrongCredentials(PtrSize_t *, bool *);

// void handler___status_CHANGING_USER_CLIENT___STATE_CLIENT_HANDSHAKE(PtrSize_t *, bool *);

Expand Down Expand Up @@ -202,14 +203,17 @@ class MySQL_Session
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session();
int handler_again___status_PINGING_SERVER();
int handler_again___status_RESETTING_CONNECTION();
bool handler_again___status_SHOW_WARNINGS(MySQL_Data_Stream *, bool);
void handler_again___new_thread_to_kill_connection();
void handler_KillConnectionIfNeeded();

bool handler_again___verify_init_connect();
bool handler_again___verify_ldap_user_variable();
bool handler_again___verify_backend_autocommit();
bool handler_again___verify_backend_session_track_gtids();
bool handler_again___verify_backend_multi_statement();
bool handler_again___verify_backend_user_schema();
bool handler_again___verify_multiple_variables(MySQL_Connection *);
bool handler_again___status_SETTING_INIT_CONNECT(int *);
bool handler_again___status_SETTING_LDAP_USER_VARIABLE(int *);
bool handler_again___status_SETTING_SQL_MODE(int *);
Expand All @@ -221,6 +225,7 @@ class MySQL_Session
bool handler_again___status_CHANGING_AUTOCOMMIT(int *);
bool handler_again___status_SETTING_MULTI_STMT(int *_rc);
bool handler_again___multiple_statuses(int *rc);

void init();
void reset();
void add_ldap_comment_to_pkt(PtrSize_t *);
Expand All @@ -229,7 +234,17 @@ class MySQL_Session
* performing any processing on received client packets.
*/
void housekeeping_before_pkts();

int get_pkts_from_client(bool&, PtrSize_t&);

// GPFC_ functions are subfunctions of get_pkts_from_client()
int GPFC_Statuses2(bool&, PtrSize_t&);
void GPFC_DetectedMultiPacket_SetDDS();
int GPFC_WaitingClientData_FastForwardSession(PtrSize_t&);
void GPFC_PreparedStatements(PtrSize_t&, unsigned char);
void GPFC_Replication_SwitchToFastForward(PtrSize_t&, unsigned char);
bool GPFC_QueryUSE(PtrSize_t&, int&);

void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STMT_RESET(PtrSize_t&);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STMT_CLOSE(PtrSize_t&);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STMT_SEND_LONG_DATA(PtrSize_t&);
Expand All @@ -249,6 +264,7 @@ class MySQL_Session
int RunQuery(MySQL_Data_Stream *myds, MySQL_Connection *myconn);
void handler___status_WAITING_CLIENT_DATA();
void handler_rc0_Process_GTID(MySQL_Connection *myconn);
void handler_rc0_RefreshActiveTransactions(MySQL_Connection* myconn);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_INIT_DB_replace_CLICKHOUSE(PtrSize_t& pkt);
void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___not_mysql(PtrSize_t& pkt);
bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_detect_SQLi();
Expand Down
9 changes: 9 additions & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class __attribute__((aligned(64))) MySQL_Thread
void idle_thread_prepares_session_to_send_to_worker_thread(int i);
void idle_thread_to_kill_idle_sessions();
bool move_session_to_idle_mysql_sessions(MySQL_Data_Stream *myds, unsigned int n);
void run_Handle_epoll_wait(int);
#endif // IDLE_THREADS

unsigned int find_session_idx_in_mysql_sessions(MySQL_Session *sess);
Expand All @@ -142,6 +143,13 @@ class __attribute__((aligned(64))) MySQL_Thread
void tune_timeout_for_session_needs_pause(MySQL_Data_Stream *myds);
void configure_pollout(MySQL_Data_Stream *myds, unsigned int n);

void run_MoveSessionsBetweenThreads();
void run_BootstrapListener();
int run_ComputePollTimeout();
void run_StopListener();
void run_SetAllSession_ToProcess0();


protected:
int nfds;

Expand Down Expand Up @@ -212,6 +220,7 @@ class __attribute__((aligned(64))) MySQL_Thread
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);
void process_all_sessions();
void refresh_variables();
void register_session_connection_handler(MySQL_Session *_sess, bool _new=false);
Expand Down
14 changes: 13 additions & 1 deletion include/mysql_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MySQLServers_SslParams;
class Variable {
public:
char *value = (char*)"";
void fill_server_internal_session(json &j, int conn_num, int idx);
void fill_server_internal_session(json &j, int idx);
void fill_client_internal_session(json &j, int idx);
};

Expand Down Expand Up @@ -60,6 +60,15 @@ class MySQL_Connection {
void update_warning_count_from_statement();
bool is_expired(unsigned long long timeout);
unsigned long long inserted_into_pool;
void connect_start_SetAttributes();
void connect_start_SetCharset();
void connect_start_SetClientFlag(unsigned long&);
char * connect_start_DNS_lookup();
void connect_start_SetSslSettings();
void ProcessQueryAndSetStatusFlags_Warnings(char *);
void ProcessQueryAndSetStatusFlags_UserVariables(char *, int);
void ProcessQueryAndSetStatusFlags_Savepoint(char *);
void ProcessQueryAndSetStatusFlags_SetBackslashEscapes();
public:
struct {
char *server_version;
Expand Down Expand Up @@ -254,5 +263,8 @@ class MySQL_Connection {
unsigned int number_of_matching_session_variables(const MySQL_Connection *client_conn, unsigned int& not_matching);
unsigned long get_mysql_thread_id() { return mysql ? mysql->thread_id : 0; }
static void set_ssl_params(MYSQL *mysql, MySQLServers_SslParams *ssl_params);

void get_mysql_info_json(json&);
void get_backend_conn_info_json(json&);
};
#endif /* __CLASS_MYSQL_CONNECTION_H */
12 changes: 12 additions & 0 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ class ProxySQL_Admin {
void flush_mysql_variables___runtime_to_database(SQLite3DB *db, bool replace, bool del, bool onlyifempty, bool runtime=false, bool use_lock=true);
void flush_mysql_variables___database_to_runtime(SQLite3DB *db, bool replace, const std::string& checksum = "", const time_t epoch = 0);

void flush_GENERIC_variables__checksum__database_to_runtime(const std::string& modname, const std::string& checksum, const time_t epoch);
bool flush_GENERIC_variables__retrieve__database_to_runtime(const std::string& modname, char* &error, int& cols, int& affected_rows, SQLite3_result* &resultset);
void flush_GENERIC_variables__process__database_to_runtime(
const std::string& modname, SQLite3DB *db, SQLite3_result* resultset,
const bool& lock, const bool& replace,
const std::unordered_set<std::string>& variables_read_only,
const std::unordered_set<std::string>& variables_to_delete_silently,
const std::unordered_set<std::string>& variables_deprecated,
const std::unordered_set<std::string>& variables_special_values,
std::function<void(const std::string&, const char *, SQLite3DB *)> special_variable_action = nullptr
);

char **get_variables_list();
bool set_variable(char *name, char *value, bool lock = true);
void flush_admin_variables___database_to_runtime(SQLite3DB *db, bool replace, const std::string& checksum = "", const time_t epoch = 0, bool lock = true);
Expand Down
4 changes: 2 additions & 2 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ __thread int mysql_thread___monitor_groupreplication_healthcheck_interval;
__thread int mysql_thread___monitor_groupreplication_healthcheck_timeout;
__thread int mysql_thread___monitor_groupreplication_healthcheck_max_timeout_count;
__thread int mysql_thread___monitor_groupreplication_max_transactions_behind_count;
__thread int mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only;
__thread int mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only;
__thread int mysql_thread___monitor_galera_healthcheck_interval;
__thread int mysql_thread___monitor_galera_healthcheck_timeout;
__thread int mysql_thread___monitor_galera_healthcheck_max_timeout_count;
Expand Down Expand Up @@ -1087,7 +1087,7 @@ extern __thread int mysql_thread___monitor_replication_lag_count;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_interval;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_timeout;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_max_timeout_count;
extern __thread int mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only;
extern __thread int mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only;
extern __thread int mysql_thread___monitor_groupreplication_max_transactions_behind_count;
extern __thread int mysql_thread___monitor_galera_healthcheck_interval;
extern __thread int mysql_thread___monitor_galera_healthcheck_timeout;
Expand Down
16 changes: 15 additions & 1 deletion include/query_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define DIGEST_STATS_FAST_MINSIZE 100000
#define DIGEST_STATS_FAST_THREADS 4


#include "../deps/json/json.hpp"


#include "khash.h"
Expand Down Expand Up @@ -204,6 +204,20 @@ class Query_Processor_Output {
free(comment);
}
}
void get_info_json(nlohmann::json& j) {
j["create_new_connection"] = create_new_conn;
j["reconnect"] = reconnect;
j["sticky_conn"] = sticky_conn;
j["cache_timeout"] = cache_timeout;
j["cache_ttl"] = cache_ttl;
j["delay"] = delay;
j["destination_hostgroup"] = destination_hostgroup;
j["firewall_whitelist_mode"] = firewall_whitelist_mode;
j["multiplex"] = multiplex;
j["timeout"] = timeout;
j["retries"] = retries;
j["max_lag_ms"] = max_lag_ms;
}
};

static char *commands_counters_desc[MYSQL_COM_QUERY___NONE];
Expand Down
8 changes: 4 additions & 4 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2873,8 +2873,8 @@ void MySQL_HostGroups_Manager::group_replication_lag_action(
MyHGC* myhgc = nullptr;

if (
mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only == 0 ||
mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only == 2 ||
mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only == 0 ||
mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only == 2 ||
enable
) {
if (read_only == false) {
Expand All @@ -2884,8 +2884,8 @@ void MySQL_HostGroups_Manager::group_replication_lag_action(
}

if (
mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only == 1 ||
mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only == 2 ||
mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only == 1 ||
mysql_thread___monitor_groupreplication_max_transactions_behind_for_read_only == 2 ||
enable
) {
myhgc = MyHGM->MyHGC_find(reader_hostgroup);
Expand Down
Loading

0 comments on commit ca93da5

Please sign in to comment.