[tracker/wip/carlosg/anonymous-nodes: 42/46] libtracker-data: Refurbish version management
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/anonymous-nodes: 42/46] libtracker-data: Refurbish version management
- Date: Sun, 12 Dec 2021 14:15:45 +0000 (UTC)
commit 1811ac62da23e4fcf1fdd4469d538f3f639bdddb
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Sep 27 11:56:42 2021 +0200
libtracker-data: Refurbish version management
Since 3.0, this version check just ensured we didn't open too old
database versions. Add some infrastructure so the TrackerDataManager
can handle format changes as new versions come in the 3.x series.
src/libtracker-data/tracker-data-manager.c | 28 ++++++++++++++
src/libtracker-data/tracker-db-manager.c | 61 +++++++++++-------------------
src/libtracker-data/tracker-db-manager.h | 13 +++++++
3 files changed, 63 insertions(+), 39 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index de84158e1..9d5ae2b78 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -4111,6 +4111,15 @@ update_interface_cb (TrackerDBManager *db_manager,
}
}
+static gboolean
+tracker_data_manager_update_from_version (TrackerDataManager *manager,
+ TrackerDBVersion version,
+ GError **error)
+{
+ tracker_db_manager_update_version (manager->db_manager);
+ return TRUE;
+}
+
static gboolean
tracker_data_manager_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -4214,6 +4223,8 @@ tracker_data_manager_initable_init (GInitable *initable,
return FALSE;
}
+ tracker_db_manager_update_version (manager->db_manager);
+
for (l = sorted; l; l = l->next) {
GError *ontology_error = NULL;
GFile *ontology_file = l->data;
@@ -4372,6 +4383,23 @@ tracker_data_manager_initable_init (GInitable *initable,
GError *n_error = NULL;
gboolean transaction_started = FALSE;
guint num_parsing_errors = 0;
+ TrackerDBVersion cur_version;
+
+ cur_version = tracker_db_manager_get_version (manager->db_manager);
+
+ if (cur_version < TRACKER_DB_VERSION_NOW) {
+ tracker_data_begin_ontology_transaction (manager->data_update, &internal_error);
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
+ }
+ transaction_started = TRUE;
+
+ if (!tracker_data_manager_update_from_version (manager,
+ cur_version,
+ error))
+ return FALSE;
+ }
seen_classes = g_ptr_array_new_with_free_func (g_object_unref);
seen_properties = g_ptr_array_new_with_free_func (g_object_unref);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 96061c03f..1f09b2b48 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -53,9 +53,6 @@
/* Required minimum space needed to create databases (5Mb) */
#define TRACKER_DB_MIN_REQUIRED_SPACE 5242880
-/* Set current database version we are working with */
-#define TRACKER_DB_VERSION_NOW TRACKER_DB_VERSION_2_3
-
#define TRACKER_VACUUM_CHECK_SIZE ((goffset) 4 * 1024 * 1024 * 1024) /* 4GB */
#define IN_USE_FILENAME ".meta.isrunning"
@@ -69,35 +66,6 @@
TRACKER_DB_MANAGER_FTS_ENABLE_STOP_WORDS | \
TRACKER_DB_MANAGER_FTS_IGNORE_NUMBERS)
-typedef enum {
- TRACKER_DB_VERSION_UNKNOWN, /* Unknown */
- TRACKER_DB_VERSION_0_6_6, /* before indexer-split */
- TRACKER_DB_VERSION_0_6_90, /* after indexer-split */
- TRACKER_DB_VERSION_0_6_91, /* stable release */
- TRACKER_DB_VERSION_0_6_92, /* current TRUNK */
- TRACKER_DB_VERSION_0_7_0, /* vstore branch */
- TRACKER_DB_VERSION_0_7_4, /* nothing special */
- TRACKER_DB_VERSION_0_7_12, /* nmo ontology */
- TRACKER_DB_VERSION_0_7_13, /* coalesce & writeback */
- TRACKER_DB_VERSION_0_7_17, /* mlo ontology */
- TRACKER_DB_VERSION_0_7_20, /* nco im ontology */
- TRACKER_DB_VERSION_0_7_21, /* named graphs/localtime */
- TRACKER_DB_VERSION_0_7_22, /* fts-limits branch */
- TRACKER_DB_VERSION_0_7_28, /* RC1 + mto + nco:url */
- TRACKER_DB_VERSION_0_8_0, /* stable release */
- TRACKER_DB_VERSION_0_9_0, /* unstable release */
- TRACKER_DB_VERSION_0_9_8, /* affiliation cardinality + volumes */
- TRACKER_DB_VERSION_0_9_15, /* mtp:hidden */
- TRACKER_DB_VERSION_0_9_16, /* Fix for NB#184823 */
- TRACKER_DB_VERSION_0_9_19, /* collation */
- TRACKER_DB_VERSION_0_9_21, /* Fix for NB#186055 */
- TRACKER_DB_VERSION_0_9_24, /* nmo:PhoneMessage class */
- TRACKER_DB_VERSION_0_9_34, /* ontology cache */
- TRACKER_DB_VERSION_0_9_38, /* nie:url an inverse functional property */
- TRACKER_DB_VERSION_0_15_2, /* fts4 */
- TRACKER_DB_VERSION_2_3 /* sparql1.1 */
-} TrackerDBVersion;
-
typedef struct {
TrackerDBInterface *iface;
const gchar *file;
@@ -129,6 +97,7 @@ struct _TrackerDBManager {
guint s_cache_size;
guint u_cache_size;
gboolean first_time;
+ TrackerDBVersion db_version;
gpointer vtab_data;
@@ -323,7 +292,7 @@ db_get_version (TrackerDBManager *db_manager)
return version;
}
-static void
+void
tracker_db_manager_update_version (TrackerDBManager *db_manager)
{
TrackerDBInterface *iface;
@@ -554,7 +523,6 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
GError **error)
{
TrackerDBManager *db_manager;
- TrackerDBVersion version;
int in_use_file;
TrackerDBInterface *resources_iface;
GError *internal_error = NULL;
@@ -614,14 +582,25 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
return NULL;
}
} else if ((flags & TRACKER_DB_MANAGER_SKIP_VERSION_CHECK) == 0) {
- version = db_get_version (db_manager);
+ db_manager->db_version = db_get_version (db_manager);
- if (version < TRACKER_DB_VERSION_NOW) {
+ if (db_manager->db_version < TRACKER_DB_VERSION_3_0 ||
+ ((flags & TRACKER_DB_MANAGER_READONLY) != 0 &&
+ db_manager->db_version < TRACKER_DB_VERSION_NOW)) {
g_set_error (error,
TRACKER_DB_INTERFACE_ERROR,
TRACKER_DB_OPEN_ERROR,
"Database version is too old: got version %i, but %i is needed",
- version, TRACKER_DB_VERSION_NOW);
+ db_manager->db_version, TRACKER_DB_VERSION_NOW);
+
+ g_object_unref (db_manager);
+ return NULL;
+ } else if (db_manager->db_version > TRACKER_DB_VERSION_NOW) {
+ g_set_error (error,
+ TRACKER_DB_INTERFACE_ERROR,
+ TRACKER_DB_OPEN_ERROR,
+ "Database version is too new: got version %i, but %i is needed",
+ db_manager->db_version, TRACKER_DB_VERSION_NOW);
g_object_unref (db_manager);
return NULL;
@@ -673,8 +652,6 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
}
g_clear_object (&db_manager->db.iface);
-
- tracker_db_manager_update_version (db_manager);
} else {
TRACKER_NOTE (SQLITE, g_message ("Loading files for database %s...",
db_manager->db.abs_filename));
@@ -1174,3 +1151,9 @@ tracker_db_manager_release_memory (TrackerDBManager *db_manager)
g_async_queue_unlock (db_manager->interfaces);
}
+
+TrackerDBVersion
+tracker_db_manager_get_version (TrackerDBManager *db_manager)
+{
+ return db_manager->db_version;
+}
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 3f90f53ce..45fecb12a 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -50,6 +50,15 @@ typedef enum {
TRACKER_DB_MANAGER_SKIP_VERSION_CHECK = 1 << 9,
} TrackerDBManagerFlags;
+typedef enum {
+ TRACKER_DB_VERSION_UNKNOWN = 0,
+ /* Starts at 25 because we forgot to clean up */
+ TRACKER_DB_VERSION_3_0 = 25, /* 3.0 */
+} TrackerDBVersion;
+
+/* Set current database version we are working with */
+#define TRACKER_DB_VERSION_NOW TRACKER_DB_VERSION_3_0
+
void tracker_db_manager_rollback_db_creation (TrackerDBManager *db_manager);
gboolean tracker_db_manager_db_exists (GFile *cache_location);
@@ -97,6 +106,10 @@ gboolean tracker_db_manager_detach_database (TrackerDBManager
GError **error);
void tracker_db_manager_release_memory (TrackerDBManager *db_manager);
+TrackerDBVersion tracker_db_manager_get_version (TrackerDBManager *db_manager);
+void tracker_db_manager_update_version (TrackerDBManager *db_manager);
+
+
G_END_DECLS
#endif /* __LIBTRACKER_DB_MANAGER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]