use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class BlockBasedIndexPopulator method newPopulatingUpdater.
@Override
public IndexUpdater newPopulatingUpdater(CursorContext cursorContext) {
if (scanCompleted) {
// Will need the reader from newReader, which a sub-class of this class implements
return new DelegatingIndexUpdater(super.newPopulatingUpdater(cursorContext)) {
@Override
public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
validateUpdate(valueUpdate);
numberOfIndexUpdatesSinceSample.incrementAndGet();
super.process(valueUpdate);
}
};
}
return new IndexUpdater() {
private volatile boolean closed;
@Override
public void process(IndexEntryUpdate<?> update) {
assertOpen();
ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
try {
validateUpdate(valueUpdate);
externalUpdates.add(valueUpdate);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public void close() {
closed = true;
}
private void assertOpen() {
if (closed) {
throw new IllegalStateException("Updater has been closed");
}
}
};
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method shouldUpdateEntryForNodeThatHasAlreadyBeenIndexed.
@Test
void shouldUpdateEntryForNodeThatHasAlreadyBeenIndexed() throws Exception {
// given
populator = newPopulator();
addUpdate(populator, 1, "value1");
// when
IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
updater.process(change(1, schemaDescriptor, "value1", "value2"));
populator.close(true, NULL);
// then
assertEquals(Collections.EMPTY_LIST, getAllNodes(getDirectory(), "value1"));
assertEquals(singletonList(1L), getAllNodes(getDirectory(), "value2"));
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method shouldRejectDuplicateEntryAfterUsingPopulatingUpdater.
@Test
void shouldRejectDuplicateEntryAfterUsingPopulatingUpdater() throws Exception {
// given
populator = newPopulator();
String valueString = "value1";
IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
updater.process(add(1, schemaDescriptor, valueString));
addUpdate(populator, 2, valueString);
Value value = Values.of(valueString);
when(nodePropertyAccessor.getNodePropertyValue(1, PROPERTY_KEY_ID, NULL)).thenReturn(value);
when(nodePropertyAccessor.getNodePropertyValue(2, PROPERTY_KEY_ID, NULL)).thenReturn(value);
// when
var conflict = assertThrows(IndexEntryConflictException.class, () -> populator.verifyDeferredConstraints(nodePropertyAccessor));
assertEquals(1, conflict.getExistingNodeId());
assertEquals(value, conflict.getSinglePropertyValue());
assertEquals(2, conflict.getAddedNodeId());
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method shouldRejectDuplicateEntryWhenUsingPopulatingUpdater.
@Test
void shouldRejectDuplicateEntryWhenUsingPopulatingUpdater() throws Exception {
// given
populator = newPopulator();
addUpdate(populator, 1, "value1");
addUpdate(populator, 2, "value2");
Value value = Values.of("value1");
when(nodePropertyAccessor.getNodePropertyValue(1, PROPERTY_KEY_ID, NULL)).thenReturn(value);
when(nodePropertyAccessor.getNodePropertyValue(3, PROPERTY_KEY_ID, NULL)).thenReturn(value);
// when
var conflict = assertThrows(IndexEntryConflictException.class, () -> {
IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
updater.process(add(3, schemaDescriptor, "value1"));
updater.close();
});
assertEquals(1, conflict.getExistingNodeId());
assertEquals(value, conflict.getSinglePropertyValue());
assertEquals(3, conflict.getAddedNodeId());
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.
@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesThatAreNotIndexed(IndexSize indexSize) throws Exception {
indexSize.createAdditionalData(fixture);
// given
Iterator<IndexDescriptor> indexDescriptorIterator = getValueIndexDescriptors();
while (indexDescriptorIterator.hasNext()) {
IndexDescriptor indexDescriptor = indexDescriptorIterator.next();
IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexDescriptor);
try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
for (long nodeId : indexedNodes) {
EntityUpdates updates = fixture.nodeAsUpdates(nodeId);
for (IndexEntryUpdate<?> update : updates.valueUpdatesForIndexKeys(singletonList(indexDescriptor))) {
updater.process(IndexEntryUpdate.remove(nodeId, indexDescriptor, ((ValueIndexEntryUpdate<?>) update).values()));
}
}
}
}
// when
ConsistencySummaryStatistics stats = check();
// then
// 1 node missing from 1 index + 1 node missing from 2 indexes
on(stats).verify(RecordType.NODE, 3).andThatsAllFolks();
}
Aggregations