]> arthur.barton.de Git - netdata.git/blobdiff - src/rrd.c
Add missing comma to demosites.html
[netdata.git] / src / rrd.c
index 365ad87624edd24d7fba6118dee66273e9ecad65..a17704394165246919c0c7b4783198a5b7487256 100644 (file)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -302,9 +302,9 @@ int rrd_memory_mode_id(const char *name)
 
 int rrddim_algorithm_id(const char *name)
 {
-    if(strcmp(name, RRDDIM_INCREMENTAL_NAME) == 0)          return RRDDIM_INCREMENTAL;
-    if(strcmp(name, RRDDIM_ABSOLUTE_NAME) == 0)             return RRDDIM_ABSOLUTE;
-    if(strcmp(name, RRDDIM_PCENT_OVER_ROW_TOTAL_NAME) == 0)         return RRDDIM_PCENT_OVER_ROW_TOTAL;
+    if(strcmp(name, RRDDIM_INCREMENTAL_NAME) == 0)              return RRDDIM_INCREMENTAL;
+    if(strcmp(name, RRDDIM_ABSOLUTE_NAME) == 0)                 return RRDDIM_ABSOLUTE;
+    if(strcmp(name, RRDDIM_PCENT_OVER_ROW_TOTAL_NAME) == 0)     return RRDDIM_PCENT_OVER_ROW_TOTAL;
     if(strcmp(name, RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME) == 0)    return RRDDIM_PCENT_OVER_DIFF_TOTAL;
     return RRDDIM_ABSOLUTE;
 }
@@ -392,19 +392,11 @@ char *rrdset_cache_dir(const char *id)
 {
     char *ret = NULL;
 
-    static char *cache_dir = NULL;
-    if(!cache_dir) {
-        cache_dir = config_get("global", "cache directory", CACHE_DIR);
-        int r = mkdir(cache_dir, 0755);
-        if(r != 0 && errno != EEXIST)
-            error("Cannot create directory '%s'", cache_dir);
-    }
-
     char b[FILENAME_MAX + 1];
     char n[FILENAME_MAX + 1];
     rrdset_strncpyz_name(b, id, FILENAME_MAX);
 
-    snprintfz(n, FILENAME_MAX, "%s/%s", cache_dir, b);
+    snprintfz(n, FILENAME_MAX, "%s/%s", netdata_configured_cache_dir, b);
     ret = config_get(id, "cache directory", n);
 
     if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
@@ -485,7 +477,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
 
     RRDSET *st = rrdset_find(fullid);
     if(st) {
-        error("Cannot create rrd stats for '%s', it already exists.", fullid);
+        debug(D_RRD_CALLS, "RRDSET '%s', already exists.", fullid);
         return st;
     }
 
@@ -650,7 +642,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
 {
     RRDDIM *rd = rrddim_find(st, id);
     if(rd) {
-        error("Cannot create rrd dimension '%s/%s', it already exists.", st->id, name);
+        debug(D_RRD_CALLS, "Cannot create rrd dimension '%s/%s', it already exists.", st->id, name?name:"<NONAME>");
         return rd;
     }
 
@@ -692,11 +684,6 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
             error("File %s does not have the same divisor. Clearing it.", fullfilename);
             memset(rd, 0, size);
         }
-        else if(rd->algorithm != algorithm) {
-            errno = 0;
-            error("File %s does not have the same algorithm. Clearing it.", fullfilename);
-            memset(rd, 0, size);
-        }
         else if(rd->update_every != st->update_every) {
             errno = 0;
             error("File %s does not have the same refresh frequency. Clearing it.", fullfilename);
@@ -714,6 +701,9 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
             // rd = NULL;
             memset(rd, 0, size);
         }
+
+        if(rd->algorithm && rd->algorithm != algorithm)
+            error("File %s does not have the expected algorithm (expected %d '%s', found %d '%s'). Previous values may be wrong.", fullfilename, algorithm, rrddim_algorithm_name(algorithm), rd->algorithm, rrddim_algorithm_name(rd->algorithm));
     }
 
     if(rd) {
@@ -880,14 +870,7 @@ void rrdset_free_all(void)
 
         pthread_rwlock_unlock(&st->rwlock);
 
-        if(st->mapped == RRD_MEMORY_MODE_SAVE) {
-            debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename);
-            savememory(st->cache_filename, st, st->memsize);
-
-            debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name);
-            munmap(st, st->memsize);
-        }
-        else if(st->mapped == RRD_MEMORY_MODE_MAP) {
+        if(st->mapped == RRD_MEMORY_MODE_SAVE || st->mapped == RRD_MEMORY_MODE_MAP) {
             debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name);
             munmap(st, st->memsize);
         }
@@ -909,7 +892,10 @@ void rrdset_save_all(void) {
     RRDSET *st;
     RRDDIM *rd;
 
-    rrdhost_rdlock(&localhost);
+    // we get an write lock
+    // to ensure only one thread is saving the database
+    rrdhost_rwlock(&localhost);
+
     for(st = localhost.rrdset_root; st ; st = st->next) {
         pthread_rwlock_rdlock(&st->rwlock);
 
@@ -927,6 +913,7 @@ void rrdset_save_all(void) {
 
         pthread_rwlock_unlock(&st->rwlock);
     }
+
     rrdhost_unlock(&localhost);
 }
 
@@ -1045,8 +1032,10 @@ void rrdset_next_usec(RRDSET *st, usec_t microseconds)
     }
     else {
         // microseconds has the time since the last collection
+#ifdef NETDATA_INTERNAL_CHECKS
         usec_t now_usec = timeval_usec(&now);
         usec_t last_usec = timeval_usec(&st->last_collected_time);
+#endif
         usec_t since_last_usec = dt_usec(&now, &st->last_collected_time);
 
         // verify the microseconds given is good