Source
records += delete_history("proxy_dhistory", "dhistory_lastid", now, config_offline_buffer, config_local_buffer);
/*
** 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.
**/
/******************************************************************************
* *
* Purpose: remove outdated information from historical table *
* *
* Parameters: table - [IN] *
* fieldname - [IN] *
* now - [IN] current timestamp *
* config_offline_buffer - [IN] hours to keep data when offline *
* config_local_buffer - [IN] hours to keep data *
* *
* Return value: number of rows records *
* *
******************************************************************************/
static int delete_history(const char *table, const char *fieldname, int now, int config_offline_buffer,
int config_local_buffer)
{
zbx_db_result_t result;
zbx_db_row_t row;
int records = 0;
zbx_uint64_t lastid, maxid;
char *condition = NULL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() table:'%s' now:%d", __func__, table, now);
zbx_db_begin();
result = zbx_db_select(
"select nextid"
" from ids"
" where table_name='%s'"
" and field_name='%s'",
table, fieldname);
if (NULL == (row = zbx_db_fetch(result)))
goto rollback;
ZBX_STR2UINT64(lastid, row[0]);
zbx_db_free_result(result);
result = zbx_db_select("select max(id) from %s",
table);
if (NULL == (row = zbx_db_fetch(result)) || SUCCEED == zbx_db_is_null(row[0]))
goto rollback;
ZBX_STR2UINT64(maxid, row[0]);
zbx_db_free_result(result);
if (0 != config_local_buffer)
condition = zbx_dsprintf(NULL, " and clock<%d", now - config_local_buffer * SEC_PER_HOUR);
records = zbx_db_execute(
"delete from %s"
" where id<" ZBX_FS_UI64
" and (clock<%d"
" or (id<=" ZBX_FS_UI64 "%s))",
table, maxid,
now - config_offline_buffer * SEC_PER_HOUR,