Source
******************************************************************************************************************/
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/*
* The cache (zbx_vc_cache_t) is organized as a hashset of item records (zbx_vc_item_t).
*
* Each record holds item data (itemid, value_type), statistics (hits, last access time,...)
* and the historical data (timestamp,value pairs in ascending order).
*
* The historical data are stored from largest request (+timeshift) range to the
* current time. The data is automatically fetched from DB whenever a request
* exceeds cached value range.
*
* In addition to active range value cache tracks item range for last 24 hours. Once
* per day the active range is updated with daily range and the daily range is reset.
*
* If an item is already being cached the new values are automatically added to the cache
* after being written into database.
*
* When cache runs out of memory to store new items it enters in low memory mode.
* In low memory mode cache continues to function as before with few restrictions:
* 1) items that weren't accessed during the last day are removed from cache.
* 2) items with worst hits/values ratio might be removed from cache to free the space.
* 3) no new items are added to the cache.
*
* The low memory mode can't be turned off - it will persist until server is rebooted.
* In low memory mode a warning message is written into log every 5 minutes.
*/
/* the period of low memory warning messages */
/* time period after which value cache will switch back to normal mode */
static zbx_shmem_info_t *vc_mem = NULL;
zbx_rwlock_t vc_lock = ZBX_RWLOCK_NULL;
/* value cache enable/disable flags */
/* value cache state, after initialization value cache is always disabled */
static int vc_state = ZBX_VC_DISABLED;
ZBX_SHMEM_FUNC_IMPL(__vc, vc_mem)
/* the range synchronization period in hours */
/* the data chunk used to store data fragment */
typedef struct zbx_vc_chunk
{
/* a pointer to the previous chunk or NULL if this is the tail chunk */
struct zbx_vc_chunk *prev;
/* a pointer to the next chunk or NULL if this is the head chunk */