use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertLabelRemovalToNodePropertyUpdates.
@Test
public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeAddProperty(nodeId, propertyId1, value1);
recordState.nodeAddProperty(nodeId, propertyId2, value2);
addLabelsToNode(recordState, nodeId, oneLabelId);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
removeLabelsFromNode(recordState, nodeId, oneLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, noLabels).buildWithExistingProperties(Property.stringProperty(propertyId1, value1), Property.intProperty(propertyId2, value2));
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.api.index.NodeUpdates 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.api.index.NodeUpdates in project neo4j by neo4j.
the class NeoStoreIndexStoreView method nodeAsUpdates.
@Override
public void nodeAsUpdates(long nodeId, Collection<NodeUpdates> target) {
NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), FORCE);
if (!node.inUse()) {
return;
}
long firstPropertyId = node.getNextProp();
if (firstPropertyId == Record.NO_NEXT_PROPERTY.intValue()) {
// no properties => no updates (it's not going to be in any index)
return;
}
long[] labels = parseLabelsField(node).get(nodeStore);
if (labels.length == 0) {
// no labels => no updates (it's not going to be in any index)
return;
}
NodeUpdates.Builder update = NodeUpdates.forNode(nodeId, labels);
for (PropertyRecord propertyRecord : propertyStore.getPropertyRecordChain(firstPropertyId)) {
for (PropertyBlock property : propertyRecord) {
Object value = property.getType().getValue(property, propertyStore);
update.added(property.getKeyIndexId(), value);
}
}
target.add(update.build());
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates.
@Test
public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
addLabelsToNode(recordState, nodeId, bothLabelIds);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
removeLabelsFromNode(recordState, nodeId, secondLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).added(property2.propertyKeyId(), property2.value()).buildWithExistingProperties(property1, property2);
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertLabelAdditionToNodePropertyUpdates.
@Test
public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
Object value1 = LONG_STRING, value2 = LONG_STRING.getBytes();
recordState.nodeCreate(nodeId);
recordState.nodeAddProperty(nodeId, propertyId1, value1);
recordState.nodeAddProperty(nodeId, propertyId2, value2);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
addLabelsToNode(recordState, nodeId, oneLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, noLabels, oneLabelId).buildWithExistingProperties(Property.stringProperty(propertyId1, LONG_STRING), Property.byteArrayProperty(propertyId2, LONG_STRING.getBytes()));
assertEquals(expected, Iterables.single(indexUpdates));
}
Aggregations