- 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
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 */
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 */
* 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));
}
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;
-}
#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
{
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;
+}
+
(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);