Ejemplo n.º 1
0
        private void InitializeMainIndexStorage(Transaction tx, StorageEnvironment environment)
        {
            _directory = new LuceneVoronDirectory(tx, environment);

            using (_directory.SetTransaction(tx, out IState state))
            {
                CreateIndexStructure(_directory, state);
                RecreateSearcher(tx);
            }
        }
        public LuceneSuggestionIndexWriter(string field, LuceneVoronDirectory directory, SnapshotDeletionPolicy snapshotter, IndexWriter.MaxFieldLength maxFieldLength, Index index, IState state)
        {
            _directory           = directory;
            _indexDeletionPolicy = snapshotter;
            _maxFieldLength      = maxFieldLength;
            _index  = index;
            _field  = field;
            _logger = LoggingSource.Instance.GetLogger <LuceneSuggestionIndexWriter>(_index.DocumentDatabase.Name);

            RecreateIndexWriter(state);
        }
Ejemplo n.º 3
0
 public LuceneIndexWriter(LuceneVoronDirectory d, Analyzer a, IndexDeletionPolicy deletionPolicy,
                          IndexWriter.MaxFieldLength mfl, IndexWriter.IndexReaderWarmer indexReaderWarmer, Index index, IState state)
 {
     _directory           = d;
     _analyzer            = a;
     _indexDeletionPolicy = deletionPolicy;
     _maxFieldLength      = mfl;
     _indexReaderWarmer   = indexReaderWarmer;
     _logger = LoggingSource.Instance.GetLogger <LuceneIndexWriter>(index.DocumentDatabase.Name);
     RecreateIndexWriter(state);
 }
Ejemplo n.º 4
0
        public void Lucene_directory_must_be_aware_of_created_outputs()
        {
            using (var tx = Env.WriteTransaction())
            {
                var dir = new LuceneVoronDirectory(tx, Env);

                var state = new VoronState(tx);

                dir.CreateOutput("file", state);
                Assert.True(dir.FileExists("file", state));

                dir.DeleteFile("file", state);
                Assert.False(dir.FileExists("file", state));
            }
        }
