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