rrd_notify_row patch:
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 20 Oct 2008 11:46:08 +0000 (11:46 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 20 Oct 2008 11:46:08 +0000 (11:46 +0000)
 - Delegate choice of starting row for newly created RRD  files to the  rrd_open.c API.
 - Introduce the rrd_notify_row() function so that an implementation can choose to align the rows of new RRDs with existing  RRDs, if desirable.
 - Maintain the existing behaviour (random starting row) by default.

-- Daniel.Pocock

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1622 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd.h
src/rrd_create.c
src/rrd_open.c
src/rrd_update.c

index 3e0c871..b40251f 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -378,6 +378,18 @@ extern    "C" {
     int       rrd_lock(
     rrd_file_t *file)
               RRD_DEPRECATED;
     int       rrd_lock(
     rrd_file_t *file)
               RRD_DEPRECATED;
+    void      rrd_notify_row(
+    rrd_file_t *rrd_file,
+    int rra_idx,
+    unsigned long rra_row,
+    time_t rra_time)
+              RRD_DEPRECATED;
+    unsigned long rrd_select_initial_row(
+    rrd_file_t *rrd_file,
+    int rra_idx,
+    rra_def_t *rra
+    )
+              RRD_DEPRECATED;
 #endif                  /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
 
 #endif                  /* _RRDLIB_H */
 #endif                  /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
 
 #endif                  /* _RRDLIB_H */
index c48900f..48a4d8f 100644 (file)
@@ -24,8 +24,6 @@ void      parseGENERIC_DS(
     const char *def,
     rrd_t *rrd,
     int ds_idx);
     const char *def,
     rrd_t *rrd,
     int ds_idx);
-long int  rra_random_row(
-    rra_def_t *);
 
 static void rrd_free2(
     rrd_t *rrd);        /* our onwn copy, immmune to mmap */
 
 static void rrd_free2(
     rrd_t *rrd);        /* our onwn copy, immmune to mmap */
@@ -771,7 +769,7 @@ int rrd_create_fn(
      * would occur for cur_row = 1 because rrd_update increments
      * the pointer a priori. */
     for (i = 0; i < rrd->stat_head->rra_cnt; i++) {
      * would occur for cur_row = 1 because rrd_update increments
      * the pointer a priori. */
     for (i = 0; i < rrd->stat_head->rra_cnt; i++) {
-        rrd->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]);
+        rrd->rra_ptr->cur_row = rrd_select_initial_row(rrd_file_dn, i, &rrd->rra_def[i]);
         rrd_write(rrd_file_dn, rrd->rra_ptr, sizeof(rra_ptr_t));
     }
 
         rrd_write(rrd_file_dn, rrd->rra_ptr, sizeof(rra_ptr_t));
     }
 
@@ -825,15 +823,3 @@ static void rrd_free2(
     free(rrd->rrd_value);
 }
 
     free(rrd->rrd_value);
 }
 
-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;
-}
index a83031a..654005f 100644 (file)
 #endif
 #endif
 
 #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
 /* 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
@@ -707,3 +711,46 @@ void rrd_freemem(
 {
     free(mem);
 }
 {
     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;
+}
+
index 62c8c3b..1d9d515 100644 (file)
@@ -1928,6 +1928,8 @@ static int write_to_rras(
                 (rrd_file, rrd, rra_idx, scratch_idx,
                  pcdp_summary, rra_time) == -1)
                 return -1;
                 (rrd_file, rrd, rra_idx, scratch_idx,
                  pcdp_summary, rra_time) == -1)
                 return -1;
+
+            rrd_notify_row(rrd_file, rra_idx, rra_pos_new, rra_time);
         }
 
         rra_start += rra_def->row_cnt * ds_cnt * sizeof(rrd_value_t);
         }
 
         rra_start += rra_def->row_cnt * ds_cnt * sizeof(rrd_value_t);