Skip to content

Commit

Permalink
support load mysql_group_replication_hostgroups from the config file (s…
Browse files Browse the repository at this point in the history
…ysown#1050), sample config file update
  • Loading branch information
aminet committed Apr 24, 2018
1 parent 21b91ae commit 8b3c54e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/ProxySQL_Admin.cpp
Expand Up @@ -7580,6 +7580,38 @@ int ProxySQL_Admin::Read_MySQL_Servers_from_configfile() {
rows++;
}
}
if (root.exists("mysql_group_replication_hostgroups")==true) {
const Setting &mysql_group_replication_hostgroups = root["mysql_group_replication_hostgroups"];
int count = mysql_group_replication_hostgroups.getLength();
char *q=(char *)"INSERT OR REPLACE INTO mysql_group_replication_hostgroups (writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup, active, max_writers, writer_is_also_reader, max_transactions_behind, comment) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, '%s')";
for (i=0; i< count; i++) {
const Setting &line = mysql_group_replication_hostgroups[i];
int writer_hostgroup;
int backup_writer_hostgroup;
int reader_hostgroup;
int offline_hostgroup;
int active=1; // default
int max_writers=1; // default
int writer_is_also_reader=0;
int max_transactions_behind=0;
std::string comment="";
if (line.lookupValue("writer_hostgroup", writer_hostgroup)==false) continue;
if (line.lookupValue("backup_writer_hostgroup", backup_writer_hostgroup)==false) continue;
if (line.lookupValue("reader_hostgroup", reader_hostgroup)==false) continue;
if (line.lookupValue("offline_hostgroup", offline_hostgroup)==false) continue;
line.lookupValue("comment", comment);
char *o1=strdup(comment.c_str());
char *o=escape_string_single_quotes(o1, false);
char *query=(char *)malloc(strlen(q)+strlen(o)+128); // 128 vs sizeof(int)*8
sprintf(query,q, writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup, active, max_writers, writer_is_also_reader, max_transactions_behind, o);
//fprintf(stderr, "%s\n", query);
admindb->execute(query);
if (o!=o1) free(o);
free(o1);
free(query);
rows++;
}
}
admindb->execute("PRAGMA foreign_keys = ON");
return rows;
}
Expand Down
16 changes: 16 additions & 0 deletions src/proxysql.cfg
Expand Up @@ -81,6 +81,22 @@ mysql_replication_hostgroups=
}
)


mysql_group_replication_hostgroups=
(
{
writer_hostgroup=10
reader_hostgroup=20
backup_writer_hostgroup=11
offline_hostgroup=0
active=1
max_writers=1
writer_is_also_reader=0
max_transactions_behind=0
comment="repl group 1"
}
)

mysql_users:
(
{
Expand Down

0 comments on commit 8b3c54e

Please sign in to comment.