@cryptotaxi247 / netdata-1 / commits / 308c6c24b

chart and dimension variables tested and debugged

Costa Tsaousis committed Aug 7, 2016 at 22:12 UTC 308c6c24b914e0f22486e4c123a8089564a47d00
5 files changed +78 -30
src/health.c
+58 -24
@@ -46,6 +46,7 @@ static inline RRDVAR *rrdvar_create(const char *name, uint32_t hash, int type, c
46 }
47
48 static inline void rrdvar_free(RRDVAR *rv) {
49 + // FIXME: find all references of this and NULL them.
50 free(rv);
51 }
52
@@ -64,6 +65,24 @@ static inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *
65 else
66 debug(D_VARIABLES, "Variable '%s' created in scope '%s'", name, scope);
67 }
68 + else {
69 + // already exists
70 + rv = NULL;
71 + }
72 +
73 + /*
74 + * check
75 + if(rv) {
76 + RRDVAR *ret = rrdvar_index_find(tree, name, hash);
77 + if(ret != rv) fatal("oops! 1");
78 +
79 + ret = rrdvar_index_del(tree, rv);
80 + if(ret != rv) fatal("oops! 2");
81 +
82 + ret = rrdvar_index_add(tree, rv);
83 + if(ret != rv) fatal("oops! 3");
84 + }
85 + */
86
87 return rv;
88 }
@@ -74,16 +93,17 @@ static inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *
93 #define RRDSETVAR_ID_MAX 1024
94
95 RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
96 + debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
97 RRDSETVAR *rs = (RRDSETVAR *)calloc(1, sizeof(RRDSETVAR));
98 if(!rs) fatal("Cannot allocate memory for RRDSETVAR");
99
100 char buffer[RRDSETVAR_ID_MAX + 1];
81 - snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s.%s", st->type, st->id, variable);
101 + snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s", st->id, variable);
102 rs->fullid = strdup(buffer);
103 if(!rs->fullid) fatal("Cannot allocate memory for RRDVASET id");
104 rs->hash_fullid = simple_hash(rs->fullid);
105
86 - snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s.%s", st->type, st->name, variable);
106 + snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s", st->name, variable);
107 rs->fullname = strdup(buffer);
108 if(!rs->fullname) fatal("Cannot allocate memory for RRDVASET name");
109 rs->hash_fullname = simple_hash(rs->fullname);
@@ -95,6 +115,7 @@ RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *va
115 rs->type = type;
116 rs->value = value;
117 rs->options = options;
118 + rs->rrdset = st;
119
120 rs->local = rrdvar_create_and_index("local", &st->variables_root_index, rs->variable, rs->hash_variable, rs->type, rs->value);
121 rs->context = rrdvar_create_and_index("context", &st->rrdcontext->variables_root_index, rs->fullid, rs->hash_fullid, rs->type, rs->value);
@@ -109,6 +130,8 @@ RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *va
130 }
131
132 void rrdsetvar_rename_all(RRDSET *st) {
133 + debug(D_VARIABLES, "RRDSETVAR rename for chart id '%s' name '%s'", st->id, st->name);
134 +
135 // only these 2 can change name
136 // rs->context_name
137 // rs->host_name
@@ -118,7 +141,7 @@ void rrdsetvar_rename_all(RRDSET *st) {
141 while((rs = next)) {
142 next = rs->next;
143
121 - snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s.%s", st->type, st->name, rs->variable);
144 + snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s", st->name, rs->variable);
145
146 if (strcmp(buffer, rs->fullname)) {
147 // name changed
@@ -144,6 +167,7 @@ void rrdsetvar_rename_all(RRDSET *st) {
167
168 void rrdsetvar_free(RRDSETVAR *rs) {
169 RRDSET *st = rs->rrdset;
170 + debug(D_VARIABLES, "RRDSETVAR free for chart id '%s' name '%s', variable '%s'", st->id, st->name, rs->variable);
171
172 if(rs->local) {
173 rrdvar_index_del(&st->variables_root_index, rs->local);
@@ -194,6 +218,8 @@ void rrdsetvar_free(RRDSETVAR *rs) {
218 RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options) {
219 RRDSET *st = rd->rrdset;
220
221 + debug(D_VARIABLES, "RRDDIMSET create for chart id '%s' name '%s', dimension id '%s', name '%s%s%s'", st->id, st->name, rd->id, (prefix)?prefix:"", rd->name, (suffix)?suffix:"");
222 +
223 if(!prefix) prefix = "";
224 if(!suffix) suffix = "";
225
@@ -217,22 +243,22 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
243 if(!rs->name) fatal("Cannot allocate memory for RRDIM name");
244 rs->hash_name = simple_hash(rs->name);
245
220 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", rd->rrdset->type, rd->rrdset->id, rs->id);
246 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->id, rs->id);
247 rs->fullidid = strdup(buffer);
248 if(!rs->fullidid) fatal("Cannot allocate memory for RRDDIMVAR fullidid");
249 rs->hash_fullidid = simple_hash(rs->fullidid);
250
225 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", rd->rrdset->type, rd->rrdset->id, rs->name);
251 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->id, rs->name);
252 rs->fullidname = strdup(buffer);
253 if(!rs->fullidname) fatal("Cannot allocate memory for RRDDIMVAR fullidname");
254 rs->hash_fullidname = simple_hash(rs->fullidname);
255
230 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", rd->rrdset->type, rd->rrdset->name, rs->id);
256 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->name, rs->id);
257 rs->fullnameid = strdup(buffer);
258 if(!rs->fullnameid) fatal("Cannot allocate memory for RRDDIMVAR fullnameid");
259 rs->hash_fullnameid = simple_hash(rs->fullnameid);
260
235 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", rd->rrdset->type, rd->rrdset->name, rs->name);
261 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->name, rs->name);
262 rs->fullnamename = strdup(buffer);
263 if(!rs->fullnamename) fatal("Cannot allocate memory for RRDDIMVAR fullnamename");
264 rs->hash_fullnamename = simple_hash(rs->fullnamename);
@@ -240,6 +266,7 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
266 rs->type = type;
267 rs->value = value;
268 rs->options = options;
269 + rs->rrddim = rd;
270
271 rs->local_id = rrdvar_create_and_index("local", &st->variables_root_index, rs->id, rs->hash, rs->type, rs->value);
272 rs->local_name = rrdvar_create_and_index("local", &st->variables_root_index, rs->name, rs->hash_name, rs->type, rs->value);
@@ -262,6 +289,7 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
289
290 void rrddimvar_rename_all(RRDDIM *rd) {
291 RRDSET *st = rd->rrdset;
292 + debug(D_VARIABLES, "RRDDIMSET rename for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
293
294 RRDDIMVAR *rs, *next = rd->variables;
295 while((rs = next)) {
@@ -293,7 +321,7 @@ void rrddimvar_rename_all(RRDDIM *rd) {
321 rrdvar_free(rs->host_fullidname);
322 }
323 free(rs->fullidname);
296 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", st->type, st->id, rs->name);
324 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->name);
325 rs->fullidname = strdup(buffer);
326 if(!rs->fullidname) fatal("Cannot allocate memory for RRDDIMVAR fullidname");
327 rs->hash_fullidname = simple_hash(rs->fullidname);
@@ -312,7 +340,7 @@ void rrddimvar_rename_all(RRDDIM *rd) {
340 rrdvar_free(rs->host_fullnameid);
341 }
342 free(rs->fullnameid);
315 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", st->type, st->name, rs->id);
343 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->id);
344 rs->fullnameid = strdup(buffer);
345 if(!rs->fullnameid) fatal("Cannot allocate memory for RRDDIMVAR fullnameid");
346 rs->hash_fullnameid = simple_hash(rs->fullnameid);
@@ -331,7 +359,7 @@ void rrddimvar_rename_all(RRDDIM *rd) {
359 rrdvar_free(rs->host_fullnamename);
360 }
361 free(rs->fullnamename);
334 - snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s.%s", st->type, st->name, rs->name);
362 + snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->name);
363 rs->fullnamename = strdup(buffer);
364 if(!rs->fullnamename) fatal("Cannot allocate memory for RRDDIMVAR fullnamename");
365 rs->hash_fullnamename = simple_hash(rs->fullnamename);
@@ -344,56 +372,62 @@ void rrddimvar_rename_all(RRDDIM *rd) {
372 }
373
374 void rrddimvar_free(RRDDIMVAR *rs) {
375 + RRDDIM *rd = rs->rrddim;
376 + RRDSET *st = rd->rrdset;
377 + debug(D_VARIABLES, "RRDDIMSET free for chart id '%s' name '%s', dimension id '%s', name '%s', prefix='%s', suffix='%s'", st->id, st->name, rd->id, rd->name, rs->prefix, rs->suffix);
378 +
379 if(rs->local_id) {
348 - rrdvar_index_del(&rs->rrddim->rrdset->variables_root_index, rs->local_id);
380 + rrdvar_index_del(&st->variables_root_index, rs->local_id);
381 rrdvar_free(rs->local_id);
382 }
383 if(rs->local_name) {
352 - rrdvar_index_del(&rs->rrddim->rrdset->variables_root_index, rs->local_name);
384 + rrdvar_index_del(&st->variables_root_index, rs->local_name);
385 rrdvar_free(rs->local_name);
386 }
387
388 if(rs->context_fullidid) {
357 - rrdvar_index_del(&rs->rrddim->rrdset->rrdcontext->variables_root_index, rs->context_fullidid);
389 + rrdvar_index_del(&st->rrdcontext->variables_root_index, rs->context_fullidid);
390 rrdvar_free(rs->context_fullidid);
391 }
392 if(rs->context_fullidname) {
361 - rrdvar_index_del(&rs->rrddim->rrdset->rrdcontext->variables_root_index, rs->context_fullidname);
393 + rrdvar_index_del(&st->rrdcontext->variables_root_index, rs->context_fullidname);
394 rrdvar_free(rs->context_fullidname);
395 }
396 if(rs->context_fullnameid) {
365 - rrdvar_index_del(&rs->rrddim->rrdset->rrdcontext->variables_root_index, rs->context_fullnameid);
397 + rrdvar_index_del(&st->rrdcontext->variables_root_index, rs->context_fullnameid);
398 rrdvar_free(rs->context_fullnameid);
399 }
400 if(rs->context_fullnamename) {
369 - rrdvar_index_del(&rs->rrddim->rrdset->rrdcontext->variables_root_index, rs->context_fullnamename);
401 + rrdvar_index_del(&st->rrdcontext->variables_root_index, rs->context_fullnamename);
402 rrdvar_free(rs->context_fullnamename);
403 }
404
405 if(rs->host_fullidid) {
374 - rrdvar_index_del(&rs->rrddim->rrdset->rrdhost->variables_root_index, rs->host_fullidid);
406 + rrdvar_index_del(&st->rrdhost->variables_root_index, rs->host_fullidid);
407 rrdvar_free(rs->host_fullidid);
408 }
409 if(rs->host_fullidname) {
378 - rrdvar_index_del(&rs->rrddim->rrdset->rrdhost->variables_root_index, rs->host_fullidname);
410 + rrdvar_index_del(&st->rrdhost->variables_root_index, rs->host_fullidname);
411 rrdvar_free(rs->host_fullidname);
412 }
413 if(rs->host_fullnameid) {
382 - rrdvar_index_del(&rs->rrddim->rrdset->rrdhost->variables_root_index, rs->host_fullnameid);
414 + rrdvar_index_del(&st->rrdhost->variables_root_index, rs->host_fullnameid);
415 rrdvar_free(rs->host_fullnameid);
416 }
417 if(rs->host_fullnamename) {
386 - rrdvar_index_del(&rs->rrddim->rrdset->rrdhost->variables_root_index, rs->host_fullnamename);
418 + rrdvar_index_del(&st->rrdhost->variables_root_index, rs->host_fullnamename);
419 rrdvar_free(rs->host_fullnamename);
420 }
421
390 - if(rs->rrddim->variables == rs) {
391 - rs->rrddim->variables = rs->next;
422 + if(rd->variables == rs) {
423 + debug(D_VARIABLES, "RRDDIMSET removing first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
424 + rd->variables = rs->next;
425 }
426 else {
427 + debug(D_VARIABLES, "RRDDIMSET removing non-first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
428 RRDDIMVAR *t;
395 - for (t = rs->rrddim->variables; t && t->next != rs; t = t->next);
396 - if(!t) error("RRDDIMVAR '%s' not found in dimension '%s.%s/%s' variables linked list", rs->name, rs->rrddim->rrdset->type, rs->rrddim->rrdset->id, rs->rrddim->id);
429 + for (t = rd->variables; t && t->next != rs; t = t->next) ;
430 + if(!t) error("RRDDIMVAR '%s' not found in dimension '%s/%s' variables linked list", rs->name, st->id, rd->id);
431 else t->next = rs->next;
432 }
433
src/log.c
+2
@@ -125,6 +125,8 @@ void debug_int( const char *file, const char *function, const unsigned long line
125 vsyslog(LOG_ERR, fmt, args );
126 va_end( args );
127 }
128 +
129 + fflush(stdout);
130 }
131
132 void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
src/main.c
+4
@@ -10,7 +10,11 @@ void netdata_cleanup_and_exit(int ret) {
10 error_log_limit_unlimited();
11
12 info("Called: netdata_cleanup_and_exit()");
13 +#ifdef NETDATA_INTERNAL_CHECKS
14 + rrdset_free_all();
15 +#else
16 rrdset_save_all();
17 +#endif
18 // kill_childs();
19
20 if(pidfile[0]) {
src/rrd.c
+13 -6
@@ -619,8 +619,6 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
619 }
620 rd->memsize = size;
621
622 - rd->rrdset = st;
623 -
622 strcpy(rd->magic, RRDDIMENSION_MAGIC);
623 strcpy(rd->cache_filename, fullfilename);
624 strncpyz(rd->id, id, RRD_ID_LENGTH_MAX);
@@ -654,8 +652,9 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
652 rd->values[st->current_entry] = pack_storage_number(0, SN_NOT_EXISTS);
653 rd->last_collected_time.tv_sec = 0;
654 rd->last_collected_time.tv_usec = 0;
655 + rd->rrdset = st;
656
658 - // append this dimension
657 + // append this dimension
658 pthread_rwlock_wrlock(&st->rwlock);
659 if(!st->dimensions)
660 st->dimensions = rd;
@@ -730,22 +729,28 @@ void rrdset_free_all(void)
729 {
730 info("Freeing all memory...");
731
732 + pthread_rwlock_wrlock(&localhost.rrdset_root_rwlock);
733 +
734 RRDSET *st;
735 for(st = localhost.rrdset_root; st ;) {
736 RRDSET *next = st->next;
737
737 - while(st->dimensions)
738 - rrddim_free(st, st->dimensions);
738 + pthread_rwlock_wrlock(&st->rwlock);
739
740 while(st->variables)
741 rrdsetvar_free(st->variables);
742
743 - rrdset_index_del(&localhost, st);
743 + while(st->dimensions)
744 + rrddim_free(st, st->dimensions);
745 +
746 + rrdset_index_del(&localhost, st);
747
748 st->rrdcontext->use_count--;
749 if(!st->rrdcontext->use_count)
750 rrdcontext_free(st->rrdcontext);
751
752 + pthread_rwlock_unlock(&st->rwlock);
753 +
754 if(st->mapped == RRD_MEMORY_MODE_SAVE) {
755 debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename);
756 savememory(st->cache_filename, st, st->memsize);
@@ -764,6 +769,8 @@ void rrdset_free_all(void)
769 }
770 localhost.rrdset_root = NULL;
771
772 + pthread_rwlock_unlock(&localhost.rrdset_root_rwlock);
773 +
774 info("Memory cleanup completed...");
775 }
776
src/web_client.c
+1
@@ -1844,6 +1844,7 @@ void web_client_process(struct web_client *w) {
1844 buffer_strcat(w->response.data, "I am doing it already");
1845
1846 error("web request to exit received.");
1847 + netdata_cleanup_and_exit(0);
1848 netdata_exit = 1;
1849 }
1850 else if(hash == hash_debug && strcmp(tok, "debug") == 0) {