Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihails Prihodko <mihails.prihodko@zabbix.com>2022-04-14 12:50:09 +0300
committerMihails Prihodko <mihails.prihodko@zabbix.com>2022-04-14 12:53:10 +0300
commit0484861e77acb53f63b598c6806689d7cdae6d7b (patch)
tree3989de32d442707120dc6b968677b121da1bdf2d
parent40772a214b121403b2a332bdb79d68b2f934f1a9 (diff)
........S. [ZBX-20743] refactored according to conversation with MVekslers
-rw-r--r--ChangeLog.d/bugfix/ZBX-207432
-rw-r--r--include/db.h2
-rw-r--r--include/zbxdb.h20
-rw-r--r--src/libs/zbxdb/db.c29
-rw-r--r--src/libs/zbxdbhigh/db.c66
-rw-r--r--src/zabbix_server/server.c5
6 files changed, 65 insertions, 59 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-20743 b/ChangeLog.d/bugfix/ZBX-20743
index 51a68e20f5a..263a166fc87 100644
--- a/ChangeLog.d/bugfix/ZBX-20743
+++ b/ChangeLog.d/bugfix/ZBX-20743
@@ -1 +1 @@
-........S. [ZBX-20743] Compression with Apache licensed TimescaleDB 2.x (mprihodko)
+........S. [ZBX-20743] fixed error handling in compression with Apache licensed TimescaleDB 2.x (mprihodko)
diff --git a/include/db.h b/include/db.h
index b9cc7c98d5c..547444e4bd5 100644
--- a/include/db.h
+++ b/include/db.h
@@ -546,7 +546,7 @@ zbx_uint64_t DBget_maxid_num(const char *tablename, int num);
void DBextract_version_info(struct zbx_db_version_info_t *version_info);
void DBextract_dbextension_info(struct zbx_db_version_info_t *version_info);
void DBflush_version_requirements(const char *version);
-int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info);
+int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info, int allow_unsupported_ver);
#ifdef HAVE_POSTGRESQL
char *zbx_db_get_schema_esc(void);
diff --git a/include/zbxdb.h b/include/zbxdb.h
index 23332e162f5..ef1ed6d1c88 100644
--- a/include/zbxdb.h
+++ b/include/zbxdb.h
@@ -188,16 +188,16 @@ int zbx_db_strlen_n(const char *text_loc, size_t maxlen);
#define ZBX_POSTGRESQL_MIN_VERSION_WITH_TIMESCALEDB 100002
#define ZBX_POSTGRESQL_MIN_VERSION_WITH_TIMESCALEDB_FRIENDLY "10.2"
-#define ZBX_TIMESCALEDB_MIN_VERSION 10500
-#define ZBX_TIMESCALEDB_MIN_VERSION_FRIENDLY "1.5.0"
-#define ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION 20001
-#define ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION_FRIENDLY "2.0.1"
-#define ZBX_TIMESCALEDB_MAX_VERSION 20399
-#define ZBX_TIMESCALEDB_MAX_VERSION_FRIENDLY "2.3"
-#define ZBX_TIMESCALEDB_LICENSE_APACHE "apache"
-#define ZBX_TIMESCALEDB_LICENSE_APACHE_FRIENDLY "TimescaleDB Apache 2 Edition"
-#define ZBX_TIMESCALEDB_LICENSE_TIMESCALE "timescale"
-#define ZBX_TIMESCALEDB_LICENSE_TIMESCALE_FRIENDLY "TimescaleDB Community Edition"
+#define ZBX_TIMESCALE_MIN_VERSION 10500
+#define ZBX_TIMESCALE_MIN_VERSION_FRIENDLY "1.5.0"
+#define ZBX_TIMESCALE_MIN_SUPPORTED_VERSION 20001
+#define ZBX_TIMESCALE_MIN_SUPPORTED_VERSION_FRIENDLY "2.0.1"
+#define ZBX_TIMESCALE_MAX_VERSION 20399
+#define ZBX_TIMESCALE_MAX_VERSION_FRIENDLY "2.3"
+#define ZBX_TIMESCALE_LICENSE_APACHE "apache"
+#define ZBX_TIMESCALE_LICENSE_APACHE_FRIENDLY "TimescaleDB Apache 2 Edition"
+#define ZBX_TIMESCALE_LICENSE_COMMUNITY "timescale"
+#define ZBX_TIMESCALE_LICENSE_COMMUNITY_FRIENDLY "TimescaleDB Community Edition"
typedef enum
{ /* db version status flags shared with FRONTEND */
diff --git a/src/libs/zbxdb/db.c b/src/libs/zbxdb/db.c
index 5e959617703..89b93541ea1 100644
--- a/src/libs/zbxdb/db.c
+++ b/src/libs/zbxdb/db.c
@@ -2541,12 +2541,8 @@ void zbx_db_version_json_create(struct zbx_json *json, struct zbx_db_version_inf
zbx_json_addstring(json, "min_version", info->ext_friendly_min_version, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(json, "max_version", info->ext_friendly_max_version, ZBX_JSON_TYPE_STRING);
-
- if (NULL != info->ext_friendly_min_supported_version)
- {
- zbx_json_addstring(json, "min_supported_version", info->ext_friendly_min_supported_version,
- ZBX_JSON_TYPE_STRING);
- }
+ zbx_json_addstring(json, "min_supported_version", info->ext_friendly_min_supported_version,
+ ZBX_JSON_TYPE_STRING);
zbx_json_addint64(json, "flag", info->ext_flag);
@@ -2845,16 +2841,16 @@ void zbx_tsdb_info_extract(struct zbx_db_version_info_t *version_info)
tsdb_ver = zbx_tsdb_get_version();
version_info->ext_current_version = (zbx_uint32_t)tsdb_ver;
- version_info->ext_min_version = ZBX_TIMESCALEDB_MIN_VERSION;
- version_info->ext_max_version = ZBX_TIMESCALEDB_MAX_VERSION;
- version_info->ext_min_supported_version = ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION;
+ version_info->ext_min_version = ZBX_TIMESCALE_MIN_VERSION;
+ version_info->ext_max_version = ZBX_TIMESCALE_MAX_VERSION;
+ version_info->ext_min_supported_version = ZBX_TIMESCALE_MIN_SUPPORTED_VERSION;
- version_info->ext_friendly_current_version = zbx_dsprintf(NULL, "%d.%d.%d",
- RIGHT2(tsdb_ver/10000), RIGHT2(tsdb_ver/100), RIGHT2(tsdb_ver));
+ version_info->ext_friendly_current_version = zbx_dsprintf(NULL, "%d.%d.%d", RIGHT2(tsdb_ver/10000),
+ RIGHT2(tsdb_ver/100), RIGHT2(tsdb_ver));
- version_info->ext_friendly_min_version = ZBX_TIMESCALEDB_MIN_VERSION_FRIENDLY;
- version_info->ext_friendly_max_version = ZBX_TIMESCALEDB_MAX_VERSION_FRIENDLY;
- version_info->ext_friendly_min_supported_version = ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION_FRIENDLY;
+ version_info->ext_friendly_min_version = ZBX_TIMESCALE_MIN_VERSION_FRIENDLY;
+ version_info->ext_friendly_max_version = ZBX_TIMESCALE_MAX_VERSION_FRIENDLY;
+ version_info->ext_friendly_min_supported_version = ZBX_TIMESCALE_MIN_SUPPORTED_VERSION_FRIENDLY;
version_info->ext_flag = zbx_db_version_check(version_info->extension, version_info->ext_current_version,
version_info->ext_min_version, version_info->ext_max_version,
@@ -2862,7 +2858,8 @@ void zbx_tsdb_info_extract(struct zbx_db_version_info_t *version_info)
version_info->ext_lic = zbx_tsdb_get_license();
- zabbix_log(LOG_LEVEL_DEBUG, "TimescaleDB version: [%d], license: [%s]", tsdb_ver, version_info->ext_lic);
+ zabbix_log(LOG_LEVEL_DEBUG, "TimescaleDB version: [%d], license: [%s]", tsdb_ver,
+ ZBX_NULL2EMPTY_STR(version_info->ext_lic));
}
#endif
@@ -2944,7 +2941,7 @@ char *zbx_tsdb_get_license(void)
{
DB_RESULT result;
DB_ROW row;
- char *tsdb_lic = NULL;
+ char *tsdb_lic = NULL;
result = zbx_db_select("show timescaledb.license");
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index 4730afaebd7..f2aa338b0ea 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -805,7 +805,7 @@ void DBextract_version_info(struct zbx_db_version_info_t *version_info)
/******************************************************************************
* *
- * Purpose: connects to DB and tries to detect DB extension info *
+ * Purpose: connects to DB and tries to detect DB extension version info *
* *
******************************************************************************/
void DBextract_dbextension_info(struct zbx_db_version_info_t *version_info)
@@ -857,15 +857,20 @@ void DBflush_version_requirements(const char *version)
/******************************************************************************
* *
- * Purpose: checks TSDB for compression support *
+ * Purpose: checks if TimescaleDB version is allowed and if it supports *
+ * compression *
* *
- * Parameters: db_version - [IN/OUT] version of DB *
+ * Parameters: allow_unsupported_ver - [IN] flag that indicates whether to *
+ * allow unsupported versions of *
+ * TimescaleDB or not *
+ * db_version_info - [IN/OUT] information about version of *
+ * DB and its extensions *
* *
* Return value: SUCCEED - if there are no critical errors *
* FAIL - otherwise *
* *
******************************************************************************/
-int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info)
+int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info, int allow_unsupported_ver)
{
int ret = SUCCEED;
#ifdef HAVE_POSTGRESQL
@@ -879,8 +884,8 @@ int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info)
/* timescaledb.license parameter is available in TimescaleDB API starting from TimescaleDB 2.0. */
if (ZBX_POSTGRESQL_MIN_VERSION_WITH_TIMESCALEDB > db_version_info->current_version)
{
- zabbix_log(LOG_LEVEL_ERR, "PostgreSQL version %lu is not supported with TimescaleDB, minimum required"
- " is %d", (unsigned long)db_version_info->current_version,
+ zabbix_log(LOG_LEVEL_WARNING, "PostgreSQL version %lu is not supported with TimescaleDB, minimum"
+ " required is %d", (unsigned long)db_version_info->current_version,
ZBX_POSTGRESQL_MIN_VERSION_WITH_TIMESCALEDB);
ret = FAIL;
goto out;
@@ -888,46 +893,51 @@ int DBcheck_tsdb_capabilities(struct zbx_db_version_info_t *db_version_info)
if (DB_VERSION_FAILED_TO_RETRIEVE == db_version_info->ext_flag)
{
- zabbix_log(LOG_LEVEL_ERR, "Cannot determine TimescaleDB version");
ret = FAIL;
goto out;
}
- if (ZBX_TIMESCALEDB_MIN_VERSION > db_version_info->ext_current_version)
+ if (DB_VERSION_LOWER_THAN_MINIMUM == db_version_info->ext_flag)
{
- zabbix_log(LOG_LEVEL_ERR, "TimescaleDB version %d is too old.", db_version_info->ext_current_version);
- zabbix_log(LOG_LEVEL_ERR, "Version must be at least %d. Recommended version should be at least %s %s.",
- ZBX_TIMESCALEDB_MIN_VERSION, ZBX_TIMESCALEDB_LICENSE_TIMESCALE_FRIENDLY,
- ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION_FRIENDLY);
+ zabbix_log(LOG_LEVEL_WARNING, "Version must be at least %d. Recommended version should be at least"
+ " %s %s.", ZBX_TIMESCALE_MIN_VERSION, ZBX_TIMESCALE_LICENSE_COMMUNITY_FRIENDLY,
+ ZBX_TIMESCALE_MIN_SUPPORTED_VERSION_FRIENDLY);
ret = FAIL;
goto out;
}
- if (ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION > db_version_info->ext_current_version)
+ if (DB_VERSION_NOT_SUPPORTED_ERROR == db_version_info->ext_flag)
{
- db_version_info->ext_status |= ZBX_DB_EXT_STATUS_FLAGS_TSDB_COMPRESSION_AVAILABLE;
zabbix_log(LOG_LEVEL_WARNING, "TimescaleDB version %d is not officially supported.",
- db_version_info->ext_current_version);
+ db_version_info->ext_current_version);
zabbix_log(LOG_LEVEL_WARNING, "Recommended version should be at least %s %s.",
- ZBX_TIMESCALEDB_LICENSE_TIMESCALE_FRIENDLY,
- ZBX_TIMESCALEDB_MIN_SUPPORTED_VERSION_FRIENDLY);
- }
- else
- {
- if (0 == zbx_strcmp_null(db_version_info->ext_lic, ZBX_TIMESCALEDB_LICENSE_TIMESCALE))
+ ZBX_TIMESCALE_LICENSE_COMMUNITY_FRIENDLY, ZBX_TIMESCALE_MIN_SUPPORTED_VERSION_FRIENDLY);
+ if (0 == allow_unsupported_ver)
{
- db_version_info->ext_status |= ZBX_DB_EXT_STATUS_FLAGS_TSDB_COMPRESSION_AVAILABLE;
- zabbix_log(LOG_LEVEL_DEBUG, "%s was detected. Timescale compression is supported.",
- ZBX_TIMESCALEDB_LICENSE_TIMESCALE_FRIENDLY);
+ ret = FAIL;
+ goto out;
}
else
{
- zabbix_log(LOG_LEVEL_WARNING, "[%s] license does not support Timescale compression.",
- db_version_info->ext_lic);
- zabbix_log(LOG_LEVEL_WARNING, "%s is required to use Timescale compression.",
- ZBX_TIMESCALEDB_LICENSE_TIMESCALE_FRIENDLY);
+ db_version_info->ext_flag = DB_VERSION_NOT_SUPPORTED_WARNING;
+ db_version_info->ext_status |= ZBX_DB_EXT_STATUS_FLAGS_TSDB_COMPRESSION_AVAILABLE;
+ goto out;
}
}
+
+ if (0 == zbx_strcmp_null(db_version_info->ext_lic, ZBX_TIMESCALE_LICENSE_COMMUNITY))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "%s was detected. TimescaleDB compression is supported.",
+ ZBX_TIMESCALE_LICENSE_COMMUNITY_FRIENDLY);
+ db_version_info->ext_status |= ZBX_DB_EXT_STATUS_FLAGS_TSDB_COMPRESSION_AVAILABLE;
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "[%s] license does not support TimescaleDB compression.",
+ ZBX_NULL2EMPTY_STR(db_version_info->ext_lic));
+ zabbix_log(LOG_LEVEL_WARNING, "%s is required to use TimescaleDB compression.",
+ ZBX_TIMESCALE_LICENSE_COMMUNITY_FRIENDLY);
+ }
out:
#else
ZBX_UNUSED(db_version_info);
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index ed2a214a157..16ab16405eb 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -1139,14 +1139,14 @@ static void zbx_check_db(void)
DBextract_dbextension_info(&db_version_info);
}
- if (SUCCEED == result && (SUCCEED != DBcheck_tsdb_capabilities(&db_version_info) ||
+ if (SUCCEED == result &&
+ (SUCCEED != DBcheck_tsdb_capabilities(&db_version_info, CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS) ||
SUCCEED != DBcheck_version()))
{
result = FAIL;
}
DBconnect(ZBX_DB_CONNECT_NORMAL);
-
#if defined(HAVE_POSTGRESQL)
if (SUCCEED == result && 0 == zbx_strcmp_null(db_version_info.extension, ZBX_DB_EXTENSION_TIMESCALE) &&
0 == (ZBX_DB_EXT_STATUS_FLAGS_TSDB_COMPRESSION_AVAILABLE & db_version_info.ext_status) &&
@@ -1155,7 +1155,6 @@ static void zbx_check_db(void)
zabbix_log(LOG_LEVEL_ERR, "failed to set database compression status");
}
#endif
-
if (SUCCEED == DBfield_exists("config", "dbversion_status"))
{
zbx_json_initarray(&db_version_json, ZBX_JSON_STAT_BUF_LEN);