r10323 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10322‎ | r10323 | r10324 >
Date:23:26, 30 July 2005
Author:vibber
Status:old
Tags:
Comment:
Include option to optimize indexes on flush. (This can be slow for large indexes)
Modified paths:
  • /trunk/mwsearch/Search/SearchState.cs (modified) (history)
  • /trunk/mwsearch/UpdateDaemon/Daemon.cs (modified) (history)
  • /trunk/mwsearch/UpdateDaemon/UpdateThread.cs (modified) (history)

Diff [purge]

Index: trunk/mwsearch/Search/SearchState.cs
@@ -391,5 +391,10 @@
392392 public Query Parse(string term) {
393393 return QueryParser.Parse(term, "contents", analyzer);
394394 }
 395+
 396+ public void Optimize() {
 397+ OpenForWrite();
 398+ writer.Optimize();
 399+ }
395400 }
396401 }
Index: trunk/mwsearch/UpdateDaemon/Daemon.cs
@@ -91,6 +91,12 @@
9292 UpdateThread.Quit();
9393 return true;
9494 }
 95+
 96+ [XmlRpcMethod("searchupdater.optimize")]
 97+ public bool Optimize() {
 98+ UpdateThread.Optimize();
 99+ return true;
 100+ }
95101
96102 }
97103 }
Index: trunk/mwsearch/UpdateDaemon/UpdateThread.cs
@@ -35,6 +35,7 @@
3636 static bool _isRunning = false;
3737 static bool _done = false;
3838 static bool _flushNow = false;
 39+ static bool _flushOptimize = false;
3940 static object _threadLock = new object();
4041
4142 // If more than this number are queued, try to flush out updates
@@ -64,7 +65,7 @@
6566
6667 // Apply any remaining updates before we quit
6768 lock (_threadLock) {
68 - ApplyAll(_queuedUpdates);
 69+ ApplyAll(_queuedUpdates, _flushOptimize);
6970 }
7071
7172 log.Info("Updater thread ending, quit requested.");
@@ -74,6 +75,7 @@
7576 log.Debug("Checking for updates...");
7677 try {
7778 Hashtable workUpdates = null;
 79+ bool optimize;
7880 lock (_threadLock) {
7981 if (!_isRunning && !_flushNow) {
8082 log.Debug("Update thread suspended.");
@@ -97,8 +99,9 @@
98100 }
99101
100102 workUpdates = SwitchOut();
 103+ optimize = _flushOptimize;
101104 }
102 - ApplyAll(workUpdates);
 105+ ApplyAll(workUpdates, optimize);
103106 } catch (Exception e) {
104107 log.Error("Unexpected error in update thread: " + e);
105108 return;
@@ -119,12 +122,13 @@
120123 _queuedUpdates = new Hashtable();
121124 _lastFlush = DateTime.UtcNow;
122125 _flushNow = false;
 126+ _flushOptimize = false;
123127
124128 return workUpdates;
125129 }
126130 }
127131
128 - private static void ApplyOn(string databaseName, ICollection queue) {
 132+ private static void ApplyOn(string databaseName, ICollection queue, bool optimize) {
129133 try {
130134 log.Info("Applying updates to " + databaseName);
131135 SearchState state = GetSearchState(databaseName);
@@ -136,6 +140,8 @@
137141 log.Info("Applying write pass: " + record);
138142 record.ApplyWrites(state);
139143 }
 144+ if (optimize)
 145+ state.Optimize();
140146 state.Reopen();
141147 log.Info("Closed updates on " + databaseName);
142148 } catch (Exception e) {
@@ -144,9 +150,9 @@
145151 }
146152 }
147153
148 - private static void ApplyAll(Hashtable workUpdates) {
 154+ private static void ApplyAll(Hashtable workUpdates, bool optimize) {
149155 foreach (string dbname in workUpdates.Keys) {
150 - ApplyOn(dbname, ((Hashtable)workUpdates[dbname]).Values);
 156+ ApplyOn(dbname, ((Hashtable)workUpdates[dbname]).Values, optimize);
151157 }
152158 }
153159
@@ -214,5 +220,11 @@
215221 log.Info("Flush requested.");
216222 _flushNow = true;
217223 }
 224+
 225+ public static void Optimize() {
 226+ log.Info("Flush with optimization requested.");
 227+ _flushOptimize = true;
 228+ _flushNow = true;
 229+ }
218230 }
219231 }

Status & tagging log