@cryptotaxi247 / netdata-1 / commits / 69a709d87

Handle corrupted journal data when populating the MRG during startup. (#20128)

Stelios Fragkakis committed Apr 15, 2025 at 20:53 UTC 69a709d87fad552111832f503217b7297da926f5
1 file changed +25 -12
src/database/engine/journalfile.c
+25 -12
@@ -1012,7 +1012,6 @@ void journalfile_v2_populate_retention_to_mrg(struct rrdengine_instance *ctx, st
1012 return;
1013
1014 uint8_t *data_start = (uint8_t *)j2_header;
1015 - uint32_t entries = j2_header->metric_count;
1015
1016 if (journalfile->v2.flags & JOURNALFILE_FLAG_METRIC_CRC_CHECK) {
1017 journalfile->v2.flags &= ~JOURNALFILE_FLAG_METRIC_CRC_CHECK;
@@ -1023,21 +1022,35 @@ void journalfile_v2_populate_retention_to_mrg(struct rrdengine_instance *ctx, st
1022 }
1023 }
1024
1026 - struct journal_metric_list *metric = (struct journal_metric_list *) (data_start + j2_header->metric_offset);
1027 - time_t header_start_time_s = (time_t) (j2_header->start_time_ut / USEC_PER_SEC);
1028 - time_t global_first_time_s = header_start_time_s;
1029 - time_t now_s = max_acceptable_collected_time();
1030 - for (size_t i=0; i < entries; i++) {
1031 - time_t start_time_s = header_start_time_s + metric->delta_start_s;
1032 - time_t end_time_s = header_start_time_s + metric->delta_end_s;
1033 -
1034 - mrg_update_metric_retention_and_granularity_by_uuid(
1025 + char path_v2[RRDENG_PATH_MAX];
1026 + journalfile_v2_generate_path(journalfile->datafile, path_v2, sizeof(path_v2));
1027 + time_t global_first_time_s;
1028 + bool failed = false;
1029 + uint32_t entries;
1030 + PROTECTED_ACCESS_SETUP(data_start, journalfile->mmap.size, path_v2, "mrg-load");
1031 + if(no_signal_received) {
1032 + entries = j2_header->metric_count;
1033 + struct journal_metric_list *metric = (struct journal_metric_list *) (data_start + j2_header->metric_offset);
1034 + time_t header_start_time_s = (time_t) (j2_header->start_time_ut / USEC_PER_SEC);
1035 + global_first_time_s = header_start_time_s;
1036 + time_t now_s = max_acceptable_collected_time();
1037 + for (size_t i=0; i < entries; i++) {
1038 + time_t start_time_s = header_start_time_s + metric->delta_start_s;
1039 + time_t end_time_s = header_start_time_s + metric->delta_end_s;
1040 +
1041 + mrg_update_metric_retention_and_granularity_by_uuid(
1042 main_mrg, (Word_t)ctx, &metric->uuid, start_time_s, end_time_s, metric->update_every_s, now_s);
1043
1037 - metric++;
1038 - }
1044 + metric++;
1045 + }
1046 + } else
1047 + failed = true;
1048
1049 journalfile_v2_data_release(journalfile);
1050 +
1051 + if (unlikely(failed))
1052 + return;
1053 +
1054 usec_t ended_ut = now_monotonic_usec();
1055
1056 nd_log_daemon(NDLP_DEBUG, "DBENGINE: journal v2 of tier %d, datafile %u populated, size: %0.2f MiB, metrics: %0.2f k, %0.2f ms"