use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.
the class BatchInserterImpl method repopulateAllIndexes.
private void repopulateAllIndexes() throws IOException, IndexEntryConflictException {
if (!labelsTouched) {
return;
}
final IndexRule[] rules = getIndexesNeedingPopulation();
final IndexPopulator[] populators = new IndexPopulator[rules.length];
// the store is uncontended at this point, so creating a local LockService is safe.
final NewIndexDescriptor[] descriptors = new NewIndexDescriptor[rules.length];
for (int i = 0; i < rules.length; i++) {
IndexRule rule = rules[i];
descriptors[i] = rule.getIndexDescriptor();
populators[i] = schemaIndexProviders.apply(rule.getProviderDescriptor()).getPopulator(rule.getId(), descriptors[i], new IndexSamplingConfig(config));
populators[i].create();
}
Visitor<NodeUpdates, IOException> propertyUpdateVisitor = updates -> {
for (int i = 0; i < descriptors.length; i++) {
Optional<IndexEntryUpdate> update = updates.forIndex(descriptors[i].schema());
if (update.isPresent()) {
try {
populators[i].add(Collections.singletonList(update.get()));
} catch (IndexEntryConflictException conflict) {
throw conflict.notAllowed(descriptors[i]);
}
}
}
return true;
};
List<NewIndexDescriptor> descriptorList = Arrays.asList(descriptors);
int[] labelIds = descriptorList.stream().mapToInt(index -> index.schema().getLabelId()).toArray();
int[] propertyKeyIds = descriptorList.stream().flatMapToInt(d -> Arrays.stream(d.schema().getPropertyIds())).toArray();
InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor();
StoreScan<IOException> storeScan = indexStoreView.visitNodes(labelIds, (propertyKeyId) -> PrimitiveIntCollections.contains(propertyKeyIds, propertyKeyId), propertyUpdateVisitor, labelUpdateVisitor, true);
storeScan.run();
for (IndexPopulator populator : populators) {
populator.verifyDeferredConstraints(indexStoreView);
populator.close(true);
}
labelUpdateVisitor.close();
}
use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.
the class FullScanStoreViewTest method shouldIgnoreDeletedNodesDuringScan.
@Test
void shouldIgnoreDeletedNodesDuringScan() {
// given
deleteAlistairAndStefanNodes();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitNodes(new int[] { labelId }, id -> id == propertyKeyId, propertyScanConsumer, new TestTokenScanConsumer(), false, true, NULL, INSTANCE);
// when
storeScan.run(NO_EXTERNAL_UPDATES);
// then
assertTrue(propertyScanConsumer.batches.isEmpty());
}
use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.
the class FullScanStoreViewTest method shouldLockRelationshipsWhileReadingThem.
@Test
void shouldLockRelationshipsWhileReadingThem() throws Exception {
// given
StoreScan storeScan = storeView.visitRelationships(new int[] { relTypeId }, id -> id == relPropertyKeyId, new TestPropertyScanConsumer(), null, true, true, NULL, INSTANCE);
// when
storeScan.run(NO_EXTERNAL_UPDATES);
// then
assertThat(lockMocks.size()).as("allocated locks: " + lockMocks.keySet()).isGreaterThanOrEqualTo(2);
Lock lock0 = lockMocks.get(0L);
Lock lock1 = lockMocks.get(1L);
assertNotNull(lock0, "Lock[relationship=0] never acquired");
assertNotNull(lock1, "Lock[relationship=1] never acquired");
InOrder order = inOrder(locks, lock0, lock1);
order.verify(locks).acquireRelationshipLock(0, SHARED);
order.verify(lock0).release();
order.verify(locks).acquireRelationshipLock(1, SHARED);
order.verify(lock1).release();
}
use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.
the class FullScanStoreViewTest method shouldIgnoreDeletedRelationshipsDuringScan.
@Test
void shouldIgnoreDeletedRelationshipsDuringScan() {
// given
deleteAlistairAndStefanNodes();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitRelationships(new int[] { relTypeId }, id -> id == relPropertyKeyId, propertyScanConsumer, null, true, true, NULL, INSTANCE);
// when
storeScan.run(NO_EXTERNAL_UPDATES);
// then
assertTrue(propertyScanConsumer.batches.isEmpty());
}
use of org.neo4j.kernel.impl.api.index.StoreScan in project neo4j by neo4j.
the class FullScanStoreViewTest method processAllRelationshipTypes.
@Test
void processAllRelationshipTypes() throws Exception {
// Given
TestTokenScanConsumer tokenScanConsumer = new TestTokenScanConsumer();
StoreScan storeViewRelationshipStoreScan = storeView.visitRelationships(EMPTY_INT_ARRAY, ALWAYS_TRUE_INT, null, tokenScanConsumer, true, true, NULL, INSTANCE);
// When
storeViewRelationshipStoreScan.run(NO_EXTERNAL_UPDATES);
// Then
var updates = tokenScanConsumer.batches.get(0);
assertThat(updates.size()).isEqualTo(2);
for (var update : updates) {
long[] tokensAfter = update.getTokens();
assertThat(tokensAfter.length).isEqualTo(1);
assertThat(tokensAfter[0]).isEqualTo(0);
assertThat(update.getEntityId()).satisfiesAnyOf(id -> assertThat(id).isEqualTo(0), id -> assertThat(id).isEqualTo(1));
}
}
Aggregations