From b515f1f246b6a10b1fc0f3ae3c60c97b0a705b24 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 22 Jul 2007 09:47:53 +0000 Subject: [PATCH] Only create version 4 rrd files if the new holtwinters MHW.. CF is used. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1167 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/NEWS | 6 ++++-- program/src/rrd_create.c | 7 ++++--- program/src/rrd_dump.c | 6 +++++- program/src/rrd_format.h | 1 + program/src/rrd_restore.c | 14 ++++++-------- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/program/NEWS b/program/NEWS index 542783b8..6054e359 100644 --- a/program/NEWS +++ b/program/NEWS @@ -35,8 +35,10 @@ Forecasting (Evan Miller) method. It is a drop-in replacement for HWPREDICT, and is better suited for data whose seasonal variations grow or shrink in proportion to the average. -* Due to the new aggregation function, we also get a new version of the - rrd file format. +Incompatibility +--------------- +* If you create an RRD with the new MHWPREDICT function, the resulting rrdfile will + be version 0004 and can only be used in rrdtool 1.3. Locale Independent Input ------------------------ diff --git a/program/src/rrd_create.c b/program/src/rrd_create.c index 0e2f82c1..4e442d2a 100644 --- a/program/src/rrd_create.c +++ b/program/src/rrd_create.c @@ -133,8 +133,8 @@ int rrd_create_r( } /* set some defaults */ - strcpy(rrd.stat_head->cookie, RRD_COOKIE); - strcpy(rrd.stat_head->version, RRD_VERSION); + strcpy(rrd.stat_head->cookie, RRD_COOKIE); + strcpy(rrd.stat_head->version, RRD_VERSION3); /* by default we are still version 3 */ rrd.stat_head->float_cookie = FLOAT_COOKIE; rrd.stat_head->ds_cnt = 0; /* this will be adjusted later */ rrd.stat_head->rra_cnt = 0; /* ditto */ @@ -247,8 +247,9 @@ int rrd_create_r( rrd_set_error("Failed to parse CF name"); switch (cf_conv (rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam)) { - case CF_HWPREDICT: case CF_MHWPREDICT: + strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */ + case CF_HWPREDICT: /* initialize some parameters */ rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha]. u_val = 0.1; diff --git a/program/src/rrd_dump.c b/program/src/rrd_dump.c index eb9b4690..be000f9c 100644 --- a/program/src/rrd_dump.c +++ b/program/src/rrd_dump.c @@ -100,7 +100,11 @@ int rrd_dump_r( fputs("", out_file); fputs("", out_file); - fprintf(out_file, "\t %s \n", RRD_VERSION); + if ( atoi(rrd.stat_head->version) <= 3) { + fprintf(out_file, "\t %s \n", RRD_VERSION3); + } else { + fprintf(out_file, "\t %s \n", RRD_VERSION); + } fprintf(out_file, "\t %lu \n", rrd.stat_head->pdp_step); #if HAVE_STRFTIME diff --git a/program/src/rrd_format.h b/program/src/rrd_format.h index 7dbc8edb..d95ea4a7 100644 --- a/program/src/rrd_format.h +++ b/program/src/rrd_format.h @@ -22,6 +22,7 @@ /* #define RRD_VERSION "0002" */ /* changed because microsecond precision requires another field */ #define RRD_VERSION "0004" +#define RRD_VERSION3 "0003" #define FLOAT_COOKIE 8.642135E130 #include "rrd_nan_inf.h" diff --git a/program/src/rrd_restore.c b/program/src/rrd_restore.c index 65bbb104..1164adbe 100644 --- a/program/src/rrd_restore.c +++ b/program/src/rrd_restore.c @@ -223,14 +223,12 @@ int xml2rrd( rrd->stat_head = NULL; return -1; } - /* make sure we output the right version */ - strcpy(rrd->stat_head->version, RRD_VERSION); - - /* if (atoi(rrd -> stat_head -> version) < 2) - { - rrd_set_error("Can only restore version >= 2 (Not %s). Dump your old rrd using a current rrdtool dump.", rrd -> stat_head -> version ); - return -1; - } */ + /* make sure we output the right version only go over 3 if input is over 3 too */ + if (input_version > 3 ){ + strcpy(rrd->stat_head->version, RRD_VERSION); + } else { + strcpy(rrd->stat_head->version, RRD_VERSION3); + } rrd->stat_head->float_cookie = FLOAT_COOKIE; rrd->stat_head->ds_cnt = 0; -- 2.30.2