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);
}
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))));
}
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))));
}
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);
}
}
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();
}
Aggregations