[tracker/lru-stmt-cache] libtracker-data, tracker-store: Make statement cache sizes configurable with env var



commit 6f672491342e5ee81456cc779c1b4c2a748048cd
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Sep 23 10:36:59 2010 +0200

    libtracker-data, tracker-store: Make statement cache sizes configurable with env var

 src/libtracker-data/tracker-db-interface-sqlite.c |    6 +++++-
 src/libtracker-direct/tracker-direct.vala         |   10 +++++++++-
 src/tracker-store/tracker-main.c                  |   21 +++++++++++++++++++--
 3 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 397c55f..c686f35 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -837,7 +837,11 @@ tracker_db_interface_set_max_stmt_cache_size (TrackerDBInterface         *db_int
 		return;
 	}
 
-	stmt_lru->max = max_size;
+	/* Must be larger than 2 to make sense (to have a tail and head) */
+	if (max_size > 2)
+		stmt_lru->max = max_size;
+	else
+		stmt_lru->max = 3;
 }
 
 TrackerDBStatement *
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index b8f33bb..10fee09 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -28,6 +28,8 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 
 	public Connection () throws Sparql.Error
 	requires (!initialized) {
+		uint select_cache_size = 100;
+
 		try {
 			var connection = DBus.Bus.get (DBus.BusType.SESSION);
 
@@ -39,7 +41,13 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
 			throw new Sparql.Error.INTERNAL ("Unable to initialize database");
 		}
 
-		if (!Data.Manager.init (DBManagerFlags.READONLY, null, null, false, 100, 0, null, null)) {
+		string env_cache_size = Environment.get_variable ("TRACKER_SPARQL_CACHE_SIZE");
+
+		if (env_cache_size != null) {
+			select_cache_size = env_cache_size.to_int();
+		}
+
+		if (!Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null)) {
 			throw new Sparql.Error.INTERNAL ("Unable to initialize database");
 		}
 
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index e262a6b..6996bce 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -341,6 +341,9 @@ main (gint argc, gchar *argv[])
 	const gchar *rotate_to;
 	TrackerDBConfig *db_config;
 	gboolean do_rotating;
+	const gchar *cache_size_s;
+	guint select_cache_size;
+	guint update_cache_size;
 
 	g_type_init ();
 
@@ -477,12 +480,26 @@ main (gint argc, gchar *argv[])
 
 	tracker_db_journal_set_rotating (do_rotating, chunk_size, rotate_to);
 
+	cache_size_s = g_getenv ("TRACKER_STORE_SELECT_CACHE_SIZE");
+	if (cache_size_s != NULL && cache_size_s[0] != '\0') {
+		select_cache_size = atoi (cache_size_s);
+	} else {
+		select_cache_size = TRACKER_STORE_SELECT_CACHE_SIZE;
+	}
+
+	cache_size_s = g_getenv ("TRACKER_STORE_UPDATE_CACHE_SIZE");
+	if (cache_size_s != NULL && cache_size_s[0] != '\0') {
+		update_cache_size = atoi (cache_size_s);
+	} else {
+		update_cache_size = TRACKER_STORE_UPDATE_CACHE_SIZE;
+	}
+
 	if (!tracker_data_manager_init (flags,
 	                                NULL,
 	                                &is_first_time_index,
 	                                TRUE,
-	                                TRACKER_STORE_SELECT_CACHE_SIZE,
-	                                TRACKER_STORE_UPDATE_CACHE_SIZE,
+	                                select_cache_size,
+	                                update_cache_size,
 	                                busy_callback,
 	                                busy_user_data,
 	                                "Journal replaying")) {



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