public void Clean(IndexCleanup mode) { Debug.Assert(mode != IndexCleanup.None, "mode != IndexCleanup.None"); _converter?.Clean(); _indexSearcherHolder.Cleanup(_index._indexStorage.Environment().PossibleOldestReadTransaction(null), mode); if (mode.HasFlag(IndexCleanup.Writers)) { if (_indexWriter != null) { // schedule index run only if clean is really needed _indexWriterCleanupNeeded = true; _index.ScheduleIndexingRun(); } } if (mode.HasFlag(IndexCleanup.Readers)) { lock (_readersLock) { _lastReader?.DecRef(null); _lastReader = null; } } }
public void Cleanup(long oldestTx, IndexCleanup mode = IndexCleanup.Basic) { // note: cleanup cannot be called concurrently if (_states.Count > 1) { // let's mark states which are no longer needed as ready for disposal for (var i = _states.Count - 1; i >= 1; i--) { var state = _states[i]; if (state.AsOfTxId >= oldestTx) { break; } var nextState = _states[i - 1]; if (nextState.AsOfTxId > oldestTx) { break; } Interlocked.Increment(ref state.Usage); using (state) { state.MarkForDisposal(); } _states = _states.Remove(state); } } if (mode.HasFlag(IndexCleanup.Readers)) { foreach (var state in _states) { state.MoveBackToLazy(); } } }