private void OpenIndex(PathSetting path, string indexPath, List <Exception> exceptions, string name) { Index index = null; try { index = Index.Open(indexPath, _documentDatabase); index.Start(); if (_logger.IsInfoEnabled) { _logger.Info($"Started {index.Name} from {indexPath}"); } _indexes.Add(index); } catch (Exception e) { var alreadyFaulted = false; if (index != null && _indexes.TryGetByName(index.Name, out Index i)) { if (i is FaultyInMemoryIndex) { alreadyFaulted = true; } } index?.Dispose(); exceptions?.Add(e); if (alreadyFaulted) { return; } var configuration = new FaultyInMemoryIndexConfiguration(path, _documentDatabase.Configuration); var fakeIndex = new FaultyInMemoryIndex(e, name, configuration); var message = $"Could not open index at '{indexPath}'. Created in-memory, fake instance: {fakeIndex.Name}"; if (_logger.IsInfoEnabled) { _logger.Info(message, e); } _documentDatabase.NotificationCenter.Add(AlertRaised.Create( _documentDatabase.Name, "Indexes store initialization error", message, AlertType.IndexStore_IndexCouldNotBeOpened, NotificationSeverity.Error, key: fakeIndex.Name, details: new ExceptionDetails(e))); _indexes.Add(fakeIndex); } }
private void HandleChangesForStaticIndexes(DatabaseRecord record, long index) { foreach (var kvp in record.Indexes) { var name = kvp.Key; var definition = kvp.Value; try { HandleStaticIndexChange(name, definition); } catch (Exception exception) { _documentDatabase.RachisLogIndexNotifications.NotifyListenersAbout(index, exception); var indexName = name; if (_logger.IsInfoEnabled) { _logger.Info($"Could not update static index {name}", exception); } //If we don't have the index in memory this means that it is corrupted when trying to load it //If we do have the index and it is not faulted this means that this is the replacment index that is faulty //If we already have a replacment that is faulty don't add a new one if (_indexes.TryGetByName(indexName, out Index i)) { if (i is FaultyInMemoryIndex) { return; } indexName = Constants.Documents.Indexing.SideBySideIndexNamePrefix + name; if (_indexes.TryGetByName(indexName, out Index j) && j is FaultyInMemoryIndex) { return; } } var configuration = new FaultyInMemoryIndexConfiguration(_documentDatabase.Configuration.Indexing.StoragePath, _documentDatabase.Configuration); var fakeIndex = new FaultyInMemoryIndex(exception, indexName, configuration); _indexes.Add(fakeIndex); } } }
private void OpenIndexesFromDirectory(string path) { if (Directory.Exists(path) == false) { return; } if (_logger.IsInfoEnabled) { _logger.Info($"Starting to load indexes from {path}"); } var indexes = new SortedList <int, Tuple <string, string> >(); foreach (var indexDirectory in new DirectoryInfo(path).GetDirectories()) { if (_documentDatabase.DatabaseShutdown.IsCancellationRequested) { return; } int indexId; string indexName; if (IndexDefinitionBase.TryReadIdFromDirectory(indexDirectory, out indexId, out indexName) == false) { continue; } indexes[indexId] = Tuple.Create(indexDirectory.FullName, indexName); } foreach (var indexDirectory in indexes) { if (_documentDatabase.DatabaseShutdown.IsCancellationRequested) { return; } int indexId = indexDirectory.Key; string indexName = indexDirectory.Value.Item2; var indexPath = indexDirectory.Value.Item1; List <Exception> exceptions = null; if (_documentDatabase.Configuration.Core.ThrowIfAnyIndexOrTransformerCouldNotBeOpened) { exceptions = new List <Exception>(); } Index _; if (_indexes.TryGetById(indexId, out _)) { var message = $"Could not open index with id {indexId} at '{indexPath}'. Index with the same id already exists."; exceptions?.Add(new InvalidOperationException(message)); if (_logger.IsOperationsEnabled) { _logger.Operations(message); } } else { Index index = null; try { index = Index.Open(indexId, indexPath, _documentDatabase); index.Start(); if (_logger.IsInfoEnabled) { _logger.Info($"Started {index.Name} from {indexPath}"); } _indexes.Add(index); } catch (Exception e) { index?.Dispose(); exceptions?.Add(e); var fakeIndex = new FaultyInMemoryIndex(e, indexId, IndexDefinitionBase.TryReadNameFromMetadataFile(indexPath) ?? indexName); if (_logger.IsInfoEnabled) { _logger.Info($"Could not open index with id {indexId} at '{indexPath}'. Created in-memory, fake instance: {fakeIndex.Name}", e); } // TODO arek: add alert _indexes.Add(fakeIndex); } } if (exceptions != null && exceptions.Count > 0) { throw new AggregateException("Could not load some of the indexes", exceptions); } } }