@cryptotaxi247 / netdata-1 / commits / e21e52daa

fixed an incomplete calculation that forced a whole db dump if the range given at API was accessing data not yet filled

Costa Tsaousis (ktsaou) committed Dec 2, 2015 at 11:31 UTC e21e52daa086f07f1ea2e097e0b9e4ae5e37dfef
1 file changed +11 -11
src/rrd.h
+11 -11
@@ -287,27 +287,27 @@ extern unsigned long long rrdset_done(RRDSET *st);
287 #define rrdset_first_entry_t(st) ((time_t)(rrdset_last_entry_t(st) - rrdset_duration(st)))
288
289 // get the last slot updated in the round robin database
290 -#define rrdset_last_slot(st) (((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1)
290 +#define rrdset_last_slot(st) ((unsigned long)(((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1))
291
292 // get the first / oldest slot updated in the round robin database
293 -#define rrdset_first_slot(st) ((st)->current_entry)
293 +#define rrdset_first_slot(st) ((unsigned long)( (((st)->counter >= ((unsigned long)(st)->entries)) ? (unsigned long)( ((unsigned long)(st)->current_entry > 0) ? ((unsigned long)(st)->current_entry) : ((unsigned long)(st)->entries) ) - 1 : 0) ))
294
295 // get the slot of the round robin database, for the given timestamp (t)
296 // it always returns a valid slot, although may not be for the time requested if the time is outside the round robin database
297 #define rrdset_time2slot(st, t) ( \
298 - ( (t) >= rrdset_last_entry_t(st)) ? ( rrdset_last_slot(st) ) : \
299 - ( ((t) <= rrdset_first_entry_t(st)) ? rrdset_first_slot(st) : \
300 - ( (rrdset_last_slot(st) >= ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) ) ? \
301 - (rrdset_last_slot(st) - ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) ) : \
302 - (rrdset_last_slot(st) - ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) + (st)->entries ) \
298 + ( (time_t)(t) >= rrdset_last_entry_t(st)) ? ( rrdset_last_slot(st) ) : \
299 + ( ((time_t)(t) <= rrdset_first_entry_t(st)) ? rrdset_first_slot(st) : \
300 + ( (rrdset_last_slot(st) >= (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) ) ? \
301 + (rrdset_last_slot(st) - (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) ) : \
302 + (rrdset_last_slot(st) - (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) + (unsigned long)(st)->entries ) \
303 )))
304
305 // get the timestamp of a specific slot in the round robin database
306 #define rrdset_slot2time(st, slot) ( rrdset_last_entry_t(st) - \
307 - ((st)->update_every * ( \
308 - ( (slot) > rrdset_last_slot(st)) ? \
309 - ( (rrdset_last_slot(st) - slot + (st)->entries) ) : \
310 - ( (rrdset_last_slot(st) - slot) )) \
307 + ((unsigned long)(st)->update_every * ( \
308 + ( (unsigned long)(slot) > rrdset_last_slot(st)) ? \
309 + ( (rrdset_last_slot(st) - (unsigned long)(slot) + (unsigned long)(st)->entries) ) : \
310 + ( (rrdset_last_slot(st) - (unsigned long)(slot)) )) \
311 ))
312
313 // ----------------------------------------------------------------------------