use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.
the class PartitionedIndexReaderTest method samplingOverPartitions.
@Test
public void samplingOverPartitions() throws IndexNotFoundKernelException {
PartitionedIndexReader 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());
}
use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.
the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.
@Test
public void partitionedIndexPopulation() throws Exception {
try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor).withFileSystem(fileSystemRule.get()).withIndexRootFolder(testDir.directory("partitionIndex" + affectedNodes)).withIndexIdentifier("uniqueIndex" + affectedNodes).build()) {
uniqueIndex.open();
// index is empty and not yet exist
assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
assertFalse(uniqueIndex.exists());
try (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, descriptor)) {
generateUpdates(indexAccessor, affectedNodes);
indexAccessor.force();
// now index is online and should contain updates data
assertTrue(uniqueIndex.isOnline());
try (IndexReader indexReader = indexAccessor.newReader()) {
long[] nodes = PrimitiveLongCollections.asArray(indexReader.query(IndexQuery.exists(1)));
assertEquals(affectedNodes, nodes.length);
IndexSampler indexSampler = indexReader.createSampler();
IndexSample sample = indexSampler.sampleIndex();
assertEquals(affectedNodes, sample.indexSize());
assertEquals(affectedNodes, sample.uniqueValues());
assertEquals(affectedNodes, sample.sampleSize());
}
}
}
}
use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.
the class DirectNonUniqueIndexSampler method result.
@Override
public IndexSample result() {
try {
// lucene index needs to be flushed to be sure that reader will see all the data :(
luceneIndex.flush();
luceneIndex.maybeRefreshBlocking();
try (IndexReader indexReader = luceneIndex.getIndexReader()) {
IndexSampler sampler = indexReader.createSampler();
return sampler.sampleIndex();
} catch (IOException | IndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.storageengine.api.schema.IndexSampler in project neo4j by neo4j.
the class DatabaseCompositeIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.
@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
// given
updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
// when
// needs to be acquired before drop() is called
IndexReader indexReader = accessor.newReader();
IndexSampler indexSampler = indexReader.createSampler();
Future<Void> drop = threading.executeAndAwait(new IOFunction<Void, Void>() {
@Override
public Void apply(Void nothing) throws IOException {
accessor.drop();
return nothing;
}
}, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
try (IndexReader reader = indexReader) /* do not inline! */
{
indexSampler.sampleIndex();
fail("expected exception");
} catch (IndexNotFoundKernelException e) {
assertEquals("Index dropped while sampling.", e.getMessage());
} finally {
drop.get();
}
}
use of org.neo4j.storageengine.api.schema.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
// needs to be acquired before drop() is called
IndexReader indexReader = accessor.newReader();
IndexSampler indexSampler = indexReader.createSampler();
Future<Void> drop = threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
accessor.drop();
return nothing;
}, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
try (IndexReader reader = indexReader) /* do not inline! */
{
indexSampler.sampleIndex();
fail("expected exception");
} catch (IndexNotFoundKernelException e) {
assertEquals("Index dropped while sampling.", e.getMessage());
} finally {
drop.get();
}
}
Aggregations