Search in sources :

Example 6 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 7 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 8 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 9 with IndexAccessor

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

the class IndexProxyCreator method createOnlineIndexProxy.

public IndexProxy createOnlineIndexProxy(long ruleId, NewIndexDescriptor descriptor, SchemaIndexProvider.Descriptor providerDescriptor) {
    // TODO Hook in version verification/migration calls to the SchemaIndexProvider here
    try {
        IndexAccessor onlineAccessor = onlineAccessorFromProvider(providerDescriptor, ruleId, descriptor, samplingConfig);
        IndexProxy proxy;
        proxy = new OnlineIndexProxy(ruleId, descriptor, onlineAccessor, storeView, providerDescriptor, false);
        proxy = new ContractCheckingIndexProxy(proxy, true);
        return proxy;
    } catch (IOException e) {
        logProvider.getLog(getClass()).error("Failed to open index: " + ruleId + " (" + descriptor.userDescription(tokenNameLookup) + "), requesting re-population.", e);
        return createRecoveringIndexProxy(descriptor, providerDescriptor);
    }
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IOException(java.io.IOException)

Example 10 with IndexAccessor

use of org.neo4j.kernel.api.index.IndexAccessor 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)

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