X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_open.c;h=654005fac248cf786bf87d79a64bd7e82cce91fe;hp=101e3c3d03a27e82770d67d9db6b0f5f53138ad4;hb=04ddf3a097198c83d74a60bc2f260b33db5ba92e;hpb=45f97327ebf242442e2d9dfb8528cae01e300cc1 diff --git a/src/rrd_open.c b/src/rrd_open.c index 101e3c3..654005f 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 @@ -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; +} +