Code

When fetching data from 'past' an rra, rrd_fetch was seeking past the rrd
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 3 Dec 2008 11:08:48 +0000 (11:08 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 3 Dec 2008 11:08:48 +0000 (11:08 +0000)
file. This did cause seek errors in some setups. Fixed. Thanks to Daniel Pocock for finding the problem.

git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@1689 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/src/rrd_fetch.c

index 0f1a238dbdb0578e19dbb4000efbda05ad495f4f..9d4765c1f0ad82a5f0e42a18218dfbe8396c2c91 100644 (file)
@@ -361,31 +361,34 @@ fprintf(stderr,"partial match, not best\n");
 #endif
 
     /* fill the gap at the start if needs be */
-
-    if (start_offset <= 0)
-       rra_pointer = rrd.rra_ptr[chosen_rra].cur_row+1;
-    else 
-       rra_pointer = rrd.rra_ptr[chosen_rra].cur_row+1+start_offset;
+    if (*start <= rra_end_time && *end >= rra_start_time - *step){
+        
+        if (start_offset <= 0)
+            rra_pointer = rrd.rra_ptr[chosen_rra].cur_row+1;
+        else 
+            rra_pointer = rrd.rra_ptr[chosen_rra].cur_row+1+start_offset;
     
-    if(fseek(in_file,(rra_base 
+        if(fseek(in_file,(rra_base 
                   + (rra_pointer
                      * *ds_cnt
                      * sizeof(rrd_value_t))),SEEK_SET) != 0){
-       rrd_set_error("seek error in RRA");
-       for (i=0;(unsigned)i<*ds_cnt;i++)
-             free((*ds_namv)[i]);
-       free(*ds_namv);
-       rrd_free(&rrd);
-       free(*data);
-       *data = NULL;
-       fclose(in_file);
-       return(-1);
-
-    }
+            rrd_set_error("seek error in RRA");
+            for (i=0;(unsigned)i<*ds_cnt;i++)
+                free((*ds_namv)[i]);
+            free(*ds_namv);
+            rrd_free(&rrd);
+            free(*data);
+            *data = NULL;
+            fclose(in_file);
+            return(-1);
+
+        }
 #ifdef DEBUG
-    fprintf(stderr,"First Seek: rra_base %lu rra_pointer %lu\n",
-           rra_base, rra_pointer);
+        fprintf(stderr,"First Seek: rra_base %lu rra_pointer %lu\n",
+                rra_base, rra_pointer);
 #endif
+    }
+    
     /* step trough the array */
 
     for (i=start_offset;