// PRIVATE

        // READ INDEX

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.storageengine.api.schema.StoreIndexDescriptor readIndexRule(long id, ByteBuffer source) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private static StoreIndexDescriptor ReadIndexRule(long id, ByteBuffer source)
        {
            IndexProviderDescriptor indexProvider = ReadIndexProviderDescriptor(source);
            sbyte             indexRuleType       = source.get();
            Optional <string> name;

            switch (indexRuleType)
            {
            case GENERAL_INDEX:
            {
                SchemaDescriptor schema = ReadSchema(source);
                name = ReadRuleName(source);
                return(IndexDescriptorFactory.forSchema(schema, name, indexProvider).withId(id));
            }

            case UNIQUE_INDEX:
            {
                long             owningConstraint = source.Long;
                SchemaDescriptor schema           = ReadSchema(source);
                name = ReadRuleName(source);
                IndexDescriptor descriptor = IndexDescriptorFactory.uniqueForSchema(schema, name, indexProvider);
                return(owningConstraint == NO_OWNING_CONSTRAINT_YET?descriptor.WithId(id) : descriptor.WithIds(id, owningConstraint));
            }

            default:
                throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
            }
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverIndexCountsBySamplingThemOnStartup()
        public virtual void ShouldRecoverIndexCountsBySamplingThemOnStartup()
        {
            // given some aliens in a database
            CreateAliens();

            // that have been indexed
            AwaitIndexOnline(IndexAliensBySpecimen());

            // where ALIEN and SPECIMEN are both the first ids of their kind
            IndexDescriptor index   = TestIndexDescriptorFactory.forLabel(LabelId(_alien), PkId(SPECIMEN));
            SchemaStorage   storage = new SchemaStorage(NeoStores().SchemaStore);
            long            indexId = storage.IndexGetForSchema(index).Id;

            // for which we don't have index counts
            ResetIndexCounts(indexId);

            // when we shutdown the database and restart it
            Restart();

            // then we should have re-sampled the index
            CountsTracker tracker = NeoStores().Counts;

            AssertEqualRegisters("Unexpected updates and size for the index", newDoubleLongRegister(0, 32), tracker.IndexUpdatesAndSize(indexId, newDoubleLongRegister()));
            AssertEqualRegisters("Unexpected sampling result", newDoubleLongRegister(16, 32), tracker.IndexSample(indexId, newDoubleLongRegister()));

            // and also
            AssertLogExistsForRecoveryOn(":Alien(specimen)");
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void detectUniqueIndexWithoutOwningConstraint()
        public virtual void DetectUniqueIndexWithoutOwningConstraint()
        {
            IndexDescriptor      descriptor = UniqueForLabel(LABEL_ID, PROPERTY_ID_1);
            StoreIndexDescriptor indexRule  = descriptor.WithId(RULE_ID);

            assertTrue(indexRule.IndexWithoutOwningConstraint);
        }
 public override void Initialize(IndexDescriptor descriptor, IndexProgressor progressor, IndexQuery[] query, IndexOrder order, bool needsValues)
 {
     this.Descriptor          = descriptor;
     this.Progressor          = progressor;
     this.Query               = query;
     this.Order               = order;
     this.NeedsValuesConflict = needsValues;
 }
Beispiel #5
0
        private void AssertEqualityByDescriptor(IndexDescriptor descriptor)
        {
            StoreIndexDescriptor rule1 = descriptor.WithId(RULE_ID);
            StoreIndexDescriptor rule2 = descriptor.WithId(RULE_ID_2);
            StoreIndexDescriptor rule3 = (descriptor.Type() == IndexDescriptor.Type.GENERAL ? forSchema(descriptor.Schema()) : uniqueForSchema(descriptor.Schema())).withId(RULE_ID);

            AssertEquality(rule1, rule2);
            AssertEquality(rule1, rule3);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTriggerResampling() throws org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException, org.neo4j.internal.kernel.api.exceptions.ProcedureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTriggerResampling()
        {
            IndexDescriptor index = TestIndexDescriptorFactory.forLabel(123, 456);

            when(_schemaRead.index(anyInt(), any())).thenReturn(index);

            _procedure.resampleIndex(":Person(name)");

            verify(_indexingService).triggerIndexSampling(index.Schema(), IndexSamplingMode.TRIGGER_REBUILD_ALL);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws org.neo4j.internal.kernel.api.exceptions.ProcedureException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLookUpTheIndexByLabelIdAndPropertyKeyId()
        {
            IndexDescriptor index = TestIndexDescriptorFactory.forLabel(0, 0);

            when(_tokenRead.nodeLabel(anyString())).thenReturn(123);
            when(_tokenRead.propertyKey(anyString())).thenReturn(456);
            when(_schemaRead.index(anyInt(), any())).thenReturn(index);

            _procedure.resampleIndex(":Person(name)");

            verify(_schemaRead).index(123, 456);
        }
Beispiel #8
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.IndexDescriptor descriptor) throws java.io.IOException
        private bool IndexIsOnline(PartitionedIndexStorage indexStorage, IndexDescriptor descriptor)
        {
            using (SchemaIndex index = LuceneSchemaIndexBuilder.Create(descriptor, _config).withIndexStorage(indexStorage).build())
            {
                if (index.exists())
                {
                    index.open();
                    return(index.Online);
                }
                return(false);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLookUpTheCompositeIndexByLabelIdAndPropertyKeyId() throws org.neo4j.internal.kernel.api.exceptions.ProcedureException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLookUpTheCompositeIndexByLabelIdAndPropertyKeyId()
        {
            IndexDescriptor index = TestIndexDescriptorFactory.forLabel(0, 0, 1);

            when(_tokenRead.nodeLabel(anyString())).thenReturn(123);
            when(_tokenRead.propertyKey("name")).thenReturn(0);
            when(_tokenRead.propertyKey("lastName")).thenReturn(1);
            when(_schemaRead.index(123, 0, 1)).thenReturn(index);

            _procedure.resampleIndex(":Person(name, lastName)");

            verify(_schemaRead).index(123, 0, 1);
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateGeneralIndex()
        public virtual void ShouldCreateGeneralIndex()
        {
            // GIVEN
            IndexDescriptor      descriptor = ForLabel(LABEL_ID, PROPERTY_ID_1);
            StoreIndexDescriptor indexRule  = descriptor.WithId(RULE_ID);

            // THEN
            assertThat(indexRule.Id, equalTo(RULE_ID));
            assertFalse(indexRule.CanSupportUniqueConstraint());
            assertThat(indexRule.Schema(), equalTo(descriptor.Schema()));
            assertThat(indexRule, equalTo(descriptor));
            assertThat(indexRule.ProviderDescriptor(), equalTo(ProviderDescriptor));
            assertException(indexRule.getOwningConstraint, typeof(System.InvalidOperationException));
            assertException(() => indexRule.WithOwningConstraint(RULE_ID_2), typeof(System.InvalidOperationException));
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void visitsUniqueConstraintsAndIndices() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void VisitsUniqueConstraintsAndIndices()
        {
            DbStructureVisitor visitor = mock(typeof(DbStructureVisitor));
            int labelId = CreateLabel("Person");
            int pkId    = CreatePropertyKey("name");

            CommitAndReOpen();

            ConstraintDescriptor constraint = CreateUniqueConstraint(labelId, pkId);
            IndexDescriptor      descriptor = TestIndexDescriptorFactory.uniqueForLabel(labelId, pkId);

            // WHEN
            Accept(visitor);

            // THEN
            verify(visitor).visitIndex(descriptor, ":Person(name)", 1.0d, 0L);
            verify(visitor).visitUniqueConstraint(( UniquenessConstraintDescriptor )constraint, "CONSTRAINT ON ( person:Person ) ASSERT person.name IS " + "UNIQUE");
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateUniqueIndex()
        public virtual void ShouldCreateUniqueIndex()
        {
            // GIVEN
            IndexDescriptor      descriptor = UniqueForLabel(LABEL_ID, PROPERTY_ID_1);
            StoreIndexDescriptor indexRule  = descriptor.WithId(RULE_ID);

            // THEN
            assertThat(indexRule.Id, equalTo(RULE_ID));
            assertTrue(indexRule.CanSupportUniqueConstraint());
            assertThat(indexRule.Schema(), equalTo(descriptor.Schema()));
            assertThat(indexRule, equalTo(descriptor));
            assertThat(indexRule.ProviderDescriptor(), equalTo(ProviderDescriptor));
            assertThat(indexRule.OwningConstraint, equalTo(null));

            StoreIndexDescriptor withConstraint = indexRule.WithOwningConstraint(RULE_ID_2);

            assertThat(withConstraint.OwningConstraint, equalTo(RULE_ID_2));
            assertThat(indexRule.OwningConstraint, equalTo(null));                   // this is unchanged
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateCountsOnClusterWhenCreatingANodeOnSlaveAndAnIndexOnMaster() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateCountsOnClusterWhenCreatingANodeOnSlaveAndAnIndexOnMaster()
        {
            // when creating a node on the master
            CreateANode(_slave1, _label, PROPERTY_VALUE, PROPERTY_NAME);
            IndexDescriptor schemaIndexDescriptor = CreateAnIndex(_master, _label, PROPERTY_NAME);

            AwaitOnline(_master);

            // and the updates are propagate in the cluster
            _cluster.sync();

            AwaitOnline(_slave1);
            AwaitOnline(_slave2);

            // then the slaves has updated counts
            AssertOnIndexCounts(0, 1, 1, 1, schemaIndexDescriptor, _master);
            AssertOnIndexCounts(0, 1, 1, 1, schemaIndexDescriptor, _slave1);
            AssertOnIndexCounts(0, 1, 1, 1, schemaIndexDescriptor, _slave2);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseIndexRule(String serialized, String name) throws Exception
        private void AssertParseIndexRule(string serialized, string name)
        {
            // GIVEN
            long                    ruleId        = 24;
            IndexDescriptor         index         = ForLabel(512, 4);
            IndexProviderDescriptor indexProvider = new IndexProviderDescriptor("index-provider", "25.0");

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            StoreIndexDescriptor deserialized = AssertIndexRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized, equalTo(index));
            assertThat(deserialized.Schema(), equalTo(index.Schema()));
            assertThat(deserialized.ProviderDescriptor(), equalTo(indexProvider));
            assertThat(deserialized.Name, @is(name));
            assertException(deserialized.getOwningConstraint, typeof(System.InvalidOperationException));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertParseUniqueIndexRule(String serialized, String name) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        private void AssertParseUniqueIndexRule(string serialized, string name)
        {
            // GIVEN
            long                    ruleId        = 33;
            long                    constraintId  = 11;
            IndexDescriptor         index         = TestIndexDescriptorFactory.uniqueForLabel(61, 988);
            IndexProviderDescriptor indexProvider = new IndexProviderDescriptor("index-provider", "25.0");

            sbyte[] bytes = DecodeBase64(serialized);

            // WHEN
            StoreIndexDescriptor deserialized = AssertIndexRule(SchemaRuleSerialization.Deserialize(ruleId, ByteBuffer.wrap(bytes)));

            // THEN
            assertThat(deserialized.Id, equalTo(ruleId));
            assertThat(deserialized, equalTo(index));
            assertThat(deserialized.Schema(), equalTo(index.Schema()));
            assertThat(deserialized.ProviderDescriptor(), equalTo(indexProvider));
            assertThat(deserialized.OwningConstraint, equalTo(constraintId));
            assertThat(deserialized.Name, @is(name));
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void closeMustCloseAll()
        public virtual void CloseMustCloseAll()
        {
            IndexDescriptor         index      = TestIndexDescriptorFactory.forLabel(1, 2, 3);
            BridgingIndexProgressor progressor = new BridgingIndexProgressor(null, index.Schema().PropertyIds);

            IndexProgressor[] parts = new IndexProgressor[] { mock(typeof(IndexProgressor)), mock(typeof(IndexProgressor)) };

            // Given
            foreach (IndexProgressor part in parts)
            {
                progressor.Initialize(index, part, null, IndexOrder.NONE, false);
            }

            // When
            progressor.Close();

            // Then
            foreach (IndexProgressor part in parts)
            {
                verify(part, times(1)).close();
            }
        }
Beispiel #17
0
 internal StringIndexReader(GBPTree <StringIndexKey, NativeIndexValue> tree, IndexLayout <StringIndexKey, NativeIndexValue> layout, IndexDescriptor descriptor) : base(tree, layout, descriptor)
 {
 }
Beispiel #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }
Beispiel #19
0
 public CompositeIndexPopulatorCompatibility(IndexProviderCompatibilityTestSuite testSuite, IndexDescriptor descriptor) : base(testSuite, descriptor)
 {
 }
Beispiel #20
0
 internal TemporalIndexPartReader(GBPTree <KEY, NativeIndexValue> tree, IndexLayout <KEY, NativeIndexValue> layout, IndexDescriptor descriptor) : base(tree, layout, descriptor)
 {
 }
Beispiel #21
0
 public LuceneIndexAccessor(SchemaIndex luceneIndex, IndexDescriptor descriptor) : base(luceneIndex, descriptor)
 {
 }
Beispiel #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, org.neo4j.storageengine.api.schema.IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static void AssertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db)
        {
            using ([email protected] tx = Db.DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED))
            {
                IndexReference indexReference = tx.SchemaRead().index(indexDescriptor.Schema());
                AssertDoubleLongEquals(expectedIndexUpdates, expectedIndexSize, tx.SchemaRead().indexUpdatesAndSize(indexReference, newDoubleLongRegister()));
                AssertDoubleLongEquals(expectedUniqueValues, expectedSampleSize, tx.SchemaRead().indexSample(indexReference, newDoubleLongRegister()));
            }
        }
Beispiel #23
0
 public override void Initialize(IndexDescriptor descriptor, IndexProgressor progressor, IndexQuery[] query, IndexOrder indexOrder, bool needsValues)
 {
     this._progressor = progressor;
 }
Beispiel #24
0
 public UniqueLuceneIndexPopulator(SchemaIndex index, IndexDescriptor descriptor) : base(index)
 {
     this._propertyKeyIds = descriptor.Schema().PropertyIds;
     this._sampler        = new UniqueIndexSampler();
 }