Search in sources :

Example 11 with NodeUpdates

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));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 12 with NodeUpdates

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();
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) Arrays(java.util.Arrays) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Iterators(org.neo4j.helpers.collection.Iterators) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) RelationshipGroupGetter(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter) PrimitiveIntCollections(org.neo4j.collection.primitive.PrimitiveIntCollections) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) NodeLabelsField.parseLabelsField(org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) PropertyStore.encodeString(org.neo4j.kernel.impl.store.PropertyStore.encodeString) Map(java.util.Map) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NodeMultiPropertyDescriptor(org.neo4j.kernel.api.schema.NodeMultiPropertyDescriptor) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) IndexDefinitionImpl(org.neo4j.kernel.impl.coreapi.schema.IndexDefinitionImpl) NullLog(org.neo4j.logging.NullLog) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) HighestSelectionStrategy(org.neo4j.kernel.extension.dependency.HighestSelectionStrategy) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Locks(org.neo4j.kernel.impl.locking.Locks) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) RelationshipType(org.neo4j.graphdb.RelationshipType) NodeStore(org.neo4j.kernel.impl.store.NodeStore) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IndexCreatorImpl(org.neo4j.kernel.impl.coreapi.schema.IndexCreatorImpl) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) PageCacheLifecycle(org.neo4j.kernel.impl.pagecache.PageCacheLifecycle) IteratorWrapper(org.neo4j.helpers.collection.IteratorWrapper) ArrayList(java.util.ArrayList) InternalSchemaActions(org.neo4j.kernel.impl.coreapi.schema.InternalSchemaActions) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) DirectRecordAccessSet(org.neo4j.unsafe.batchinsert.DirectRecordAccessSet) SchemaCache(org.neo4j.kernel.impl.api.store.SchemaCache) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) UnsatisfiedDependencyStrategies(org.neo4j.kernel.extension.UnsatisfiedDependencyStrategies) Listener(org.neo4j.kernel.impl.util.Listener) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) BaseNodeConstraintCreator(org.neo4j.kernel.impl.coreapi.schema.BaseNodeConstraintCreator) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) IOException(java.io.IOException) Label.label(org.neo4j.graphdb.Label.label) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) IoPrimitiveUtils.safeCastLongToInt(org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt) File(java.io.File) Iterables(org.neo4j.helpers.collection.Iterables) ConstraintDescriptorFactory(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) SchemaIndexProviderMap(org.neo4j.kernel.impl.api.index.SchemaIndexProviderMap) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) PropertyDeleter(org.neo4j.kernel.impl.transaction.state.PropertyDeleter) Log(org.neo4j.logging.Log) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) RelationshipTypeTokenStore(org.neo4j.kernel.impl.store.RelationshipTypeTokenStore) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Record(org.neo4j.kernel.impl.store.record.Record) PageCache(org.neo4j.io.pagecache.PageCache) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PropertyCreator(org.neo4j.kernel.impl.transaction.state.PropertyCreator) Collection(java.util.Collection) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) KernelException(org.neo4j.kernel.api.exceptions.KernelException) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) StoreLocker(org.neo4j.kernel.internal.StoreLocker) Entry(java.util.Map.Entry) Optional(java.util.Optional) EmbeddedGraphDatabase(org.neo4j.kernel.internal.EmbeddedGraphDatabase) Label(org.neo4j.graphdb.Label) SchemaDescriptorFactory(org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) Token(org.neo4j.storageengine.api.Token) NotFoundException(org.neo4j.graphdb.NotFoundException) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) RelationshipTypeTokenRecord(org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord) PrintStream(java.io.PrintStream) Config(org.neo4j.kernel.configuration.Config) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordProxy(org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) LockService(org.neo4j.kernel.impl.locking.LockService) RelationshipCreator(org.neo4j.kernel.impl.transaction.state.RelationshipCreator) Iterator(java.util.Iterator) LongFunction(java.util.function.LongFunction) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) RecordAccess(org.neo4j.kernel.impl.transaction.state.RecordAccess) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) IdValidator(org.neo4j.kernel.impl.store.id.validation.IdValidator) PropertyTraverser(org.neo4j.kernel.impl.transaction.state.PropertyTraverser) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) Visitor(org.neo4j.helpers.collection.Visitor) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Optional(java.util.Optional) IOException(java.io.IOException) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Example 13 with NodeUpdates

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());
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 14 with NodeUpdates

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));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 15 with NodeUpdates

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));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Aggregations

NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)28 Test (org.junit.Test)25 NeoStores (org.neo4j.kernel.impl.store.NeoStores)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)5 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)5 ArrayList (java.util.ArrayList)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 Transaction (org.neo4j.graphdb.Transaction)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Collection (java.util.Collection)2 Visitor (org.neo4j.helpers.collection.Visitor)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1