Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for syncing 'mysql-variables' and 'admin-variables' #2820 #2856

Merged
merged 10 commits into from
Oct 21, 2020
Merged
29 changes: 29 additions & 0 deletions include/ProxySQL_Cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class ProxySQL_Cluster_Nodes {
void get_peer_to_sync_mysql_query_rules(char **host, uint16_t *port);
void get_peer_to_sync_mysql_servers(char **host, uint16_t *port, char **peer_checksum);
void get_peer_to_sync_mysql_users(char **host, uint16_t *port);
void get_peer_to_sync_mysql_variables(char **host, uint16_t *port);
void get_peer_to_sync_admin_variables(char **host, uint16_t* port);
void get_peer_to_sync_proxysql_servers(char **host, uint16_t *port);
};

Expand Down Expand Up @@ -141,15 +143,25 @@ struct p_cluster_counter {
pulled_proxysql_servers_success,
pulled_proxysql_servers_failure,

pulled_mysql_variables_success,
pulled_mysql_variables_failure,

pulled_admin_variables_success,
pulled_admin_variables_failure,

sync_conflict_mysql_query_rules_share_epoch,
sync_conflict_mysql_servers_share_epoch,
sync_conflict_proxysql_servers_share_epoch,
sync_conflict_mysql_users_share_epoch,
sync_conflict_mysql_variables_share_epoch,
sync_conflict_admin_variables_share_epoch,

sync_delayed_mysql_query_rules_version_one,
sync_delayed_mysql_servers_version_one,
sync_delayed_mysql_users_version_one,
sync_delayed_proxysql_servers_version_one,
sync_delayed_mysql_variables_version_one,
sync_delayed_admin_variables_version_one,

__size
};
Expand All @@ -168,6 +180,14 @@ struct cluster_metrics_map_idx {
};
};

struct variable_type {
enum type {
mysql,
admin,
__size
};
};

/**
* @brief Simple struct for holding a query, and three messages to report
* the progress of the query execution.
Expand Down Expand Up @@ -196,6 +216,7 @@ class ProxySQL_Cluster {
pthread_mutex_t update_mysql_query_rules_mutex;
pthread_mutex_t update_mysql_servers_mutex;
pthread_mutex_t update_mysql_users_mutex;
pthread_mutex_t update_mysql_variables_mutex;
pthread_mutex_t update_proxysql_servers_mutex;
int cluster_check_interval_ms;
int cluster_check_status_frequency;
Expand Down Expand Up @@ -244,6 +265,14 @@ class ProxySQL_Cluster {
void pull_mysql_query_rules_from_peer();
void pull_mysql_servers_from_peer();
void pull_mysql_users_from_peer();
/**
* @brief Pulls from peer the specified global variables by the type parameter.
* @param type A string specifying the type of global variables to pull from the peer, supported
* values right now are:
* - 'mysql'.
* - 'admin'.
*/
void pull_global_variables_from_peer(const std::string& type);
void pull_proxysql_servers_from_peer();
};
#endif /* CLASS_PROXYSQL_CLUSTER_H */
5 changes: 5 additions & 0 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ class ProxySQL_Admin {
void flush_mysql_query_rules__from_disk_to_memory();
void flush_mysql_firewall__from_memory_to_disk();
void flush_mysql_firewall__from_disk_to_memory();
void flush_mysql_variables__from_disk_to_memory();
void flush_mysql_variables__from_memory_to_disk();
void flush_admin_variables__from_disk_to_memory();
void flush_admin_variables__from_memory_to_disk();

void load_mysql_servers_to_runtime();
void save_mysql_servers_from_runtime();
char * load_mysql_query_rules_to_runtime();
Expand Down
36 changes: 35 additions & 1 deletion lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3180,6 +3180,7 @@ bool ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign

if (admin) {
if (dump_global_variables) {
pthread_mutex_lock(&GloVars.checksum_mutex);
admindb->execute("DELETE FROM runtime_global_variables"); // extra
flush_admin_variables___runtime_to_database(admindb, false, false, false, true);
flush_mysql_variables___runtime_to_database(admindb, false, false, false, true);
Expand All @@ -3188,6 +3189,7 @@ bool ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign
#endif /* PROXYSQLCLICKHOUSE */
flush_sqliteserver_variables___runtime_to_database(admindb, false, false, false, true);
flush_ldap_variables___runtime_to_database(admindb, false, false, false, true);
pthread_mutex_unlock(&GloVars.checksum_mutex);
}
if (runtime_mysql_servers) {
int old_hostgroup_manager_verbose = mysql_thread___hostgroup_manager_verbose;
Expand Down Expand Up @@ -6009,7 +6011,7 @@ void ProxySQL_Admin::flush_mysql_variables___database_to_runtime(SQLite3DB *db,
int cols=0;
int affected_rows=0;
SQLite3_result *resultset=NULL;
char *q=(char *)"SELECT variable_name, variable_value FROM runtime_global_variables WHERE variable_name LIKE 'mysql-\%' ORDER BY variable_name";
char *q=(char *)"SELECT variable_name, variable_value FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%' ORDER BY variable_name";
admindb->execute_statement(q, &error , &cols , &affected_rows , &resultset);
uint64_t hash1 = resultset->raw_checksum();
uint32_t d32[2];
Expand Down Expand Up @@ -9455,6 +9457,38 @@ void ProxySQL_Admin::flush_mysql_query_rules__from_memory_to_disk() {
admindb->wrunlock();
}

void ProxySQL_Admin::flush_mysql_variables__from_disk_to_memory() {
admindb->wrlock();
admindb->execute("PRAGMA foreign_keys = OFF");
admindb->execute("INSERT OR REPLACE INTO main.global_variables SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%'");
admindb->execute("PRAGMA foreign_keys = ON");
admindb->wrunlock();
}

void ProxySQL_Admin::flush_mysql_variables__from_memory_to_disk() {
admindb->wrlock();
admindb->execute("PRAGMA foreign_keys = OFF");
admindb->execute("INSERT OR REPLACE INTO disk.global_variables SELECT * FROM main.global_variables WHERE variable_name LIKE 'mysql-%'");
admindb->execute("PRAGMA foreign_keys = ON");
admindb->wrunlock();
}

void ProxySQL_Admin::flush_admin_variables__from_disk_to_memory() {
admindb->wrlock();
admindb->execute("PRAGMA foreign_keys = OFF");
admindb->execute("INSERT OR REPLACE INTO main.global_variables SELECT * FROM disk.global_variables WHERE variable_name LIKE 'admin-%'");
admindb->execute("PRAGMA foreign_keys = ON");
admindb->wrunlock();
}

void ProxySQL_Admin::flush_admin_variables__from_memory_to_disk() {
admindb->wrlock();
admindb->execute("PRAGMA foreign_keys = OFF");
admindb->execute("INSERT OR REPLACE INTO disk.global_variables SELECT * FROM main.global_variables WHERE variable_name LIKE 'admin-%'");
admindb->execute("PRAGMA foreign_keys = ON");
admindb->wrunlock();
}

void ProxySQL_Admin::__attach_db(SQLite3DB *db1, SQLite3DB *db2, char *alias) {
const char *a="ATTACH DATABASE '%s' AS %s";
int l=strlen(a)+strlen(db2->get_url())+strlen(alias)+5;
Expand Down
Loading