public static void Startup(System.IO.TextWriter consoleOut) { // initalize from index CompletionState cud; using (var readerFrame = LuceneManager.GetIndexReaderFrame()) cud = CompletionState.ParseFromReader(readerFrame.IndexReader); var lastDatabaseId = LuceneManager.GetLastStoredIndexingActivityId(); using (var op = SnTrace.Index.StartOperation("IAQ: InitializeFromIndex. LastIndexedActivityId: {0}, LastDatabaseId: {1}, TotalUnprocessed: {2}" , cud.LastActivityId, lastDatabaseId, lastDatabaseId - cud.LastActivityId + cud.GapsLength)) { Startup(lastDatabaseId, cud.LastActivityId, cud.Gaps, consoleOut); op.Successful = true; } }
/*======================================================================================================= IIndexPopulator Members */ // caller: IndexPopulator.Populator, Import.Importer, Tests.Initializer, RunOnce public void ClearAndPopulateAll(bool backup = true) { var lastActivityId = LuceneManager.GetLastStoredIndexingActivityId(); var commitData = CompletionState.GetCommitUserData(lastActivityId); using (var op = SnTrace.Index.StartOperation("IndexPopulator ClearAndPopulateAll")) { // recreate var writer = IndexManager.GetIndexWriter(true); try { var excludedNodeTypes = LuceneManager.GetNotIndexedNodeTypes(); foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath("/Root", excludedNodeTypes)) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } RepositoryInstance.Instance.ConsoleWrite(" Commiting ... "); writer.Commit(commitData); RepositoryInstance.Instance.ConsoleWriteLine("ok"); RepositoryInstance.Instance.ConsoleWrite(" Optimizing ... "); writer.Optimize(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } finally { writer.Close(); } RepositoryInstance.Instance.ConsoleWrite(" Deleting indexing activities ... "); LuceneManager.DeleteAllIndexingActivities(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); if (backup) { RepositoryInstance.Instance.ConsoleWrite(" Making backup ... "); BackupTools.BackupIndexImmediatelly(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } op.Successful = true; } }
internal static void HealthCheck() { if (IsWorking()) { SnTrace.Index.Write("IAQ: Health check triggered but ignored."); return; } SnTrace.Index.Write("IAQ: Health check triggered."); var state = TerminationHistory.GetCurrentState(); var gapsLength = state.Gaps.Length; if (gapsLength > 0) { SnTrace.IndexQueue.Write("IAQ: Health checker is processing {0} gap{1}.", gapsLength, gapsLength > 1 ? "s" : ""); foreach (LuceneIndexingActivity activity in new IndexingActivityLoader(state.Gaps, false)) { WaitIfOverloaded(); IndexingActivityQueue.ExecuteActivity(activity); } } var lastId = TerminationHistory.GetLastTerminatedId(); var lastDbId = LuceneManager.GetLastStoredIndexingActivityId(); var newerCount = lastDbId - lastId; if (lastId < lastDbId) { SnTrace.IndexQueue.Write("IAQ: Health checker is processing activities from {0} to {1}", (lastId + 1), lastDbId); foreach (LuceneIndexingActivity activity in new IndexingActivityLoader(lastId + 1, lastDbId, false)) { WaitIfOverloaded(); IndexingActivityQueue.ExecuteActivity(activity); } } }
public static object CheckIndexIntegrity(SenseNet.ContentRepository.Content content, bool recurse) { var path = content == null ? null : content.Path; CompletionState completionState; using (var readerFrame = LuceneManager.GetIndexReaderFrame()) completionState = CompletionState.ParseFromReader(readerFrame.IndexReader); var lastDatabaseId = LuceneManager.GetLastStoredIndexingActivityId(); var channel = SenseNet.ContentRepository.DistributedApplication.ClusterChannel; var appDomainName = channel == null ? null : channel.ReceiverName; return(new { AppDomainName = appDomainName, LastStoredActivity = lastDatabaseId, LastProcessedActivity = completionState.LastActivityId, GapsLength = completionState.GapsLength, Gaps = completionState.Gaps, Differences = Check(path, recurse) }); }