diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 77441ae52..5870fadb7 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -4408,50 +4408,81 @@ int ProxySQL_Admin::Read_MySQL_Query_Rules_from_configfile() { int ProxySQL_Admin::Read_MySQL_Servers_from_configfile() { const Setting& root = GloVars.confFile->cfg->getRoot(); - if (root.exists("mysql_servers")==false) return 0; - const Setting &mysql_servers = root["mysql_servers"]; - int count = mysql_servers.getLength(); - //fprintf(stderr, "Found %d servers\n",count); int i; int rows=0; admindb->execute("PRAGMA foreign_keys = OFF"); - char *q=(char *)"INSERT OR REPLACE INTO mysql_servers (hostname, port, hostgroup_id, compression, weight, status, max_connections, max_replication_lag, use_ssl, max_latency_ms) VALUES (\"%s\", %d, %d, %d, %d, \"%s\", %d, %d, %d, %d)"; - for (i=0; i< count; i++) { - const Setting &server = mysql_servers[i]; - std::string address; - std::string status="ONLINE"; - int port; - int hostgroup; - int weight=1; - int compression=0; - int max_connections=1000; // default - int max_replication_lag=0; // default - int use_ssl=0; - int max_latency_ms=0; - if (server.lookupValue("address", address)==false) continue; - if (server.lookupValue("port", port)==false) continue; - if (server.lookupValue("hostgroup", hostgroup)==false) continue; - server.lookupValue("status", status); - if ( - (strcasecmp(status.c_str(),(char *)"ONLINE")) - && (strcasecmp(status.c_str(),(char *)"SHUNNED")) - && (strcasecmp(status.c_str(),(char *)"OFFLINE_SOFT")) - && (strcasecmp(status.c_str(),(char *)"OFFLINE_HARD")) - ) { - status="ONLINE"; - } - server.lookupValue("compression", compression); - server.lookupValue("weight", weight); - server.lookupValue("max_connections", max_connections); - server.lookupValue("max_replication_lag", max_replication_lag); - server.lookupValue("use_ssl", use_ssl); - server.lookupValue("max_latency_ms", max_latency_ms); - char *query=(char *)malloc(strlen(q)+strlen(status.c_str())+strlen(address.c_str())+128); - sprintf(query,q, address.c_str(), port, hostgroup, compression, weight, status.c_str(), max_connections, max_replication_lag, use_ssl, max_latency_ms); - //fprintf(stderr, "%s\n", query); - admindb->execute(query); - free(query); - rows++; + if (root.exists("mysql_servers")==true) { + const Setting &mysql_servers = root["mysql_servers"]; + int count = mysql_servers.getLength(); + //fprintf(stderr, "Found %d servers\n",count); + char *q=(char *)"INSERT OR REPLACE INTO mysql_servers (hostname, port, hostgroup_id, compression, weight, status, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment) VALUES (\"%s\", %d, %d, %d, %d, \"%s\", %d, %d, %d, %d, '%s')"; + for (i=0; i< count; i++) { + const Setting &server = mysql_servers[i]; + std::string address; + std::string status="ONLINE"; + int port; + int hostgroup; + int weight=1; + int compression=0; + int max_connections=1000; // default + int max_replication_lag=0; // default + int use_ssl=0; + int max_latency_ms=0; + std::string comment=""; + if (server.lookupValue("address", address)==false) continue; + if (server.lookupValue("port", port)==false) continue; + if (server.lookupValue("hostgroup", hostgroup)==false) continue; + server.lookupValue("status", status); + if ( + (strcasecmp(status.c_str(),(char *)"ONLINE")) + && (strcasecmp(status.c_str(),(char *)"SHUNNED")) + && (strcasecmp(status.c_str(),(char *)"OFFLINE_SOFT")) + && (strcasecmp(status.c_str(),(char *)"OFFLINE_HARD")) + ) { + status="ONLINE"; + } + server.lookupValue("compression", compression); + server.lookupValue("weight", weight); + server.lookupValue("max_connections", max_connections); + server.lookupValue("max_replication_lag", max_replication_lag); + server.lookupValue("use_ssl", use_ssl); + server.lookupValue("max_latency_ms", max_latency_ms); + server.lookupValue("comment", comment); + char *o1=strdup(comment.c_str()); + char *o=escape_string_single_quotes(o1, false); + char *query=(char *)malloc(strlen(q)+strlen(status.c_str())+strlen(address.c_str())+strlen(o)+128); + sprintf(query,q, address.c_str(), port, hostgroup, compression, weight, status.c_str(), max_connections, max_replication_lag, use_ssl, max_latency_ms, o); + //fprintf(stderr, "%s\n", query); + admindb->execute(query); + if (o!=o1) free(o); + free(o1); + free(query); + rows++; + } + } + if (root.exists("mysql_replication_hostgroups")==true) { + const Setting &mysql_replication_hostgroups = root["mysql_replication_hostgroups"]; + int count = mysql_replication_hostgroups.getLength(); + char *q=(char *)"INSERT OR REPLACE INTO mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup, comment) VALUES (%d, %d, '%s')"; + for (i=0; i< count; i++) { + const Setting &line = mysql_replication_hostgroups[i]; + int writer_hostgroup; + int reader_hostgroup; + std::string comment=""; + if (line.lookupValue("writer_hostgroup", writer_hostgroup)==false) continue; + if (line.lookupValue("reader_hostgroup", reader_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)+32); + sprintf(query,q, writer_hostgroup, reader_hostgroup, 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; diff --git a/src/proxysql.cfg b/src/proxysql.cfg index bc4bb9bd2..6b65d04ca 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -46,9 +46,24 @@ mysql_servers = port=3306 hostgroup=0 max_connections=200 + comment="test server" } ) +mysql_replication_hostgroups= +( + { + writer_hostgroup=30 + reader_hostgroup=40 + comment="test repl 1" + }, + { + writer_hostgroup=50 + reader_hostgroup=60 + comment="test repl 2" + } +) + mysql_users: ( {