simplified renaming of variables, due to dimension renames
Costa Tsaousis (ktsaou) committed
Nov 12, 2016 at 20:34 UTC
23247d6fcc3ce24a9aebbc902d875aee8932f9ea
1 file changed
+92
-80
src/health.c
+92
-80
@@ -699,19 +699,72 @@ void rrdsetvar_free(RRDSETVAR *rs) {
699
700
#define RRDDIMVAR_ID_MAX 1024
701
702
-RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options) {
702
+static inline void rrddimvar_free_instances(RRDDIMVAR *rs) {
703
+ RRDDIM *rd = rs->rrddim;
704
RRDSET *st = rd->rrdset;
705
705
- 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:"");
706
+ rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_id);
707
+ rs->local_id = NULL;
708
707
- if(!prefix) prefix = "";
708
- if(!suffix) suffix = "";
709
+ rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_name);
710
+ rs->local_name = NULL;
711
710
- char buffer[RRDDIMVAR_ID_MAX + 1];
711
- RRDDIMVAR *rs = (RRDDIMVAR *)callocz(1, sizeof(RRDDIMVAR));
712
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_id);
713
+ rs->family_id = NULL;
714
713
- rs->prefix = strdupz(prefix);
714
- rs->suffix = strdupz(suffix);
715
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
716
+ rs->family_name = NULL;
717
+
718
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextid);
719
+ rs->family_contextid = NULL;
720
+
721
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextname);
722
+ rs->family_contextname = NULL;
723
+
724
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidid);
725
+ rs->host_fullidid = NULL;
726
+
727
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidname);
728
+ rs->host_fullidname = NULL;
729
+
730
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnameid);
731
+ rs->host_fullnameid = NULL;
732
+
733
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnamename);
734
+ rs->host_fullnamename = NULL;
735
+
736
+ freez(rs->id);
737
+ rs->id = NULL;
738
+
739
+ freez(rs->name);
740
+ rs->name = NULL;
741
+
742
+ freez(rs->fullidid);
743
+ rs->fullidid = NULL;
744
+
745
+ freez(rs->fullidname);
746
+ rs->fullidname = NULL;
747
+
748
+ freez(rs->contextid);
749
+ rs->contextid = NULL;
750
+
751
+ freez(rs->contextname);
752
+ rs->contextname = NULL;
753
+
754
+ freez(rs->fullnameid);
755
+ rs->fullnameid = NULL;
756
+
757
+ freez(rs->fullnamename);
758
+ rs->fullnamename = NULL;
759
+}
760
+
761
+static inline void rrddimvar_create_instances(RRDDIMVAR *rs) {
762
+ rrddimvar_free_instances(rs);
763
+
764
+ RRDDIM *rd = rs->rrddim;
765
+ RRDSET *st = rd->rrdset;
766
+
767
+ char buffer[RRDDIMVAR_ID_MAX + 1];
768
769
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->id, rs->suffix);
770
rs->id = strdupz(buffer);
@@ -719,29 +772,24 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
772
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->name, rs->suffix);
773
rs->name = strdupz(buffer);
774
722
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->id, rs->id);
775
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->id);
776
rs->fullidid = strdupz(buffer);
777
725
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->id, rs->name);
778
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->name);
779
rs->fullidname = strdupz(buffer);
780
728
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->context, rs->id);
781
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->id);
782
rs->contextid = strdupz(buffer);
783
731
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->context, rs->name);
784
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->name);
785
rs->contextname = strdupz(buffer);
786
734
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->name, rs->id);
787
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->id);
788
rs->fullnameid = strdupz(buffer);
789
737
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->name, rs->name);
790
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->name);
791
rs->fullnamename = strdupz(buffer);
792
740
- rs->type = type;
741
- rs->value = value;
742
- rs->options = options;
743
- rs->rrddim = rd;
744
-
793
rs->local_id = rrdvar_create_and_index("local", &st->variables_root_index, rs->id, rs->type, rs->value);
794
rs->local_name = rrdvar_create_and_index("local", &st->variables_root_index, rs->name, rs->type, rs->value);
795
@@ -754,10 +802,32 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
802
rs->host_fullidname = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullidname, rs->type, rs->value);
803
rs->host_fullnameid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnameid, rs->type, rs->value);
804
rs->host_fullnamename = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnamename, rs->type, rs->value);
805
+}
806
+
807
+
808
+RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options) {
809
+ RRDSET *st = rd->rrdset;
810
+
811
+ 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:"");
812
+
813
+ if(!prefix) prefix = "";
814
+ if(!suffix) suffix = "";
815
+
816
+ RRDDIMVAR *rs = (RRDDIMVAR *)callocz(1, sizeof(RRDDIMVAR));
817
+
818
+ rs->prefix = strdupz(prefix);
819
+ rs->suffix = strdupz(suffix);
820
+
821
+ rs->type = type;
822
+ rs->value = value;
823
+ rs->options = options;
824
+ rs->rrddim = rd;
825
826
rs->next = rd->variables;
827
rd->variables = rs;
828
829
+ rrddimvar_create_instances(rs);
830
+
831
return rs;
832
}
833
@@ -769,47 +839,8 @@ void rrddimvar_rename_all(RRDDIM *rd) {
839
while((rs = next)) {
840
next = rs->next;
841
772
- if (strcmp(rd->name, rs->name)) {
773
- char buffer[RRDDIMVAR_ID_MAX + 1];
774
- // name changed
775
-
776
- // name and family name
777
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_name);
778
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
779
- freez(rs->name);
780
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->name, rs->suffix);
781
- rs->name = strdupz(buffer);
782
- rs->local_name = rrdvar_create_and_index("local", &st->variables_root_index, rs->name, rs->type, rs->value);
783
- rs->family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->name, rs->type, rs->value);
784
-
785
- // family_contextname
786
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->family_contextname);
787
- freez(rs->contextname);
788
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", rd->rrdset->context, rs->name);
789
- rs->contextname = strdupz(buffer);
790
- rs->family_contextname = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->contextname, rs->type, rs->value);
791
-
792
- // fullidname
793
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidname);
794
- freez(rs->fullidname);
795
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->name);
796
- rs->fullidname = strdupz(buffer);
797
- rs->host_fullidname = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullidname, rs->type, rs->value);
798
-
799
- // fullnameid
800
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnameid);
801
- freez(rs->fullnameid);
802
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->id);
803
- rs->fullnameid = strdupz(buffer);
804
- rs->host_fullnameid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnameid, rs->type, rs->value);
805
-
806
- // fullnamename
807
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnamename);
808
- freez(rs->fullnamename);
809
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->name);
810
- rs->fullnamename = strdupz(buffer);
811
- rs->host_fullnamename = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnamename, rs->type, rs->value);
812
- }
842
+ if (strcmp(rd->name, rs->name))
843
+ rrddimvar_create_instances(rs);
844
}
845
}
846
@@ -818,18 +849,7 @@ void rrddimvar_free(RRDDIMVAR *rs) {
849
RRDSET *st = rd->rrdset;
850
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);
851
821
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_id);
822
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_name);
823
-
824
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_id);
825
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
826
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextid);
827
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextname);
828
-
829
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidid);
830
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidname);
831
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnameid);
832
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnamename);
852
+ rrddimvar_free_instances(rs);
853
854
if(rd->variables == rs) {
855
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);
@@ -845,14 +865,6 @@ void rrddimvar_free(RRDDIMVAR *rs) {
865
866
freez(rs->prefix);
867
freez(rs->suffix);
848
- freez(rs->id);
849
- freez(rs->name);
850
- freez(rs->contextid);
851
- freez(rs->contextname);
852
- freez(rs->fullidid);
853
- freez(rs->fullidname);
854
- freez(rs->fullnameid);
855
- freez(rs->fullnamename);
868
freez(rs);
869
}
870