Simple fix for the data API query (#11787)
Vladimir Kobal committed
Nov 22, 2021 at 16:13 UTC
c511d98c34f6cfde537f75ff71d5e1cb015ec45b
3 files changed
+12
-8
daemon/unit_test.c
+7
-7
@@ -1604,7 +1604,7 @@ static time_t test_dbengine_create_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS
1604
collected_number next;
1605
1606
update_every = REGION_UPDATE_EVERY[current_region];
1607
- time_now = time_start + update_every;
1607
+ time_now = time_start;
1608
// feed it with the test data
1609
for (i = 0 ; i < CHARTS ; ++i) {
1610
for (j = 0 ; j < DIMS ; ++j) {
@@ -1615,7 +1615,7 @@ static time_t test_dbengine_create_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS
1615
}
1616
}
1617
for (c = 0; c < REGION_POINTS[current_region] ; ++c) {
1618
- time_now += update_every; // time_now = start + (c + 2) * update_every
1618
+ time_now += update_every; // time_now = start + (c + 1) * update_every
1619
for (i = 0 ; i < CHARTS ; ++i) {
1620
st[i]->usec_since_last_update = USEC_PER_SEC * update_every;
1621
@@ -1647,7 +1647,7 @@ static int test_dbengine_check_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DI
1647
1648
// check the result
1649
for (c = 0; c < REGION_POINTS[current_region] ; c += QUERY_BATCH) {
1650
- time_now = time_start + (c + 2) * update_every;
1650
+ time_now = time_start + (c + 1) * update_every;
1651
for (i = 0 ; i < CHARTS ; ++i) {
1652
for (j = 0; j < DIMS; ++j) {
1653
rd[i][j]->state->query_ops.init(rd[i][j], &handle, time_now, time_now + QUERY_BATCH * update_every);
@@ -1692,7 +1692,7 @@ static int test_dbengine_check_rrdr(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DIMS]
1692
1693
errors = 0;
1694
update_every = REGION_UPDATE_EVERY[current_region];
1695
- long points = (time_end - time_start) / update_every - 1;
1695
+ long points = (time_end - time_start) / update_every;
1696
for (i = 0 ; i < CHARTS ; ++i) {
1697
RRDR *r = rrd2rrdr(st[i], points, time_start + update_every, time_end, RRDR_GROUPING_AVERAGE, 0, 0, NULL, NULL);
1698
if (!r) {
@@ -1711,7 +1711,7 @@ static int test_dbengine_check_rrdr(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DIMS]
1711
value = cn[j];
1712
assert(rd[i][j] == d);
1713
1714
- last = i * DIMS * REGION_POINTS[current_region] + j * REGION_POINTS[current_region] + c;
1714
+ last = i * DIMS * REGION_POINTS[current_region] + j * REGION_POINTS[current_region] + c + 1;
1715
expected = unpack_storage_number(pack_storage_number((calculated_number)last, SN_DEFAULT_FLAGS));
1716
1717
same = (calculated_number_round(value) == calculated_number_round(expected)) ? 1 : 0;
@@ -1810,7 +1810,7 @@ int test_dbengine(void)
1810
current_region = 1;
1811
update_every = REGION_UPDATE_EVERY[current_region]; // use the maximum update_every = 3
1812
errors = 0;
1813
- long points = (time_end[REGIONS - 1] - time_start[0]) / update_every - 1; // cover all time regions with RRDR
1813
+ long points = (time_end[REGIONS - 1] - time_start[0]) / update_every; // cover all time regions with RRDR
1814
long point_offset = (time_start[current_region] - time_start[0]) / update_every;
1815
for (i = 0 ; i < CHARTS ; ++i) {
1816
RRDR *r = rrd2rrdr(st[i], points, time_start[0] + update_every, time_end[REGIONS - 1], RRDR_GROUPING_AVERAGE, 0, 0, NULL, NULL);
@@ -1833,7 +1833,7 @@ int test_dbengine(void)
1833
calculated_number value = cn[j];
1834
assert(rd[i][j] == d);
1835
1836
- collected_number last = i * DIMS * REGION_POINTS[current_region] + j * REGION_POINTS[current_region] + c - point_offset;
1836
+ collected_number last = i * DIMS * REGION_POINTS[current_region] + j * REGION_POINTS[current_region] + c - point_offset + 1;
1837
calculated_number expected = unpack_storage_number(pack_storage_number((calculated_number)last, SN_DEFAULT_FLAGS));
1838
1839
uint8_t same = (calculated_number_round(value) == calculated_number_round(expected)) ? 1 : 0;
database/rrd.h
+4
-1
@@ -1150,7 +1150,10 @@ static inline time_t rrdset_first_entry_t_nolock(RRDSET *st)
1150
time_t first_entry_t = LONG_MAX;
1151
1152
rrddim_foreach_read(rd, st) {
1153
- first_entry_t = MIN(first_entry_t, rd->state->query_ops.oldest_time(rd));
1153
+ first_entry_t =
1154
+ MIN(first_entry_t,
1155
+ rd->state->query_ops.oldest_time(rd) > st->update_every ?
1156
+ rd->state->query_ops.oldest_time(rd) - st->update_every : 0);
1157
}
1158
1159
if (unlikely(LONG_MAX == first_entry_t)) return 0;
database/rrdset.c
+1
@@ -1362,6 +1362,7 @@ static inline void rrdset_done_fill_the_gap(RRDSET *st) {
1362
st->last_updated.tv_sec += c * st->update_every;
1363
1364
st->current_entry += c;
1365
+ st->counter += c;
1366
if(st->current_entry >= st->entries)
1367
st->current_entry -= st->entries;
1368
}