use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method shouldCheckAllCollisionsFromPopulatorAdd.
@Test
void shouldCheckAllCollisionsFromPopulatorAdd() throws Exception {
// given
populator = newPopulator();
// This value has to be high enough to stress the EntrySet implementation
int iterations = 228;
IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
for (int nodeId = 0; nodeId < iterations; nodeId++) {
updater.process(add(nodeId, schemaDescriptor, "1"));
when(nodePropertyAccessor.getNodePropertyValue(nodeId, PROPERTY_KEY_ID, NULL)).thenReturn(Values.of(nodeId));
}
// ... and the actual conflicting property:
updater.process(add(iterations, schemaDescriptor, "1"));
when(nodePropertyAccessor.getNodePropertyValue(iterations, PROPERTY_KEY_ID, NULL)).thenReturn(// This collision is real!!!
Values.of(1));
// when
var conflict = assertThrows(IndexEntryConflictException.class, updater::close);
assertEquals(1, conflict.getExistingNodeId());
assertEquals(Values.of(1), conflict.getSinglePropertyValue());
assertEquals(iterations, conflict.getAddedNodeId());
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class NodeCheckerTest method shouldReportNodeDoesNotHaveExpectedLabel.
@Test
void shouldReportNodeDoesNotHaveExpectedLabel() throws Exception {
// given
try (AutoCloseable ignored = tx()) {
// (N) w/ label L
// LabelIndex does not have the N:L entry
long nodeId = node(nodeStore.nextId(CursorContext.NULL), NULL, NULL);
try (IndexUpdater writer = labelIndexWriter()) {
writer.process(IndexEntryUpdate.change(nodeId, IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
}
}
// when
check();
// then
expect(LabelScanConsistencyReport.class, report -> report.nodeDoesNotHaveExpectedLabel(any(), anyLong()));
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class NodeCheckerTest method shouldReportNodeNotInUse.
@Test
void shouldReportNodeNotInUse() throws Exception {
// given
try (AutoCloseable ignored = tx()) {
// A couple of nodes w/ correct label indexing
try (IndexUpdater writer = labelIndexWriter()) {
for (int i = 0; i < 10; i++) {
long nodeId = node(nodeStore.nextId(CursorContext.NULL), NULL, NULL, label1);
writer.process(IndexEntryUpdate.change(nodeId, IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
}
}
// Label index having (N) which is not in use in the store
try (IndexUpdater writer = labelIndexWriter()) {
writer.process(IndexEntryUpdate.change(nodeStore.nextId(CursorContext.NULL), IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
}
}
// when
check();
// then
expect(LabelScanConsistencyReport.class, report -> report.nodeNotInUse(any()));
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class NodeCheckerTest method shouldReportNodeNotInUseOnEmptyStore.
@Test
void shouldReportNodeNotInUseOnEmptyStore() throws Exception {
// given
try (AutoCloseable ignored = tx()) {
// Label index having (N) which is not in use in the store
try (IndexUpdater writer = labelIndexWriter()) {
writer.process(IndexEntryUpdate.change(nodeStore.nextId(CursorContext.NULL), IndexDescriptor.NO_INDEX, EMPTY_LONG_ARRAY, new long[] { label1 }));
}
}
// when
check();
// then
expect(LabelScanConsistencyReport.class, report -> report.nodeNotInUse(any()));
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class LimitedFullCheckIT method shouldFindDuplicatesInUniqueIndexEvenWhenInDifferentRanges.
@Test
void shouldFindDuplicatesInUniqueIndexEvenWhenInDifferentRanges() throws ConsistencyCheckIncompleteException, IndexEntryConflictException, IOException {
// given
Iterator<IndexDescriptor> indexRuleIterator = getValueIndexDescriptors();
// Create 2 extra nodes to guarantee that the node id of our duplicate is not in the same range as the original entry.
createOneNode();
createOneNode();
// Create a node so the duplicate in the index refers to a valid node
// (IndexChecker only reports the duplicate if it refers to a node id lower than highId)
long nodeId = createOneNode();
while (indexRuleIterator.hasNext()) {
IndexDescriptor indexRule = indexRuleIterator.next();
// Don't close this accessor. It will be done when shutting down db.
IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexRule);
try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
// There is already another node (created in generateInitialData()) that has this value
updater.process(IndexEntryUpdate.add(nodeId, indexRule, values(indexRule)));
}
accessor.force(NULL);
}
// when
ConsistencySummaryStatistics stats = check();
// then
// the duplicate in unique index
on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, // the index entries pointing to node that should not be in index
3).andThatsAllFolks();
}
Aggregations