コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void deleteIndex(IndexIdentifier identifier, boolean recovery) throws java.io.IOException
        internal virtual void DeleteIndex(IndexIdentifier identifier, bool recovery)
        {
            if (_readOnly)
            {
                throw new System.InvalidOperationException("Index deletion in read only mode is not supported.");
            }
            CloseIndex(identifier);
            FileUtils.deleteRecursively(GetFileDirectory(_baseStorePath, identifier));
            _indexTypeMap.Remove(identifier);
            bool removeFromIndexStore = !recovery || (_indexStore.has(identifier.EntityType.entityClass(), identifier.IndexName));

            if (removeFromIndexStore)
            {
                _indexStore.remove(identifier.EntityType.entityClass(), identifier.IndexName);
            }
            _typeCache.invalidate(identifier);
        }
コード例 #2
0
 private void CloseIndex(IndexIdentifier identifier)
 {
     lock (this)
     {
         try
         {
             IndexReference searcher = _indexSearchers.remove(identifier);
             if (searcher != null)
             {
                 searcher.Dispose();
             }
         }
         catch (IOException e)
         {
             throw new Exception("Unable to close lucene writer " + identifier, e);
         }
     }
 }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRecreatesWriterWhenRequestedAgainAfterCacheEviction() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestRecreatesWriterWhenRequestedAgainAfterCacheEviction()
        {
            AddIndex("bar");
            AddIndex("baz");
            Config config = Config.defaults(CacheSizeConfig());

            _dataSource = _life.add(GetLuceneDataSource(config));
            IndexIdentifier fooIdentifier     = Identifier("foo");
            IndexIdentifier barIdentifier     = Identifier("bar");
            IndexIdentifier bazIdentifier     = Identifier("baz");
            IndexWriter     oldFooIndexWriter = _dataSource.getIndexSearcher(fooIdentifier).Writer;

            _dataSource.getIndexSearcher(barIdentifier);
            _dataSource.getIndexSearcher(bazIdentifier);
            IndexWriter newFooIndexWriter = _dataSource.getIndexSearcher(fooIdentifier).Writer;

            assertNotSame(oldFooIndexWriter, newFooIndexWriter);
            assertTrue(newFooIndexWriter.Open);
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private synchronized IndexReference syncGetIndexSearcher(IndexIdentifier identifier) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        private IndexReference SyncGetIndexSearcher(IndexIdentifier identifier)
        {
            lock (this)
            {
                try
                {
                    IndexReference indexReference = _indexSearchers.get(identifier);
                    if (indexReference == null)
                    {
                        indexReference = _indexReferenceFactory.createIndexReference(identifier);
                        _indexSearchers.put(identifier, indexReference);
                        ConcurrentDictionary <string, DocValuesType> fieldTypes = new ConcurrentDictionary <string, DocValuesType>();
                        IndexSearcher             searcher = indexReference.Searcher;
                        IList <LeafReaderContext> leaves   = searcher.TopReaderContext.leaves();
                        foreach (LeafReaderContext leafReaderContext in leaves)
                        {
                            foreach (FieldInfo fieldInfo in leafReaderContext.reader().FieldInfos)
                            {
                                fieldTypes[fieldInfo.name] = fieldInfo.DocValuesType;
                            }
                        }
                        _indexTypeMap[identifier] = fieldTypes;
                    }
                    else
                    {
                        if (!_readOnly)
                        {
                            lock ( indexReference )
                            {
                                indexReference = RefreshSearcherIfNeeded(indexReference);
                            }
                        }
                    }
                    indexReference.IncRef();
                    return(indexReference);
                }
                catch (IOException e)
                {
                    throw new UncheckedIOException(e);
                }
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.apache.lucene.index.IndexWriter newIndexWriter(IndexIdentifier identifier) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        private IndexWriter NewIndexWriter(IndexIdentifier identifier)
        {
            try
            {
                Directory         indexDirectory = GetIndexDirectory(identifier);
                IndexType         type           = GetType(identifier);
                IndexWriterConfig writerConfig   = new IndexWriterConfig(type.Analyzer);
                writerConfig.IndexDeletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
                Similarity similarity = type.Similarity;
                if (similarity != null)
                {
                    writerConfig.Similarity = similarity;
                }
                return(new IndexWriter(indexDirectory, writerConfig));
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testClosesOldestIndexSearcherWhenCacheSizeIsExceeded() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestClosesOldestIndexSearcherWhenCacheSizeIsExceeded()
        {
            AddIndex("bar");
            AddIndex("baz");
            Config config = Config.defaults(CacheSizeConfig());

            _dataSource = _life.add(GetLuceneDataSource(config));
            IndexIdentifier fooIdentifier = Identifier("foo");
            IndexIdentifier barIdentifier = Identifier("bar");
            IndexIdentifier bazIdentifier = Identifier("baz");
            IndexReference  fooSearcher   = _dataSource.getIndexSearcher(fooIdentifier);
            IndexReference  barSearcher   = _dataSource.getIndexSearcher(barIdentifier);

            assertFalse(fooSearcher.Closed);
            IndexReference bazSearcher = _dataSource.getIndexSearcher(bazIdentifier);

            assertTrue(fooSearcher.Closed);
            barSearcher.Close();
            bazSearcher.Close();
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void refreshReadOnlyIndexSearcherInReadOnlyMode() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RefreshReadOnlyIndexSearcherInReadOnlyMode()
        {
            IndexIdentifier indexIdentifier = Identifier("foo");

            PrepareIndexesByIdentifiers(indexIdentifier);
            StopDataSource();

            Config readOnlyConfig = Config.defaults(readOnlyConfig());

            _dataSource = _life.add(GetLuceneDataSource(readOnlyConfig));

            IndexReference indexSearcher  = _dataSource.getIndexSearcher(indexIdentifier);
            IndexReference indexSearcher2 = _dataSource.getIndexSearcher(indexIdentifier);
            IndexReference indexSearcher3 = _dataSource.getIndexSearcher(indexIdentifier);
            IndexReference indexSearcher4 = _dataSource.getIndexSearcher(indexIdentifier);

            assertSame("Refreshed read only searcher should be the same.", indexSearcher, indexSearcher2);
            assertSame("Refreshed read only searcher should be the same.", indexSearcher2, indexSearcher3);
            assertSame("Refreshed read only searcher should be the same.", indexSearcher3, indexSearcher4);
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private CommitContext commitContext(org.neo4j.kernel.impl.index.IndexCommand command) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        private CommitContext CommitContext(IndexCommand command)
        {
            IDictionary <string, CommitContext> contextMap = CommitContextMap(command.EntityType);
            string        indexName = _definitions.getIndexName(command.IndexNameId);
            CommitContext context   = contextMap[indexName];

            if (context == null)
            {
                IndexIdentifier identifier = new IndexIdentifier(IndexEntityType.byId(command.EntityType), indexName);

                // TODO the fact that we look up index type from config here using the index store
                // directly should be avoided. But how can we do it in, say recovery?
                // The `dataSource.getType()` call can throw an exception if the index is concurrently deleted.
                // To avoid bubbling an exception during commit, we instead ignore the commands related to that index,
                // and proceed as if the index never existed, and thus cannot accept any modifications.
                IndexType type = _dataSource.getType(identifier, _recovery);
                context = new CommitContext(_dataSource, identifier, type, _recovery);
                contextMap[indexName] = context;
            }
            return(context);
        }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: IndexType getIndexType(IndexIdentifier identifier, boolean recovery) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        internal virtual IndexType GetIndexType(IndexIdentifier identifier, bool recovery)
        {
            Pair <int, IndexType>        type   = _cache[identifier];
            IDictionary <string, string> config = _indexStore.get(identifier.EntityType.entityClass(), identifier.IndexName);

            if (config == null)
            {
                if (recovery)
                {
                    return(null);
                }
                throw new ExplicitIndexNotFoundKernelException("Index '%s' doesn't exist.", identifier);
            }
            if (type != null && config.GetHashCode() == type.First())
            {
                return(type.Other());
            }
            type = Pair.of(config.GetHashCode(), IndexType.GetIndexType(config));
            _cache[identifier] = type;
            return(type.Other());
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRecreatesSearcherWhenRequestedAgain() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestRecreatesSearcherWhenRequestedAgain()
        {
            AddIndex("bar");
            AddIndex("baz");
            Config config = Config.defaults(CacheSizeConfig());

            _dataSource = _life.add(GetLuceneDataSource(config));
            IndexIdentifier fooIdentifier  = Identifier("foo");
            IndexIdentifier barIdentifier  = Identifier("bar");
            IndexIdentifier bazIdentifier  = Identifier("baz");
            IndexReference  oldFooSearcher = _dataSource.getIndexSearcher(fooIdentifier);
            IndexReference  barSearcher    = _dataSource.getIndexSearcher(barIdentifier);
            IndexReference  bazSearcher    = _dataSource.getIndexSearcher(bazIdentifier);
            IndexReference  newFooSearcher = _dataSource.getIndexSearcher(bazIdentifier);

            assertNotSame(oldFooSearcher, newFooSearcher);
            assertFalse(newFooSearcher.Closed);
            oldFooSearcher.Close();
            barSearcher.Close();
            bazSearcher.Close();
            newFooSearcher.Close();
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void assertValidType(String key, Object value, IndexIdentifier identifier) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        internal virtual void AssertValidType(string key, object value, IndexIdentifier identifier)
        {
            DocValuesType expectedType;
            string        expectedTypeName;

            if (value is Number)
            {
                expectedType     = DocValuesType.SORTED_NUMERIC;
                expectedTypeName = "numbers";
            }
            else
            {
                expectedType     = DocValuesType.SORTED_SET;
                expectedTypeName = "strings";
            }
            IDictionary <string, DocValuesType> stringDocValuesTypeMap = _indexTypeMap[identifier];
            // If the index searcher has never been loaded, we need to load it now to populate the map.
            int iterations = 0;               // Iterate a bit in case we race with an index drop or create.

            while (stringDocValuesTypeMap == null && iterations++ < 20)
            {
                // We don't use ensureInstantiated because we want to surface the exception in this case.
                GetIndexSearcher(identifier).close();
                stringDocValuesTypeMap = _indexTypeMap[identifier];
            }

            if (stringDocValuesTypeMap == null)
            {
                // Looks like we are running into some adversarial racing, so let's just give up.
                throw new ExplicitIndexNotFoundKernelException("Index '%s' doesn't exist.", identifier);
            }

            DocValuesType actualType = stringDocValuesTypeMap.putIfAbsent(key, expectedType);

            if (actualType != null && !actualType.Equals(DocValuesType.NONE) && !actualType.Equals(expectedType))
            {
                throw new System.ArgumentException(string.Format("Cannot index '{0}' for key '{1}', since this key has been used to index {2}. Raw value of the index type is {3}", value, key, expectedTypeName, actualType));
            }
        }
コード例 #12
0
 private BatchInserterIndex Index(IndexIdentifier identifier, IDictionary <string, string> config)
 {
     // We don't care about threads here... c'mon... it's a
     // single-threaded batch inserter
     return(_indexes.computeIfAbsent(identifier, k => GetLuceneBatchInserterIndex(identifier, config)));
 }
コード例 #13
0
 private LuceneBatchInserterIndex GetLuceneBatchInserterIndex(IndexIdentifier identifier, IDictionary <string, string> config)
 {
     return(new LuceneBatchInserterIndex(new File(_inserter.StoreDir), identifier, config, _relationshipLookup));
 }
コード例 #14
0
 internal virtual void Invalidate(IndexIdentifier identifier)
 {
     _cache.Remove(identifier);
 }
コード例 #15
0
        /// <summary>
        /// Create new <seealso cref="IndexReference"/> for provided <seealso cref="IndexIdentifier"/>. </summary>
        /// <param name="indexIdentifier"> index identifier to build index for. </param>
        /// <returns> newly create <seealso cref="IndexReference"/>
        /// </returns>
        /// <exception cref="IOException"> in case of exception during accessing lucene reader/writer. </exception>
        /// <exception cref="ExplicitIndexNotFoundKernelException"> if the index is dropped prior to, or concurrently with, this
        /// operation. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: abstract IndexReference createIndexReference(IndexIdentifier indexIdentifier) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
        internal abstract IndexReference CreateIndexReference(IndexIdentifier indexIdentifier);
コード例 #16
0
        internal virtual void Delete(LuceneExplicitIndex index)
        {
            IndexIdentifier identifier = index.Identifier;

            _txData[identifier] = new DeletedTxDataBoth(this, index);
        }
コード例 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.apache.lucene.store.Directory getIndexDirectory(IndexIdentifier identifier) throws java.io.IOException
        internal virtual Directory GetIndexDirectory(IndexIdentifier identifier)
        {
            return(_filesystemFacade.getDirectory(_baseStorePath, identifier));
        }
コード例 #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static org.apache.lucene.store.Directory getDirectory(java.io.File storeDir, IndexIdentifier identifier) throws java.io.IOException
        internal static Directory GetDirectory(File storeDir, IndexIdentifier identifier)
        {
            return(FSDirectory.open(GetFileDirectory(storeDir, identifier).toPath()));
        }
コード例 #19
0
 internal static File GetFileDirectory(File storeDir, IndexIdentifier identifier)
 {
     return(new File(GetFileDirectory(storeDir, identifier.EntityType), identifier.IndexName));
 }
コード例 #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: IndexType getType(IndexIdentifier identifier, boolean recovery) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        internal virtual IndexType GetType(IndexIdentifier identifier, bool recovery)
        {
            return(_typeCache.getIndexType(identifier, recovery));
        }
コード例 #21
0
 internal WritableIndexReference(IndexIdentifier identifier, IndexSearcher searcher, IndexWriter writer) : base(identifier, searcher)
 {
     this._writer = writer;
 }
コード例 #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: IndexType getType(IndexIdentifier identifier) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
        internal virtual IndexType GetType(IndexIdentifier identifier)
        {
            return(_typeCache.getIndexType(identifier, false));
        }
コード例 #23
0
 internal IndexReference(IndexIdentifier identifier, IndexSearcher searcher)
 {
     this._identifier = identifier;
     this._searcher   = searcher;
 }
コード例 #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: abstract org.apache.lucene.store.Directory getDirectory(java.io.File baseStorePath, IndexIdentifier identifier) throws java.io.IOException;
            internal abstract org.apache.lucene.store.Directory getDirectory(java.io.File baseStorePath, IndexIdentifier identifier);
コード例 #25
0
 internal ReadOnlyIndexReference(IndexIdentifier identifier, IndexSearcher searcher) : base(identifier, searcher)
 {
 }
コード例 #26
0
 internal RelationshipExplicitIndex(LuceneDataSource dataSource, IndexIdentifier identifier, LuceneTransactionState transaction, IndexType type, IndexCommandFactory commandFactory) : base(dataSource, identifier, transaction, type, commandFactory)
 {
 }