summaryrefslogtreecommitdiffstats
path: root/ml/ml.cc
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2023-09-28 19:40:02 +0300
committerGitHub <noreply@github.com>2023-09-28 19:40:02 +0300
commitf90c2a23e9d3e5a96dcf908cbf332cfe14dc8512 (patch)
tree46121bd20902df0d3506f63a700683a523f85ef8 /ml/ml.cc
parent5ff2ec1a293af5f946c8629e1659576c6fda4fe4 (diff)
Convert the ML database (#16046)
* Convert a db to WAL with auto vacuum * Use single sqlite configuration function * Remove UNUSED statements
Diffstat (limited to 'ml/ml.cc')
-rw-r--r--ml/ml.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/ml/ml.cc b/ml/ml.cc
index 9804fc343c..0bba2060d7 100644
--- a/ml/ml.cc
+++ b/ml/ml.cc
@@ -9,6 +9,8 @@
#include "ad_charts.h"
#include "database/sqlite/sqlite3.h"
+#define ML_METADATA_VERSION 2
+
#define WORKER_TRAIN_QUEUE_POP 0
#define WORKER_TRAIN_ACQUIRE_DIMENSION 1
#define WORKER_TRAIN_QUERY 2
@@ -1625,6 +1627,8 @@ static void ml_flush_pending_models(ml_training_thread_t *training_thread) {
training_thread->num_models_to_prune += training_thread->pending_model_info.size();
}
+ vacuum_database(db, "ML", 0, 0);
+
training_thread->pending_model_info.clear();
}
@@ -1777,14 +1781,22 @@ void ml_init()
// create table
if (db) {
- char *err = NULL;
- int rc = sqlite3_exec(db, db_models_create_table, NULL, NULL, &err);
- if (rc != SQLITE_OK) {
- error_report("Failed to create models table (%s, %s)", sqlite3_errstr(rc), err ? err : "");
+ int target_version = perform_ml_database_migration(db, ML_METADATA_VERSION);
+ if (configure_sqlite_database(db, target_version)) {
+ error_report("Failed to setup ML database");
sqlite3_close(db);
- sqlite3_free(err);
db = NULL;
}
+ else {
+ char *err = NULL;
+ int rc = sqlite3_exec(db, db_models_create_table, NULL, NULL, &err);
+ if (rc != SQLITE_OK) {
+ error_report("Failed to create models table (%s, %s)", sqlite3_errstr(rc), err ? err : "");
+ sqlite3_close(db);
+ sqlite3_free(err);
+ db = NULL;
+ }
+ }
}
}