X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=inline;f=src%2Frrdtool.c;h=84fcceff9d76d3217ad0dbc110a8ca6ec9ee9953;hb=20115ea505208ac2f1e8b453a35284b871db1321;hp=d357cad0f460734f56991e9045f7d148711c8434;hpb=2079ee1517e34de372f58e7e2267ad5c71a8a41f;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index d357cad0..84fcceff 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -505,7 +505,6 @@ static void rrd_cache_flush(cdtime_t timeout) { CDTIME_T_TO_DOUBLE(timeout)); now = cdtime(); - timeout = TIME_T_TO_CDTIME_T(timeout); /* Build a list of entries to be flushed */ iter = c_avl_get_iterator(cache); @@ -606,9 +605,6 @@ static int rrd_cache_flush_identifier(cdtime_t timeout, } /* int rrd_cache_flush_identifier */ static int64_t rrd_get_random_variation(void) { - long min; - long max; - if (random_timeout == 0) return (0); @@ -619,10 +615,7 @@ static int64_t rrd_get_random_variation(void) { random_timeout = cache_timeout; } - max = (long)(random_timeout / 2); - min = max - ((long)random_timeout); - - return ((int64_t)cdrand_range(min, max)); + return (int64_t)cdrand_range(-random_timeout, random_timeout); } /* int64_t rrd_get_random_variation */ static int rrd_cache_insert(const char *filename, const char *value, @@ -740,7 +733,7 @@ static int rrd_cache_insert(const char *filename, const char *value, if ((cache_timeout > 0) && ((cdtime() - cache_flush_last) > cache_flush_timeout)) - rrd_cache_flush(cache_flush_timeout); + rrd_cache_flush(cache_timeout); pthread_mutex_unlock(&cache_lock); @@ -885,7 +878,7 @@ static int rrd_config(const char *key, const char *value) { "be greater than 0.\n"); return (1); } - cache_flush_timeout = tmp; + cache_flush_timeout = TIME_T_TO_CDTIME_T(tmp); } else if (strcasecmp("DataDir", key) == 0) { char *tmp; size_t len; @@ -1066,8 +1059,14 @@ static int rrd_init(void) { cache_flush_last = cdtime(); if (cache_timeout == 0) { cache_flush_timeout = 0; - } else if (cache_flush_timeout < cache_timeout) + } else if (cache_flush_timeout < cache_timeout) { + INFO("rrdtool plugin: \"CacheFlush %u\" is less than \"CacheTimeout %u\". " + "Ajusting \"CacheFlush\" to %u seconds.", + (unsigned int)CDTIME_T_TO_TIME_T(cache_flush_timeout), + (unsigned int)CDTIME_T_TO_TIME_T(cache_timeout), + (unsigned int)CDTIME_T_TO_TIME_T(cache_timeout * 10)); cache_flush_timeout = 10 * cache_timeout; + } pthread_mutex_unlock(&cache_lock);