[tracker/fts: 2/5] libtracker-fts: Do not use TLS



commit d06a632cac8d217880d6a0b16a7b47291a93542e
Author: Jürg Billeter <j bitron ch>
Date:   Fri Sep 10 15:57:43 2010 +0200

    libtracker-fts: Do not use TLS

 src/libtracker-data/tracker-data-update.c         |   39 +++++++----
 src/libtracker-data/tracker-db-interface-sqlite.c |   40 ++++++++++--
 src/libtracker-data/tracker-db-interface-sqlite.h |   12 ++++
 src/libtracker-data/tracker-db-manager.c          |    8 --
 src/libtracker-fts/tracker-fts.c                  |   72 ++++++++-------------
 src/libtracker-fts/tracker-fts.h                  |   23 ++++--
 6 files changed, 113 insertions(+), 81 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 77aca13..7d15047 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -29,14 +29,11 @@
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-ontologies.h>
 
-#if HAVE_TRACKER_FTS
-#include <libtracker-fts/tracker-fts.h>
-#endif
-
 #include "tracker-class.h"
 #include "tracker-data-manager.h"
 #include "tracker-data-update.h"
 #include "tracker-data-query.h"
+#include "tracker-db-interface-sqlite.h"
 #include "tracker-db-manager.h"
 #include "tracker-db-dbus.h"
 #include "tracker-db-journal.h"
@@ -849,7 +846,7 @@ tracker_data_resource_buffer_flush (GError **error)
 		TrackerProperty *prop;
 		GValueArray *values;
 
-		tracker_fts_update_init (resource_buffer->id);
+		tracker_db_interface_sqlite_fts_update_init (iface, resource_buffer->id);
 
 		g_hash_table_iter_init (&iter, resource_buffer->predicates);
 		while (g_hash_table_iter_next (&iter, (gpointer*) &prop, (gpointer*) &values)) {
@@ -861,12 +858,14 @@ tracker_data_resource_buffer_flush (GError **error)
 					g_string_append (fts, g_value_get_string (g_value_array_get_nth (values, i)));
 					g_string_append_c (fts, ' ');
 				}
-				tracker_fts_update_text (resource_buffer->id,
-							 tracker_data_query_resource_id (tracker_property_get_uri (prop)),
-							 fts->str, !tracker_property_get_fulltext_no_limit (prop));
+				tracker_db_interface_sqlite_fts_update_text (iface,
+					resource_buffer->id,
+					tracker_data_query_resource_id (tracker_property_get_uri (prop)),
+					fts->str,
+					!tracker_property_get_fulltext_no_limit (prop));
 				g_string_free (fts, TRUE);
 
-				/* Set that we ever updated FTS, so that tracker_fts_update_commit()
+				/* Set that we ever updated FTS, so that tracker_db_interface_sqlite_fts_update_commit()
 				 * gets called */
 				update_buffer.fts_ever_updated = TRUE;
 			}
