]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Read all input data at once - this is in preparation of upcoming code
authorPeter Stamfest <peter@stamfest.at>
Sun, 2 Mar 2014 10:27:04 +0000 (11:27 +0100)
committerPeter Stamfest <peter@stamfest.at>
Sun, 2 Mar 2014 10:27:04 +0000 (11:27 +0100)
for populating newly added rows

src/rrd_modify.c

index 0383165c7e53cbcab0db4456ad4c3c3889e88146..1511fa8e4ce7633d9a535643e017506ab3841b32 100644 (file)
@@ -381,6 +381,27 @@ static int rrd_modify_r(const char *infilename,
     int total_cnt = 0, total_cnt_out = 0;
 
     int out_rra = 0;
+
+
+    /*  
+       Before we do any other operation on RRAs, we read in all
+       data. This is important, because in the second pass we may
+       have to populate newly added rows from existing data - and we
+       might need any data we have from the input RRD.
+     */
+
+    size_t to_read = total_in_rra_rows * sizeof(rrd_value_t) * in.stat_head->ds_cnt;
+    size_t read_bytes;
+    
+    read_bytes = rrd_read(rrd_file, all_data, to_read);
+    
+    if (read_bytes != to_read) {
+       rrd_set_error("short read 2");
+       goto done;
+    }
+
+    total_cnt = 0;
+
     for (i = 0; i < in.stat_head->rra_cnt; i++) {
        rra_op = NULL;
        for (r = 0 ; r < rra_mod_ops_cnt ; r++) {
@@ -404,18 +425,6 @@ static int rrd_modify_r(const char *infilename,
        ssize_t rra_size     = sizeof(rrd_value_t) * rra_values;
        ssize_t rra_size_out = sizeof(rrd_value_t) * rra_values_out;
 
-       size_t to_read = in.rra_def[i].row_cnt * sizeof(rrd_value_t) * in.stat_head->ds_cnt;
-       size_t read_bytes;
-
-       read_bytes = 
-           rrd_read(rrd_file, 
-                    all_data + rra_start,
-                    to_read);
-       
-       if (read_bytes != to_read) {
-           rrd_set_error("short read 2");
-           goto done;
-       }
 
        /* we now have all the data for the current RRA available, now
           start to transfer it to the output RRD: For every row copy