Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRemoveAndAddEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRemoveAndAddEntries()
        {
            // given
            PartitionedIndexStorage indexStorage = IndexStorage;

            LuceneIndexAccessor accessor = CreateAccessor(indexStorage);

            // when
            UpdateAndCommit(accessor, asList(Add(1L, "value1")));
            UpdateAndCommit(accessor, asList(Add(2L, "value2")));
            UpdateAndCommit(accessor, asList(Add(3L, "value3")));
            UpdateAndCommit(accessor, asList(Add(4L, "value4")));
            UpdateAndCommit(accessor, asList(Remove(1L, "value1")));
            UpdateAndCommit(accessor, asList(Remove(2L, "value2")));
            UpdateAndCommit(accessor, asList(Remove(3L, "value3")));
            UpdateAndCommit(accessor, asList(Add(1L, "value1")));
            UpdateAndCommit(accessor, asList(Add(3L, "value3b")));
            accessor.Dispose();

            // then
            assertEquals(asList(1L), GetAllNodes(indexStorage, "value1"));
            assertEquals(emptyList(), GetAllNodes(indexStorage, "value2"));
            assertEquals(emptyList(), GetAllNodes(indexStorage, "value3"));
            assertEquals(asList(3L), GetAllNodes(indexStorage, "value3b"));
            assertEquals(asList(4L), GetAllNodes(indexStorage, "value4"));
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private LuceneIndexAccessor createAccessor(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage indexStorage) throws java.io.IOException
        private LuceneIndexAccessor CreateAccessor(PartitionedIndexStorage indexStorage)
        {
            SchemaIndex luceneIndex = LuceneSchemaIndexBuilder.Create(_index, Config.defaults()).withIndexStorage(indexStorage).build();

            luceneIndex.open();
            return(new LuceneIndexAccessor(luceneIndex, _index));
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            File folder = _testDir.directory("folder");

            _indexStorage     = new PartitionedIndexStorage(_directoryFactory, _fileSystemRule.get(), folder);
            _index            = LuceneSchemaIndexBuilder.create(_descriptor, Config.defaults()).withIndexStorage(_indexStorage).build();
            _schemaDescriptor = _descriptor.schema();
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeEach void setUp()
        internal virtual void SetUp()
        {
            File folder = _testDir.directory("folder");
            PartitionedIndexStorage indexStorage = new PartitionedIndexStorage(_dirFactory, _fileSystem, folder);

            IndexDescriptor descriptor = IndexDescriptorFactory.forSchema(_labelSchemaDescriptor);

            _index = LuceneSchemaIndexBuilder.create(descriptor, Config.defaults()).withIndexStorage(indexStorage).build();
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private WritableTestDatabaseIndex createTestLuceneIndex(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory dirFactory, java.io.File folder) throws java.io.IOException
        private WritableTestDatabaseIndex CreateTestLuceneIndex(DirectoryFactory dirFactory, File folder)
        {
            PartitionedIndexStorage   indexStorage = new PartitionedIndexStorage(dirFactory, _fileSystem, folder);
            WritableTestDatabaseIndex index        = new WritableTestDatabaseIndex(indexStorage);

            index.Create();
            index.open();
            return(index);
        }
Example #6
0
        internal LuceneFulltextIndex(PartitionedIndexStorage storage, IndexPartitionFactory partitionFactory, FulltextIndexDescriptor descriptor, TokenHolder propertyKeyTokenHolder) : base(storage, partitionFactory, descriptor)
        {
            this._analyzer               = descriptor.Analyzer();
            this._identifier             = descriptor.Name;
            this._type                   = descriptor.Schema().entityType();
            this._properties             = descriptor.PropertyNames();
            this._propertyKeyTokenHolder = propertyKeyTokenHolder;
            File indexFolder = storage.IndexFolder;

            _transactionsFolder = new File(indexFolder.Parent, indexFolder.Name + ".tx");
        }
Example #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean indexIsOnline(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage indexStorage, org.neo4j.storageengine.api.schema.StoreIndexDescriptor descriptor) throws java.io.IOException
        private bool IndexIsOnline(PartitionedIndexStorage indexStorage, StoreIndexDescriptor descriptor)
        {
            using (SchemaIndex index = LuceneSchemaIndexBuilder.create(descriptor, _config).withIndexStorage(indexStorage).build())
            {
                if (index.exists())
                {
                    index.open();
                    return(index.Online);
                }
                return(false);
            }
        }
Example #8
0
        public override IndexPopulator GetPopulator(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory)
        {
            PartitionedIndexStorage             indexStorage            = GetIndexStorage(descriptor.Id);
            FulltextIndexDescriptor             fulltextIndexDescriptor = readOrInitialiseDescriptor(descriptor, _defaultAnalyzerName, _tokenHolders.propertyKeyTokens(), indexStorage.IndexFolder, _fileSystem);
            DatabaseIndex <FulltextIndexReader> fulltextIndex           = FulltextIndexBuilder.Create(fulltextIndexDescriptor, _config, _tokenHolders.propertyKeyTokens()).withFileSystem(_fileSystem).withOperationalMode(_operationalMode).withIndexStorage(indexStorage).withPopulatingMode(true).build();

            if (fulltextIndex.ReadOnly)
            {
                throw new System.NotSupportedException("Can't create populator for read only index");
            }
            _log.debug("Creating populator for fulltext schema index: %s", descriptor);
            return(new FulltextIndexPopulator(fulltextIndexDescriptor, fulltextIndex, () => FulltextIndexSettings.saveFulltextIndexSettings(fulltextIndexDescriptor, indexStorage.IndexFolder, _fileSystem)));
        }
Example #9
0
 internal virtual PartitionedIndexStorage NewFaultyPartitionedIndexStorage()
 {
     try
     {
         PartitionedIndexStorage storage = mock(typeof(PartitionedIndexStorage));
         when(storage.ListFolders()).thenReturn(singletonList(new File("/some/path/somewhere/1")));
         when(storage.OpenDirectory(any())).thenThrow(Error);
         return(storage);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUpdateUniqueEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldUpdateUniqueEntries()
        {
            // given
            PartitionedIndexStorage indexStorage = IndexStorage;

            LuceneIndexAccessor accessor = CreateAccessor(indexStorage);

            // when
            UpdateAndCommit(accessor, asList(Add(1L, "value1")));
            UpdateAndCommit(accessor, asList(Change(1L, "value1", "value2")));
            accessor.Dispose();

            // then
            assertEquals(asList(1L), GetAllNodes(indexStorage, "value2"));
            assertEquals(emptyList(), GetAllNodes(indexStorage, "value1"));
        }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldConsiderWholeTransactionForValidatingUniqueness() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldConsiderWholeTransactionForValidatingUniqueness()
        {
            // given
            PartitionedIndexStorage indexStorage = IndexStorage;

            LuceneIndexAccessor accessor = CreateAccessor(indexStorage);

            // when
            UpdateAndCommit(accessor, asList(Add(1L, "value1")));
            UpdateAndCommit(accessor, asList(Add(2L, "value2")));
            UpdateAndCommit(accessor, asList(Change(1L, "value1", "value2"), Change(2L, "value2", "value1")));
            accessor.Dispose();

            // then
            assertEquals(asList(2L), GetAllNodes(indexStorage, "value1"));
            assertEquals(asList(1L), GetAllNodes(indexStorage, "value2"));
        }
Example #12
0
        public override InternalIndexState GetInitialState(StoreIndexDescriptor descriptor)
        {
            PartitionedIndexStorage indexStorage = GetIndexStorage(descriptor.Id);
            string failure = indexStorage.StoredIndexFailure;

            if (!string.ReferenceEquals(failure, null))
            {
                return(InternalIndexState.FAILED);
            }
            try
            {
                return(IndexIsOnline(indexStorage, descriptor) ? InternalIndexState.ONLINE : InternalIndexState.POPULATING);
            }
            catch (IOException)
            {
                return(InternalIndexState.POPULATING);
            }
        }
Example #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.api.index.IndexAccessor getOnlineAccessor(org.neo4j.storageengine.api.schema.StoreIndexDescriptor descriptor, org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig samplingConfig) throws java.io.IOException
        public override IndexAccessor GetOnlineAccessor(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig)
        {
            PartitionedIndexStorage indexStorage = GetIndexStorage(descriptor.Id);

            FulltextIndexDescriptor fulltextIndexDescriptor = readOrInitialiseDescriptor(descriptor, _defaultAnalyzerName, _tokenHolders.propertyKeyTokens(), indexStorage.IndexFolder, _fileSystem);
            FulltextIndexBuilder    fulltextIndexBuilder    = FulltextIndexBuilder.Create(fulltextIndexDescriptor, _config, _tokenHolders.propertyKeyTokens()).withFileSystem(_fileSystem).withOperationalMode(_operationalMode).withIndexStorage(indexStorage).withPopulatingMode(false);

            if (fulltextIndexDescriptor.EventuallyConsistent)
            {
                fulltextIndexBuilder = fulltextIndexBuilder.WithIndexUpdateSink(_indexUpdateSink);
            }
            DatabaseFulltextIndex fulltextIndex = fulltextIndexBuilder.Build();

            fulltextIndex.open();

            ThreadStart           onClose  = () => _openOnlineAccessors.remove(descriptor);
            FulltextIndexAccessor accessor = new FulltextIndexAccessor(_indexUpdateSink, fulltextIndex, fulltextIndexDescriptor, onClose);

            _openOnlineAccessors.put(descriptor, accessor);
            _log.debug("Created online accessor for fulltext schema index %s: %s", descriptor, accessor);
            return(accessor);
        }
Example #14
0
        public override IndexCapability GetCapability(StoreIndexDescriptor descriptor)
        {
            FulltextIndexDescriptor fulltextIndexDescriptor;

            if (descriptor is FulltextIndexDescriptor)
            {
                // We got our own index descriptor type, so we can ask it directly.
                fulltextIndexDescriptor = ( FulltextIndexDescriptor )descriptor;
                return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
            }
            SchemaDescriptor schema = descriptor.Schema();

            if (schema is FulltextSchemaDescriptor)
            {
                // The fulltext schema descriptor is readily available with our settings.
                // This could be the situation where the index creation is about to be committed.
                // In that case, the schema descriptor is our own legit type, but the StoreIndexDescriptor is generic.
                FulltextSchemaDescriptor fulltextSchemaDescriptor = ( FulltextSchemaDescriptor )schema;
                return(new FulltextIndexCapability(fulltextSchemaDescriptor.EventuallyConsistent));
            }
            // The schema descriptor is probably a generic multi-token descriptor.
            // This happens if it was loaded from the schema store instead of created by our provider.
            // This would be the case when the IndexingService is starting up, and if so, we probably have an online accessor that we can ask instead.
            FulltextIndexAccessor accessor = GetOpenOnlineAccessor(descriptor);

            if (accessor != null)
            {
                fulltextIndexDescriptor = accessor.Descriptor;
                return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
            }
            // All of the above has failed, so we need to load the settings in from the storage directory of the index.
            // This situation happens during recovery.
            PartitionedIndexStorage indexStorage = GetIndexStorage(descriptor.Id);

            fulltextIndexDescriptor = readOrInitialiseDescriptor(descriptor, _defaultAnalyzerName, _tokenHolders.propertyKeyTokens(), indexStorage.IndexFolder, _fileSystem);
            return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
        }
Example #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<long> getAllNodes(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage indexStorage, String propertyValue) throws java.io.IOException
        private IList <long> GetAllNodes(PartitionedIndexStorage indexStorage, string propertyValue)
        {
            return(AllNodesCollector.GetAllNodes(indexStorage.OpenDirectory(indexStorage.GetPartitionFolder(1)), Values.stringValue(propertyValue)));
        }
Example #16
0
 internal WritableTestDatabaseIndex(PartitionedIndexStorage indexStorage) : base(new TestLuceneIndex(indexStorage, new WritableIndexPartitionFactory(IndexWriterConfigs.standard)))
 {
 }
Example #17
0
 internal TestLuceneIndex(PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory) : base(indexStorage, partitionFactory, null)
 {
 }
Example #18
0
 public ReadOnlyDatabaseSchemaIndex(PartitionedIndexStorage indexStorage, IndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ReadOnlyIndexPartitionFactory readOnlyIndexPartitionFactory) : base(new LuceneSchemaIndex(indexStorage, descriptor, samplingConfig, readOnlyIndexPartitionFactory))
 {
 }
Example #19
0
 public AbstractLuceneIndex(PartitionedIndexStorage indexStorage, IndexPartitionFactory partitionFactory, IndexDescriptor descriptor)
 {
     this.IndexStorage       = indexStorage;
     this._partitionFactory  = partitionFactory;
     this.DescriptorConflict = descriptor;
 }
Example #20
0
 internal LuceneSchemaIndex(PartitionedIndexStorage indexStorage, IndexDescriptor descriptor, IndexSamplingConfig samplingConfig, IndexPartitionFactory partitionFactory) : base(indexStorage, partitionFactory, descriptor)
 {
     this._samplingConfig = samplingConfig;
 }