Search in sources :

Example 1 with IndexAccessor

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

the class IndexingServiceTest method closingOfValidatedUpdatesShouldCloseUpdaters.

@Test
public void closingOfValidatedUpdatesShouldCloseUpdaters() throws Exception {
    // Given
    long indexId1 = 1;
    long indexId2 = 2;
    int labelId1 = 24;
    int labelId2 = 42;
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
    IndexAccessor accessor1 = mock(IndexAccessor.class);
    IndexUpdater updater1 = mock(IndexUpdater.class);
    when(accessor1.newUpdater(any(IndexUpdateMode.class))).thenReturn(updater1);
    IndexAccessor accessor2 = mock(IndexAccessor.class);
    IndexUpdater updater2 = mock(IndexUpdater.class);
    when(accessor2.newUpdater(any(IndexUpdateMode.class))).thenReturn(updater2);
    when(indexProvider.getOnlineAccessor(eq(1L), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(accessor1);
    when(indexProvider.getOnlineAccessor(eq(2L), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(accessor2);
    life.start();
    indexing.createIndexes(indexRule(indexId1, labelId1, propertyKeyId, PROVIDER_DESCRIPTOR));
    indexing.createIndexes(indexRule(indexId2, labelId2, propertyKeyId, PROVIDER_DESCRIPTOR));
    waitForIndexesToComeOnline(indexing, indexId1, indexId2);
    verify(populator, timeout(1000).times(2)).close(true);
    // When
    indexing.apply(updates(asList(addNodeUpdate(1, "foo", labelId1), addNodeUpdate(2, "bar", labelId2))));
    // Then
    verify(updater1).close();
    verify(updater2).close();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 2 with IndexAccessor

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

the class IndexingServiceTest method shouldNotLoseIndexDescriptorDueToOtherSimilarIndexDuringRecovery.

/*
     * See comments in IndexingService#createIndex
     */
@SuppressWarnings("unchecked")
@Test
public void shouldNotLoseIndexDescriptorDueToOtherSimilarIndexDuringRecovery() throws Exception {
    // GIVEN
    long nodeId = 0, indexId = 1, otherIndexId = 2;
    NodeUpdates update = addNodeUpdate(nodeId, "value");
    doAnswer(nodeUpdatesAnswer(update)).when(storeView).nodeAsUpdates(eq(nodeId), any(Collection.class));
    DoubleLongRegister register = mock(DoubleLongRegister.class);
    when(register.readSecond()).thenReturn(42L);
    when(storeView.indexSample(anyLong(), any(DoubleLongRegister.class))).thenReturn(register);
    // For some reason the usual accessor returned null from newUpdater, even when told to return the updater
    // so spying on a real object instead.
    IndexAccessor accessor = spy(new TrackingIndexAccessor());
    IndexRule index = IndexRule.indexRule(1, this.index, PROVIDER_DESCRIPTOR);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(update), index);
    when(indexProvider.getInitialState(indexId, index.getIndexDescriptor())).thenReturn(ONLINE);
    life.init();
    // WHEN dropping another index, which happens to have the same label/property... while recovering
    IndexRule otherIndex = IndexRule.indexRule(otherIndexId, index.getIndexDescriptor(), PROVIDER_DESCRIPTOR);
    indexing.createIndexes(otherIndex);
    indexing.dropIndex(otherIndex);
    indexing.apply(nodeIdsAsIndexUpdates(PrimitiveLongCollections.asSet(PrimitiveLongCollections.iterator(nodeId))));
    // and WHEN finally creating our index again (at a later point in recovery)
    indexing.createIndexes(index);
    reset(accessor);
    // and WHEN starting, i.e. completing recovery
    life.start();
    // THEN our index should still have been recovered properly
    // apparently we create updaters two times during recovery, get over it
    verify(accessor, times(2)).newUpdater(RECOVERY);
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) Iterators.asCollection(org.neo4j.helpers.collection.Iterators.asCollection) Collection(java.util.Collection) Test(org.junit.Test)

Example 3 with IndexAccessor

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

the class IndexingServiceTest method shouldNotSnapshotPopulatingIndexes.

@Test
public void shouldNotSnapshotPopulatingIndexes() throws Exception {
    // GIVEN
    CountDownLatch populatorLatch = new CountDownLatch(1);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    int indexId = 1;
    int indexId2 = 2;
    IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, indexAccessor, new DataUpdates(), rule1, rule2);
    File theFile = new File("Blah");
    doAnswer(waitForLatch(populatorLatch)).when(populator).create();
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(indexId, rule1.getIndexDescriptor())).thenReturn(POPULATING);
    when(indexProvider.getInitialState(indexId2, rule2.getIndexDescriptor())).thenReturn(ONLINE);
    when(storeView.indexSample(anyLong(), any(DoubleLongRegister.class))).thenReturn(newDoubleLongRegister(32L, 32L));
    life.start();
    // WHEN
    ResourceIterator<File> files = indexing.snapshotStoreFiles();
    // only now, after the snapshot, is the population job allowed to finish
    populatorLatch.countDown();
    waitForIndexesToComeOnline(indexing, indexId, indexId2);
    // THEN
    // We get a snapshot from the online index, but no snapshot from the populating one
    assertThat(asCollection(files), equalTo(asCollection(iterator(theFile))));
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test)

Example 4 with IndexAccessor

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

the class IndexingServiceTest method shouldSnapshotOnlineIndexes.

@Test
public void shouldSnapshotOnlineIndexes() throws Exception {
    // GIVEN
    int indexId = 1;
    int indexId2 = 2;
    IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), indexAccessor, new DataUpdates(), rule1, rule2);
    File theFile = new File("Blah");
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(indexId, rule1.getIndexDescriptor())).thenReturn(ONLINE);
    when(indexProvider.getInitialState(indexId2, rule2.getIndexDescriptor())).thenReturn(ONLINE);
    when(storeView.indexSample(anyLong(), any(DoubleLongRegister.class))).thenReturn(newDoubleLongRegister(32L, 32L));
    life.start();
    // WHEN
    ResourceIterator<File> files = indexing.snapshotStoreFiles();
    // THEN
    // We get a snapshot per online index
    assertThat(asCollection(files), equalTo(asCollection(iterator(theFile, theFile))));
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) File(java.io.File) Test(org.junit.Test)

Example 5 with IndexAccessor

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

the class IndexLookup method getIndexReader.

private IndexReader getIndexReader(IndexRule rule) throws IOException {
    IndexReader reader = readerCache.get(rule);
    if (reader == null) {
        IndexAccessor accessor = schemaIndexProvider.getOnlineAccessor(rule.getId(), rule.getIndexDescriptor(), samplingConfig);
        indexAccessors.add(accessor);
        reader = accessor.newReader();
        readerCache.put(rule, reader);
    }
    return reader;
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Aggregations

IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)13 Test (org.junit.Test)8 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)7 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)5 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)3 Config (org.neo4j.kernel.configuration.Config)3 DoubleLongRegister (org.neo4j.register.Register.DoubleLongRegister)3 Registers.newDoubleLongRegister (org.neo4j.register.Registers.newDoubleLongRegister)3 File (java.io.File)2 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)2 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Iterators.asCollection (org.neo4j.helpers.collection.Iterators.asCollection)1 DirectoryFactory (org.neo4j.kernel.api.impl.index.storage.DirectoryFactory)1