Skip to content

Commit

Permalink
Merge pull request #3305 from sysown/v2.1.2-cluster
Browse files Browse the repository at this point in the history
Cluster improvements
  • Loading branch information
renecannao authored Jan 22, 2022
2 parents fdb0abd + 43c6acb commit ae80989
Show file tree
Hide file tree
Showing 34 changed files with 1,148 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ test/tap/tests/generate_set_session_csv
test/tap/tests/set_testing-240.csv
local_testing_datadir/

test/cluster/node??/*


#files generated during CI run
proxysql-save.cfg
test/tap/tests/test_cluster_sync_config/cluster_sync_node_stderr.txt
Expand Down
1 change: 1 addition & 0 deletions include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class MySQL_Session

Session_Regex **match_regexes;

ProxySQL_Node_Address * proxysql_node_address; // this is used ONLY for Admin, and only if the other party is another proxysql instance part of a cluster
bool use_ldap_auth;

// this variable is relevant only if status == SETTING_VARIABLE
Expand Down
28 changes: 27 additions & 1 deletion include/ProxySQL_Cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ class ProxySQL_Node_Metrics {
}
};

class ProxySQL_Node_Address {
public:
pthread_t thrid;
uint64_t hash; // unused for now
char *uuid;
char *hostname;
char *admin_mysql_ifaces;
uint16_t port;
ProxySQL_Node_Address(char *h, uint16_t p) {
hostname = strdup(h);
admin_mysql_ifaces = NULL;
port = p;
uuid = NULL;
hash = 0;
}
~ProxySQL_Node_Address() {
if (hostname) free(hostname);
if (uuid) free(uuid);
if (admin_mysql_ifaces) free(admin_mysql_ifaces);
}
};

class ProxySQL_Node_Entry {
private:
uint64_t hash;
Expand Down Expand Up @@ -228,6 +250,9 @@ class ProxySQL_Cluster {
pthread_mutex_t update_mysql_users_mutex;
pthread_mutex_t update_mysql_variables_mutex;
pthread_mutex_t update_proxysql_servers_mutex;
// this records the interface that Admin is listening to
pthread_mutex_t admin_mysql_ifaces_mutex;
char *admin_mysql_ifaces;
int cluster_check_interval_ms;
int cluster_check_status_frequency;
int cluster_mysql_query_rules_diffs_before_sync;
Expand All @@ -254,6 +279,7 @@ class ProxySQL_Cluster {
void get_credentials(char **, char **);
void set_username(char *);
void set_password(char *);
void set_admin_mysql_ifaces(char *);
bool Update_Node_Metrics(char * _h, uint16_t _p, MYSQL_RES *_r, unsigned long long _response_time) {
return nodes.Update_Node_Metrics(_h, _p, _r, _response_time);
}
Expand Down Expand Up @@ -285,6 +311,6 @@ class ProxySQL_Cluster {
* - 'admin'.
*/
void pull_global_variables_from_peer(const std::string& type);
void pull_proxysql_servers_from_peer();
void pull_proxysql_servers_from_peer(const char *expected_checksum);
};
#endif /* CLASS_PROXYSQL_CLUSTER_H */
4 changes: 4 additions & 0 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class ProxySQL_Admin {

prometheus::SerialExposer serial_exposer;

std::mutex proxysql_servers_mutex;

void wrlock();
void wrunlock();

Expand Down Expand Up @@ -336,6 +338,8 @@ class ProxySQL_Admin {
void load_admin_variables_to_runtime() { flush_admin_variables___database_to_runtime(admindb, true); }
void save_admin_variables_from_runtime() { flush_admin_variables___runtime_to_database(admindb, true, true, false); }

void load_or_update_global_settings(SQLite3DB *);

void load_mysql_variables_to_runtime() { flush_mysql_variables___database_to_runtime(admindb, true); }
void save_mysql_variables_from_runtime() { flush_mysql_variables___runtime_to_database(admindb, true, true, false); }

Expand Down
6 changes: 6 additions & 0 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef __CLASS_PROXYSQL_GLOVARS_H
#define __CLASS_PROXYSQL_GLOVARS_H

#define CLUSTER_SYNC_INTERFACES_ADMIN "('admin-mysql_ifaces','admin-restapi_port','admin-telnet_admin_ifaces','admin-telnet_stats_ifaces','admin-web_port')"
#define CLUSTER_SYNC_INTERFACES_MYSQL "('mysql-interfaces')"

#include <memory>
#include <prometheus/registry.h>

Expand Down Expand Up @@ -45,14 +48,17 @@ class ProxySQL_GlobalVariables {
bool configfile_open;
char *__cmd_proxysql_config_file;
char *__cmd_proxysql_datadir;
char *__cmd_proxysql_uuid;
int __cmd_proxysql_nostart;
int __cmd_proxysql_foreground;
int __cmd_proxysql_gdbg;
bool __cmd_proxysql_initial;
bool __cmd_proxysql_reload;
bool cluster_sync_interfaces; // If true, also mysql-interfaces and admin-mysql_ifaces are synced. false by default
char *__cmd_proxysql_admin_socket;
char *config_file;
char *datadir;
char *uuid;
char *admindb;
char *statsdb_disk;
char *sqlite3serverdb;
Expand Down
1 change: 1 addition & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ class MySQL_ResultSet;
class Query_Processor_Output;
class MySrvC;
class Web_Interface_plugin;
class ProxySQL_Node_Address;
#endif /* PROXYSQL_CLASSES */
//#endif /* __cplusplus */

Expand Down
1 change: 1 addition & 0 deletions include/query_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class Query_Processor {
SQLite3_result * fast_routing_resultset;
void load_fast_routing(SQLite3_result *resultset);
SQLite3_result * get_current_query_rules_fast_routing();
int get_current_query_rules_fast_routing_count();
int testing___find_HG_in_mysql_query_rules_fast_routing(char *username, char *schemaname, int flagIN);
int testing___find_HG_in_mysql_query_rules_fast_routing_dual(char *username, char *schemaname, int flagIN);

Expand Down
5 changes: 5 additions & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ MySQL_Session::MySQL_Session() {
last_insert_id=0; // #1093

last_HG_affected_rows = -1; // #1421 : advanced support for LAST_INSERT_ID()
proxysql_node_address = NULL;
use_ldap_auth = false;
}

Expand Down Expand Up @@ -654,6 +655,10 @@ MySQL_Session::~MySQL_Session() {
__sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1);
GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement();
}
if (proxysql_node_address) {
delete proxysql_node_address;
proxysql_node_address = NULL;
}
}


Expand Down
Loading

0 comments on commit ae80989

Please sign in to comment.