[tracker/journal: 1/8] libtracker-data: Use integer IDs > 100000 for non-ontology resources



commit 28e90223db1e0d1b64f631eafff0b6bfcbf58d06
Author: Jürg Billeter <j bitron ch>
Date:   Thu Sep 23 14:17:14 2010 +0200

    libtracker-data: Use integer IDs > 100000 for non-ontology resources

 src/libtracker-data/tracker-data-manager.c |    6 +-
 src/libtracker-data/tracker-data-update.c  |   85 +++++++++++++++++++++-------
 src/libtracker-data/tracker-data-update.h  |    1 +
 src/libtracker-data/tracker-ontologies.h   |    2 +
 4 files changed, 71 insertions(+), 23 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 89191d5..79896e8 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -2693,7 +2693,7 @@ get_new_service_id (TrackerDBInterface *iface)
 	iface = tracker_db_manager_get_db_interface ();
 
 	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
-	                                              "SELECT MAX(ID) AS A FROM Resource");
+	                                              "SELECT MAX(ID) AS A FROM Resource WHERE ID <= %d", TRACKER_ONTOLOGIES_MAX_ID);
 
 	if (stmt) {
 		cursor = tracker_db_statement_start_cursor (stmt, &error);
@@ -2888,7 +2888,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 			}
 		}
 
-		tracker_data_begin_transaction (NULL);
+		tracker_data_begin_ontology_transaction (NULL);
 
 		/* This is a no-op when FTS is disabled */
 		tracker_db_interface_sqlite_fts_init (iface, TRUE);
@@ -2966,7 +2966,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		/* check ontology against database */
 
-		tracker_data_begin_transaction (NULL);
+		tracker_data_begin_ontology_transaction (NULL);
 
 		/* This _is_ an ontology transaction, it represents a change to the
 		 * ontology. We mark it up as such in the journal, so that replay_journal
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index da97371..8a6e88e 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -145,6 +145,7 @@ typedef struct {
 } QueuedStatement;
 
 static gboolean in_transaction = FALSE;
+static gboolean in_ontology_transaction = FALSE;
 static gboolean in_journal_replay = FALSE;
 static TrackerDataUpdateBuffer update_buffer;
 /* current resource */
@@ -157,6 +158,7 @@ static GPtrArray *delete_callbacks = NULL;
 static GPtrArray *commit_callbacks = NULL;
 static GPtrArray *rollback_callbacks = NULL;
 static gint max_service_id = 0;
+static gint max_ontology_id = 0;
 static gint max_modseq = 0;
 
 static gint ensure_resource_id (const gchar *uri, gboolean    *create);
@@ -338,40 +340,74 @@ tracker_data_update_get_new_service_id (void)
 	TrackerDBStatement *stmt;
 	GError *error = NULL;
 
-	if (G_LIKELY (max_service_id != 0)) {
-		return ++max_service_id;
-	}
+	if (in_ontology_transaction) {
+		if (G_LIKELY (max_ontology_id != 0)) {
+			return ++max_ontology_id;
+		}
 
-	iface = tracker_db_manager_get_db_interface ();
+		iface = tracker_db_manager_get_db_interface ();
 
-	stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
-	                                              "SELECT MAX(ID) AS A FROM Resource");
+		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
+			                                      "SELECT MAX(ID) AS A FROM Resource WHERE ID <= %d", TRACKER_ONTOLOGIES_MAX_ID);
 
-	if (stmt) {
-		cursor = tracker_db_statement_start_cursor (stmt, &error);
-		g_object_unref (stmt);
-	}
+		if (stmt) {
+			cursor = tracker_db_statement_start_cursor (stmt, &error);
+			g_object_unref (stmt);
+		}
 
-	if (cursor) {
-		if (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
-			max_service_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_service_id);
+		if (cursor) {
+			if (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
+				max_ontology_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_ontology_id);
+			}
+
+			g_object_unref (cursor);
 		}
 
-		g_object_unref (cursor);
-	}
+		if (G_UNLIKELY (error)) {
+			g_warning ("Could not get new resource ID: %s\n", error->message);
+			g_error_free (error);
+		}
 
-	if (G_UNLIKELY (error)) {
-		g_warning ("Could not get new resource ID: %s\n", error->message);
-		g_error_free (error);
-	}
+		return ++max_ontology_id;
+	} else {
+		if (G_LIKELY (max_service_id != 0)) {
+			return ++max_service_id;
+		}
+
+		max_service_id = TRACKER_ONTOLOGIES_MAX_ID;
+
+		iface = tracker_db_manager_get_db_interface ();
+
+		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
+			                                      "SELECT MAX(ID) AS A FROM Resource");
+
+		if (stmt) {
+			cursor = tracker_db_statement_start_cursor (stmt, &error);
+			g_object_unref (stmt);
+		}
+
+		if (cursor) {
+			if (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
+				max_service_id = MAX (tracker_db_cursor_get_int (cursor, 0), max_service_id);
+			}
 
-	return ++max_service_id;
+			g_object_unref (cursor);
+		}
+
+		if (G_UNLIKELY (error)) {
+			g_warning ("Could not get new resource ID: %s\n", error->message);
+			g_error_free (error);
+		}
+
+		return ++max_service_id;
+	}
 }
 
 void
 tracker_data_update_shutdown (void)
 {
 	max_service_id = 0;
+	max_ontology_id = 0;
 	max_modseq = 0;
 }
 
@@ -2228,6 +2264,13 @@ tracker_data_begin_transaction (GError **error)
 }
 
 void
+tracker_data_begin_ontology_transaction (GError **error)
+{
+	tracker_data_begin_transaction (error);
+	in_ontology_transaction = TRUE;
+}
+
+void
 tracker_data_begin_transaction_for_replay (time_t time, GError **error)
 {
 	in_journal_replay = TRUE;
@@ -2252,6 +2295,7 @@ tracker_data_commit_transaction (GError **error)
 	}
 
 	in_transaction = FALSE;
+	in_ontology_transaction = FALSE;
 
 	if (!in_journal_replay) {
 		tracker_db_journal_commit_db_transaction ();
@@ -2562,6 +2606,7 @@ tracker_data_rollback_transaction (void)
 	g_return_if_fail (in_transaction);
 
 	in_transaction = FALSE;
+	in_ontology_transaction = FALSE;
 
 	iface = tracker_db_manager_get_db_interface ();
 
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index aaed202..d1a276f 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -75,6 +75,7 @@ void     tracker_data_insert_statement_with_string  (const gchar               *
                                                      const gchar               *object,
                                                      GError                   **error);
 void     tracker_data_begin_transaction             (GError                   **error);
+void     tracker_data_begin_ontology_transaction    (GError                   **error);
 void     tracker_data_begin_transaction_for_replay  (time_t                     time,
                                                      GError                   **error);
 void     tracker_data_commit_transaction            (GError                   **error);
diff --git a/src/libtracker-data/tracker-ontologies.h b/src/libtracker-data/tracker-ontologies.h
index df5ce6a..278a79d 100644
--- a/src/libtracker-data/tracker-ontologies.h
+++ b/src/libtracker-data/tracker-ontologies.h
@@ -34,6 +34,8 @@ G_BEGIN_DECLS
 #error "only <libtracker-data/tracker-data.h> must be included directly."
 #endif
 
+#define TRACKER_ONTOLOGIES_MAX_ID 100000
+
 void               tracker_ontologies_init                 (void);
 void               tracker_ontologies_shutdown             (void);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]