Index: trunk/mwsearch/Search/SearchState.cs |
— | — | @@ -391,5 +391,10 @@ |
392 | 392 | public Query Parse(string term) { |
393 | 393 | return QueryParser.Parse(term, "contents", analyzer); |
394 | 394 | } |
| 395 | + |
| 396 | + public void Optimize() { |
| 397 | + OpenForWrite(); |
| 398 | + writer.Optimize(); |
| 399 | + } |
395 | 400 | } |
396 | 401 | } |
Index: trunk/mwsearch/UpdateDaemon/Daemon.cs |
— | — | @@ -91,6 +91,12 @@ |
92 | 92 | UpdateThread.Quit(); |
93 | 93 | return true; |
94 | 94 | } |
| 95 | + |
| 96 | + [XmlRpcMethod("searchupdater.optimize")] |
| 97 | + public bool Optimize() { |
| 98 | + UpdateThread.Optimize(); |
| 99 | + return true; |
| 100 | + } |
95 | 101 | |
96 | 102 | } |
97 | 103 | } |
Index: trunk/mwsearch/UpdateDaemon/UpdateThread.cs |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | static bool _isRunning = false; |
37 | 37 | static bool _done = false; |
38 | 38 | static bool _flushNow = false; |
| 39 | + static bool _flushOptimize = false; |
39 | 40 | static object _threadLock = new object(); |
40 | 41 | |
41 | 42 | // If more than this number are queued, try to flush out updates |
— | — | @@ -64,7 +65,7 @@ |
65 | 66 | |
66 | 67 | // Apply any remaining updates before we quit |
67 | 68 | lock (_threadLock) { |
68 | | - ApplyAll(_queuedUpdates); |
| 69 | + ApplyAll(_queuedUpdates, _flushOptimize); |
69 | 70 | } |
70 | 71 | |
71 | 72 | log.Info("Updater thread ending, quit requested."); |
— | — | @@ -74,6 +75,7 @@ |
75 | 76 | log.Debug("Checking for updates..."); |
76 | 77 | try { |
77 | 78 | Hashtable workUpdates = null; |
| 79 | + bool optimize; |
78 | 80 | lock (_threadLock) { |
79 | 81 | if (!_isRunning && !_flushNow) { |
80 | 82 | log.Debug("Update thread suspended."); |
— | — | @@ -97,8 +99,9 @@ |
98 | 100 | } |
99 | 101 | |
100 | 102 | workUpdates = SwitchOut(); |
| 103 | + optimize = _flushOptimize; |
101 | 104 | } |
102 | | - ApplyAll(workUpdates); |
| 105 | + ApplyAll(workUpdates, optimize); |
103 | 106 | } catch (Exception e) { |
104 | 107 | log.Error("Unexpected error in update thread: " + e); |
105 | 108 | return; |
— | — | @@ -119,12 +122,13 @@ |
120 | 123 | _queuedUpdates = new Hashtable(); |
121 | 124 | _lastFlush = DateTime.UtcNow; |
122 | 125 | _flushNow = false; |
| 126 | + _flushOptimize = false; |
123 | 127 | |
124 | 128 | return workUpdates; |
125 | 129 | } |
126 | 130 | } |
127 | 131 | |
128 | | - private static void ApplyOn(string databaseName, ICollection queue) { |
| 132 | + private static void ApplyOn(string databaseName, ICollection queue, bool optimize) { |
129 | 133 | try { |
130 | 134 | log.Info("Applying updates to " + databaseName); |
131 | 135 | SearchState state = GetSearchState(databaseName); |
— | — | @@ -136,6 +140,8 @@ |
137 | 141 | log.Info("Applying write pass: " + record); |
138 | 142 | record.ApplyWrites(state); |
139 | 143 | } |
| 144 | + if (optimize) |
| 145 | + state.Optimize(); |
140 | 146 | state.Reopen(); |
141 | 147 | log.Info("Closed updates on " + databaseName); |
142 | 148 | } catch (Exception e) { |
— | — | @@ -144,9 +150,9 @@ |
145 | 151 | } |
146 | 152 | } |
147 | 153 | |
148 | | - private static void ApplyAll(Hashtable workUpdates) { |
| 154 | + private static void ApplyAll(Hashtable workUpdates, bool optimize) { |
149 | 155 | foreach (string dbname in workUpdates.Keys) { |
150 | | - ApplyOn(dbname, ((Hashtable)workUpdates[dbname]).Values); |
| 156 | + ApplyOn(dbname, ((Hashtable)workUpdates[dbname]).Values, optimize); |
151 | 157 | } |
152 | 158 | } |
153 | 159 | |
— | — | @@ -214,5 +220,11 @@ |
215 | 221 | log.Info("Flush requested."); |
216 | 222 | _flushNow = true; |
217 | 223 | } |
| 224 | + |
| 225 | + public static void Optimize() { |
| 226 | + log.Info("Flush with optimization requested."); |
| 227 | + _flushOptimize = true; |
| 228 | + _flushNow = true; |
| 229 | + } |
218 | 230 | } |
219 | 231 | } |