[rrd-users] rrd resize error

Daniel De Marco ddm at bartol.udel.edu
Wed Jun 29 15:48:07 CEST 2011


* Tobias Oetiker <tobi at oetiker.ch> [06/28/2011 18:39]:
> neat ... so I guess the following should fix this problem:
>         atoi(rrd->stat_head->version) < 3 ? sizeof(time_t) : sizeof(live_head_t) + \

this crashes badly. I think it's because the plus has higher precedence.

This seems to work ok:
--- ../../rrdtool-1.4.5/src/rrd_format.c        2010-12-26 14:24:48.000000000 -0500
+++ rrd_format.c        2011-06-29 08:35:38.000000000 -0400
@@ -105,8 +105,7 @@
     return sizeof(stat_head_t) + \
         sizeof(ds_def_t) * rrd->stat_head->ds_cnt + \
         sizeof(rra_def_t) * rrd->stat_head->rra_cnt + \
-        sizeof(time_t) + \
-        sizeof(live_head_t) + \
+       (atoi(rrd->stat_head->version) < 3 ? sizeof(time_t) : sizeof(live_head_t)) + \
         sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt + \
         sizeof(cdp_prep_t) * rrd->stat_head->ds_cnt * rrd->stat_head->rra_cnt + \
         sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt;

However this solves the problem only for new files. 

In order to be able to grow or shrink files created with the old version I used the following:
--- ../../rrdtool-1.4.5/src/rrd_resize.c        2010-12-26 14:24:48.000000000 -0500
+++ rrd_resize.c        2011-06-29 09:07:14.000000000 -0400
@@ -262,9 +262,14 @@
     /* Move the rest of the CDPs
      */
     while (1) {
-        if (rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1) <= 0)
+        ssize_t b_read;
+        if ((b_read=rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1)) <= 0)
             break;
-        rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1);
+        if(rrd_out_file->pos+b_read > rrd_out_file->file_len) {
+            fprintf(stderr,"WARNING: ignoring last %zu bytes\nWARNING: if you see this message multiple times for a single file you're in trouble\n", b_read);
+            continue;
+        }
+        rrd_write(rrd_out_file, &buffer, b_read);
     }
     rrdnew.rra_def[target_rra].row_cnt += modify;
     rrd_seek(rrd_out_file,

Daniel.



More information about the rrd-users mailing list