use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.
the class NativeIndexAccessorTests method shouldSampleIndex.
@Test
void shouldSampleIndex() throws Exception {
// given
ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
processAll(updates);
try (var reader = accessor.newValueReader();
IndexSampler sampler = reader.createSampler()) {
// when
IndexSample sample = sampler.sampleIndex(NULL);
// then
assertEquals(updates.length, sample.indexSize());
assertEquals(updates.length, sample.sampleSize());
assertEquals(countUniqueValues(updates), sample.uniqueValues());
}
}
use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.
the class PartitionedValueIndexReaderTest method samplingOverPartitions.
@Test
void samplingOverPartitions() throws IndexNotFoundKernelException {
PartitionedValueIndexReader indexReader = createPartitionedReaderFromReaders();
when(indexReader1.createSampler()).thenReturn(new SimpleSampler(1));
when(indexReader2.createSampler()).thenReturn(new SimpleSampler(2));
when(indexReader3.createSampler()).thenReturn(new SimpleSampler(3));
IndexSampler sampler = indexReader.createSampler();
assertEquals(new IndexSample(6, 6, 6), sampler.sampleIndex(NULL));
}
use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.
the class AggregatingIndexSamplerTest method samplePartitionedIndex.
@Test
void samplePartitionedIndex() {
List<IndexSampler> samplers = Arrays.asList(createSampler(1), createSampler(2));
AggregatingIndexSampler partitionedSampler = new AggregatingIndexSampler(samplers);
IndexSample sample = partitionedSampler.sampleIndex(NULL);
assertEquals(new IndexSample(3, 3, 6), sample);
}
use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.
the class IndexingServiceTest method setUp.
@BeforeEach
void setUp() throws IndexNotFoundKernelException {
when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample());
when(storeViewFactory.createTokenIndexStoreView(any())).thenReturn(storeView);
when(storeView.newPropertyAccessor(any(CursorContext.class), any())).thenReturn(propertyAccessor);
ValueIndexReader indexReader = mock(ValueIndexReader.class);
IndexSampler indexSampler = mock(IndexSampler.class);
when(indexSampler.sampleIndex(any())).thenReturn(new IndexSample());
when(indexReader.createSampler()).thenReturn(indexSampler);
when(accessor.newValueReader()).thenReturn(indexReader);
}
use of org.neo4j.kernel.api.index.IndexSampler in project neo4j by neo4j.
the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.
@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
// given
updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
// when
var indexReader = accessor.newValueReader();
BinaryLatch dropLatch = new BinaryLatch();
BinaryLatch sampleLatch = new BinaryLatch();
LuceneIndexSampler indexSampler = spy((LuceneIndexSampler) indexReader.createSampler());
doAnswer(inv -> {
var obj = inv.callRealMethod();
// We have now started the sampling, let the index try to drop
dropLatch.release();
// Wait for the drop to be blocked
sampleLatch.await();
return obj;
}).when(indexSampler).newTask();
List<Future<?>> futures = new ArrayList<>();
try (var reader = indexReader;
/* do not inline! */
IndexSampler sampler = indexSampler) /* do not inline! */
{
futures.add(threading.execute((IOFunction<Void, Void>) nothing -> {
try {
indexSampler.sampleIndex(NULL);
fail("expected exception");
} catch (IndexNotFoundKernelException e) {
assertEquals("Index dropped while sampling.", e.getMessage());
} finally {
dropLatch.release();
}
return nothing;
}, null));
futures.add(threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
dropLatch.await();
accessor.drop();
return nothing;
}, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 10, MINUTES));
} finally {
// drop is blocked, okay to finish sampling (will fail since index is dropped)
sampleLatch.release();
for (Future<?> future : futures) {
future.get();
}
}
}
Aggregations