mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-02 03:47:41 +08:00
fix slave delay is negative
This commit is contained in:
parent
6d35b7dc65
commit
10509cf954
@ -572,28 +572,31 @@ check_slave_timestamp(int fd, short what, void *arg)
|
||||
}
|
||||
} else {
|
||||
g_critical("Check slave delay no data:%s", sql);
|
||||
ts_slave = (double)G_MAXINT32;
|
||||
ts_slave = 0;
|
||||
}
|
||||
double delay_secs;
|
||||
if (ts_slave != 0) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
double ts_now = tv.tv_sec + ((double)tv.tv_usec) / 1000000;
|
||||
double delay_secs = ts_now - ts_slave;
|
||||
delay_secs = ts_now - ts_slave;
|
||||
backend->slave_delay_msec = (int)delay_secs *1000;
|
||||
if (delay_secs > chas->slave_delay_down_threshold_sec && backend->state != BACKEND_STATE_DOWN) {
|
||||
ret = network_backends_modify(bs, i, backend->type, BACKEND_STATE_DOWN, oldstate);
|
||||
if(ret == 0) {
|
||||
g_critical("Slave delay %.3f seconds. Set slave to DOWN.", delay_secs);
|
||||
} else {
|
||||
g_critical("Slave delay %.3f seconds. Set slave to DOWN failed.", delay_secs);
|
||||
}
|
||||
} else if (delay_secs <= chas->slave_delay_recover_threshold_sec && backend->state != BACKEND_STATE_UP) {
|
||||
ret = network_backends_modify(bs, i, backend->type, BACKEND_STATE_UP, oldstate);
|
||||
if(ret == 0) {
|
||||
g_message("Slave delay %.3f seconds. Recovered. Set slave to UP.", delay_secs);
|
||||
} else {
|
||||
g_message("Slave delay %.3f seconds. Recovered. Set slave to UP failed.", delay_secs);
|
||||
}
|
||||
} else {
|
||||
backend->slave_delay_msec = G_MAXINT32;
|
||||
}
|
||||
if (delay_secs > chas->slave_delay_down_threshold_sec && backend->state != BACKEND_STATE_DOWN) {
|
||||
ret = network_backends_modify(bs, i, backend->type, BACKEND_STATE_DOWN, oldstate);
|
||||
if(ret == 0) {
|
||||
g_critical("Slave delay %.3f seconds. Set slave to DOWN.", delay_secs);
|
||||
} else {
|
||||
g_critical("Slave delay %.3f seconds. Set slave to DOWN failed.", delay_secs);
|
||||
}
|
||||
} else if (delay_secs <= chas->slave_delay_recover_threshold_sec && backend->state != BACKEND_STATE_UP) {
|
||||
ret = network_backends_modify(bs, i, backend->type, BACKEND_STATE_UP, oldstate);
|
||||
if(ret == 0) {
|
||||
g_message("Slave delay %.3f seconds. Recovered. Set slave to UP.", delay_secs);
|
||||
} else {
|
||||
g_message("Slave delay %.3f seconds. Recovered. Set slave to UP failed.", delay_secs);
|
||||
}
|
||||
}
|
||||
mysql_free_result(rs_set);
|
||||
|
Loading…
Reference in New Issue
Block a user