use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class RelationshipCheckerWithRelationshipTypeIndexTest method doVerifyCorrectReport.
@SafeVarargs
private void doVerifyCorrectReport(Density density, ThrowingConsumer<IndexUpdater, IndexEntryConflictException> targetRelationshipAction, Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport>... expectedCalls) throws Exception {
double recordFrequency = densityAsFrequency(density);
int nbrOfRelationships = random.nextInt(1, 2 * IDS_PER_CHUNK);
int targetRelationshipRelationship = random.nextInt(nbrOfRelationships);
// given
try (Transaction tx = db.beginTx();
IndexUpdater writer = relationshipTypeIndexWriter()) {
for (int i = 0; i < nbrOfRelationships; i++) {
if (i == targetRelationshipRelationship) {
targetRelationshipAction.accept(writer);
} else {
if (random.nextDouble() < recordFrequency) {
createCompleteEntry(writer, type);
} else {
notInUse(createStoreEntry(type));
}
}
}
tx.commit();
}
// when
ConsistencyFlags flags = new ConsistencyFlags(true, true, true);
check(context(flags));
// then
if (expectedCalls != null) {
for (Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport> expectedCall : expectedCalls) {
expect(ConsistencyReport.RelationshipTypeScanConsistencyReport.class, expectedCall);
}
} else {
verifyNoInteractions(monitor);
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FullCheckIntegrationTest method writeToNodeLabelStructure.
void writeToNodeLabelStructure(GraphStoreFixture fixture, Iterable<EntityTokenUpdate> entityTokenUpdates) throws IOException, IndexEntryConflictException {
IndexDescriptor tokenIndex = findTokenIndex(fixture, EntityType.NODE);
IndexAccessor accessor = fixture.indexAccessorLookup().apply(tokenIndex);
try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
for (EntityTokenUpdate entityTokenUpdate : entityTokenUpdates) {
indexUpdater.process(IndexEntryUpdate.change(entityTokenUpdate.getEntityId(), tokenIndex, entityTokenUpdate.getTokensBefore(), entityTokenUpdate.getTokensAfter()));
}
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodesWithDuplicatePropertyValueInUniqueIndex.
@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex(IndexSize indexSize) throws Exception {
// given
indexSize.createAdditionalData(fixture);
Iterator<IndexDescriptor> indexRuleIterator = getValueIndexDescriptors();
// 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.schema(), 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();
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class LuceneIndexAccessorIT method removeSomeNodes.
private static void removeSomeNodes(IndexDescriptor indexDescriptor, int nodes, IndexAccessor accessor, MutableLongSet expectedNodes) throws IndexEntryConflictException {
try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
for (long id = 0; id < nodes; id++) {
updater.process(IndexEntryUpdate.remove(id, indexDescriptor, values(indexDescriptor, id)));
expectedNodes.remove(id);
}
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FusionIndexUpdater method process.
@Override
public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
switch(valueUpdate.updateMode()) {
case ADDED:
instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF)).process(valueUpdate);
break;
case CHANGED:
// Hmm, here's a little conundrum. What if we change from a value that goes into native
// to a value that goes into fallback, or vice versa? We also don't want to blindly pass
// all CHANGED updates to both updaters since not all values will work in them.
IndexUpdater from = instanceSelector.select(slotSelector.selectSlot(valueUpdate.beforeValues(), CATEGORY_OF));
IndexUpdater to = instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF));
// - both before/after go into the same updater --> pass update into that updater
if (from == to) {
from.process(valueUpdate);
} else // - before go into one and after into the other --> REMOVED from one and ADDED into the other
{
from.process(IndexEntryUpdate.remove(valueUpdate.getEntityId(), valueUpdate.indexKey(), valueUpdate.beforeValues()));
to.process(IndexEntryUpdate.add(valueUpdate.getEntityId(), valueUpdate.indexKey(), valueUpdate.values()));
}
break;
case REMOVED:
instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF)).process(valueUpdate);
break;
default:
throw new IllegalArgumentException("Unknown update mode");
}
}
Aggregations