Search in sources :

Example 31 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class DynamicIndexStoreViewTest method shouldVisitRelationshipsUsingTokenIndex.

@Test
void shouldVisitRelationshipsUsingTokenIndex() throws Throwable {
    // Given
    StubTokenIndexReader tokenReader = new StubTokenIndexReader();
    StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    IndexDescriptor descriptor = forSchema(forAnyEntityTokens(RELATIONSHIP), DESCRIPTOR).withName("index").materialise(0);
    when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    when(indexProxy.newTokenReader()).thenReturn(tokenReader);
    when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
    int targetType = 1;
    int notTargetType = 2;
    int[] indexedTypes = { targetType };
    String targetPropertyKey = "key";
    String notTargetPropertyKey = "not-key";
    Value propertyValue = Values.stringValue("value");
    MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
    long id = 0;
    int wantedPropertyUpdates = 5;
    for (int i = 0; i < wantedPropertyUpdates; i++) {
        // Relationships that are indexed
        cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
        tokenReader.index(indexedTypes, id);
        relationshipsWithTargetType.add(id++);
        // Relationship with wrong property
        cursors.withRelationship(id++, 1, targetType, 3).properties(notTargetPropertyKey, propertyValue);
        // Relationship with wrong type
        cursors.withRelationship(id++, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
    }
    // When
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(indexedTypes, relationType -> true, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    // Then make sure all the fitting relationships where included
    assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
    assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(wantedPropertyUpdates);
    // and that we didn't visit any more relationships than what we would get from scan store
    assertThat(tokenConsumer.batches.size()).isEqualTo(1);
    assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Example 32 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class DefaultSchemaIndexConfigTest method validateIndexConfig.

private void validateIndexConfig(GraphDatabaseService db) throws IndexNotFoundKernelException {
    try (Transaction tx = db.beginTx()) {
        GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        IndexingService indexingService = getIndexingService(api);
        IndexProxy indexProxy = indexingService.getIndexProxy(index);
        Map<String, Value> indexConfig = indexProxy.indexConfig();
        // Expected default values for schema index
        assertEquals(Values.doubleArray(new double[] { -1000000.0, -1000000.0 }), indexConfig.get("spatial.cartesian.min"));
        assertEquals(Values.doubleArray(new double[] { 1000000.0, 1000000.0 }), indexConfig.get("spatial.cartesian.max"));
        assertEquals(Values.doubleArray(new double[] { -1000000.0, -1000000.0, -1000000.0 }), indexConfig.get("spatial.cartesian-3d.min"));
        assertEquals(Values.doubleArray(new double[] { 1000000.0, 1000000.0, 1000000.0 }), indexConfig.get("spatial.cartesian-3d.max"));
        assertEquals(Values.doubleArray(new double[] { -180.0, -90.0 }), indexConfig.get("spatial.wgs-84.min"));
        assertEquals(Values.doubleArray(new double[] { 180.0, 90.0 }), indexConfig.get("spatial.wgs-84.max"));
        assertEquals(Values.doubleArray(new double[] { -180.0, -90.0, -1000000.0 }), indexConfig.get("spatial.wgs-84-3d.min"));
        assertEquals(Values.doubleArray(new double[] { 180.0, 90.0, 1000000.0 }), indexConfig.get("spatial.wgs-84-3d.max"));
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Value(org.neo4j.values.storable.Value) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy)

Example 33 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustDiscoverRelationshipInStoreMissingFromIndex.

@Test
void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("REL"), asStrList("prop"))).close();
        tx.commit();
    }
    IndexDescriptor indexDescriptor;
    long relId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        indexDescriptor = getFulltextIndexDescriptor(tx.schema().getIndexes());
        Node node = tx.createNode();
        Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("REL"));
        rel.setProperty("prop", "value");
        relId = rel.getId();
        tx.commit();
    }
    IndexingService indexes = getIndexingService(db);
    IndexProxy indexProxy = indexes.getIndexProxy(indexDescriptor);
    try (IndexUpdater updater = indexProxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
    }
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)33 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 Test (org.junit.jupiter.api.Test)21 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)15 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)8 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)4 Transaction (org.neo4j.graphdb.Transaction)3 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)3 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)3 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Node (org.neo4j.graphdb.Node)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexPopulationFailedKernelException (org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException)2 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 IndexProxyProvider (org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider)2