Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
                }
            }
        }