diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2023-07-26 15:56:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 15:56:25 +0300 |
commit | 12cfe104261d56167f6d5794e8e8b45ff965d77f (patch) | |
tree | 902ba81ae323a249fde212257c366a900849982b /database | |
parent | 440bd51e08fdfa2a4daa191fb68643456028a753 (diff) |
Avoid an extra uuid_copy when creating new MRG entries (#15502)
Avoid an extra uuid_copy when creating new mrg entries
Diffstat (limited to 'database')
-rw-r--r-- | database/engine/journalfile.c | 2 | ||||
-rw-r--r-- | database/engine/metric.c | 20 | ||||
-rw-r--r-- | database/engine/metric.h | 2 | ||||
-rw-r--r-- | database/engine/rrdengineapi.c | 2 |
4 files changed, 13 insertions, 13 deletions
diff --git a/database/engine/journalfile.c b/database/engine/journalfile.c index 5485bb3a99..aacfb0b5f0 100644 --- a/database/engine/journalfile.c +++ b/database/engine/journalfile.c @@ -696,12 +696,12 @@ static void journalfile_restore_extent_metadata(struct rrdengine_instance *ctx, bool update_metric_time = true; if (!metric) { MRG_ENTRY entry = { + .uuid = temp_id, .section = (Word_t)ctx, .first_time_s = vd.start_time_s, .last_time_s = vd.end_time_s, .latest_update_every_s = (uint32_t) vd.update_every_s, }; - uuid_copy(entry.uuid, *temp_id); bool added; metric = mrg_metric_add_and_acquire(main_mrg, entry, &added); diff --git a/database/engine/metric.c b/database/engine/metric.c index c447577ee3..1187941a2f 100644 --- a/database/engine/metric.c +++ b/database/engine/metric.c @@ -168,7 +168,7 @@ static inline bool metric_release_and_can_be_deleted(MRG *mrg __maybe_unused, ME } static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *ret) { - size_t partition = uuid_partition(mrg, &entry->uuid); + size_t partition = uuid_partition(mrg, entry->uuid); METRIC *allocation = aral_mallocz(mrg->index[partition].aral); @@ -176,7 +176,7 @@ static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *r size_t mem_before_judyl, mem_after_judyl; - Pvoid_t *sections_judy_pptr = JudyHSIns(&mrg->index[partition].uuid_judy, &entry->uuid, sizeof(uuid_t), PJE0); + Pvoid_t *sections_judy_pptr = JudyHSIns(&mrg->index[partition].uuid_judy, entry->uuid, sizeof(uuid_t), PJE0); if(unlikely(!sections_judy_pptr || sections_judy_pptr == PJERR)) fatal("DBENGINE METRIC: corrupted UUIDs JudyHS array"); @@ -209,8 +209,7 @@ static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *r } METRIC *metric = allocation; - // memcpy(metric->uuid, entry->uuid, sizeof(uuid_t)); - uuid_copy(metric->uuid, entry->uuid); + uuid_copy(metric->uuid, *entry->uuid); metric->section = entry->section; metric->first_time_s = MAX(0, entry->first_time_s); metric->latest_time_s_clean = MAX(0, entry->last_time_s); @@ -692,13 +691,12 @@ inline void mrg_update_metric_retention_and_granularity_by_uuid( METRIC *metric = mrg_metric_get_and_acquire(mrg, uuid, section); if (!metric) { MRG_ENTRY entry = { + .uuid = uuid, .section = section, .first_time_s = first_time_s, .last_time_s = last_time_s, .latest_update_every_s = (uint32_t) update_every_s }; - // memcpy(entry.uuid, *uuid, sizeof(uuid_t)); - uuid_copy(entry.uuid, *uuid); metric = mrg_metric_add_and_acquire(mrg, entry, &added); } @@ -790,13 +788,15 @@ int mrg_unittest(void) { METRIC *m1_t1, *m2_t1, *m3_t1, *m4_t1; bool ret; + uuid_t test_uuid; + uuid_generate(test_uuid); MRG_ENTRY entry = { + .uuid = &test_uuid, .section = 0, .first_time_s = 2, .last_time_s = 3, .latest_update_every_s = 4, }; - uuid_generate(entry.uuid); m1_t0 = mrg_metric_add_and_acquire(mrg, entry, &ret); if(!ret) fatal("DBENGINE METRIC: failed to add metric"); @@ -808,7 +808,7 @@ int mrg_unittest(void) { if(ret) fatal("DBENGINE METRIC: managed to add the same metric twice"); - m3_t0 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section); + m3_t0 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section); if(m3_t0 != m1_t0) fatal("DBENGINE METRIC: cannot find the metric added"); @@ -832,7 +832,7 @@ int mrg_unittest(void) { if(ret) fatal("DBENGINE METRIC: managed to add the same metric twice in (section 0)"); - m3_t1 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section); + m3_t1 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section); if(m3_t1 != m1_t1) fatal("DBENGINE METRIC: cannot find the metric added (section %zu)", (size_t)entry.section); @@ -846,7 +846,7 @@ int mrg_unittest(void) { if(!mrg_metric_release_and_delete(mrg, m1_t0)) fatal("DBENGINE METRIC: cannot delete the first metric"); - m4_t1 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section); + m4_t1 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section); if(m4_t1 != m1_t1) fatal("DBENGINE METRIC: cannot find the metric added (section %zu), after deleting the first one", (size_t)entry.section); diff --git a/database/engine/metric.h b/database/engine/metric.h index 40abb6d57d..c55800f051 100644 --- a/database/engine/metric.h +++ b/database/engine/metric.h @@ -11,7 +11,7 @@ typedef struct metric METRIC; typedef struct mrg MRG; typedef struct mrg_entry { - uuid_t uuid; + uuid_t *uuid; Word_t section; time_t first_time_s; time_t last_time_s; diff --git a/database/engine/rrdengineapi.c b/database/engine/rrdengineapi.c index 3b6863f12c..fc289debdd 100644 --- a/database/engine/rrdengineapi.c +++ b/database/engine/rrdengineapi.c @@ -111,12 +111,12 @@ static METRIC *rrdeng_metric_create(STORAGE_INSTANCE *db_instance, uuid_t *uuid) struct rrdengine_instance *ctx = (struct rrdengine_instance *)db_instance; MRG_ENTRY entry = { + .uuid = uuid, .section = (Word_t)ctx, .first_time_s = 0, .last_time_s = 0, .latest_update_every_s = 0, }; - uuid_copy(entry.uuid, *uuid); METRIC *metric = mrg_metric_add_and_acquire(main_mrg, entry, NULL); return metric; |