protected override void HandleCommitPoints(IndexedItemsInfo itemsInfo, IndexSegmentsInfo segmentsInfo) { logIndexing.Error("HandlingCommitPoint for index {0} in DB {1}", this.PublicName, this.context.DatabaseName); if (ShouldStoreCommitPoint(itemsInfo) && itemsInfo.HighestETag != null) { context.IndexStorage.StoreCommitPoint(indexId.ToString(), new IndexCommitPoint { HighestCommitedETag = itemsInfo.HighestETag, TimeStamp = LastIndexTime, SegmentsInfo = segmentsInfo ?? IndexStorage.GetCurrentSegmentsInfo(indexDefinition.Name, directory) }); LastCommitPointStoreTime = SystemTime.UtcNow; } else if (itemsInfo.DeletedKeys != null && directory is RAMDirectory == false) { context.IndexStorage.AddDeletedKeysToCommitPoints(indexDefinition, itemsInfo.DeletedKeys); } }
private bool ShouldStoreCommitPoint(IndexedItemsInfo itemsInfo) { if (itemsInfo.DisableCommitPoint) return false; if (directory is RAMDirectory) // no point in trying to store commits for ram index return false; // no often than specified indexing interval return (LastIndexTime - PreviousIndexTime > context.Configuration.MinIndexingTimeIntervalToStoreCommitPoint || // at least once for specified time interval LastIndexTime - LastCommitPointStoreTime > context.Configuration.MaxIndexCommitPointStoreTimeInterval); }
protected override void HandleCommitPoints(IndexedItemsInfo itemsInfo, IndexSegmentsInfo segmentsInfo) { if (ShouldStoreCommitPoint(itemsInfo) && itemsInfo.HighestETag != null) { context.IndexStorage.StoreCommitPoint(indexId.ToString(), new IndexCommitPoint { HighestCommitedETag = itemsInfo.HighestETag, TimeStamp = LastIndexTime, SegmentsInfo = segmentsInfo ?? IndexStorage.GetCurrentSegmentsInfo(indexDefinition.Name, directory) }); LastCommitPointStoreTime = SystemTime.UtcNow; } else if (itemsInfo.DeletedKeys != null && directory is RAMDirectory == false) { context.IndexStorage.AddDeletedKeysToCommitPoints(indexDefinition, itemsInfo.DeletedKeys); } }
protected abstract void HandleCommitPoints(IndexedItemsInfo itemsInfo, IndexSegmentsInfo segmentsInfo);
protected void Write(Func<RavenIndexWriter, Analyzer, IndexingWorkStats, IndexedItemsInfo> action) { if (disposed) throw new ObjectDisposedException("Index " + name + " has been disposed"); PreviousIndexTime = LastIndexTime; LastIndexTime = SystemTime.UtcNow; lock (writeLock) { bool shouldRecreateSearcher; var toDispose = new List<Action>(); Analyzer searchAnalyzer = null; var itemsInfo = new IndexedItemsInfo(null); bool flushed = false; try { waitReason = "Write"; try { searchAnalyzer = CreateAnalyzer(new LowerCaseKeywordAnalyzer(), toDispose); } catch (Exception e) { context.AddError(name, "Creating Analyzer", e.ToString(), "Analyzer"); throw; } if (indexWriter == null) { CreateIndexWriter(); } var locker = directory.MakeLock("writing-to-index.lock"); try { var stats = new IndexingWorkStats(); try { if (locker.Obtain() == false) { throw new InvalidOperationException( string.Format("Could not obtain the 'writing-to-index' lock of '{0}' index", name)); } itemsInfo = action(indexWriter, searchAnalyzer, stats); shouldRecreateSearcher = itemsInfo.ChangedDocs > 0; foreach (var indexExtension in indexExtensions.Values) { indexExtension.OnDocumentsIndexed(currentlyIndexDocuments, searchAnalyzer); } } catch (Exception e) { context.AddError(name, null, e.ToString(), "Write"); throw; } if (itemsInfo.ChangedDocs > 0) { WriteInMemoryIndexToDiskIfNecessary(itemsInfo.HighestETag); if(indexWriter != null && indexWriter.RamSizeInBytes() >= flushSize) { Flush(itemsInfo.HighestETag); // just make sure changes are flushed to disk flushed = true; } UpdateIndexingStats(context, stats); } } finally { locker.Release(); } } catch (Exception e) { throw new InvalidOperationException("Could not properly write to index " + name, e); } finally { currentlyIndexDocuments.Clear(); if (searchAnalyzer != null) searchAnalyzer.Close(); foreach (Action dispose in toDispose) { dispose(); } waitReason = null; LastIndexTime = SystemTime.UtcNow; } if (flushed) { try { HandleCommitPoints(itemsInfo, GetCurrentSegmentsInfo()); } catch (Exception e) { logIndexing.WarnException("Could not handle commit point properly, ignoring", e); } } if (shouldRecreateSearcher) RecreateSearcher(); } }
protected override void HandleCommitPoints(IndexedItemsInfo itemsInfo, IndexSegmentsInfo segmentsInfo) { // MapReduce index does not store and use any commit points }
protected override void HandleCommitPoints(IndexedItemsInfo itemsInfo) { if (ShouldStoreCommitPoint() && itemsInfo.HighestETag != null) { context.IndexStorage.StoreCommitPoint(name, new IndexCommitPoint { HighestCommitedETag = itemsInfo.HighestETag, TimeStamp = LastIndexTime, SegmentsInfo = GetCurrentSegmentsInfo() }); LastCommitPointStoreTime = SystemTime.UtcNow; } else if (itemsInfo.DeletedKeys != null && directory is RAMDirectory == false) { context.IndexStorage.AddDeletedKeysToCommitPoints(name, itemsInfo.DeletedKeys); } }