X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=4655b96ee77c79a74dca16f9f412bd2df55d3cd7;hb=66f9d645f883eee0aa408428eefdebdcc6dcfa7e;hp=ee5d70c8255ed7631e1c6f770ce5b74b7f5fd5f2;hpb=08597c4e80e8dd5d0a04c823b055ef230194a2b6;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index ee5d70c8..4655b96e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -432,11 +432,6 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) sfree (queue_entry); } /* while (42) */ - pthread_mutex_lock (&cache_lock); - c_avl_destroy (cache); - cache = NULL; - pthread_mutex_unlock (&cache_lock); - pthread_exit ((void *) 0); return ((void *) 0); } /* void *rrd_queue_thread */ @@ -676,6 +671,7 @@ static int rrd_cache_insert (const char *filename, rc->values = NULL; rc->first_value = 0; rc->last_value = 0; + rc->random_variation = 0; rc->flags = FLAG_NONE; new_rc = 1; } @@ -683,7 +679,7 @@ static int rrd_cache_insert (const char *filename, if (rc->last_value >= value_time) { pthread_mutex_unlock (&cache_lock); - WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)", + DEBUG ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)", (unsigned int) rc->last_value, (unsigned int) value_time); return (-1); @@ -785,6 +781,59 @@ static int rrd_cache_insert (const char *filename, return (0); } /* int rrd_cache_insert */ +static int rrd_cache_destroy (void) /* {{{ */ +{ + void *key = NULL; + void *value = NULL; + + int non_empty = 0; + + pthread_mutex_lock (&cache_lock); + + if (cache == NULL) + { + pthread_mutex_unlock (&cache_lock); + return (0); + } + + while (c_avl_pick (cache, &key, &value) == 0) + { + rrd_cache_t *rc; + int i; + + sfree (key); + key = NULL; + + rc = value; + value = NULL; + + if (rc->values_num > 0) + non_empty++; + + for (i = 0; i < rc->values_num; i++) + sfree (rc->values[i]); + sfree (rc->values); + sfree (rc); + } + + c_avl_destroy (cache); + cache = NULL; + + if (non_empty > 0) + { + INFO ("rrdtool plugin: %i cache %s had values when destroying the cache.", + non_empty, (non_empty == 1) ? "entry" : "entries"); + } + else + { + DEBUG ("rrdtool plugin: No values have been lost " + "when destroying the cache."); + } + + pthread_mutex_unlock (&cache_lock); + return (0); +} /* }}} int rrd_cache_destroy */ + static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr) { int a = *((int *) a_ptr); @@ -806,6 +855,9 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl, char values[512]; int status; + if (do_shutdown) + return (0); + if (0 != strcmp (ds->type, vl->type)) { ERROR ("rrdtool plugin: DS type does not match value list type"); return -1; @@ -1062,7 +1114,7 @@ static int rrd_shutdown (void) DEBUG ("rrdtool plugin: queue_thread exited."); } - /* TODO: Maybe it'd be a good idea to free the cache here.. */ + rrd_cache_destroy (); return (0); } /* int rrd_shutdown */