zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: DCsync_expressions                                               *
 *                                                                            *
 * Purpose: Updates expressions configuration cache                           *
 *                                                                            *
 * Parameters: result - [IN] the result of expressions database select        *
 *                                                                            *
 ******************************************************************************/
DCsync_expressions

Purpose: Updates expressions configuration cache

Parameters: result - [IN] the result of expressions database select
DCsync_expressions Purpose : Updates expressions configuration cache Parameters : result - [ IN ] the result of expressions database select
static void	DCsync_expressions(zbx_dbsync_t *sync)
{
	char			**row;
	zbx_uint64_t		rowid;
	unsigned char		tag;
	zbx_hashset_iter_t	iter;
	ZBX_DC_EXPRESSION	*expression;
	ZBX_DC_REGEXP		*regexp, regexp_local;
	zbx_uint64_t		expressionid;
	int			found, ret;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	while (SUCCEED == (ret = zbx_dbsync_next(sync, &rowid, &row, &tag)))
	{
		if (ZBX_DBSYNC_ROW_REMOVE == tag)
			break;
		ZBX_STR2UINT64(expressionid, row[1]);
		expression = (ZBX_DC_EXPRESSION *)DCfind_id(&config->expressions, expressionid, sizeof(ZBX_DC_EXPRESSION), &found);
		if (0 != found)
			dc_regexp_remove_expression(expression->regexp, expressionid);
		DCstrpool_replace(found, &expression->regexp, row[0]);
		DCstrpool_replace(found, &expression->expression, row[2]);
		ZBX_STR2UCHAR(expression->type, row[3]);
		ZBX_STR2UCHAR(expression->case_sensitive, row[5]);
		expression->delimiter = *row[4];
		regexp_local.name = row[0];
		if (NULL == (regexp = (ZBX_DC_REGEXP *)zbx_hashset_search(&config->regexps, &regexp_local)))
		{
			DCstrpool_replace(0, &regexp_local.name, row[0]);
			zbx_vector_uint64_create_ext(&regexp_local.expressionids,
					__config_mem_malloc_func,
					__config_mem_realloc_func,
					__config_mem_free_func);
			regexp = (ZBX_DC_REGEXP *)zbx_hashset_insert(&config->regexps, &regexp_local, sizeof(ZBX_DC_REGEXP));
		}
		zbx_vector_uint64_append(&regexp->expressionids, expressionid);
	}
	zbx_hashset_iter_reset(&config->regexps, &iter);
	while (NULL != (regexp = (ZBX_DC_REGEXP *)zbx_hashset_iter_next(&iter)))
	{
		if (0 < regexp->expressionids.values_num)
			continue;
		zbx_strpool_release(regexp->name);
		zbx_vector_uint64_destroy(&regexp->expressionids);
		zbx_hashset_iter_remove(&iter);
	}
	for (; SUCCEED == ret; ret = zbx_dbsync_next(sync, &rowid, &row, &tag))
	{
		if (NULL == (expression = (ZBX_DC_EXPRESSION *)zbx_hashset_search(&config->expressions, &rowid)))
			continue;
		if (NULL != (regexp = dc_regexp_remove_expression(expression->regexp, expression->expressionid)))
		{
			if (0 == regexp->expressionids.values_num)
			{
				zbx_strpool_release(regexp->name);
				zbx_vector_uint64_destroy(&regexp->expressionids);
				zbx_hashset_remove_direct(&config->regexps, regexp);
			}
		}
		zbx_strpool_release(expression->expression);
		zbx_strpool_release(expression->regexp);
		zbx_hashset_remove_direct(&config->expressions, expression);
	}
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
}
static void DCsync_expressions ( zbx_dbsync_t * sync ) { char * * row ; zbx_uint64_t rowid ; unsigned char tag ; zbx_hashset_iter_t iter ; ZBX_DC_EXPRESSION * expression ; ZBX_DC_REGEXP * regexp , regexp_local ; zbx_uint64_t expressionid ; int found , ret ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; while ( SUCCEED == ( ret = zbx_dbsync_next ( sync , & rowid , & row , & tag ) ) ) { if ( ZBX_DBSYNC_ROW_REMOVE == tag ) break ; ZBX_STR2UINT64 ( expressionid , row [ 1 ] ) ; expression = ( ZBX_DC_EXPRESSION * ) DCfind_id ( & config -> expressions , expressionid , sizeof ( ZBX_DC_EXPRESSION ) , & found ) ; if ( 0 != found ) dc_regexp_remove_expression ( expression -> regexp , expressionid ) ; DCstrpool_replace ( found , & expression -> regexp , row [ 0 ] ) ; DCstrpool_replace ( found , & expression -> expression , row [ 2 ] ) ; ZBX_STR2UCHAR ( expression -> type , row [ 3 ] ) ; ZBX_STR2UCHAR ( expression -> case_sensitive , row [ 5 ] ) ; expression -> delimiter = * row [ 4 ] ; regexp_local . name = row [ 0 ] ; if ( NULL == ( regexp = ( ZBX_DC_REGEXP * ) zbx_hashset_search ( & config -> regexps , & regexp_local ) ) ) { DCstrpool_replace ( 0 , & regexp_local . name , row [ 0 ] ) ; zbx_vector_uint64_create_ext ( & regexp_local . expressionids , __config_mem_malloc_func , __config_mem_realloc_func , __config_mem_free_func ) ; regexp = ( ZBX_DC_REGEXP * ) zbx_hashset_insert ( & config -> regexps , & regexp_local , sizeof ( ZBX_DC_REGEXP ) ) ; } zbx_vector_uint64_append ( & regexp -> expressionids , expressionid ) ; } zbx_hashset_iter_reset ( & config -> regexps , & iter ) ; while ( NULL != ( regexp = ( ZBX_DC_REGEXP * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( 0 < regexp -> expressionids . values_num ) continue ; zbx_strpool_release ( regexp -> name ) ; zbx_vector_uint64_destroy ( & regexp -> expressionids ) ; zbx_hashset_iter_remove ( & iter ) ; } for ( ; SUCCEED == ret ; ret = zbx_dbsync_next ( sync , & rowid , & row , & tag ) ) { if ( NULL == ( expression = ( ZBX_DC_EXPRESSION * ) zbx_hashset_search ( & config -> expressions , & rowid ) ) ) continue ; if ( NULL != ( regexp = dc_regexp_remove_expression ( expression -> regexp , expression -> expressionid ) ) ) { if ( 0 == regexp -> expressionids . values_num ) { zbx_strpool_release ( regexp -> name ) ; zbx_vector_uint64_destroy ( & regexp -> expressionids ) ; zbx_hashset_remove_direct ( & config -> regexps , regexp ) ; } } zbx_strpool_release ( expression -> expression ) ; zbx_strpool_release ( expression -> regexp ) ; zbx_hashset_remove_direct ( & config -> expressions , expression ) ; } zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; }
Function: DCsync_expressions                                               
                                                                            
 Purpose: Updates expressions configuration cache                           
                                                                            
 Parameters: result - [IN] the result of expressions database select
Function : DCsync_expressions Purpose : Updates expressions configuration cache Parameters : result - [ IN ] the result of expressions database select
/* removed rows will be always added at the end */ /* remove regexps with no expressions related to it */ /* remove unused expressions */