rrd_notify_row patch:
[rrdtool.git] / src / rrd_open.c
index 101e3c3..654005f 100644 (file)
 #endif
 #endif
 
+long int  rra_random_row(
+    rra_def_t *);
+
+
 /* Open a database file, return its header and an open filehandle,
  * positioned to the first cdp in the first rra.
  * In the error path of rrd_open, only rrd_free(&rrd) has to be called
@@ -71,7 +75,6 @@ rrd_file_t *rrd_open(
 {
     int i;
     int       flags = 0;
-    mode_t    mode = S_IRUSR;
     int       version;
 
 #ifdef HAVE_MMAP
@@ -146,7 +149,6 @@ rrd_file_t *rrd_open(
 #endif
     } else {
         if (rdwr & RRD_READWRITE) {
-            mode |= S_IWUSR;
             flags |= O_RDWR;
 #ifdef HAVE_MMAP
             rrd_simple_file->mm_flags = MAP_SHARED;
@@ -169,7 +171,7 @@ rrd_file_t *rrd_open(
     flags |= O_BINARY;
 #endif
 
-    if ((rrd_simple_file->fd = open(file_name, flags, mode)) < 0) {
+    if ((rrd_simple_file->fd = open(file_name, flags, 0666)) < 0) {
         rrd_set_error("opening '%s': %s", file_name, rrd_strerror(errno));
         goto out_free;
     }
@@ -709,3 +711,46 @@ void rrd_freemem(
 {
     free(mem);
 }
+
+/*
+ * rra_update informs us about the RRAs being updated
+ * The low level storage API may use this information for
+ * aligning RRAs within stripes, or other performance enhancements
+ */
+void rrd_notify_row(
+    rrd_file_t *rrd_file,
+    int rra_idx,
+    unsigned long rra_row,
+    time_t rra_time)
+{
+}
+
+/*
+ * This function is called when creating a new RRD
+ * The storage implementation can use this opportunity to select
+ * a sensible starting row within the file.
+ * The default implementation is random, to ensure that all RRAs
+ * don't change to a new disk block at the same time
+ */
+unsigned long rrd_select_initial_row(
+    rrd_file_t *rrd_file,
+    int rra_idx,
+    rra_def_t *rra
+    )
+{
+    return rra_random_row(rra);
+}
+
+static int rand_init = 0;
+
+long int rra_random_row(
+    rra_def_t *rra)
+{
+    if (!rand_init) {
+        srandom((unsigned int) time(NULL) + (unsigned int) getpid());
+        rand_init++;
+    }
+
+    return random() % rra->row_cnt;
+}
+