]> arthur.barton.de Git - netdata.git/commitdiff
ensure only one thread is saving the db at a time
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 14 Jan 2017 12:29:25 +0000 (14:29 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 14 Jan 2017 12:29:25 +0000 (14:29 +0200)
src/rrd.c

index 16375c579b94f914acf78bd2df0cb7f2a19f574b..27e8e6b235620fe004ee371ec7e1108f08fd9c1b 100644 (file)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -902,7 +902,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);
 
@@ -920,6 +923,7 @@ void rrdset_save_all(void) {
 
         pthread_rwlock_unlock(&st->rwlock);
     }
+
     rrdhost_unlock(&localhost);
 }