beagle r4766 - trunk/beagle/beagled



Author: dbera
Date: Sun Jun  1 03:28:24 2008
New Revision: 4766
URL: http://svn.gnome.org/viewvc/beagle?rev=4766&view=rev

Log:
r2417 had partly negated the performance boost added in r2215 by allowing the search methods to call ReleaseReader. This essentially led to the creation of a new IndexReader almost everytime. Now we ensure that we have 1 IndexReader open at all times. Add a special method to even remove that 1 always-open IndexReader and use that from StaticQueryable to unload removable indexes.


Modified:
   trunk/beagle/beagled/LuceneCommon.cs
   trunk/beagle/beagled/StaticQueryable.cs

Modified: trunk/beagle/beagled/LuceneCommon.cs
==============================================================================
--- trunk/beagle/beagled/LuceneCommon.cs	(original)
+++ trunk/beagle/beagled/LuceneCommon.cs	Sun Jun  1 03:28:24 2008
@@ -1913,6 +1913,19 @@
 				this.Version = version;
 				this.Refcount = 1;
 			}
+
+			// Use these methods to keep one instance of a reader
+			// always opened.
+
+			public void MarkNoClose ()
+			{
+				this.Refcount ++;
+			}
+
+			public void MarkClose ()
+			{
+				this.Refcount --;
+			}
 		}
 
 		static private Hashtable directory_rav_map = new Hashtable ();
@@ -1938,6 +1951,7 @@
 					reader = IndexReader.Open (directory);
 
 					rav = new ReaderAndVersion (reader, version);
+					rav.MarkNoClose (); // keep this reader open until...
 
 					directory_rav_map [directory] = rav;
 					reader_rav_map [reader] = rav;
@@ -1948,6 +1962,8 @@
 				version = IndexReader.GetCurrentVersion (directory);
 				
 				if (version != rav.Version) {
+					rav.MarkClose ();
+
 					reader = IndexReader.Open (directory);
 
 					rav = new ReaderAndVersion (reader, version);
@@ -1985,6 +2001,21 @@
 			}
 		}
 
+		// Special function to permanently remove this reader
+		// Called when StaticQueryables need to unload
+		static internal void CloseReader (IndexReader reader)
+		{
+			lock (reader_rav_map) {
+				ReaderAndVersion rav = (ReaderAndVersion) reader_rav_map [reader];
+
+				if (rav != null) {
+					rav.MarkClose ();
+					UnrefReaderAndVersion_Unlocked (rav);
+				} else
+					reader.Close ();
+			}
+		}
+
 		static public void ReleaseSearcher (LNS.IndexSearcher searcher)
 		{
 			IndexReader reader = searcher.GetIndexReader ();
@@ -2201,5 +2232,31 @@
 
 			return hits_by_uri.Values;
 		}
+
+		//////////////////////////////////////////////////
+
+		public static void DebugHook ()
+		{
+			lock (reader_rav_map) {
+				Lucene.Net.Store.Directory dir;
+				ReaderAndVersion rav;
+				IndexReader reader;
+
+				Log.Debug ("Cached readers per directory:");
+				foreach (DictionaryEntry entry in directory_rav_map) {
+					dir = entry.Key as Lucene.Net.Store.Directory;
+					rav = entry.Value as ReaderAndVersion;
+					Log.Debug ("\tDirectory {0} has {1} readers open", dir.GetLockID (), rav.Refcount);
+				}
+
+				Log.Debug ("Opened readers:");
+				foreach (DictionaryEntry entry in reader_rav_map) {
+					reader = entry.Key as IndexReader;
+					rav = entry.Value as ReaderAndVersion;
+					dir = reader.Directory ();
+					Log.Debug ("\t{2} readers v{0} opened for directory {1}", rav.Version, dir.GetLockID (), rav.Refcount);
+				}
+			}
+		}
 	}
 }

Modified: trunk/beagle/beagled/StaticQueryable.cs
==============================================================================
--- trunk/beagle/beagled/StaticQueryable.cs	(original)
+++ trunk/beagle/beagled/StaticQueryable.cs	Sun Jun  1 03:28:24 2008
@@ -60,6 +60,11 @@
 			Log.Debug ("Removing static queryable {0}", IndexName);
 			if (text_cache != null)
 				text_cache.Dispose ();
+
+			// Free the cached IndexReaders
+			LuceneCommon.CloseReader (LuceneCommon.GetReader (Driver.PrimaryStore));
+			LuceneCommon.CloseReader (LuceneCommon.GetReader (Driver.SecondaryStore));
+
 			Driver.PrimaryStore.Close ();
 			Driver.SecondaryStore.Close ();
 			FileAttributesStore.Dispose ();



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