]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix some commented out code to change RRD version when certain RRA
authorPeter Stamfest <peter@stamfest.at>
Sun, 2 Mar 2014 20:47:39 +0000 (21:47 +0100)
committerPeter Stamfest <peter@stamfest.at>
Sun, 2 Mar 2014 21:07:30 +0000 (22:07 +0100)
definitions require this.

src/rrd_create.c
src/rrd_create.h
src/rrd_modify.c

index 614d6a4d58aef1804134de302d9dd6c586392e76..1a2fb8dc799b041f06ee0b2cff9931dfac7d13d8 100644 (file)
@@ -189,6 +189,7 @@ int parseDS(const char *def,
 
 int parseRRA(const char *def,
             rra_def_t *rra_def, 
+            rrd_t *rrd,
             unsigned long hash) {
     char     *argvcopy;
     char     *tokptr = "";
@@ -196,6 +197,7 @@ int parseRRA(const char *def,
     int       cf_id = -1;
     int       token_min = 4;
     int       row_cnt;
+    char     *require_version = NULL;
 
     memset(rra_def, 0, sizeof(rra_def_t));
 
@@ -211,7 +213,7 @@ int parseRRA(const char *def,
            cf_id = cf_conv(rra_def->cf_nam);
            switch (cf_id) {
            case CF_MHWPREDICT:
-               // FIXME                strcpy(rrd.stat_head->version, RRD_VERSION);    /* MHWPREDICT causes Version 4 */
+               require_version = RRD_VERSION;    /* MHWPREDICT causes Version 4 */
            case CF_HWPREDICT:
                token_min = 5;
                /* initialize some parameters */
@@ -385,7 +387,7 @@ int parseRRA(const char *def,
                if (sscanf(token, "smoothing-window=%lf",
                           &(rra_def->par[RRA_seasonal_smoothing_window].
                             u_val))) {
-                   // FIXME                 strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing-window causes Version 4 */
+                   require_version = RRD_VERSION;    /* smoothing-window causes Version 4 */
                    if (rra_def->par[RRA_seasonal_smoothing_window].u_val < 0.0
                        || rra_def->par[RRA_seasonal_smoothing_window].u_val >
                        1.0) {
@@ -444,6 +446,15 @@ int parseRRA(const char *def,
        rrd_set_error("Expected at least %i arguments for RRA but got %i",token_min,token_idx);
        return(-1);
     }
+
+    // parsing went well. ONLY THEN are we allowed to produce
+    // additional side effects.
+    if (require_version != NULL) {
+        if (rrd) {
+            strcpy(rrd->stat_head->version, RRD_VERSION);
+        }
+    }
+
 #ifdef DEBUG
     fprintf(stderr,
            "Creating RRA CF: %s, dep idx %lu\n",
@@ -589,7 +600,7 @@ int rrd_create_r2(
                 return (-1);
             }
 
-           parseRRA(argv[i], rrd.rra_def + rrd.stat_head->rra_cnt,
+           parseRRA(argv[i], rrd.rra_def + rrd.stat_head->rra_cnt, &rrd,
                     hashed_name);
 
            if (rrd_test_error()) {
index 682931b2301c5b24d275488a5063cf360b752cab..52b7ebdd6d69cf92c86df3132bf439f1d8345d46 100644 (file)
@@ -17,8 +17,19 @@ int parseDS(const char *def,
            void *key_hash,
            long (*lookup)(void *, char *));
 
+/* Parse a textual RRA definition into rra_def. The rra_def might be
+   disconnected from any RRD. However, because some definitions cause
+   modifications to other parts of an RRD (like the version) it is
+   possible to pass the RRD that is about to hold the RRA. If the
+   definition really is to stay disconnected, it is permitted to pass
+   NULL to the rrd parameter.
+   The hash is a parameter to introduce some randomness to avoid 
+   potential performance problems when doing bulk updates to many RRDs
+   at once.
+*/
 int parseRRA(const char *def,
             rra_def_t *rra_def, 
+            rrd_t *rrd,
             unsigned long hash);
 
 rra_def_t *handle_dependent_rras(rra_def_t *rra_def_array, 
index f8d06c17423ea1f0ea819b56f9695e8f4a3e1267..401f2780bf3d30c9bc61ad4b894267c52ff86364 100644 (file)
@@ -858,10 +858,12 @@ static int add_rras(rrd_t *out, rra_mod_op_t *rra_mod_ops, int rra_mod_ops_cnt)
            rra_def_t rra_def;
 
            // the hash doesn't really matter...
-           if (parseRRA(rra_mod_ops[r].def, &rra_def, 0x123123823123) != 0) {
+           parseRRA(rra_mod_ops[r].def, &rra_def, out, 0x123123823123);
+
+           if (rrd_test_error()) {
                // failed!!!
                goto done;
-           }
+            }
 
            out->rra_def = copy_over_realloc(out->rra_def, out->stat_head->rra_cnt,
                                            &rra_def, 0,