From 367e0d3cbbb08b9faf177928f63e8c2d63e7bd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 14 Sep 2015 08:22:00 +0000 Subject: [PATCH] Improved replication lag monitoring --- doc/admin_tables.md | 2 +- lib/MySQL_Monitor.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/admin_tables.md b/doc/admin_tables.md index 2a67fa10b..673f3dda3 100644 --- a/doc/admin_tables.md +++ b/doc/admin_tables.md @@ -78,7 +78,7 @@ The fields have the following semantics: * status: * ONLINE - backend server is fully operational * SHUNNED - backend sever is temporarily taken out of use because of either too many connection errors in a time that was too short, or replication lag exceeded the allowed threshold - * OFFLINE_SOFT - when a server is put into OFFLINE_SOFT mode, new incoming connections aren't accepted anymore, while the existing connections are kept until they became inactive. In other words, connections are kept in use until the current transaction is completed. This allows to greacefully detach a backend + * OFFLINE_SOFT - when a server is put into OFFLINE_SOFT mode, new incoming connections aren't accepted anymore, while the existing connections are kept until they became inactive. In other words, connections are kept in use until the current transaction is completed. This allows to gracefully detach a backend * OFFLINE_HARD - when a server is put into OFFLINE_HARD mode, the existing connections are dropped, while new incoming connections aren't accepted either. This is equivalent to deleting the server from a hostgroup, or temporarily taking it out of the hostgroup for maintenance work * weight - the bigger the weight of a server relative to other weights, the higher the probability of the server to be chosen from a hostgroup * compression - not supported yet, feature being rededigned diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index d80cf5558..ffebddf8a 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -887,7 +887,7 @@ __end_monitor_replication_lag_loop: assert(rc==SQLITE_OK); while (i>0) { i--; - int repl_lag=-1; + int repl_lag=-2; MySQL_Monitor_State_Data *mmsd=sds[i]; rc=sqlite3_bind_text(statement, 1, mmsd->hostname, -1, SQLITE_TRANSIENT); assert(rc==SQLITE_OK); rc=sqlite3_bind_int(statement, 2, mmsd->port); assert(rc==SQLITE_OK); @@ -896,9 +896,8 @@ __end_monitor_replication_lag_loop: if (mmsd->result) { unsigned int num_fields; unsigned int k; - int j=-1; MYSQL_FIELD *fields; - + int j=-1; num_fields = mysql_num_fields(mmsd->result); fields = mysql_fetch_fields(mmsd->result); for(k = 0; k < num_fields; k++) { @@ -908,8 +907,11 @@ __end_monitor_replication_lag_loop: } if (j>-1) { MYSQL_ROW row=mysql_fetch_row(mmsd->result); - if (row[j]) { - repl_lag=atoi(row[j]); + if (row) { + repl_lag=-1; + if (row[j]) { + repl_lag=atoi(row[j]); + } } } if (repl_lag>=0) { @@ -926,7 +928,7 @@ __end_monitor_replication_lag_loop: SAFE_SQLITE3_STEP(statement); rc=sqlite3_clear_bindings(statement); assert(rc==SQLITE_OK); rc=sqlite3_reset(statement); assert(rc==SQLITE_OK); - MyHGM->replication_lag_action(mmsd->hostgroup_id, mmsd->hostname, mmsd->port, repl_lag); + MyHGM->replication_lag_action(mmsd->hostgroup_id, mmsd->hostname, mmsd->port, (repl_lag==-1 ? 0 : repl_lag)); delete mmsd; } sqlite3_finalize(statement);