From 9e6dd6a7c7768d90a8f62d7379d3dfa361e3ad7f Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 14 Oct 2008 20:14:35 +0000 Subject: [PATCH] This moves selection of the initial RRA row into the rrd_open.c API 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 --- src/rrd.h | 12 ++++++++++++ src/rrd_create.c | 16 +--------------- src/rrd_open.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/rrd_update.c | 2 ++ 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/rrd.h b/src/rrd.h index d87275e..5542a42 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -369,6 +369,18 @@ extern "C" { 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 ffc1892..3b57c9f 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -24,8 +24,6 @@ void parseGENERIC_DS( 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 */ @@ -767,7 +765,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++) { - 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)); } @@ -824,15 +822,3 @@ static void rrd_free2( 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 86d608c..6b2d6ac 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -54,6 +54,10 @@ #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 @@ -648,3 +652,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; +} + diff --git a/src/rrd_update.c b/src/rrd_update.c index 5e26055..d43740e 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -1962,6 +1962,8 @@ static int write_to_rras( (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); -- 2.30.2