Code

fix update compatibility with rrd-1.0.x files
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 25 May 2008 20:00:45 +0000 (20:00 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 25 May 2008 20:00:45 +0000 (20:00 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1374 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/src/rrd_format.h
program/src/rrd_open.c
program/src/rrd_update.c

index 9deb5abf1f862f632505af1389047f6f5e46ba7d..8539f0264cd8934936844e5e4a39c557ca875e72 100644 (file)
@@ -383,7 +383,8 @@ typedef struct rrd_t {
     stat_head_t *stat_head; /* the static header */
     ds_def_t *ds_def;   /* list of data source definitions */
     rra_def_t *rra_def; /* list of round robin archive def */
-    live_head_t *live_head;
+    live_head_t *live_head; /* rrd v >= 3 last_up with us */
+    time_t *legacy_last_up; /* rrd v < 3 last_up time */
     pdp_prep_t *pdp_prep;   /* pdp data prep area */
     cdp_prep_t *cdp_prep;   /* cdp prep area */
     rra_ptr_t *rra_ptr; /* list of rra pointers */
index b6f3abb52d1234fad9e7540c449a239dd533903f..2ef43095d509cac518631a3a31e0f7f796f3d482 100644 (file)
@@ -226,12 +226,14 @@ rrd_file_t *rrd_open(
             rrd_set_error("live_head_t malloc");
             goto out_close;
         }
-#ifdef HAVE_MMAP
-        memmove(&rrd->live_head->last_up, data + offset, sizeof(long));
-        offset += sizeof(long);
-#else
-        offset += read(rrd_file->fd, &rrd->live_head->last_up, sizeof(long));
-#endif
+
+#if defined USE_MADVISE
+        /* the live_head will be needed soonish, so hint accordingly */
+        madvise(data + PAGE_START(offset),
+                sizeof(time_t), MADV_WILLNEED);
+#endif        
+        __rrd_read(rrd->legacy_last_up,time_t,1);
+        rrd->live_head->last_up = *rrd->legacy_last_up;
         rrd->live_head->last_up_usec = 0;
     } else {
 #if defined USE_MADVISE
@@ -512,6 +514,7 @@ void rrd_init(
     rrd->ds_def = NULL;
     rrd->rra_def = NULL;
     rrd->live_head = NULL;
+    rrd->legacy_last_up = NULL;
     rrd->rra_ptr = NULL;
     rrd->pdp_prep = NULL;
     rrd->cdp_prep = NULL;
@@ -522,9 +525,12 @@ void rrd_init(
 /* free RRD header data.  */
 
 #ifdef HAVE_MMAP
-inline void rrd_free(
-    rrd_t UNUSED(*rrd))
+void rrd_free(
+    rrd_t *rrd)
 {
+    if (rrd->legacy_last_up){ /* this gets set for version < 3 only */
+        free(rrd->live_head);  
+    }
 }
 #else
 void rrd_free(
index d861e9e776f7740b0e0b68629d58fe6bbc3c7a21..becce2c4fbb67c251a77dad8e22d602fadce8ada 100644 (file)
@@ -832,6 +832,9 @@ static int process_arg(
     rrd->live_head->last_up = *current_time;
     rrd->live_head->last_up_usec = *current_time_usec;
 
+    if ( version < 3 ){
+        *rrd->legacy_last_up = rrd->live_head->last_up;
+    }
     free(seasonal_coef);
     free(last_seasonal_coef);
     return 0;
@@ -2053,7 +2056,7 @@ static int write_changes_to_disk(
             return -1;
         }
     } else {
-        if (rrd_write(rrd_file, &rrd->live_head->last_up,
+        if (rrd_write(rrd_file, rrd->legacy_last_up,
                       sizeof(time_t) * 1) != sizeof(time_t) * 1) {
             rrd_set_error("rrd_write live_head to rrd");
             return -1;