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;
}
RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm)
{
+ RRDDIM *rd = rrddim_find(st, id);
+ if(rd) {
+ debug(D_RRD_CALLS, "Cannot create rrd dimension '%s/%s', it already exists.", st->id, name?name:"<NONAME>");
+ return rd;
+ }
+
char filename[FILENAME_MAX + 1];
char fullfilename[FILENAME_MAX + 1];
char varname[CONFIG_MAX_NAME + 1];
- RRDDIM *rd = NULL;
unsigned long size = sizeof(RRDDIM) + (st->entries * sizeof(storage_number));
debug(D_RRD_CALLS, "Adding dimension '%s/%s'.", st->id, id);
rrdset_strncpyz_name(filename, id, FILENAME_MAX);
snprintfz(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
- if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 1);
+
+ if(rrd_memory_mode != RRD_MEMORY_MODE_RAM)
+ rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 1);
+
if(rd) {
struct timeval now;
now_realtime_timeval(&now);
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);
}
RRDSET *st;
RRDDIM *rd;
+ // 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_wrlock(&st->rwlock);
+ pthread_rwlock_rdlock(&st->rwlock);
if(st->mapped == RRD_MEMORY_MODE_SAVE) {
debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename);
pthread_rwlock_unlock(&st->rwlock);
}
+
rrdhost_unlock(&localhost);
}
}
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