internal override void Execute() { using (var optrace = new OperationTrace("WriterRestartActivity Execute")) { LuceneManager.Restart(); optrace.IsSuccessful = true; } }
internal override void Execute() { using (var optrace = new OperationTrace("RemoveDocumentActivity Execute")) { var delTerm = new Term(LuceneManager.KeyFieldName, NumericUtils.IntToPrefixCoded(this.VersionId)); LuceneManager.DeleteDocuments(new[] { delTerm }, MoveOrRename); base.Execute(); optrace.IsSuccessful = true; } }
internal override void Execute() { using (var optrace = new OperationTrace("UpdateDocumentActivity Execute")) { if (Document != null) LuceneManager.UpdateDocument(GetIdTerm(Document), Document); base.Execute(); optrace.IsSuccessful = true; } }
internal override void Execute() { using (var optrace = new OperationTrace("RemoveTreeActivity Execute")) { var terms = new[] { new Term("InTree", TreeRoot), new Term("Path", TreeRoot) }; LuceneManager.DeleteDocuments(terms, MoveOrRename); base.Execute(); optrace.IsSuccessful = true; } }
internal override void Execute() { using (var optrace = new OperationTrace("AddDocumentActivity Execute")) { if (Document != null) { if (true == this.SingleVersion) LuceneManager.AddCompleteDocument(Document); else LuceneManager.AddDocument(Document); } base.Execute(); optrace.IsSuccessful = true; } }
internal override void Execute() { using (var optrace = new OperationTrace("AddTreeActivity Execute")) { var count = 0; foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath(TreeRoot)) { var doc = IndexDocumentInfo.GetDocument(docData); LuceneManager.AddCompleteDocument(doc); count++; } Logger.WriteInformation(String.Concat("AddTreeActivity: ", count, " item added")); base.Execute(); optrace.IsSuccessful = true; } }
public virtual Document CreateDocument() { using (var optrace = new OperationTrace("CreateDocument")) { if (_indexDocumentData != null) { //Trace.WriteLine("###I> create document from indexdocumentdata"); // create document from indexdocumentdata if it has been supplied (eg via MSMQ if it was small enough to send it over) var docInfo = _indexDocumentData.IndexDocumentInfo as IndexDocumentInfo; var doc = IndexDocumentInfo.CreateDocument(docInfo, _indexDocumentData); optrace.IsSuccessful = true; return doc; } else { //Trace.WriteLine("###I> get document from db"); // create document via loading it from db (eg when indexdocumentdata was too large to send over MSMQ) var doc = IndexDocumentInfo.GetDocument(this.VersionId); optrace.IsSuccessful = true; return doc; } } }
private static void OptimizeBeforeBackup(string indexDirectoryPath) { using (var optrace = new OperationTrace("Optimize index")) { Progress.StartOptimizeBeforeBackup(); var dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexDirectoryPath, false); var writer = new Lucene.Net.Index.IndexWriter(dir, IndexManager.GetAnalyzer(), false, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); writer.Optimize(); writer.Close(); if (!SenseNet.ContentRepository.RepositoryInstance.WaitForWriterLockFileIsReleased(StorageContext.Search.IndexDirectoryBackupPath)) throw new ApplicationException("Writer lock releasing time out."); Progress.FinishOptimizeBeforeBackup(); optrace.IsSuccessful = true; } }
internal static void RestoreIndex(bool force, System.IO.TextWriter consoleOut) { using (var optrace = new OperationTrace("Restore index")) { var recoveredZipPath = IO.Path.Combine(_backupDirectoryPath, RECOVEREDFILENAME); var recoveredFilesPath = IO.Path.Combine(_backupDirectoryPath, COMPRESSIONROOT); Guid lastIdFromDb; var need = NeedRestore(out lastIdFromDb); if (force || need) { EnsureEmptyDirctory(_backupDirectoryPath); RecoverIndexBackupFromDb(recoveredZipPath); DecompressTheIndex(recoveredZipPath, _backupDirectoryPath); var dir = SenseNet.ContentRepository.Storage.IndexDirectory.CreateNew(); //EnsureEmptyDirctory(IndexDirectoryPath); MoveDirectoryContent(recoveredFilesPath, dir); SaveBackupIdToFile(lastIdFromDb, IO.Path.Combine(dir, RESTOREINFOFILENAME)); SenseNet.ContentRepository.Storage.IndexDirectory.Reset(); SenseNet.ContentRepository.Storage.IndexDirectory.RemoveUnnecessaryDirectories(); if (consoleOut != null) { consoleOut.WriteLine(" Index directory is restored."); consoleOut.WriteLine(" Path: {0},", IndexDirectoryPath); consoleOut.WriteLine(" BackupId: {0},", lastIdFromDb); } Logger.WriteInformation("Index directory is successfully restored.", Logger.EmptyCategoryList, new Dictionary<string, object> { { "BackupId", lastIdFromDb } }); } else { if (consoleOut != null) consoleOut.WriteLine(" Index directory restoring is skipped."); Logger.WriteVerbose("Index directory restoring is skipped.", Logger.EmptyCategoryList, new Dictionary<string, object> { { "BackupId", lastIdFromDb } }); } optrace.IsSuccessful = true; } }
internal static void BackupIndexImmediatelly() // caller: DocumentPopulator.ClearAndPopulateAll { using (var optrace = new OperationTrace("Backup index immediatelly.")) { EnsureEmptyDirctory(_backupDirectoryPath); CopyIndexToBackupDirectory(); OptimizeCompressAndStore(); optrace.IsSuccessful = true; } }
/// <summary> /// Synchronous backup method for console applications. /// </summary> public static void SynchronousBackupIndex() { using (var optrace = new OperationTrace("Backup index immediatelly.")) { EnsureEmptyDirctory(_backupDirectoryPath); LuceneManager.PauseIndexing(); while (!LuceneManager.Paused) { Thread.Sleep(100); } Thread.Sleep(1000); try { CopyIndexToBackupDirectory(); } finally { LuceneManager.ContinueIndexing(); } OptimizeCompressAndStore(); optrace.IsSuccessful = true; } }
//============================================================ Helper methods private static void PreloadTypes() { using (var optrace = new OperationTrace("PreloadTypes")) { try { //preload types by name foreach (var typeName in TypesToPreloadByName) { TypeHandler.GetType(typeName); } //preload types by base foreach (var typeName in TypesToPreloadByBase) { TypeHandler.GetTypesByBaseType(TypeHandler.GetType(typeName)); } //preload types by interface foreach (var typeName in TypesToPreloadByInterface) { TypeHandler.GetTypesByInterface(TypeHandler.GetType(typeName)); } optrace.IsSuccessful = true; } catch (Exception ex) { Logger.WriteException(ex); } } }