summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 607eea5)
raw | patch | inline | side by side (parent: 607eea5)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 14 Oct 2008 20:14:35 +0000 (20:14 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 14 Oct 2008 20:14:35 +0000 (20:14 +0000) |
The current implementation (random row) is used by default. However, it
now provides an opportunity for alternative implementations to integrate
with rrdtool in a single place.
Maybe there are other places in rrdtool where I should insert calls to
the function rrd_notify_row()?
This has been tested with rrdtool create and rrdtool info to verify that
random rows are selected by default (existing behaviour preserved).
-- Daniel Pocock
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1606 a5681a0c-68f1-0310-ab6d-d61299d08faa
now provides an opportunity for alternative implementations to integrate
with rrdtool in a single place.
Maybe there are other places in rrdtool where I should insert calls to
the function rrd_notify_row()?
This has been tested with rrdtool create and rrdtool info to verify that
random rows are selected by default (existing behaviour preserved).
-- Daniel Pocock
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1606 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/rrd.h | patch | blob | history | |
src/rrd_create.c | patch | blob | history | |
src/rrd_open.c | patch | blob | history | |
src/rrd_update.c | patch | blob | history |
diff --git a/src/rrd.h b/src/rrd.h
index d87275e487ae76524d27086a917563d550b6ab2d..5542a424db7211e3186d49dac782bcaea618a5eb 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
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 */
diff --git a/src/rrd_create.c b/src/rrd_create.c
index ffc1892c1106fdba91e2b9d2e13aa075bbbe9440..3b57c9f4d270f71ff37a3547d7fe99ea749781f9 100644 (file)
--- a/src/rrd_create.c
+++ b/src/rrd_create.c
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;
-}
diff --git a/src/rrd_open.c b/src/rrd_open.c
index 86d608cc556a0838419882f55dafb36341d97523..6b2d6ac00cec1f6abbdbc06ce2bce894af7e24e7 100644 (file)
--- a/src/rrd_open.c
+++ b/src/rrd_open.c
#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;
+}
+
diff --git a/src/rrd_update.c b/src/rrd_update.c
index 5e26055a66db2fa20244860359f137f3f0b010b6..d43740ed6a517a85f6f5b7b3576ef3a5aa32956f 100644 (file)
--- a/src/rrd_update.c
+++ b/src/rrd_update.c
(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);