#define MYHGM_MYSQL_SERVERS "CREATE TABLE mysql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )"
#define MYHGM_MYSQL_SERVERS_INCOMING "CREATE TABLE mysql_servers_incoming ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , PRIMARY KEY (hostgroup_id, hostname, port))"
#define MYHGM_MYSQL_SERVERS "CREATE TABLE mysql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )"
#define MYHGM_MYSQL_SERVERS_INCOMING "CREATE TABLE mysql_servers_incoming ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , status INT CHECK (status IN (0, 1, 2, 3)) NOT NULL DEFAULT 0 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port))"
classMySrvConnList;
@ -45,6 +45,7 @@ class MySrvC { // MySQL Server Container
enumMySerStatusstatus;
unsignedintcompression;
unsignedintmax_connections;
unsignedintmax_replication_lag;
unsignedintconnect_OK;
unsignedintconnect_ERR;
time_ttime_last_detected_error;
@ -54,7 +55,7 @@ class MySrvC { // MySQL Server Container
#define MONITOR_SQLITE_TABLE_MYSQL_SERVER_PING_LOG "CREATE TABLE mysql_server_ping_log ( hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , time_start INT NOT NULL DEFAULT 0 , ping_success_time INT DEFAULT 0 , ping_error VARCHAR , PRIMARY KEY (hostname, port, time_start))"
#define MONITOR_SQLITE_TABLE_MYSQL_SERVER_REPLICATION_LAG_LOG "CREATE TABLE mysql_server_replication_lag_log ( hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , time_start INT NOT NULL DEFAULT 0 , success_time INT DEFAULT 0 , lag INT DEFAULT 0 , error VARCHAR , PRIMARY KEY (hostname, port, time_start))"
#define MONITOR_SQLITE_TABLE_MYSQL_SERVER_REPLICATION_LAG_LOG "CREATE TABLE mysql_server_replication_lag_log ( hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , time_start INT NOT NULL DEFAULT 0 , success_time INT DEFAULT 0 , repl_lag INT DEFAULT 0 , error VARCHAR , PRIMARY KEY (hostname, port, time_start))"
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,7,"Adding in mysql_servers_incoming server %s:%d in hostgroup %u with weight %u , status %u, %s compression, max_connections %d\n",add,p,hid,_weight,status,(_comp?"with":"without")/*, _charset */,_max_connections);
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,7,"Adding in mysql_servers_incoming server %s:%d in hostgroup %u with weight %u , status %u, %s compression, max_connections %d, max_replication_lag %u\n",add,p,hid,_weight,status,(_comp?"with":"without")/*, _charset */,_max_connections,_max_replication_lag);
// INSERT OR IGNORE INTO mysql_servers SELECT ... FROM mysql_servers_incoming
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "INSERT OR IGNORE INTO mysql_servers(hostgroup_id, hostname, port, weight, status, compression, max_connections) SELECT hostgroup_id, hostname, port, weight, status, compression, max_connections FROM mysql_servers_incoming\n");
mydb->execute("INSERT OR IGNORE INTO mysql_servers(hostgroup_id, hostname, port, weight, status, compression, max_connections) SELECT hostgroup_id, hostname, port, weight, status, compression, max_connections FROM mysql_servers_incoming");
// proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 4, "INSERT OR IGNORE INTO mysql_servers(hostgroup_id, hostname, port, weight, status, compression, max_connections) SELECT hostgroup_id, hostname, port, weight, status, compression, max_connections FROM mysql_servers_incoming\n");
mydb->execute("INSERT OR IGNORE INTO mysql_servers(hostgroup_id, hostname, port, weight, status, compression, max_connections, max_replication_lag) SELECT hostgroup_id, hostname, port, weight, status, compression, max_connections, max_replication_lag FROM mysql_servers_incoming");
// SELECT FROM mysql_servers whatever is not identical in mysql_servers_incoming, or where mem_pointer=0 (where there is no pointer yet)
query=(char*)"SELECT t1.*, t2.weight, t2.status, t2.compression, t2.max_connections FROM mysql_servers t1 JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE mem_pointer=0 OR t1.weight<>t2.weight OR t1.status<>t2.status OR t1.compression<>t2.compression OR t1.max_connections<>t2.max_connections";
query=(char*)"SELECT t1.*, t2.weight, t2.status, t2.compression, t2.max_connections, t2.max_replication_lag FROM mysql_servers t1 JOIN mysql_servers_incoming t2 ON (t1.hostgroup_id=t2.hostgroup_id AND t1.hostname=t2.hostname AND t1.port=t2.port) WHERE mem_pointer=0 OR t1.weight<>t2.weight OR t1.status<>t2.status OR t1.compression<>t2.compression OR t1.max_connections<>t2.max_connections OR t1.max_replication_lag<>t2.max_replication_lag";
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Creating new server %s:%d , weight=%d, status=%d, compression=%d\n",r->fields[1],atoi(r->fields[2]),atoi(r->fields[3]),(MySerStatus)atoi(r->fields[4]),atoi(r->fields[5]));
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Adding new server %s:%d , weight=%d, status=%d, mem_ptr=%p into hostgroup=%d\n",r->fields[1],atoi(r->fields[2]),atoi(r->fields[3]),(MySerStatus)atoi(r->fields[4]),mysrvc,atoi(r->fields[0]));
add(mysrvc,atoi(r->fields[0]));
}else{
MySrvC*mysrvc=(MySrvC*)ptr;
if(atoi(r->fields[3])!=atoi(r->fields[8])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing weight for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[3],mysrvc->weight,atoi(r->fields[8]));
mysrvc->weight=atoi(r->fields[8]);
if(atoi(r->fields[3])!=atoi(r->fields[9])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing weight for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[3],mysrvc->weight,atoi(r->fields[9]));
mysrvc->weight=atoi(r->fields[9]);
}
if(atoi(r->fields[4])!=atoi(r->fields[9])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing status for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->status,atoi(r->fields[9]));
mysrvc->status=(MySerStatus)atoi(r->fields[9]);
if(atoi(r->fields[4])!=atoi(r->fields[10])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing status for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->status,atoi(r->fields[10]));
mysrvc->status=(MySerStatus)atoi(r->fields[10]);
if(mysrvc->status==MYSQL_SERVER_STATUS_SHUNNED){
mysrvc->shunned_automatic=false;
}
}
if(atoi(r->fields[5])!=atoi(r->fields[10])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing compression for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->compression,atoi(r->fields[10]));
mysrvc->compression=atoi(r->fields[10]);
if(atoi(r->fields[5])!=atoi(r->fields[11])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing compression for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->compression,atoi(r->fields[11]));
mysrvc->compression=atoi(r->fields[11]);
}
if(atoi(r->fields[6])!=atoi(r->fields[11])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing max_connections for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->compression,atoi(r->fields[11]));
mysrvc->max_connections=atoi(r->fields[11]);
if(atoi(r->fields[6])!=atoi(r->fields[12])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing max_connections for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->max_connections,atoi(r->fields[12]));
mysrvc->max_connections=atoi(r->fields[12]);
}
if(atoi(r->fields[7])!=atoi(r->fields[13])){
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL,5,"Changing max_replication_lag for server %s:%d (%s:%d) from %d (%d) to %d\n",mysrvc->address,mysrvc->port,r->fields[1],atoi(r->fields[2]),r->fields[4],mysrvc->max_replication_lag,atoi(r->fields[13]));
char*query=(char*)"SELECT hostgroup_id, hostname, port, weight, CASE status WHEN 0 THEN \"ONLINE\" WHEN 1 THEN \"SHUNNED\" WHEN 2 THEN \"OFFLINE_SOFT\" WHEN 3 THEN \"OFFLINE_HARD\" END, compression, max_connections FROM mysql_servers";
char*query=(char*)"SELECT hostgroup_id, hostname, port, weight, CASE status WHEN 0 THEN \"ONLINE\" WHEN 1 THEN \"SHUNNED\" WHEN 2 THEN \"OFFLINE_SOFT\" WHEN 3 THEN \"OFFLINE_HARD\" END, compression, max_connections, max_replication_lag FROM mysql_servers";
char*query=(char*)"SELECT hostgroup_id, hostname, port FROM mysql_servers";
char*query=(char*)"SELECT hostgroup_id, hostname, port, max_replication_lag FROM mysql_servers WHERE max_replication_lag > 0 AND status NOT LIKE 'OFFLINE%'";
#define ADMIN_SQLITE_TABLE_MYSQL_SERVERS "CREATE TABLE mysql_servers (hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , status VARCHAR CHECK (status IN ('ONLINE','SHUNNED','OFFLINE_SOFT', 'OFFLINE_HARD')) NOT NULL DEFAULT 'ONLINE' , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , PRIMARY KEY (hostgroup_id, hostname, port) )"
#define ADMIN_SQLITE_TABLE_MYSQL_SERVERS "CREATE TABLE mysql_servers (hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , status VARCHAR CHECK (status IN ('ONLINE','SHUNNED','OFFLINE_SOFT', 'OFFLINE_HARD')) NOT NULL DEFAULT 'ONLINE' , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1 , compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )"
#define ADMIN_SQLITE_TABLE_MYSQL_USERS "CREATE TABLE mysql_users (username VARCHAR NOT NULL , password VARCHAR , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0 , default_hostgroup INT NOT NULL DEFAULT 0 , default_schema VARCHAR , schema_locked INT CHECK (schema_locked IN (0,1)) NOT NULL DEFAULT 0 , transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 0 , fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0 , backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1 , frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000 , PRIMARY KEY (username, backend) , UNIQUE (username, frontend))"
#define ADMIN_SQLITE_TABLE_MYSQL_QUERY_RULES "CREATE TABLE mysql_query_rules (rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0 , username VARCHAR , schemaname VARCHAR , flagIN INT NOT NULL DEFAULT 0, match_pattern VARCHAR , negate_match_pattern INT CHECK (negate_match_pattern IN (0,1)) NOT NULL DEFAULT 0 , flagOUT INT , replace_pattern VARCHAR , destination_hostgroup INT DEFAULT NULL , cache_ttl INT CHECK(cache_ttl > 0) , reconnect INT CHECK (reconnect IN (0,1)) DEFAULT NULL , timeout INT UNSIGNED , delay INT UNSIGNED , apply INT CHECK(apply IN (0,1)) NOT NULL DEFAULT 0)"
#define ADMIN_SQLITE_TABLE_GLOBAL_VARIABLES "CREATE TABLE global_variables (variable_name VARCHAR NOT NULL PRIMARY KEY , variable_value VARCHAR NOT NULL)"