@@ -932,12 +931,16 @@ tracker_data_update_buffer_might_flush (GError **error)
 static void
 tracker_data_update_buffer_clear (void)
 {
+	TrackerDBInterface *iface;
+
+	iface = tracker_db_manager_get_db_interface ();
+
 	g_hash_table_remove_all (update_buffer.resources);
 	g_hash_table_remove_all (update_buffer.resources_by_id);
 	resource_buffer = NULL;
 
 #if HAVE_TRACKER_FTS
-	tracker_fts_update_rollback ();
+	tracker_db_interface_sqlite_fts_update_rollback (iface);
 	update_buffer.fts_ever_updated = FALSE;
 #endif
 
@@ -1263,6 +1266,10 @@ get_old_property_values (TrackerProperty  *property,
 
 #if HAVE_TRACKER_FTS
 		if (tracker_property_get_fulltext_indexed (property)) {
+			TrackerDBInterface *iface;
+
+			iface = tracker_db_manager_get_db_interface ();
+
 			if (!resource_buffer->fts_updated && !resource_buffer->create) {
 				guint i, n_props;
 				TrackerProperty   **properties, *prop;
@@ -1270,7 +1277,7 @@ get_old_property_values (TrackerProperty  *property,
 				/* first fulltext indexed property to be modified
 				 * retrieve values of all fulltext indexed properties
 				 */
-				tracker_fts_update_init (resource_buffer->id);
+				tracker_db_interface_sqlite_fts_update_init (iface, resource_buffer->id);
 
 				properties = tracker_ontologies_get_properties (&n_props);
 
@@ -1285,9 +1292,11 @@ get_old_property_values (TrackerProperty  *property,
 
 						/* delete old fts entries */
 						for (i = 0; i < old_values->n_values; i++) {
-							tracker_fts_update_text (resource_buffer->id, -1,
-							                         g_value_get_string (g_value_array_get_nth (old_values, i)),
-							                         !tracker_property_get_fulltext_no_limit (prop));
+							tracker_db_interface_sqlite_fts_update_text (iface,
+								resource_buffer->id,
+								-1,
+								g_value_get_string (g_value_array_get_nth (old_values, i)),
+								!tracker_property_get_fulltext_no_limit (prop));
 						}
 					}
 				}
@@ -2249,7 +2258,7 @@ tracker_data_commit_transaction (GError **error)
 
 #if HAVE_TRACKER_FTS
 	if (update_buffer.fts_ever_updated) {
-		tracker_fts_update_commit ();
+		tracker_db_interface_sqlite_fts_update_commit (iface);
 		update_buffer.fts_ever_updated = FALSE;
 	}
 #endif
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 27153fe..0682273 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -52,7 +52,7 @@ struct TrackerDBInterface {
 
 	guint ro : 1;
 #if HAVE_TRACKER_FTS
-	guint fts_initialized : 1;
+	TrackerFts *fts;
 #endif
 	GCancellable *cancellable;
 };
@@ -627,8 +627,8 @@ close_database (TrackerDBInterface *db_interface)
 	db_interface->function_data = NULL;
 
 #if HAVE_TRACKER_FTS
-	if (db_interface->fts_initialized) {
-		tracker_fts_shutdown (G_OBJECT (db_interface));
+	if (db_interface->fts) {
+		tracker_fts_free (db_interface->fts);
 	}
 #endif
 
@@ -641,13 +641,43 @@ tracker_db_interface_sqlite_fts_init (TrackerDBInterface *db_interface,
                                       gboolean            create)
 {
 #if HAVE_TRACKER_FTS
-	tracker_fts_init (db_interface->db, create, G_OBJECT (db_interface));
-	db_interface->fts_initialized = TRUE;
+	db_interface->fts = tracker_fts_new (db_interface->db, create);
 #else
 	g_message ("FTS support is disabled");
 #endif
 }
 
+#if HAVE_TRACKER_FTS
+int
+tracker_db_interface_sqlite_fts_update_init (TrackerDBInterface *db_interface,
+                                             int                 id)
+{
+	return tracker_fts_update_init (db_interface->fts, id);
+}
+
+int
+tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
+                                             int                 id,
+                                             int                 column_id,
+                                             const char         *text,
+                                             gboolean            limit_word_length)
+{
+	return tracker_fts_update_text (db_interface->fts, id, column_id, text, limit_word_length);
+}
+
+void
+tracker_db_interface_sqlite_fts_update_commit (TrackerDBInterface *db_interface)
+{
+	return tracker_fts_update_commit (db_interface->fts);
+}
+
+void
+tracker_db_interface_sqlite_fts_update_rollback (TrackerDBInterface *db_interface)
+{
+	return tracker_fts_update_rollback (db_interface->fts);
+}
+#endif
+
 static void
 tracker_db_interface_sqlite_finalize (GObject *object)
 {
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index a923a08..cf8741e 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -37,6 +37,18 @@ void                tracker_db_interface_sqlite_enable_shared_cache    (void);
 void                tracker_db_interface_sqlite_fts_init               (TrackerDBInterface       *interface,
                                                                         gboolean                  create);
 
+#if HAVE_TRACKER_FTS
+int                 tracker_db_interface_sqlite_fts_update_init        (TrackerDBInterface       *interface,
+                                                                        int                       id);
+int                 tracker_db_interface_sqlite_fts_update_text        (TrackerDBInterface       *interface,
+                                                                        int                       id,
+                                                                        int                       column_id,
+                                                                        const char               *text,
+                                                                        gboolean                  limit_word_length);
+void                tracker_db_interface_sqlite_fts_update_commit      (TrackerDBInterface       *interface);
+void                tracker_db_interface_sqlite_fts_update_rollback    (TrackerDBInterface       *interface);
+#endif
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_DB_INTERFACE_SQLITE_H__ */
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 07ced1b..1e7b385 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -1031,14 +1031,6 @@ tracker_db_manager_shutdown (void)
 	sys_tmp_dir = NULL;
 	g_free (sql_dir);
 
-#if HAVE_TRACKER_FTS
-	/* shutdown fts in all threads
-	 * needs to be done before shutting down all db interfaces as
-	 * shutdown does not happen in thread where interface was created
-	 */
-	tracker_fts_shutdown_all ();
-#endif
-
 	/* shutdown db interfaces in all threads */
 	g_static_private_free (&interface_data_key);
 
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index db5e36b..c567aaf 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -2133,8 +2133,6 @@ static int sql_prepare(sqlite3 *db, const char *zDb, const char *zName,
 typedef struct fulltext_vtab fulltext_vtab;
 typedef struct fulltext_sqlite_vtab fulltext_sqlite_vtab;
 
-static GStaticPrivate tracker_fts_vtab_key = G_STATIC_PRIVATE_INIT;
-static GQuark quark_fulltext_vtab = 0;
 static TrackerFtsMapFunc map_function = NULL;
 
 /* A single term in a query is represented by an instances of
@@ -3327,23 +3325,12 @@ static fulltext_vtab *constructVtab(
   sqlite3 *db,		    /* The SQLite database connection */
   const char *zDb,
   const char *zName,
-  char **pzErr,             /* Write any error message here */
-  GObject *object
+  char **pzErr              /* Write any error message here */
 ){
   fulltext_vtab *v = 0;
   TrackerFTSConfig *config;
   TrackerLanguage *language;
 
-  if (G_UNLIKELY (quark_fulltext_vtab == 0)) {
-    quark_fulltext_vtab = g_quark_from_static_string ("quark_fulltext_vtab");
-  }
-
-  v = g_object_get_qdata (object, quark_fulltext_vtab);
-
-  if(v) {
-    return v;
-  }
-
   v = (fulltext_vtab *) sqlite3_malloc(sizeof(fulltext_vtab));
   if( v==0 ) return NULL;
   CLEAR(v);
@@ -3413,10 +3400,6 @@ static fulltext_vtab *constructVtab(
 
   FTSTRACE(("FTS3 Connect %p\n", v));
 
-  g_static_private_set (&tracker_fts_vtab_key, v, NULL);
-  g_object_set_qdata_full (object, quark_fulltext_vtab, v,
-                           (GDestroyNotify) fulltext_vtab_destroy);
-
   /* Config no longer needed */
   g_object_unref (config);
 
@@ -7917,7 +7900,7 @@ int sqlite3Fts3InitHashTable(sqlite3 *, fts3Hash *, const char *);
 ** SQLite. If fts3 is built as a dynamically loadable extension, this
 ** function is called by the sqlite3_extension_init() entry point.
 */
-int tracker_fts_init(sqlite3 *db, int create, GObject *object){
+TrackerFts *tracker_fts_new(sqlite3 *db, int create){
   int rc = SQLITE_OK;
   fulltext_vtab *v;
 
@@ -7925,7 +7908,11 @@ int tracker_fts_init(sqlite3 *db, int create, GObject *object){
     createTables (db, "main", "fts");
   }
 
-  v = constructVtab(db, "main", "fts", NULL, object);
+  v = constructVtab(db, "main", "fts", NULL);
+
+  if (v == NULL) {
+    return NULL;
+  }
 
   /* Create the virtual table wrapper around the hash-table and overload
   ** the two scalar functions. If this is successful, register the
@@ -7944,52 +7931,47 @@ int tracker_fts_init(sqlite3 *db, int create, GObject *object){
     rc = sqlite3_create_module_v2(
 	db, "trackerfts", &fts3Module, v, NULL
     );
-    if (SQLITE_OK != rc)
-      return rc;
+    if (SQLITE_OK != rc){
+      fulltext_vtab_destroy (v);
+      return NULL;
+    }
 
     if (create){
         rc = sqlite3_exec(db, "CREATE VIRTUAL TABLE fts USING trackerfts", NULL, 0, NULL);
     }
   }
 
-  return rc;
-}
+  if (SQLITE_OK != rc){
+    fulltext_vtab_destroy (v);
+    return NULL;
+  }
 
-void tracker_fts_shutdown (GObject *object){
-  g_object_set_qdata (object, quark_fulltext_vtab, NULL);
+  return v;
 }
 
-void tracker_fts_shutdown_all (void){
-  g_static_private_free (&tracker_fts_vtab_key);
+void tracker_fts_free (TrackerFts *fts){
+  fulltext_vtab_destroy (fts);
 }
 
 void tracker_fts_set_map_function(TrackerFtsMapFunc map_func){
   map_function = map_func;
 }
 
-int tracker_fts_update_init(int id){
-  fulltext_vtab *v = g_static_private_get (&tracker_fts_vtab_key);
-
-  return initPendingTerms(v, id);
+int tracker_fts_update_init(TrackerFts *fts, int id){
+  return initPendingTerms(fts, id);
 }
 
-int tracker_fts_update_text(int id, int column_id,
+int tracker_fts_update_text(TrackerFts *fts, int id, int column_id,
 			    const char *text, gboolean limit_word_length){
-  fulltext_vtab *v = g_static_private_get (&tracker_fts_vtab_key);
-
-  return buildTerms(v, id, text, column_id, limit_word_length);
+  return buildTerms(fts, id, text, column_id, limit_word_length);
 }
 
-void tracker_fts_update_commit(void){
-  fulltext_vtab *v = g_static_private_get (&tracker_fts_vtab_key);
-
-  flushPendingTerms(v);
-  clearPendingTerms(v);
+void tracker_fts_update_commit(TrackerFts *fts){
+  flushPendingTerms(fts);
+  clearPendingTerms(fts);
 }
 
-void tracker_fts_update_rollback(void){
-  fulltext_vtab *v = g_static_private_get (&tracker_fts_vtab_key);
-
-  clearPendingTerms(v);
+void tracker_fts_update_rollback(TrackerFts *fts){
+  clearPendingTerms(fts);
 }
 
diff --git a/src/libtracker-fts/tracker-fts.h b/src/libtracker-fts/tracker-fts.h
index ba6522a..43cc02c 100644
--- a/src/libtracker-fts/tracker-fts.h
+++ b/src/libtracker-fts/tracker-fts.h
@@ -25,14 +25,21 @@ G_BEGIN_DECLS
 
 typedef const gchar *(*TrackerFtsMapFunc) (gint id);
 
-int tracker_fts_init (sqlite3 *db, int create, GObject *object);
-void tracker_fts_shutdown (GObject *object);
-void tracker_fts_shutdown_all (void);
-void tracker_fts_set_map_function (TrackerFtsMapFunc map_func);
-int tracker_fts_update_init (int id);
-int tracker_fts_update_text (int id, int column_id, const char *text, gboolean limit_word_length);
-void tracker_fts_update_commit (void);
-void tracker_fts_update_rollback (void);
+typedef struct fulltext_vtab TrackerFts;
+
+TrackerFts *tracker_fts_new              (sqlite3           *db,
+                                          int                create);
+void        tracker_fts_free             (TrackerFts        *fts);
+void        tracker_fts_set_map_function (TrackerFtsMapFunc  map_func);
+int         tracker_fts_update_init      (TrackerFts        *fts,
+                                          int                id);
+int         tracker_fts_update_text      (TrackerFts        *fts,
+                                          int                id,
+                                          int                column_id,
+                                          const char        *text,
+                                          gboolean           limit_word_length);
+void        tracker_fts_update_commit    (TrackerFts        *fts);
+void        tracker_fts_update_rollback  (TrackerFts        *fts);
 
 G_END_DECLS
 



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