private void FlushPendingOperations(int batchedItemsAmount) { try { this.flushInprogress = true; do { PendingIndexOperation pendingOp = null; //perform all queued operations on the index lock (this.pendingIndexOperations.SyncRoot) { if (this.pendingIndexOperations.Count > 0) { pendingOp = this.pendingIndexOperations.Dequeue() as PendingIndexOperation; } } //lock //Optimizing the index is an expensive operation so we don't want to //call it if the queue is being flushed since it may delay application exit. if ((pendingOp != null) && (pendingOp.Action != IndexOperation.OptimizeIndex)) { this.PerformOperation(pendingOp); } batchedItemsAmount--; //potential race condition on this.pendingIndexOperations.Count but chances are very low } while (this.pendingIndexOperations.Count > 0 && batchedItemsAmount >= 0); } finally { this.flushInprogress = false; } }
private void RaiseFinishedIndexOperationEvent(PendingIndexOperation current) { if (this.FinishedIndexOperation != null) { this.FinishedIndexOperation(this, new FinishedIndexOperationEventArgs(current)); } }
/// <summary> /// Performs the specified PendingIndexOperation. /// </summary> /// <param name="current">The operation to perform</param> private void PerformOperation(PendingIndexOperation current) { try { switch (current.Action) { case IndexOperation.AddSingleDocument: this.AddSingleDocument((Document)current.Parameters[0], (string)current.Parameters[1]); break; case IndexOperation.AddMultipleDocuments: this.AddMultipleDocuments((Document[])current.Parameters[0], (string)current.Parameters[1]); break; case IndexOperation.DeleteDocuments: this.DeleteTerm((Term)current.Parameters[0]); break; case IndexOperation.OptimizeIndex: this.OptimizeIndex(); break; default: Debug.Assert(false, "Unknown index operation: " + current.Action); return; } }catch (FileNotFoundException fe) { /* index has gotten corrupted and refers to a non-existence index file */ this.ResetIndex(); _log.Error("Index is corrupted, recreating index:", fe); }catch (IndexOutOfRangeException ioore) { /* index has gotten corrupted, */ this.ResetIndex(); _log.Error("Index is corrupted, recreating index:", ioore); } catch (UnauthorizedAccessException uae) { /* another process may be accessing index files */ _log.Error("Index files may be in use, sleeping:", uae); Thread.Sleep(TimeToDelayBeforeRetry); }catch (ArgumentOutOfRangeException aoore) { /* index has gotten corrupted, */ this.ResetIndex(); _log.Error("Index is corrupted, recreating index:", aoore); } RaiseFinishedIndexOperationEvent(current); }
public FinishedIndexOperationEventArgs(PendingIndexOperation op) { this.Operation = op; }