-
Problem report
-
Resolution: Fixed
-
Trivial
-
4.0.11
-
Zabbix4.0.11
-
Sprint 56 (Sep 2019), Sprint 55 (Aug 2019)
-
0.125
DCget_nextid() is called for a specific 10 tables.
zbx_uint64_t DBget_maxid_num(const char *tablename, int num)
{
if (0 == strcmp(tablename, "events") ||
0 == strcmp(tablename, "event_tag") ||
0 == strcmp(tablename, "problem_tag") ||
0 == strcmp(tablename, "dservices") ||
0 == strcmp(tablename, "dhosts") ||
0 == strcmp(tablename, "alerts") ||
0 == strcmp(tablename, "escalations") ||
0 == strcmp(tablename, "autoreg_host") ||
0 == strcmp(tablename, "task_remote_command") ||
0 == strcmp(tablename, "task_remote_command_result"))
return DCget_nextid(tablename, num);
return DBget_nextid(tablename, num);
}
DCget_nextid() checks if it matches table_name of structure ZBX_DC_IDS.
/******************************************************************************
* *
* Function: DCget_nextid *
* *
* Purpose: Return next id for requested table *
* *
* Author: Alexander Vladishev *
* *
******************************************************************************/
zbx_uint64_t DCget_nextid(const char *table_name, int num)
{
const char *__function_name = "DCget_nextid";
int i;
DB_RESULT result;
DB_ROW row;
const ZBX_TABLE *table;
ZBX_DC_ID *id;
zbx_uint64_t min = 0, max = ZBX_DB_MAX_ID, nextid, lastid;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() table:'%s' num:%d",
__function_name, table_name, num);
LOCK_CACHE_IDS;
for (i = 0; i < ZBX_IDS_SIZE; i++)
{
id = &ids->id[i];
if ('\0' == *id->table_name)
break;
if (0 == strcmp(id->table_name, table_name))
{
nextid = id->lastid + 1;
id->lastid += num;
lastid = id->lastid;
UNLOCK_CACHE_IDS;
zabbix_log(LOG_LEVEL_DEBUG, "End of %s() table:'%s' [" ZBX_FS_UI64 ":" ZBX_FS_UI64 "]",
__function_name, table_name, nextid, lastid);
return nextid;
}
}
if (i == ZBX_IDS_SIZE)
{
zabbix_log(LOG_LEVEL_ERR, "insufficient shared memory for ids");
exit(EXIT_FAILURE);
}
table = DBget_table(table_name);
result = DBselect("select max(%s) from %s where %s between " ZBX_FS_UI64 " and " ZBX_FS_UI64,
table->recid, table_name, table->recid, min, max);
if (NULL != result)
{
zbx_strlcpy(id->table_name, table_name, sizeof(id->table_name));
if (NULL == (row = DBfetch(result)) || SUCCEED == DBis_null(row[0]))
id->lastid = min;
else
ZBX_STR2UINT64(id->lastid, row[0]);
nextid = id->lastid + 1;
id->lastid += num;
lastid = id->lastid;
}
else
nextid = lastid = 0;
UNLOCK_CACHE_IDS;
DBfree_result(result);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s() table:'%s' [" ZBX_FS_UI64 ":" ZBX_FS_UI64 "]",
__function_name, table_name, nextid, lastid);
return nextid;
}
If they do not match, DBget_table() is called and the table name is set in the structure ZBX_DC_IDS.
ZBX_IDS_SIZE is now 8.
#define ZBX_IDS_SIZE 8
typedef struct
{
char table_name[ZBX_TABLENAME_LEN_MAX];
zbx_uint64_t lastid;
}
ZBX_DC_ID;
typedef struct
{
ZBX_DC_ID id[ZBX_IDS_SIZE];
}
ZBX_DC_IDS;
static ZBX_DC_IDS *ids = NULL;
ZBX_IDS_SIZE is not 10, so there are two missing tables when called from DCget_nextid().
Is this the intended behavior?
I think it is better to have 8 tables or ZBX_IDS_SIZE to 10.