Code

prepare for the release of rrdtool-1.2.30
[rrdtool-all.git] / program / src / rrd_open.c
index 08c798482e94eb4349cd183ad2add4b3f7b2c9f7..8bfe6b1b92f226aa821b4061833c91e3f0fb6b6d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * RRDtool 1.2.23  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.2.30  Copyright by Tobi Oetiker, 1997-2009
  *****************************************************************************
  * rrd_open.c  Open an RRD File
  *****************************************************************************
@@ -87,6 +87,23 @@ rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr)
         rrd_set_error("opening '%s': %s",file_name, rrd_strerror(errno));
         return (-1);
     }
+
+#ifdef HAVE_POSIX_FADVISE
+    /* In general we need no read-ahead when dealing with rrd_files.
+       When we stop reading, it is highly unlikely that we start up again.
+       In this manner we actually save time and diskaccess (and buffer cache).
+       Thanks to Dave Plonka for the Idea of using POSIX_FADV_RANDOM here. */       
+    /* if (0 != posix_fadvise(fileno(*in_file), 0, 0, POSIX_FADV_RANDOM)) {
+        rrd_set_error("setting POSIX_FADV_RANDOM on '%s': %s",file_name, rrd_strerror(errno));
+        fclose(*in_file);
+        return(-1); */
+
+        /* if it does not work, then this is sad, but we should not quit */
+     posix_fadvise(fileno(*in_file), 0, 0, POSIX_FADV_RANDOM);
+        
+     /*     }     */
+#endif
+
 /*
         if (rdwr == RRD_READWRITE)
         {
@@ -108,7 +125,7 @@ rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr)
     MYFREAD(rrd->stat_head, stat_head_t,  1)
     /* lets see if the first read worked */
     if (ferror( *in_file ) || feof(*in_file)) {
-        rrd_set_error("reading the cookie off %s faild",file_name);
+        rrd_set_error("reading the cookie off %s failed",file_name);
         fclose(*in_file);
         return(-1);
     }