diff --git a/src/zabbix_server/housekeeper/housekeeper.c b/src/zabbix_server/housekeeper/housekeeper.c index b8584b9..675b8cb 100644 --- a/src/zabbix_server/housekeeper/housekeeper.c +++ b/src/zabbix_server/housekeeper/housekeeper.c @@ -1092,7 +1092,33 @@ static int housekeeping_events(int now) return 0; for (rule = rules; NULL != rule->table; rule++) + { + /* set min_clock here because min(clock) calculation of events table in + * housekeeping_process_rule() might be too slow. + * assume that the event with the smallest eventid has the smallest clock. + */ + + DB_RESULT result; + DB_ROW row; + zbx_uint64_t id = 0; + + result = DBselect("select eventid from events where %s order by eventid limit 1", rule->filter); + if (NULL != (row = DBfetch(result)) && SUCCEED != DBis_null(row[0])) + ZBX_STR2UINT64(id, row[0]); + DBfree_result(result); + + if (0 < id) + { + result = DBselect("select clock from events where eventid=%ld", id); + if (NULL != (row = DBfetch(result)) && SUCCEED != DBis_null(row[0])) + rule->min_clock = atoi(row[0]); + else + rule->min_clock = now; + DBfree_result(result); + } + deleted += housekeeping_process_rule(now, rule); + } return deleted; #undef ZBX_HK_EVENT_RULE