Index: src/libs/zbxdbcache/dbconfig.c =================================================================== --- src/libs/zbxdbcache/dbconfig.c (revision 16980) +++ src/libs/zbxdbcache/dbconfig.c (working copy) @@ -52,6 +52,10 @@ #define ZBX_DC_CONFIG struct zbx_dc_config +#define ZBX_LOC_NOWHERE 0 +#define ZBX_LOC_QUEUE 1 +#define ZBX_LOC_POLLER 2 + ZBX_DC_ITEM { zbx_uint64_t itemid; @@ -59,12 +63,12 @@ const char *key; /* interned; key[ITEM_KEY_LEN_MAX]; */ int delay; int nextcheck; - unsigned char type; + unsigned char type; unsigned char data_type; unsigned char value_type; - unsigned char poller_type; + unsigned char poller_type; unsigned char status; - unsigned char in_queue; + unsigned char location; }; ZBX_DC_ITEM_HK @@ -163,7 +167,7 @@ unsigned char snmp_available; unsigned char ipmi_available; unsigned char status; - unsigned char in_queue; + unsigned char location; }; ZBX_DC_HOST_PH @@ -281,12 +285,12 @@ else { const ZBX_DC_FLEXITEM *flexitem; - + flexitem = zbx_hashset_search(&config->flexitems, &item->itemid); nextcheck = calculate_item_nextcheck(item->itemid, item->type, item->delay, flexitem ? flexitem->delay_flex : NULL, now, NULL); } - + return nextcheck; } @@ -425,26 +429,29 @@ { zbx_binary_heap_elem_t elem; - if (item->in_queue && old_poller_type != item->poller_type) + if (ZBX_LOC_POLLER == item->location) + return; + + if (ZBX_LOC_QUEUE == item->location && old_poller_type != item->poller_type) { - item->in_queue = 0; + item->location = ZBX_LOC_NOWHERE; zbx_binary_heap_remove_direct(&config->queues[old_poller_type], item->itemid); } if (item->poller_type >= ZBX_POLLER_TYPE_COUNT) return; - if (item->in_queue && old_nextcheck == item->nextcheck) + if (ZBX_LOC_QUEUE == item->location && old_nextcheck == item->nextcheck) return; elem.key = item->itemid; elem.data = (const void *)item; - if (item->in_queue) + if (ZBX_LOC_QUEUE == item->location) zbx_binary_heap_update_direct(&config->queues[item->poller_type], &elem); else { - item->in_queue = 1; + item->location = ZBX_LOC_QUEUE; zbx_binary_heap_insert(&config->queues[item->poller_type], &elem); } } @@ -453,12 +460,15 @@ { zbx_binary_heap_elem_t elem; + if (ZBX_LOC_POLLER == host->location) + return; + if (HOST_STATUS_PROXY_PASSIVE != host->status) { - if (host->in_queue) + if (ZBX_LOC_QUEUE == host->location) { + host->location = ZBX_LOC_NOWHERE; zbx_binary_heap_remove_direct(&config->pqueue, host->hostid); - host->in_queue = 0; } return; @@ -467,11 +477,11 @@ elem.key = host->hostid; elem.data = (const void *)host; - if (host->in_queue) + if (ZBX_LOC_QUEUE == host->location) zbx_binary_heap_update_direct(&config->pqueue, &elem); else { - host->in_queue = 1; + host->location = ZBX_LOC_QUEUE; zbx_binary_heap_insert(&config->pqueue, &elem); } } @@ -553,7 +563,7 @@ if (!found) { - item->in_queue = 0; + item->location = ZBX_LOC_NOWHERE; item->poller_type = ZBX_NO_POLLER; old_nextcheck = 0; @@ -579,13 +589,13 @@ item->status = status; item->delay = delay; - old_poller_type = item->poller_type; - poller_by_item(itemid, proxy_hostid, item->type, item->key, &item->poller_type); + old_poller_type = item->poller_type; + poller_by_item(itemid, proxy_hostid, item->type, item->key, &item->poller_type); if (ZBX_POLLER_TYPE_UNREACHABLE == old_poller_type && (ZBX_POLLER_TYPE_NORMAL == item->poller_type || ZBX_POLLER_TYPE_IPMI == item->poller_type)) item->poller_type = ZBX_POLLER_TYPE_UNREACHABLE; - DCupdate_item_queue(item, old_poller_type, old_nextcheck); + DCupdate_item_queue(item, old_poller_type, old_nextcheck); /* SNMP items */ @@ -652,7 +662,7 @@ if (ITEM_TYPE_TRAPPER == item->type && SUCCEED != DBis_null(row[17]) && '\0' != *row[17]) { trapitem = DCfind_id(&config->trapitems, itemid, sizeof(ZBX_DC_TRAPITEM), &found); - + trapitem->itemid = itemid; DCstrpool_replace(found, &trapitem->trapper_hosts, row[17]); } @@ -878,7 +888,7 @@ zbx_strpool_release(item_hk.key); zbx_hashset_remove(&config->items_hk, &item_hk); - if (item->in_queue) + if (ZBX_LOC_QUEUE == item->location) zbx_binary_heap_remove_direct(&config->queues[item->poller_type], item->itemid); zbx_strpool_release(item->key); @@ -965,7 +975,7 @@ host->snmp_available = (unsigned char)atoi(row[21]); host->ipmi_errors_from = atoi(row[23]); host->ipmi_available = (unsigned char)atoi(row[24]); - host->in_queue = 0; + host->location = ZBX_LOC_NOWHERE; if (HOST_STATUS_PROXY_PASSIVE == host->status) { @@ -1042,7 +1052,7 @@ zbx_strpool_release(ipmihost->ipmi_ip); zbx_strpool_release(ipmihost->ipmi_username); zbx_strpool_release(ipmihost->ipmi_password); - + zbx_hashset_remove(&config->ipmihosts, &hostid); } @@ -1057,7 +1067,7 @@ zbx_strpool_release(host->host); zbx_strpool_release(host->ip); zbx_strpool_release(host->dns); - + zbx_hashset_iter_remove(&iter); } } @@ -1775,7 +1785,7 @@ break; zbx_binary_heap_remove_min(queue); - dc_item->in_queue = 0; + dc_item->location = ZBX_LOC_NOWHERE; if (CONFIG_REFRESH_UNSUPPORTED == 0 && ITEM_STATUS_NOTSUPPORTED == dc_item->status) continue; @@ -1786,10 +1796,10 @@ if (HOST_MAINTENANCE_STATUS_ON == dc_host->maintenance_status && MAINTENANCE_TYPE_NODATA == dc_host->maintenance_type) { - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; dc_item->nextcheck = DCget_reachable_nextcheck(dc_item, now); - DCupdate_item_queue(dc_item, dc_item->poller_type, old_nextcheck); + DCupdate_item_queue(dc_item, dc_item->poller_type, old_nextcheck); continue; } @@ -1798,9 +1808,10 @@ if (ZBX_POLLER_TYPE_UNREACHABLE == poller_type) { old_poller_type = dc_item->poller_type; - poller_by_item(dc_item->itemid, dc_host->proxy_hostid, dc_item->type, dc_item->key, &dc_item->poller_type); + poller_by_item(dc_item->itemid, dc_host->proxy_hostid, dc_item->type, dc_item->key, + &dc_item->poller_type); - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; dc_item->nextcheck = DCget_reachable_nextcheck(dc_item, now); DCupdate_item_queue(dc_item, old_poller_type, old_nextcheck); @@ -1814,7 +1825,7 @@ old_poller_type = dc_item->poller_type; dc_item->poller_type = ZBX_POLLER_TYPE_UNREACHABLE; - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; if (disable_until > now) dc_item->nextcheck = DCget_unreachable_nextcheck(dc_item, dc_host); @@ -1823,7 +1834,7 @@ } else if (disable_until > now) { - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; dc_item->nextcheck = DCget_unreachable_nextcheck(dc_item, dc_host); DCupdate_item_queue(dc_item, dc_item->poller_type, old_nextcheck); @@ -1833,6 +1844,7 @@ DCincrease_disable_until(dc_item, dc_host, now); } + dc_item->location = ZBX_LOC_POLLER; DCget_host(&items[num].host, dc_host); DCget_item(&items[num], dc_item); num++; @@ -1931,7 +1943,7 @@ ZBX_DC_ITEM *dc_item; ZBX_DC_HOST *dc_host; unsigned char old_poller_type; - int old_nextcheck; + int old_nextcheck; LOCK_CACHE; @@ -1942,12 +1954,16 @@ old_poller_type = dc_item->poller_type; if (ZBX_POLLER_TYPE_UNREACHABLE == dc_item->poller_type) if (NULL != (dc_host = zbx_hashset_search(&config->hosts, &dc_item->hostid))) - poller_by_item(dc_item->itemid, dc_host->proxy_hostid, dc_item->type, dc_item->key, &dc_item->poller_type); + poller_by_item(dc_item->itemid, dc_host->proxy_hostid, dc_item->type, dc_item->key, + &dc_item->poller_type); - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; dc_item->nextcheck = DCget_reachable_nextcheck(dc_item, now); - DCupdate_item_queue(dc_item, old_poller_type, old_nextcheck); + if (ZBX_LOC_POLLER == dc_item->location) + dc_item->location = ZBX_LOC_NOWHERE; + + DCupdate_item_queue(dc_item, old_poller_type, old_nextcheck); } UNLOCK_CACHE; @@ -1958,7 +1974,7 @@ ZBX_DC_ITEM *dc_item; ZBX_DC_HOST *dc_host; unsigned char old_poller_type; - int old_nextcheck; + int old_nextcheck; LOCK_CACHE; @@ -1969,10 +1985,13 @@ if (ZBX_POLLER_TYPE_NORMAL == dc_item->poller_type || ZBX_POLLER_TYPE_IPMI == dc_item->poller_type) dc_item->poller_type = ZBX_POLLER_TYPE_UNREACHABLE; - old_nextcheck = dc_item->nextcheck; + old_nextcheck = dc_item->nextcheck; dc_item->nextcheck = DCget_unreachable_nextcheck(dc_item, dc_host); - DCupdate_item_queue(dc_item, old_poller_type, old_nextcheck); + if (ZBX_LOC_POLLER == dc_item->location) + dc_item->location = ZBX_LOC_NOWHERE; + + DCupdate_item_queue(dc_item, old_poller_type, old_nextcheck); } UNLOCK_CACHE; @@ -2222,7 +2241,7 @@ break; zbx_binary_heap_remove_min(queue); - dc_host->in_queue = 0; + dc_host->location = ZBX_LOC_POLLER; DCget_host(&hosts[num], dc_host); @@ -2289,8 +2308,7 @@ time_t now; ZBX_DC_HOST *dc_host; - zabbix_log(LOG_LEVEL_DEBUG, "In %s() update_nextcheck:%d", - __function_name, (int)update_nextcheck); + zabbix_log(LOG_LEVEL_DEBUG, "In %s() update_nextcheck:%d", __function_name, (int)update_nextcheck); now = time(NULL); @@ -2311,6 +2329,9 @@ dc_host->disable_until = (dc_host->snmp_disable_until <= dc_host->ipmi_disable_until) ? dc_host->snmp_disable_until : dc_host->ipmi_disable_until; + if (ZBX_LOC_POLLER == dc_host->location) + dc_host->location = ZBX_LOC_NOWHERE; + DCupdate_proxy_queue(dc_host); }