Get update every from page (#14573)
* Fix warning on conversion unsigned vs int * For each metric get the update every from the last page stored in the journal
Stelios Fragkakis committed
Feb 22, 2023 at 22:06 UTC
7cd5570b49c5f156c944766dda7238611a969ff0
2 files changed
+13
-3
database/engine/datafile.c
+2
-2
@@ -379,8 +379,8 @@ static int scan_data_files_cmp(const void *a, const void *b)
379
/* Returns number of datafiles that were loaded or < 0 on error */
380
static int scan_data_files(struct rrdengine_instance *ctx)
381
{
382
- int ret;
383
- unsigned tier, no, matched_files, i,failed_to_load;
382
+ int ret, matched_files, failed_to_load;
383
+ unsigned tier, no, i;
384
uv_fs_t req;
385
uv_dirent_t dent;
386
struct rrdengine_datafile **datafiles, *datafile;
database/engine/journalfile.c
+11
-1
@@ -894,6 +894,16 @@ static int journalfile_v2_validate(void *data_start, size_t journal_v2_file_size
894
return 0;
895
}
896
897
+static inline time_t get_metric_latest_update_every(struct journal_page_header *metric_list_header)
898
+{
899
+ struct journal_page_list *metric_page =
900
+ (struct journal_page_list *)((uint8_t *)metric_list_header + sizeof(*metric_list_header));
901
+ uint32_t entries = metric_list_header->entries;
902
+ if (unlikely(!entries))
903
+ return 0;
904
+ return (time_t)metric_page[entries - 1].update_every_s;
905
+}
906
+
907
void journalfile_v2_populate_retention_to_mrg(struct rrdengine_instance *ctx, struct rrdengine_journalfile *journalfile) {
908
usec_t started_ut = now_monotonic_usec();
909
@@ -911,7 +921,7 @@ void journalfile_v2_populate_retention_to_mrg(struct rrdengine_instance *ctx, st
921
for (size_t i=0; i < entries; i++) {
922
time_t start_time_s = header_start_time_s + metric->delta_start_s;
923
time_t end_time_s = header_start_time_s + metric->delta_end_s;
914
- time_t update_every_s = (metric->entries > 1) ? ((end_time_s - start_time_s) / (entries - 1)) : 0;
924
+ time_t update_every_s = get_metric_latest_update_every((struct journal_page_header *) (data_start + metric->page_offset));
925
update_metric_retention_and_granularity_by_uuid(
926
ctx, &metric->uuid, start_time_s, end_time_s, update_every_s, now_s);
927