Merge branch 'collectd-4.1' into collectd-4.2
[collectd.git] / src / rrdtool.c
index 77d8716..e356bf1 100644 (file)
@@ -24,6 +24,8 @@
 #include "common.h"
 #include "utils_avltree.h"
 
+#include <rrd.h>
+
 #if HAVE_PTHREAD_H
 # include <pthread.h>
 #endif
@@ -652,6 +654,8 @@ static void *rrd_queue_thread (void *data)
 
                /* Write the values to the RRD-file */
                srrd_update (queue_entry->filename, NULL, values_num, values);
+               DEBUG ("rrdtool plugin: queue thread: Wrote %i values to %s",
+                               values_num, queue_entry->filename);
 
                for (i = 0; i < values_num; i++)
                {
@@ -722,8 +726,6 @@ static void rrd_cache_flush (int timeout)
        iter = avl_get_iterator (cache);
        while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
        {
-               DEBUG ("key = %s; age = %i;", key, now - rc->first_value);
-
                if (rc->flags == FLAG_QUEUED)
                        continue;
                else if ((now - rc->first_value) < timeout)
@@ -859,8 +861,10 @@ static int rrd_cache_insert (const char *filename,
                avl_insert (cache, cache_key, rc);
        }
 
-       DEBUG ("rrd_cache_insert (%s, %s, %u) = %p", filename, value,
-                       (unsigned int) value_time, (void *) rc);
+       DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
+                       "values_num = %i; age = %u;",
+                       filename, rc->values_num,
+                       rc->last_value - rc->first_value);
 
        if ((rc->last_value - rc->first_value) >= cache_timeout)
        {
@@ -1051,6 +1055,11 @@ static int rrd_shutdown (void)
        rrd_cache_flush (-1);
        pthread_mutex_unlock (&cache_lock);
 
+       pthread_mutex_lock (&queue_lock);
+       do_shutdown = 1;
+       pthread_cond_signal (&queue_cond);
+       pthread_mutex_unlock (&queue_lock);
+
        /* Wait for all the values to be written to disk before returning. */
        if (queue_thread != 0)
        {
@@ -1059,11 +1068,6 @@ static int rrd_shutdown (void)
                DEBUG ("rrdtool plugin: queue_thread exited.");
        }
 
-       pthread_mutex_lock (&queue_lock);
-       do_shutdown = 1;
-       pthread_cond_signal (&queue_cond);
-       pthread_mutex_unlock (&queue_lock);
-
        return (0);
 } /* int rrd_shutdown */