use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method mustDiscoverRelationshipInStoreMissingFromIndex.
@Test
void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception {
GraphDatabaseService db = createDatabase();
try (Transaction tx = db.beginTx()) {
tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("REL"), asStrList("prop"))).close();
tx.commit();
}
IndexDescriptor indexDescriptor;
long relId;
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
indexDescriptor = getFulltextIndexDescriptor(tx.schema().getIndexes());
Node node = tx.createNode();
Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("REL"));
rel.setProperty("prop", "value");
relId = rel.getId();
tx.commit();
}
IndexingService indexes = getIndexingService(db);
IndexProxy indexProxy = indexes.getIndexProxy(indexDescriptor);
try (IndexUpdater updater = indexProxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
}
managementService.shutdown();
ConsistencyCheckService.Result result = checkConsistency();
assertFalse(result.isSuccessful());
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldBuildNonUniqueSampleAsPartOfScanCompleted.
@Test
void shouldBuildNonUniqueSampleAsPartOfScanCompleted() throws IndexEntryConflictException, IOException {
// given
ThreadSafePeakMemoryTracker memoryTracker = new ThreadSafePeakMemoryTracker();
ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, 100);
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, memoryTracker);
Collection<IndexEntryUpdate<?>> populationUpdates = batchOfUpdates();
populator.add(populationUpdates, NULL);
// when
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
// Also a couple of updates afterwards
int numberOfUpdatesAfterCompleted = 4;
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
for (int i = 0; i < numberOfUpdatesAfterCompleted; i++) {
updater.process(IndexEntryUpdate.add(10_000 + i, SCHEMA_DESCRIPTOR, intValue(i)));
}
}
populator.close(true, NULL);
// then
IndexSample sample = populator.sample(NULL);
assertEquals(populationUpdates.size(), sample.indexSize());
assertEquals(populationUpdates.size(), sample.sampleSize());
assertEquals(populationUpdates.size(), sample.uniqueValues());
assertEquals(numberOfUpdatesAfterCompleted, sample.updates());
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldCountExternalUpdatesAsSampleUpdates.
@Test
void shouldCountExternalUpdatesAsSampleUpdates() throws IOException, IndexEntryConflictException {
// given
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
try {
populator.add(List.of(add(0), add(1)), NULL);
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(add(10));
updater.process(add(11));
updater.process(add(12));
}
// when
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(remove(10));
}
// then
IndexSample sample = populator.sample(NULL);
assertThat(sample.updates()).isEqualTo(4);
} finally {
populator.close(true, NULL);
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class DeferredConflictCheckingIndexUpdaterTest method shouldThrowOnIndexEntryConflict.
@Test
void shouldThrowOnIndexEntryConflict() throws Exception {
// given
IndexUpdater actual = mock(IndexUpdater.class);
ValueIndexReader reader = mock(ValueIndexReader.class);
doAnswer(new NodeIdsIndexReaderQueryAnswer(descriptor, 101, 202)).when(reader).query(any(), any(), any(), any());
DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater(actual, () -> reader, descriptor, NULL);
// when
updater.process(add(0, descriptor, tuple(10, 11)));
var e = assertThrows(IndexEntryConflictException.class, updater::close);
assertThat(e.getMessage()).contains("101");
assertThat(e.getMessage()).contains("202");
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class GenericBlockBasedIndexPopulatorTest method shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates.
@Test
void shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates() throws IndexEntryConflictException, IOException {
// given
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(UNIQUE_INDEX_DESCRIPTOR);
try {
// when
Value duplicate = Values.of("duplicate");
Value unique = Values.of("unique");
ValueIndexEntryUpdate<?> firstScanUpdate = ValueIndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
ValueIndexEntryUpdate<?> secondScanUpdate = ValueIndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
ValueIndexEntryUpdate<?> externalUpdate = ValueIndexEntryUpdate.change(1, INDEX_DESCRIPTOR, duplicate, unique);
populator.add(singleton(firstScanUpdate), NULL);
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(externalUpdate);
}
populator.add(singleton(secondScanUpdate), NULL);
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
// then
assertHasEntry(populator, unique, 1);
assertHasEntry(populator, duplicate, 2);
} finally {
populator.close(true, NULL);
}
}
Aggregations