Search in sources :

Example 46 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class IndexUpdaterMapTest method shouldCloseAllUpdaters.

@Test
void shouldCloseAllUpdaters() throws Exception {
    // given
    indexMap.putIndexProxy(indexProxy1);
    indexMap.putIndexProxy(indexProxy2);
    IndexUpdater updater1 = updaterMap.getUpdater(schemaIndexDescriptor1, NULL);
    IndexUpdater updater2 = updaterMap.getUpdater(schemaIndexDescriptor, NULL);
    // hen
    updaterMap.close();
    // then
    verify(updater1).close();
    verify(updater2).close();
    assertTrue(updaterMap.isEmpty(), "updater map must be empty");
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 47 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class IndexUpdaterMapTest method shouldRetrieveNoUpdaterForNonExistingIndex.

@Test
void shouldRetrieveNoUpdaterForNonExistingIndex() {
    // when
    IndexUpdater updater = updaterMap.getUpdater(schemaIndexDescriptor1, NULL);
    // then
    assertNull(updater);
    assertTrue(updaterMap.isEmpty(), "updater map must be empty");
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 48 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class IndexingService method applyRecoveredUpdates.

private void applyRecoveredUpdates() throws IOException, IndexEntryConflictException {
    if (log.isDebugEnabled()) {
        log.debug("Applying recovered updates: " + recoveredNodeIds);
    }
    monitor.applyingRecoveredData(recoveredNodeIds);
    if (!recoveredNodeIds.isEmpty()) {
        try (IndexUpdaterMap updaterMap = indexMapRef.createIndexUpdaterMap(IndexUpdateMode.RECOVERY)) {
            for (IndexUpdater updater : updaterMap) {
                updater.remove(recoveredNodeIds);
            }
            IndexUpdates updates = readRecoveredUpdatesFromStore();
            apply(updates, IndexUpdateMode.RECOVERY);
            monitor.appliedRecoveredData(updates);
        }
    }
    recoveredNodeIds.clear();
}
Also used : DirectIndexUpdates(org.neo4j.kernel.impl.transaction.state.DirectIndexUpdates) IndexUpdates(org.neo4j.kernel.impl.transaction.state.IndexUpdates) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 49 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportNodesWithDuplicatePropertyValueInUniqueIndex.

@Test
public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception {
    // given
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
    Iterator<IndexRule> indexRuleIterator = new SchemaStorage(fixture.directStoreAccess().nativeStores().getSchemaStore()).indexesGetAll();
    while (indexRuleIterator.hasNext()) {
        IndexRule indexRule = indexRuleIterator.next();
        IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(indexRule.getId(), indexRule.getIndexDescriptor(), samplingConfig);
        IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE);
        updater.process(IndexEntryUpdate.add(42, indexRule.getIndexDescriptor().schema(), "value"));
        updater.close();
        accessor.close();
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, 2).andThatsAllFolks();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 50 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class ContractCheckingIndexProxyTest method shouldNotCloseWhileUpdating.

@Test(expected = /* THEN */
IllegalStateException.class)
public void shouldNotCloseWhileUpdating() throws IOException {
    // GIVEN
    final DoubleLatch latch = new DoubleLatch();
    final IndexProxy inner = new IndexProxyAdapter() {

        @Override
        public IndexUpdater newUpdater(IndexUpdateMode mode) {
            return super.newUpdater(mode);
        }
    };
    final IndexProxy outer = newContractCheckingIndexProxy(inner);
    outer.start();
    // WHEN
    runInSeparateThread(() -> {
        try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE)) {
            updater.process(null);
            latch.startAndWaitForAllToStartAndFinish();
        } catch (IndexEntryConflictException e) {
            throw new RuntimeException(e);
        }
    });
    try {
        latch.waitForAllToStart();
        outer.close();
    } finally {
        latch.finish();
    }
}
Also used : SchemaIndexTestHelper.mockIndexProxy(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy) DoubleLatch(org.neo4j.test.DoubleLatch) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3