use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method shouldWorkWhileHavingHeavyConcurrentUpdates.
@Test
public void shouldWorkWhileHavingHeavyConcurrentUpdates() throws Exception {
// given some initial data
final long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
int initialNodes = nodes.length;
int threads = 5;
ExecutorService executorService = Executors.newFixedThreadPool(threads);
// when populating while creating
final NewIndexDescriptor index = createIndex("Person", "name");
final Collection<Callable<UpdatesTracker>> jobs = new ArrayList<>(threads);
for (int i = 0; i < threads; i++) {
jobs.add(new Callable<UpdatesTracker>() {
@Override
public UpdatesTracker call() throws Exception {
return executeCreationsDeletionsAndUpdates(nodes, index, CREATION_MULTIPLIER);
}
});
}
List<Future<UpdatesTracker>> futures = executorService.invokeAll(jobs);
// sum result into empty result
UpdatesTracker result = new UpdatesTracker();
result.notifyPopulationCompleted();
for (Future<UpdatesTracker> future : futures) {
result.add(future.get());
}
awaitOnline(index);
executorService.awaitTermination(1, TimeUnit.SECONDS);
executorService.shutdown();
// then
int tolerance = MISSED_UPDATES_TOLERANCE * threads;
double doubleTolerance = DOUBLE_ERROR_TOLERANCE * threads;
int seenWhilePopulating = initialNodes + result.createdDuringPopulation() - result.deletedDuringPopulation();
double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index), doubleTolerance);
assertCorrectIndexSize("Tracker had " + result, seenWhilePopulating, indexSize(index), tolerance);
int expectedIndexUpdates = result.deletedAfterPopulation() + result.createdAfterPopulation();
assertCorrectIndexUpdates("Tracker had " + result, expectedIndexUpdates, indexUpdates(index), tolerance);
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsIT method shouldRecoverIndexCountsBySamplingThemOnStartup.
@Test
public void shouldRecoverIndexCountsBySamplingThemOnStartup() {
// given some aliens in a database
createAliens();
// that have been indexed
awaitIndexOnline(indexAliensBySpecimen());
// where ALIEN and SPECIMEN are both the first ids of their kind
NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(labelId(ALIEN), pkId(SPECIMEN));
SchemaStorage storage = new SchemaStorage(neoStores().getSchemaStore());
long indexId = storage.indexGetForSchema(index).getId();
// for which we don't have index counts
resetIndexCounts(indexId);
// when we shutdown the database and restart it
restart();
// then we should have re-sampled the index
CountsTracker tracker = neoStores().getCounts();
assertEqualRegisters("Unexpected updates and size for the index", newDoubleLongRegister(0, 32), tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister()));
assertEqualRegisters("Unexpected sampling result", newDoubleLongRegister(16, 32), tracker.indexSample(indexId, newDoubleLongRegister()));
// and also
assertLogExistsForRecoveryOn(":Alien(specimen)");
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method shouldProvideIndexSelectivityWhenThereAreManyDuplicates.
@Test
public void shouldProvideIndexSelectivityWhenThereAreManyDuplicates() throws Exception {
// given some initial data
int created = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER).length;
// when
NewIndexDescriptor index = awaitOnline(createIndex("Person", "name"));
// then
double expectedSelectivity = UNIQUE_NAMES / created;
assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
assertCorrectIndexSize(created, indexSize(index));
assertEquals(0L, indexUpdates(index));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method createIndex.
private NewIndexDescriptor createIndex(String labelName, String propertyKeyName) throws KernelException {
try (Transaction tx = db.beginTx()) {
Statement statement = bridge.get();
int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(labelName);
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName);
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(descriptor);
tx.success();
return index;
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChanges.
@Test
public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChanges() throws Exception {
// given some initial data
long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
int initialNodes = nodes.length;
// when populating while creating
NewIndexDescriptor index = createIndex("Person", "name");
UpdatesTracker updatesTracker = executeCreationsAndUpdates(nodes, index, CREATION_MULTIPLIER);
awaitOnline(index);
// then
int seenWhilePopulating = initialNodes + updatesTracker.createdDuringPopulation();
double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
assertCorrectIndexSize(seenWhilePopulating, indexSize(index));
assertCorrectIndexUpdates(updatesTracker.createdAfterPopulation(), indexUpdates(index));
}
Aggregations