]> arthur.barton.de Git - netdata.git/commitdiff
fixed an incomplete calculation that forced a whole db dump if the range given at...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 2 Dec 2015 09:31:34 +0000 (11:31 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 2 Dec 2015 09:31:34 +0000 (11:31 +0200)
src/rrd.h

index 03798e5acce04c9198f8ec6372e6a90c2f8f7c43..ab9935ad3dda4a79c4ae23f8bab6b1d1753f6aa2 100755 (executable)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -287,27 +287,27 @@ extern unsigned long long rrdset_done(RRDSET *st);
 #define rrdset_first_entry_t(st) ((time_t)(rrdset_last_entry_t(st) - rrdset_duration(st)))
 
 // get the last slot updated in the round robin database
-#define rrdset_last_slot(st) (((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1)
+#define rrdset_last_slot(st) ((unsigned long)(((st)->current_entry == 0) ? (st)->entries - 1 : (st)->current_entry - 1))
 
 // get the first / oldest slot updated in the round robin database
-#define rrdset_first_slot(st) ((st)->current_entry)
+#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) ))
 
 // get the slot of the round robin database, for the given timestamp (t)
 // it always returns a valid slot, although may not be for the time requested if the time is outside the round robin database
 #define rrdset_time2slot(st, t) ( \
-               (  (t) >= rrdset_last_entry_t(st))  ? ( rrdset_last_slot(st) ) : \
-               ( ((t) <= rrdset_first_entry_t(st)) ?   rrdset_first_slot(st) : \
-               ( (rrdset_last_slot(st) >= ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) ) ? \
-                 (rrdset_last_slot(st) -  ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) ) : \
-                 (rrdset_last_slot(st) -  ((long)(rrdset_last_entry_t(st) - (t)) / (long)((st)->update_every)) + (st)->entries ) \
+               (  (time_t)(t) >= rrdset_last_entry_t(st))  ? ( rrdset_last_slot(st) ) : \
+               ( ((time_t)(t) <= rrdset_first_entry_t(st)) ?   rrdset_first_slot(st) : \
+               ( (rrdset_last_slot(st) >= (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) ) ? \
+                 (rrdset_last_slot(st) -  (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) ) : \
+                 (rrdset_last_slot(st) -  (unsigned long)((rrdset_last_entry_t(st) - (time_t)(t)) / (unsigned long)((st)->update_every)) + (unsigned long)(st)->entries ) \
                )))
 
 // get the timestamp of a specific slot in the round robin database
 #define rrdset_slot2time(st, slot) ( rrdset_last_entry_t(st) - \
-               ((st)->update_every * ( \
-                               ( (slot) > rrdset_last_slot(st)) ? \
-                               ( (rrdset_last_slot(st) - slot + (st)->entries) ) : \
-                               ( (rrdset_last_slot(st) - slot) )) \
+               ((unsigned long)(st)->update_every * ( \
+                               ( (unsigned long)(slot) > rrdset_last_slot(st)) ? \
+                               ( (rrdset_last_slot(st) - (unsigned long)(slot) + (unsigned long)(st)->entries) ) : \
+                               ( (rrdset_last_slot(st) - (unsigned long)(slot)) )) \
                ))
 
 // ----------------------------------------------------------------------------