Avoid an extra uuid_copy when creating new MRG entries (#15502)
Avoid an extra uuid_copy when creating new mrg entries
Stelios Fragkakis committed
Jul 26, 2023 at 15:56 UTC
12cfe104261d56167f6d5794e8e8b45ff965d77f
4 files changed
+13
-13
database/engine/journalfile.c
+1
-1
@@ -696,12 +696,12 @@ static void journalfile_restore_extent_metadata(struct rrdengine_instance *ctx,
696
bool update_metric_time = true;
697
if (!metric) {
698
MRG_ENTRY entry = {
699
+ .uuid = temp_id,
700
.section = (Word_t)ctx,
701
.first_time_s = vd.start_time_s,
702
.last_time_s = vd.end_time_s,
703
.latest_update_every_s = (uint32_t) vd.update_every_s,
704
};
704
- uuid_copy(entry.uuid, *temp_id);
705
706
bool added;
707
metric = mrg_metric_add_and_acquire(main_mrg, entry, &added);
database/engine/metric.c
+10
-10
@@ -168,7 +168,7 @@ static inline bool metric_release_and_can_be_deleted(MRG *mrg __maybe_unused, ME
168
}
169
170
static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *ret) {
171
- size_t partition = uuid_partition(mrg, &entry->uuid);
171
+ size_t partition = uuid_partition(mrg, entry->uuid);
172
173
METRIC *allocation = aral_mallocz(mrg->index[partition].aral);
174
@@ -176,7 +176,7 @@ static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *r
176
177
size_t mem_before_judyl, mem_after_judyl;
178
179
- Pvoid_t *sections_judy_pptr = JudyHSIns(&mrg->index[partition].uuid_judy, &entry->uuid, sizeof(uuid_t), PJE0);
179
+ Pvoid_t *sections_judy_pptr = JudyHSIns(&mrg->index[partition].uuid_judy, entry->uuid, sizeof(uuid_t), PJE0);
180
if(unlikely(!sections_judy_pptr || sections_judy_pptr == PJERR))
181
fatal("DBENGINE METRIC: corrupted UUIDs JudyHS array");
182
@@ -209,8 +209,7 @@ static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *r
209
}
210
211
METRIC *metric = allocation;
212
- // memcpy(metric->uuid, entry->uuid, sizeof(uuid_t));
213
- uuid_copy(metric->uuid, entry->uuid);
212
+ uuid_copy(metric->uuid, *entry->uuid);
213
metric->section = entry->section;
214
metric->first_time_s = MAX(0, entry->first_time_s);
215
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(
691
METRIC *metric = mrg_metric_get_and_acquire(mrg, uuid, section);
692
if (!metric) {
693
MRG_ENTRY entry = {
694
+ .uuid = uuid,
695
.section = section,
696
.first_time_s = first_time_s,
697
.last_time_s = last_time_s,
698
.latest_update_every_s = (uint32_t) update_every_s
699
};
700
- // memcpy(entry.uuid, *uuid, sizeof(uuid_t));
701
- uuid_copy(entry.uuid, *uuid);
700
metric = mrg_metric_add_and_acquire(mrg, entry, &added);
701
}
702
@@ -790,13 +788,15 @@ int mrg_unittest(void) {
788
METRIC *m1_t1, *m2_t1, *m3_t1, *m4_t1;
789
bool ret;
790
791
+ uuid_t test_uuid;
792
+ uuid_generate(test_uuid);
793
MRG_ENTRY entry = {
794
+ .uuid = &test_uuid,
795
.section = 0,
796
.first_time_s = 2,
797
.last_time_s = 3,
798
.latest_update_every_s = 4,
799
};
799
- uuid_generate(entry.uuid);
800
m1_t0 = mrg_metric_add_and_acquire(mrg, entry, &ret);
801
if(!ret)
802
fatal("DBENGINE METRIC: failed to add metric");
@@ -808,7 +808,7 @@ int mrg_unittest(void) {
808
if(ret)
809
fatal("DBENGINE METRIC: managed to add the same metric twice");
810
811
- m3_t0 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section);
811
+ m3_t0 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section);
812
if(m3_t0 != m1_t0)
813
fatal("DBENGINE METRIC: cannot find the metric added");
814
@@ -832,7 +832,7 @@ int mrg_unittest(void) {
832
if(ret)
833
fatal("DBENGINE METRIC: managed to add the same metric twice in (section 0)");
834
835
- m3_t1 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section);
835
+ m3_t1 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section);
836
if(m3_t1 != m1_t1)
837
fatal("DBENGINE METRIC: cannot find the metric added (section %zu)", (size_t)entry.section);
838
@@ -846,7 +846,7 @@ int mrg_unittest(void) {
846
if(!mrg_metric_release_and_delete(mrg, m1_t0))
847
fatal("DBENGINE METRIC: cannot delete the first metric");
848
849
- m4_t1 = mrg_metric_get_and_acquire(mrg, &entry.uuid, entry.section);
849
+ m4_t1 = mrg_metric_get_and_acquire(mrg, entry.uuid, entry.section);
850
if(m4_t1 != m1_t1)
851
fatal("DBENGINE METRIC: cannot find the metric added (section %zu), after deleting the first one", (size_t)entry.section);
852
database/engine/metric.h
+1
-1
@@ -11,7 +11,7 @@ typedef struct metric METRIC;
11
typedef struct mrg MRG;
12
13
typedef struct mrg_entry {
14
- uuid_t uuid;
14
+ uuid_t *uuid;
15
Word_t section;
16
time_t first_time_s;
17
time_t last_time_s;
database/engine/rrdengineapi.c
+1
-1
@@ -111,12 +111,12 @@ static METRIC *rrdeng_metric_create(STORAGE_INSTANCE *db_instance, uuid_t *uuid)
111
112
struct rrdengine_instance *ctx = (struct rrdengine_instance *)db_instance;
113
MRG_ENTRY entry = {
114
+ .uuid = uuid,
115
.section = (Word_t)ctx,
116
.first_time_s = 0,
117
.last_time_s = 0,
118
.latest_update_every_s = 0,
119
};
119
- uuid_copy(entry.uuid, *uuid);
120
121
METRIC *metric = mrg_metric_add_and_acquire(main_mrg, entry, NULL);
122
return metric;