query engine optimizations and cleanup (#12978)

* move number unpacking close to next_metric

* dont miss group value flags
This commit is contained in:
Costa Tsaousis 2022-05-21 12:29:38 +03:00 committed by GitHub
parent 619f9964a6
commit 7b272cbea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 18 deletions

View File

@ -599,12 +599,29 @@ static inline void do_dimension_fixedstep(
#endif
db_now = now; // this is needed to set db_now in case the next_metric implementation does not set it
storage_number n;
if (unlikely(rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && now <= first_time_t))
calculated_number value;
if (unlikely(rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && now <= first_time_t)) {
n = SN_EMPTY_SLOT;
else
value = NAN;
}
else {
// load the metric value
n = next_metric(&handle, &db_now);
// and unpack it
if(likely(does_storage_number_exist(n))) {
if (options & RRDR_OPTION_ANOMALY_BIT)
value = (n & SN_ANOMALY_BIT) ? 0.0 : 100.0;
else
value = unpack_storage_number(n);
}
else
value = NAN;
}
if(unlikely(db_now > before_wanted)) {
#ifdef NETDATA_INTERNAL_CHECKS
r->internal.log = "stopped, because attempted to access the db after 'wanted before'";
@ -613,26 +630,25 @@ static inline void do_dimension_fixedstep(
}
for ( ; now <= db_now ; now += dt) {
calculated_number value = NAN;
if(likely(does_storage_number_exist(n))) {
if(likely(now >= db_now && does_storage_number_exist(n))) {
#if defined(NETDATA_INTERNAL_CHECKS) && defined(ENABLE_DBENGINE)
struct rrdeng_query_handle* rrd_handle = (struct rrdeng_query_handle*)handle.handle;
if ((rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) && (now != rrd_handle->now)) {
error("INTERNAL CHECK: Unaligned query for %s, database time: %ld, expected time: %ld", rd->id, (long)rrd_handle->now, (long)now);
if(now >= db_now) {
struct rrdeng_query_handle *rrd_handle = (struct rrdeng_query_handle *)handle.handle;
if ((rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) && (now != rrd_handle->now))
error(
"INTERNAL CHECK: Unaligned query for %s, database time: %ld, expected time: %ld",
rd->id,
(long)rrd_handle->now,
(long)now);
}
#endif
if (options & RRDR_OPTION_ANOMALY_BIT)
value = (n & SN_ANOMALY_BIT) ? 0.0 : 100.0;
else
value = unpack_storage_number(n);
if(likely(value != 0.0))
values_in_group_non_zero++;
if(unlikely(did_storage_number_reset(n)))
group_value_flags |= RRDR_VALUE_RESET;
}
// add this value for grouping
@ -657,21 +673,21 @@ static inline void do_dimension_fixedstep(
// store the specific point options
*rrdr_value_options_ptr = group_value_flags;
// store the value
value = grouping_flush(r, rrdr_value_options_ptr);
r->v[rrdr_o_v_index] = value;
// store the group value
calculated_number group_value = grouping_flush(r, rrdr_value_options_ptr);
r->v[rrdr_o_v_index] = group_value;
if(likely(points_added || dim_id_in_rrdr)) {
// find the min/max across all dimensions
if(unlikely(value < min)) min = value;
if(unlikely(value > max)) max = value;
if(unlikely(group_value < min)) min = group_value;
if(unlikely(group_value > max)) max = group_value;
}
else {
// runs only when dim_id_in_rrdr == 0 && points_added == 0
// so, on the first point added for the query.
min = max = value;
min = max = group_value;
}
points_added++;