diff options
Diffstat (limited to 'database/engine')
-rw-r--r-- | database/engine/pagecache.c | 3 | ||||
-rw-r--r-- | database/engine/pagecache.h | 4 | ||||
-rwxr-xr-x | database/engine/rrdengineapi.c | 25 |
3 files changed, 32 insertions, 0 deletions
diff --git a/database/engine/pagecache.c b/database/engine/pagecache.c index 265e954f46..452a480376 100644 --- a/database/engine/pagecache.c +++ b/database/engine/pagecache.c @@ -89,6 +89,9 @@ struct rrdeng_page_descr *pg_cache_create_descr(void) descr->extent = NULL; descr->pg_cache_descr_state = 0; descr->pg_cache_descr = NULL; +#ifdef SQLITE_RT_BLOB + descr->blob = NULL; +#endif return descr; } diff --git a/database/engine/pagecache.h b/database/engine/pagecache.h index 31e9739da6..7ac869fc78 100644 --- a/database/engine/pagecache.h +++ b/database/engine/pagecache.h @@ -3,6 +3,7 @@ #ifndef NETDATA_PAGECACHE_H #define NETDATA_PAGECACHE_H +#include <sqlite3.h> #include "rrdengine.h" /* Forward declarations */ @@ -61,6 +62,9 @@ struct rrdeng_page_descr { usec_t start_time; usec_t end_time; uint32_t page_length; +#ifdef SQLITE_RT_BLOB + sqlite3_blob *blob; +#endif }; #define PAGE_INFO_SCRATCH_SZ (8) diff --git a/database/engine/rrdengineapi.c b/database/engine/rrdengineapi.c index fbe960a435..1491dc1730 100755 --- a/database/engine/rrdengineapi.c +++ b/database/engine/rrdengineapi.c @@ -187,6 +187,9 @@ void rrdeng_store_metric_flush_current_page(RRDDIM *rd) return; } sql_add_metric_page(rd->state->metric_uuid, descr); +#ifdef SQLITE_RT_BLOB + sqlite3_blob_close(descr->blob); +#endif if (likely(descr->page_length)) { int ret, page_is_empty; @@ -277,6 +280,22 @@ void rrdeng_store_metric_next(RRDDIM *rd, usec_t point_in_time, storage_number n } page = descr->pg_cache_descr->page; page[descr->page_length / sizeof(number)] = number; +#ifdef SQLITE_RT_BLOB + if (descr->blob) { + //info("Writing to BLOB at offset %d", descr->page_length); + int rc= sqlite3_blob_write(descr->blob, &number, sizeof(number), descr->page_length); + if (rc != SQLITE_OK) + info("Writing to BLOB at offset %d FAILED", descr->page_length); + + storage_number new_number = 0; + rc = sqlite3_blob_read(descr->blob, &new_number, sizeof(new_number), descr->page_length); + if (rc != SQLITE_OK) + info("Reading from BLOB at offset %d FAILED", descr->page_length); + + if (new_number != number) + info("BLOB numbers are NOT OK %d vs %d", number, new_number); + } +#endif pg_cache_atomic_set_pg_info(descr, point_in_time, descr->page_length + sizeof(number)); if (perfect_page_alignment) @@ -704,8 +723,14 @@ void *rrdeng_create_page(struct rrdengine_instance *ctx, uuid_t *id, struct rrde void *page; /* TODO: check maximum number of pages in page cache limit */ +#ifdef SQLITE_RT_BLOB + sqlite3_blob *blob = (*ret_descr) ? (*ret_descr)->blob : sql_open_metric_blob(descr->id); +#endif descr = pg_cache_create_descr(); descr->id = id; /* TODO: add page type: metric, log, something? */ +#ifdef SQLITE_RT_BLOB + descr->blob = blob; +#endif page = mallocz(RRDENG_BLOCK_SIZE); /*TODO: add page size */ rrdeng_page_descr_mutex_lock(ctx, descr); pg_cache_descr = descr->pg_cache_descr; |