Skip to content

Commit

Permalink
Adjust time retention calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
stelfrag committed May 8, 2024
1 parent 622d27c commit 15c5f52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/database/engine/journalfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ static void journalfile_restore_extent_metadata(struct rrdengine_instance *ctx,
}

time_t now_s = max_acceptable_collected_time();
time_t extent_first_time_s = journalfile->v2.first_time_s ? journalfile->v2.first_time_s : LONG_MAX;
for (i = 0; i < count ; ++i) {
uuid_t *temp_id;
uint8_t page_type = jf_metric_data->descr[i].type;
Expand Down Expand Up @@ -728,8 +729,18 @@ static void journalfile_restore_extent_metadata(struct rrdengine_instance *ctx,
journalfile->datafile,
jf_metric_data->extent_offset, jf_metric_data->extent_size, jf_metric_data->descr[i].page_length);

extent_first_time_s = MIN(extent_first_time_s, vd.start_time_s);

mrg_metric_release(main_mrg, metric);
}

journalfile->v2.first_time_s = extent_first_time_s;

time_t old = __atomic_load_n(&ctx->atomic.first_time_s, __ATOMIC_RELAXED);;
do {
if(old <= extent_first_time_s)
break;
} while(!__atomic_compare_exchange_n(&ctx->atomic.first_time_s, &old, extent_first_time_s, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED));
}

/*
Expand Down
8 changes: 7 additions & 1 deletion src/database/engine/rrdengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,11 @@ time_t get_datafile_end_time(struct rrdengine_instance *ctx)
uv_rwlock_rdlock(&ctx->datafiles.rwlock);
struct rrdengine_datafile *datafile = ctx->datafiles.first;

if (datafile)
if (datafile) {
last_time_s = datafile->journalfile->v2.last_time_s;
if (!last_time_s)
last_time_s = datafile->journalfile->v2.first_time_s;
}

uv_rwlock_rdunlock(&ctx->datafiles.rwlock);
return last_time_s;
Expand Down Expand Up @@ -1814,6 +1817,9 @@ void dbengine_retention_statistics(void)
100 * retention / multidb_ctx[tier]->config.max_retention_s :
0;

if (retention_percentage > 100.0)
retention_percentage = 100.0;

rrddim_set_by_pointer(stats[tier].st, stats[tier].rd_space, (collected_number) disk_percentage);
rrddim_set_by_pointer(stats[tier].st, stats[tier].rd_time, (collected_number) retention_percentage);

Expand Down

0 comments on commit 15c5f52

Please sign in to comment.