summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ab4956)
raw | patch | inline | side by side (parent: 9ab4956)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 15 Oct 2008 05:29:41 +0000 (05:29 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 15 Oct 2008 05:29:41 +0000 (05:29 +0000) |
diff --git a/program/src/rrd.h b/program/src/rrd.h
index 5542a424db7211e3186d49dac782bcaea618a5eb..d87275e487ae76524d27086a917563d550b6ab2d 100644 (file)
--- a/program/src/rrd.h
+++ b/program/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 */
index 3b57c9f4d270f71ff37a3547d7fe99ea749781f9..9ee68961b4ad6e3755fb1bf56f7d9ab85554bc1d 100644 (file)
--- a/program/src/rrd_create.c
+++ b/program/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 */
rrd_t *rrd)
{
unsigned long i, ii;
+ int rrd_file;
rrd_value_t *unknown;
int unkn_cnt;
rrd_file_t *rrd_file_dn;
rrd_t rrd_dn;
- unsigned rrd_flags = RRD_READWRITE | RRD_CREAT;
+ unsigned flags = O_WRONLY | O_CREAT | O_TRUNC;
- if ((rrd_file_dn = rrd_open(file_name, rrd, rrd_flags)) == NULL) {
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
+ flags |= O_BINARY;
+#endif
+
+ if ((rrd_file = open(file_name, flags, 0666)) < 0) {
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
rrd_free2(rrd);
return (-1);
}
- rrd_write(rrd_file_dn, rrd->stat_head, sizeof(stat_head_t));
+ write(rrd_file, rrd->stat_head, sizeof(stat_head_t));
- rrd_write(rrd_file_dn, rrd->ds_def, sizeof(ds_def_t) * rrd->stat_head->ds_cnt);
+ write(rrd_file, rrd->ds_def, sizeof(ds_def_t) * rrd->stat_head->ds_cnt);
- rrd_write(rrd_file_dn, rrd->rra_def,
+ write(rrd_file, rrd->rra_def,
sizeof(rra_def_t) * rrd->stat_head->rra_cnt);
- rrd_write(rrd_file_dn, rrd->live_head, sizeof(live_head_t));
+ write(rrd_file, rrd->live_head, sizeof(live_head_t));
if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) {
rrd_set_error("allocating pdp_prep");
rrd_free2(rrd);
- rrd_close(rrd_file_dn);
+ close(rrd_file);
return (-1);
}
rrd->live_head->last_up % rrd->stat_head->pdp_step;
for (i = 0; i < rrd->stat_head->ds_cnt; i++)
- rrd_write(rrd_file_dn, rrd->pdp_prep, sizeof(pdp_prep_t));
+ write(rrd_file, rrd->pdp_prep, sizeof(pdp_prep_t));
if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) {
rrd_set_error("allocating cdp_prep");
rrd_free2(rrd);
- rrd_close(rrd_file_dn);
+ close(rrd_file);
return (-1);
}
}
for (ii = 0; ii < rrd->stat_head->ds_cnt; ii++) {
- rrd_write(rrd_file_dn, rrd->cdp_prep, sizeof(cdp_prep_t));
+ write(rrd_file, rrd->cdp_prep, sizeof(cdp_prep_t));
}
}
if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) {
rrd_set_error("allocating rra_ptr");
rrd_free2(rrd);
- rrd_close(rrd_file_dn);
+ close(rrd_file);
return (-1);
}
* 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 = 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->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]);
+ write(rrd_file, rrd->rra_ptr, sizeof(rra_ptr_t));
}
/* write the empty data area */
if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) {
rrd_set_error("allocating unknown");
rrd_free2(rrd);
- rrd_close(rrd_file_dn);
+ close(rrd_file);
return (-1);
}
for (i = 0; i < 512; ++i)
unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt;
while (unkn_cnt > 0) {
- if(rrd_write(rrd_file_dn, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512)) < 0)
- {
- rrd_set_error("creating rrd: %s", rrd_strerror(errno));
- return -1;
- }
+ write(rrd_file, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512));
unkn_cnt -= 512;
}
free(unknown);
+ fdatasync(rrd_file);
rrd_free2(rrd);
- if (rrd_close(rrd_file_dn) == -1) {
+ if (close(rrd_file) == -1) {
rrd_set_error("creating rrd: %s", rrd_strerror(errno));
return -1;
}
/* flush all we don't need out of the cache */
- if((rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY)) != NULL)
- {
- rrd_dontneed(rrd_file_dn, &rrd_dn);
- /* rrd_free(&rrd_dn); */
- rrd_close(rrd_file_dn);
- }
+ rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY);
+ rrd_dontneed(rrd_file_dn, &rrd_dn);
+ rrd_free(&rrd_dn);
+ rrd_close(rrd_file_dn);
return (0);
}
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/program/src/rrd_open.c b/program/src/rrd_open.c
index 6b2d6ac00cec1f6abbdbc06ce2bce894af7e24e7..f262413befce5f8e9f561b4d32eef0bfaef8a87f 100644 (file)
--- a/program/src/rrd_open.c
+++ b/program/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
rrd_file_t *rrd_file = NULL;
off_t newfile_size = 0;
- if ((rdwr & RRD_CREAT) && (rdwr & RRD_CREAT_SETSIZE)) {
+ if (rdwr & RRD_CREAT) {
/* yes bad inline signaling alert, we are using the
floatcookie to pass the size in ... only used in resize */
newfile_size = (off_t) rrd->stat_head->float_cookie;
free(rrd->stat_head);
}
- if(!(rdwr & RRD_CREAT))
- rrd_init(rrd);
+ rrd_init(rrd);
rrd_file = malloc(sizeof(rrd_file_t));
if (rrd_file == NULL) {
rrd_set_error("allocating rrd_file descriptor for '%s'", file_name);
}
}
*/
-
#ifdef HAVE_MMAP
- if(rrd_file->file_len == 0 && (rdwr & RRD_CREAT))
- {
- rrd_file->file_start = NULL;
- goto out_done;
- }
data = mmap(0, rrd_file->file_len, mm_prot, mm_flags,
rrd_file->fd, offset);
size_t count)
{
#ifdef HAVE_MMAP
- /* These flags are used if creating a new RRD */
- int mm_prot = PROT_READ | PROT_WRITE, mm_flags = MAP_SHARED;
- int old_size = rrd_file->file_len;
- int new_size = rrd_file->file_len;
if (count == 0)
return 0;
if (buf == NULL)
return -1; /* EINVAL */
-
- if((rrd_file->pos + count) > old_size)
- {
- new_size = rrd_file->pos + count;
- rrd_file->file_len = new_size;
- lseek(rrd_file->fd, new_size - 1, SEEK_SET);
- write(rrd_file->fd, "\0", 1); /* poke */
- lseek(rrd_file->fd, 0, SEEK_SET);
- if(rrd_file->file_start == NULL)
- {
- rrd_file->file_start = mmap(0, new_size, mm_prot, mm_flags,
- rrd_file->fd, 0);
- }
- else
- rrd_file->file_start = mremap(rrd_file->file_start, old_size, new_size, MREMAP_MAYMOVE);
-
- if (rrd_file->file_start == MAP_FAILED) {
- rrd_set_error("m(re)maping file : %s",
- rrd_strerror(errno));
- return -1;
- }
- }
memcpy(rrd_file->file_start + rrd_file->pos, buf, count);
rrd_file->pos += count;
return count; /* mimmic write() semantics */
{
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 66d02afc79d71d8912d45924fd77d2ed87738296..57adbf02ffeb5676915feac648b1aee8fd8182bf 100644 (file)
--- a/program/src/rrd_resize.c
+++ b/program/src/rrd_resize.c
}
rrdnew.stat_head->float_cookie = rrd_file->file_len +
(rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify);
- rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT | RRD_CREAT_SETSIZE);
+ rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT);
if (rrd_out_file == NULL) {
rrd_set_error("Can't create '%s': %s", outfilename,
rrd_strerror(errno));
diff --git a/program/src/rrd_tool.h b/program/src/rrd_tool.h
index c281979da349907ecf3039523e2e44b9bf441aa8..43781da464783b56d6100a1eef71d9de06fa87c9 100644 (file)
--- a/program/src/rrd_tool.h
+++ b/program/src/rrd_tool.h
#define RRD_CREAT (1<<2)
#define RRD_READAHEAD (1<<3)
#define RRD_COPY (1<<4)
-#define RRD_CREAT_SETSIZE (1<<5)
enum cf_en cf_conv(
const char *string);
index d43740ed6a517a85f6f5b7b3576ef3a5aa32956f..5e26055a66db2fa20244860359f137f3f0b010b6 100644 (file)
--- a/program/src/rrd_update.c
+++ b/program/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);