summaryrefslogtreecommitdiffstats
path: root/database/sqlite/sqlite_functions.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-01 06:15:04 +0000
commite970e0b37b8bd7f246feb3f70c4136418225e434 (patch)
tree0b67c0ca45f56f2f9d9c5c2e725279ecdf52d2eb /database/sqlite/sqlite_functions.h
parentAdding upstream version 1.31.0. (diff)
downloadnetdata-e970e0b37b8bd7f246feb3f70c4136418225e434.tar.xz
netdata-e970e0b37b8bd7f246feb3f70c4136418225e434.zip
Adding upstream version 1.32.0.upstream/1.32.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'database/sqlite/sqlite_functions.h')
-rw-r--r--database/sqlite/sqlite_functions.h37
1 files changed, 29 insertions, 8 deletions
diff --git a/database/sqlite/sqlite_functions.h b/database/sqlite/sqlite_functions.h
index 30a52bf73..3e41f6aaa 100644
--- a/database/sqlite/sqlite_functions.h
+++ b/database/sqlite/sqlite_functions.h
@@ -3,7 +3,7 @@
#ifndef NETDATA_SQLITE_FUNCTIONS_H
#define NETDATA_SQLITE_FUNCTIONS_H
-#include "../../daemon/common.h"
+#include "daemon/common.h"
#include "sqlite3.h"
// return a node list
@@ -12,10 +12,17 @@ struct node_instance_list {
uuid_t host_id;
char *hostname;
int live;
- int querable;
+ int queryable;
int hops;
};
+typedef enum db_check_action_type {
+ DB_CHECK_NONE = 0x0000,
+ DB_CHECK_INTEGRITY = 0x0001,
+ DB_CHECK_FIX_DB = 0x0002,
+ DB_CHECK_RECLAIM_SPACE = 0x0004,
+ DB_CHECK_CONT = 0x00008
+} db_check_action_type_t;
#define SQLITE_INSERT_DELAY (50) // Insert delay in case of lock
@@ -34,11 +41,22 @@ struct node_instance_list {
#define SQL_STORE_DIMENSION \
"INSERT OR REPLACE into dimension (dim_id, chart_id, id, name, multiplier, divisor , algorithm) values (?0001,?0002,?0003,?0004,?0005,?0006,?0007);"
-#define SQL_FIND_DIMENSION_UUID "select dim_id from dimension where chart_id=@chart and id=@id and name=@name;"
+#define SQL_FIND_DIMENSION_UUID \
+ "select dim_id from dimension where chart_id=@chart and id=@id and name=@name and length(dim_id)=16;"
-#define SQL_STORE_ACTIVE_DIMENSION \
+#define SQL_STORE_ACTIVE_DIMENSION \
"insert or replace into dimension_active (dim_id, date_created) values (@id, strftime('%s'));"
-extern int sql_init_database(void);
+
+#define CHECK_SQLITE_CONNECTION(db_meta) \
+ if (unlikely(!db_meta)) { \
+ if (default_rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE) { \
+ return 1; \
+ } \
+ error_report("Database has not been initialized"); \
+ return 1; \
+ }
+
+extern int sql_init_database(db_check_action_type_t rebuild);
extern void sql_close_database(void);
extern int sql_store_host(uuid_t *guid, const char *hostname, const char *registry_hostname, int update_every, const char *os, const char *timezone, const char *tags);
@@ -49,8 +67,7 @@ extern int sql_store_chart(
extern int sql_store_dimension(uuid_t *dim_uuid, uuid_t *chart_uuid, const char *id, const char *name, collected_number multiplier,
collected_number divisor, int algorithm);
-extern uuid_t *find_dimension_uuid(RRDSET *st, RRDDIM *rd);
-extern uuid_t *create_dimension_uuid(RRDSET *st, RRDDIM *rd);
+extern int find_dimension_uuid(RRDSET *st, RRDDIM *rd, uuid_t *store_uuid);
extern void store_active_dimension(uuid_t *dimension_uuid);
extern uuid_t *find_chart_uuid(RRDHOST *host, const char *type, const char *id, const char *name);
@@ -63,7 +80,9 @@ extern int find_uuid_type(uuid_t *uuid);
extern void sql_rrdset2json(RRDHOST *host, BUFFER *wb);
extern RRDHOST *sql_create_host_by_uuid(char *guid);
-extern void db_execute(char *cmd);
+extern int prepare_statement(sqlite3 *database, char *query, sqlite3_stmt **statement);
+extern int execute_insert(sqlite3_stmt *res);
+extern void db_execute(const char *cmd);
extern int file_is_migrated(char *path);
extern void add_migrated_file(char *path, uint64_t file_size);
extern void db_unlock(void);
@@ -74,7 +93,9 @@ extern void sql_build_context_param_list(struct context_param **param_list, RRDH
extern void store_claim_id(uuid_t *host_id, uuid_t *claim_id);
extern int update_node_id(uuid_t *host_id, uuid_t *node_id);
extern int get_node_id(uuid_t *host_id, uuid_t *node_id);
+extern int get_host_id(uuid_t *node_id, uuid_t *host_id);
extern void invalidate_node_instances(uuid_t *host_id, uuid_t *claim_id);
extern struct node_instance_list *get_node_list(void);
extern void sql_load_node_id(RRDHOST *host);
+extern void compute_chart_hash(RRDSET *st);
#endif //NETDATA_SQLITE_FUNCTIONS_H