index 1b85edb1c602080c256b7ab440afbffeee359ab7..9d4765c1f0ad82a5f0e42a18218dfbe8396c2c91 100644 (file)
--- a/program/src/rrd_fetch.c
+++ b/program/src/rrd_fetch.c
/*****************************************************************************
- * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.2.28 Copyright by Tobi Oetiker, 1997-2008
*****************************************************************************
* rrd_fetch.c read date from an rrd to use for further processing
*****************************************************************************
rrd_t rrd;
rrd_value_t *data_ptr;
unsigned long rows;
- long rrd_head_size;
#ifdef DEBUG
fprintf(stderr,"Entered rrd_fetch_fn() searching for the best match\n");
if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1)
return(-1);
-
- rrd_head_size = ftell(in_file);
/* when was the really last update of this file ? */
tmp_step_diff = labs(*step - (rrd.stat_head->pdp_step
* rrd.rra_def[i].pdp_cnt));
/* best full match */
- if(cal_end >= *end
- && cal_start <= *start){
+ if(cal_start <= *start){
if (first_full || (tmp_step_diff < best_full_step_diff)){
first_full=0;
best_full_step_diff = tmp_step_diff;
tmp_match = full_match;
if (cal_start>*start)
tmp_match -= (cal_start-*start);
- if (cal_end<*end)
- tmp_match -= (*end-cal_end);
if (first_part ||
(best_match < tmp_match) ||
(best_match == tmp_match &&
#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;
fclose(in_file);
return(-1);
}
-#ifdef HAVE_POSIX_FADVISE
- /* don't pollute the buffer cache with data read from the file. We do this while reading to
- keep damage minimal */
- if (0 != posix_fadvise(fileno(in_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) {
- rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno));
- fclose(in_file);
- return(-1);
- }
-#endif
-
#ifdef DEBUG
fprintf(stderr,"post fetch %li -- ",i);
for(ii=0;ii<*ds_cnt;ii++)
}
rrd_free(&rrd);
-#ifdef HAVE_POSIX_FADVISE
- /* and just to be sure we drop everything except the header at the end */
- if (0 != posix_fadvise(fileno(in_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) {
- rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno));
- fclose(in_file);
- return(-1);
- }
-#endif
fclose(in_file);
return(0);
}