#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
+#include "utils_random.h"
#include "utils_rrdcreate.h"
#include <rrd.h>
{
"CacheTimeout",
"CacheFlush",
+ "CreateFilesAsync",
"DataDir",
"StepSize",
"HeartBeat",
/* timespans_num = */ 0,
/* consolidation_functions = */ NULL,
- /* consolidation_functions_num = */ 0
+ /* consolidation_functions_num = */ 0,
+
+ /* async = */ 0
};
/* XXX: If you need to lock both, cache_lock and queue_lock, at the same time,
if (datadir != NULL)
{
- size_t datadir_len = strlen (datadir);
+ size_t datadir_len = strlen (datadir) + 1;
if (datadir_len >= buffer_size)
return (ENOMEM);
sstrncpy (buffer, datadir, buffer_size);
+ buffer[datadir_len - 1] = '/';
+ buffer[datadir_len] = 0;
+
buffer += datadir_len;
buffer_size -= datadir_len;
}
static int64_t rrd_get_random_variation (void)
{
- double dbl_timeout;
- cdtime_t ctm_timeout;
- double rand_fact;
- _Bool negative;
- int64_t ret;
+ long min;
+ long max;
if (random_timeout <= 0)
return (0);
random_timeout = cache_timeout;
}
- /* This seems a bit complicated, but "random_timeout" is likely larger than
- * RAND_MAX, so we can't simply use modulo here. */
- dbl_timeout = CDTIME_T_TO_DOUBLE (random_timeout);
- rand_fact = ((double) random ())
- / ((double) RAND_MAX);
- negative = (_Bool) (random () % 2);
-
- ctm_timeout = DOUBLE_TO_CDTIME_T (dbl_timeout * rand_fact);
-
- ret = (int64_t) ctm_timeout;
- if (negative)
- ret *= -1;
+ max = (long) (random_timeout / 2);
+ min = max - ((long) random_timeout);
- return (ret);
+ return ((int64_t) cdrand_range (min, max));
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert (const char *filename,
ds, vl, &rrdcreate_config);
if (status != 0)
return (-1);
+ else if (rrdcreate_config.async)
+ return (0);
}
else
{
if (temp > 0)
rrdcreate_config.heartbeat = temp;
}
+ else if (strcasecmp ("CreateFilesAsync", key) == 0)
+ {
+ if (IS_TRUE (value))
+ rrdcreate_config.async = 1;
+ else
+ rrdcreate_config.async = 0;
+ }
else if (strcasecmp ("RRARows", key) == 0)
{
int tmp = atoi (value);