Ejemplo n.º 5
0
        public IndexReadOperation(Index index, LuceneVoronDirectory directory, IndexSearcherHolder searcherHolder, Transaction readTransaction)
            : base(index.Name, LoggingSource.Instance.GetLogger <IndexReadOperation>(index._indexStorage.DocumentDatabase.Name))
        {
            try
            {
                _analyzer = CreateAnalyzer(() => new LowerCaseKeywordAnalyzer(), index.Definition.IndexFields, forQuerying: true);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            _maxNumberOfOutputsPerDocument = index.MaxNumberOfOutputsPerDocument;
            _indexType              = index.Type;
            _indexHasBoostedFields  = index.HasBoostedFields;
            _releaseReadTransaction = directory.SetTransaction(readTransaction, out _state);
            _releaseSearcher        = searcherHolder.GetSearcher(readTransaction, _state, out _searcher);
        }
Ejemplo n.º 6
0
        private void InitializeSuggestionsIndexStorage(Transaction tx, StorageEnvironment environment)
        {
            foreach (var field in _fields)
            {
                if (!field.Value.HasSuggestions)
                {
                    continue;
                }

                var directory = new LuceneVoronDirectory(tx, environment, $"Suggestions-{field.Key}");
                _suggestionsDirectories[field.Key] = directory;

                using (directory.SetTransaction(tx, out IState state))
                {
                    CreateIndexStructure(directory, state);
                    RecreateSuggestionsSearcher(tx, field.Key);
                }
            }
        }
Ejemplo n.º 7
0
        public IndexFacetedReadOperation(string indexName,
                                         Dictionary <string, IndexField> fields,
                                         LuceneVoronDirectory directory,
                                         IndexSearcherHolder searcherHolder,
                                         Transaction readTransaction,
                                         DocumentDatabase documentDatabase)
            : base(indexName, LoggingSource.Instance.GetLogger <IndexFacetedReadOperation>(documentDatabase.Name))
        {
            try
            {
                _analyzer = CreateAnalyzer(() => new LowerCaseKeywordAnalyzer(), fields, forQuerying: true);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            _releaseReadTransaction = directory.SetTransaction(readTransaction, out _state);
            _currentStateHolder     = searcherHolder.GetStateHolder(readTransaction);
            _searcher = _currentStateHolder.GetIndexSearcher(_state);
        }
Ejemplo n.º 8
0
        public IndexWriteOperation(Index index, LuceneVoronDirectory directory, LuceneDocumentConverterBase converter, Transaction writeTransaction, LuceneIndexPersistence persistence)
            : base(index, LoggingSource.Instance.GetLogger <IndexWriteOperation>(index._indexStorage.DocumentDatabase.Name))
        {
            _converter       = converter;
            DocumentDatabase = index._indexStorage.DocumentDatabase;

            try
            {
                _analyzer = CreateAnalyzer(index, index.Definition);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            try
            {
                _releaseWriteTransaction = directory.SetTransaction(writeTransaction, out _state);
                _writer = persistence.EnsureIndexWriter(_state);

                _suggestionsWriters = persistence.EnsureSuggestionIndexWriter(_state);
                _hasSuggestions     = _suggestionsWriters.Count > 0;

                _locker    = directory.MakeLock("writing-to-index.lock");
                _directory = directory;

                if (_locker.Obtain() == false)
                {
                    throw new InvalidOperationException($"Could not obtain the 'writing-to-index' lock for '{_indexName}' index.");
                }
            }
            catch (Exception e) when(e.IsOutOfMemory())
            {
                throw;
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }
Ejemplo n.º 9
0
        public IndexFacetedReadOperation(Index index,
                                         IndexDefinitionBaseServerSide indexDefinition,
                                         LuceneVoronDirectory directory,
                                         IndexSearcherHolder searcherHolder,
                                         QueryBuilderFactories queryBuilderFactories,
                                         Transaction readTransaction,
                                         DocumentDatabase documentDatabase)
            : base(index, LoggingSource.Instance.GetLogger <IndexFacetedReadOperation>(documentDatabase.Name))
        {
            try
            {
                _analyzer = CreateAnalyzer(index, indexDefinition, forQuerying: true);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            _queryBuilderFactories  = queryBuilderFactories;
            _releaseReadTransaction = directory.SetTransaction(readTransaction, out _state);
            _releaseSearcher        = searcherHolder.GetSearcher(readTransaction, _state, out _searcher);
        }
Ejemplo n.º 10
0
        public static void TryThrowingBetterException(SystemException e, LuceneVoronDirectory directory)
        {
            if (e.Message.StartsWith("this writer hit an OutOfMemoryError"))
            {
                throw new OutOfMemoryException("Index writer hit OOM during commit", e);
            }

            if (e.InnerException is VoronUnrecoverableErrorException)
            {
                VoronUnrecoverableErrorException.Raise("Index data is corrupted", e);
            }

            if (e.IsOutOfDiskSpaceException())
            {
                // this commit stage is written to the temp scratch buffers
                var fullPath  = directory.TempFullPath;
                var driveInfo = DiskSpaceChecker.GetDiskSpaceInfo(fullPath);
                var freeSpace = driveInfo != null?driveInfo.TotalFreeSpace.ToString() : "N/A";

                throw new DiskFullException($"There isn't enough space to commit the index to {fullPath}. " +
                                            $"Currently available space: {freeSpace}", e);
            }
        }
Ejemplo n.º 11
0
 private void CreateIndexStructure(LuceneVoronDirectory directory, IState state)
 {
     new IndexWriter(directory, _dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED, state).Dispose();
 }
Ejemplo n.º 12
0
 public LuceneSuggestionIndexReader(Index index, LuceneVoronDirectory directory, IndexSearcherHolder searcherHolder, Transaction readTransaction)
     : base(index, LoggingSource.Instance.GetLogger <LuceneSuggestionIndexReader>(index._indexStorage.DocumentDatabase.Name))
 {
     _releaseReadTransaction = directory.SetTransaction(readTransaction, out _state);
     _releaseSearcher        = searcherHolder.GetSearcher(readTransaction, _state, out _searcher);
 }