use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.
the class IndexingServiceIntegrationTest method tracePageCacheAccessOnIndexUpdatesApply.
@ParameterizedTest
@MethodSource("parameters")
void tracePageCacheAccessOnIndexUpdatesApply(GraphDatabaseSettings.SchemaIndex schemaIndex) throws KernelException {
setUp(schemaIndex);
var marker = Label.label("marker");
var propertyName = "property";
var testConstraint = "testConstraint";
try (Transaction transaction = database.beginTx()) {
transaction.schema().constraintFor(marker).withName(testConstraint).assertPropertyIsUnique(propertyName).create();
transaction.commit();
}
var dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
var indexingService = dependencyResolver.resolveDependency(IndexingService.class);
var pageCacheTracer = dependencyResolver.resolveDependency(PageCacheTracer.class);
try (Transaction transaction = database.beginTx()) {
var kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(testConstraint);
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnIndexUpdatesApply"))) {
Iterable<IndexEntryUpdate<IndexDescriptor>> updates = List.of(add(1, indexDescriptor, longValue(4)));
indexingService.applyUpdates(updates, cursorContext);
PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
assertEquals(5L, cursorTracer.pins());
assertEquals(5L, cursorTracer.unpins());
assertEquals(2L, cursorTracer.hits());
assertEquals(3L, cursorTracer.faults());
}
}
}
use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldDeallocateAllAllocatedMemoryOnClose.
@Test
void shouldDeallocateAllAllocatedMemoryOnClose() throws IndexEntryConflictException, IOException {
// given
ThreadSafePeakMemoryTracker memoryTracker = new ThreadSafePeakMemoryTracker();
ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, 100);
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, memoryTracker);
boolean closed = false;
try {
// when
Collection<IndexEntryUpdate<?>> updates = batchOfUpdates();
populator.add(updates, NULL);
int nextId = updates.size();
externalUpdates(populator, nextId, nextId + 10);
nextId = nextId + 10;
long memoryBeforeScanCompleted = memoryTracker.usedNativeMemory();
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
externalUpdates(populator, nextId, nextId + 10);
// then
assertTrue(memoryTracker.peakMemoryUsage() > memoryBeforeScanCompleted, "expected some memory to have been temporarily allocated in scanCompleted");
populator.close(true, NULL);
closed = true;
bufferFactory.close();
assertEquals(0, memoryTracker.usedNativeMemory());
} finally {
if (!closed) {
populator.close(true, NULL);
}
}
}
use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.
the class FusionIndexPopulatorTest method verifyAddWithCorrectPopulator.
private void verifyAddWithCorrectPopulator(IndexPopulator correctPopulator, Value... numberValues) throws IndexEntryConflictException {
Collection<IndexEntryUpdate<LabelSchemaDescriptor>> update = Collections.singletonList(add(numberValues));
fusionIndexPopulator.add(update, NULL);
verify(correctPopulator).add(update, NULL);
for (IndexPopulator alivePopulator : alivePopulators) {
if (alivePopulator != correctPopulator) {
verify(alivePopulator, never()).add(update, NULL);
}
}
}
use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.
the class NativeIndexPopulatorTests method applyInterleaved.
void applyInterleaved(IndexEntryUpdate<IndexDescriptor>[] updates, IndexPopulator populator) throws IndexEntryConflictException {
boolean useUpdater = true;
Collection<IndexEntryUpdate<IndexDescriptor>> populatorBatch = new ArrayList<>();
IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
for (IndexEntryUpdate<IndexDescriptor> update : updates) {
if (random.nextInt(100) < 20) {
if (useUpdater) {
updater.close();
populatorBatch = new ArrayList<>();
} else {
populator.add(populatorBatch, NULL);
updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
}
useUpdater = !useUpdater;
}
if (useUpdater) {
updater.process(update);
} else {
populatorBatch.add(update);
}
}
if (useUpdater) {
updater.close();
} else {
populator.add(populatorBatch, NULL);
}
}
use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.
@Test
void sampleIncludedUpdates() {
LabelSchemaDescriptor schemaDescriptor = forLabel(1, 1);
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, schemaDescriptor, "foo"), add(2, schemaDescriptor, "bar"), add(3, schemaDescriptor, "baz"), add(4, schemaDescriptor, "qux"));
updates.forEach(populator::includeSample);
IndexSample sample = populator.sample(NULL);
assertEquals(new IndexSample(4, 4, 4), sample);
}
Aggregations