@cryptotaxi247 / netdata-1 / commits / 57eec3da0

Adjust storage tiers if we fail to create the requested number of tiers (#16999)

Do not create a dbengine-tierX directory if the tier cannot be activated Check for datafiles existence during finalize of ctx Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>

Stelios Fragkakis committed Feb 13, 2024 at 11:11 UTC 57eec3da0e51baa400037ccc4b547cb839ab6ffa
2 files changed +21 -18
src/database/engine/datafile.c
+3 -1
@@ -557,7 +557,9 @@ void finalize_data_files(struct rrdengine_instance *ctx)
557 {
558 bool logged = false;
559
560 - logged = false;
560 + if (!ctx->datafiles.first)
561 + return;
562 +
563 while(__atomic_load_n(&ctx->atomic.extents_currently_being_flushed, __ATOMIC_RELAXED)) {
564 if(!logged) {
565 netdata_log_info("Waiting for inflight flush to finish on tier %d...", ctx->config.tier);
src/database/rrdhost.c
+18 -17
@@ -879,23 +879,12 @@ void dbengine_init(char *hostname) {
879
880 struct dbengine_initialization tiers_init[RRD_STORAGE_TIERS] = {};
881
882 + bool tiers_adjusted = false;
883 size_t created_tiers = 0;
884 char dbenginepath[FILENAME_MAX + 1];
885 char dbengineconfig[200 + 1];
886 int divisor = 1;
887 for(size_t tier = 0; tier < storage_tiers ;tier++) {
887 - if(tier == 0)
888 - snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine", netdata_configured_cache_dir);
889 - else
890 - snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine-tier%zu", netdata_configured_cache_dir, tier);
891 -
892 - int ret = mkdir(dbenginepath, 0775);
893 - if (ret != 0 && errno != EEXIST) {
894 - nd_log(NDLS_DAEMON, NDLP_CRIT,
895 - "DBENGINE on '%s': cannot create directory '%s'",
896 - hostname, dbenginepath);
897 - break;
898 - }
888
889 if(tier > 0)
890 divisor *= 2;
@@ -924,10 +913,7 @@ void dbengine_init(char *hostname) {
913 else if(strcmp(bf, "full") == 0) backfill = RRD_BACKFILL_FULL;
914 else if(strcmp(bf, "none") == 0) backfill = RRD_BACKFILL_NONE;
915 else {
927 - nd_log(NDLS_DAEMON, NDLP_WARNING,
928 - "DBENGINE: unknown backfill value '%s', assuming 'new'",
929 - bf);
930 -
916 + nd_log(NDLS_DAEMON, NDLP_WARNING, "DBENGINE: unknown backfill value '%s', assuming 'new'", bf);
917 config_set(CONFIG_SECTION_DB, dbengineconfig, "new");
918 backfill = RRD_BACKFILL_NEW;
919 }
@@ -940,8 +926,21 @@ void dbengine_init(char *hostname) {
926 storage_tiers_grouping_iterations[tier] = 1;
927 nd_log(NDLS_DAEMON, NDLP_WARNING,
928 "DBENGINE on '%s': dbengine tier %zu gives aggregation of more than 65535 points of tier 0. "
943 - "Disabling tiers above %zu",
929 + "Disabling tiers %zu and above",
930 hostname, tier, tier);
931 + storage_tiers = tier;
932 + tiers_adjusted = true;
933 + break;
934 + }
935 +
936 + if(tier == 0)
937 + snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine", netdata_configured_cache_dir);
938 + else
939 + snprintfz(dbenginepath, FILENAME_MAX, "%s/dbengine-tier%zu", netdata_configured_cache_dir, tier);
940 +
941 + int ret = mkdir(dbenginepath, 0775);
942 + if (ret != 0 && errno != EEXIST) {
943 + nd_log(NDLS_DAEMON, NDLP_CRIT, "DBENGINE on '%s': cannot create directory '%s'", hostname, dbenginepath);
944 break;
945 }
946
@@ -961,6 +960,8 @@ void dbengine_init(char *hostname) {
960 else
961 dbengine_tier_init(&tiers_init[tier]);
962 }
963 + if (tiers_adjusted)
964 + config_set_number(CONFIG_SECTION_DB, "storage tiers", storage_tiers);
965
966 for(size_t tier = 0; tier < storage_tiers ;tier++) {
967 void *ptr;