Search in sources :

Example 1 with NodePropertyCommandsExtractor

use of org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode.

@Test
public void shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode() throws Exception {
    /* There was an issue where recovering a tx where a node with a label and a property
         * was created resulted in two exact copies of NodePropertyUpdates. */
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    int labelId = 5, propertyKeyId = 7;
    // -- an index
    long ruleId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    SchemaRule rule = indexRule(ruleId, forLabel(labelId, propertyKeyId), PROVIDER_DESCRIPTOR);
    recordState.createSchemaRule(rule);
    apply(neoStores, recordState);
    // -- and a tx creating a node with that label and property key
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    recordState.addLabelToNode(labelId, nodeId);
    recordState.nodeAddProperty(nodeId, propertyKeyId, "Neo");
    // WHEN
    PhysicalTransactionRepresentation transaction = transactionRepresentationOf(recordState);
    NodePropertyCommandsExtractor extractor = new NodePropertyCommandsExtractor();
    transaction.accept(extractor);
    // THEN
    // -- later recovering that tx, there should be only one update
    assertTrue(extractor.containsAnyNodeOrPropertyUpdate());
    PrimitiveLongSet recoveredNodeIds = Primitive.longSet();
    recoveredNodeIds.addAll(extractor.nodeCommandsById().iterator());
    recoveredNodeIds.addAll(extractor.propertyCommandsByNodeIds().iterator());
    assertEquals(1, recoveredNodeIds.size());
    assertEquals(nodeId, recoveredNodeIds.iterator().next());
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NeoStores(org.neo4j.kernel.impl.store.NeoStores) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) NodePropertyCommandsExtractor(org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 2 with NodePropertyCommandsExtractor

use of org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor in project neo4j by neo4j.

the class TransactionRecordStateTest method indexUpdatesOf.

private Iterable<NodeUpdates> indexUpdatesOf(NeoStores neoStores, TransactionRepresentation transaction) throws IOException {
    NodePropertyCommandsExtractor extractor = new NodePropertyCommandsExtractor();
    transaction.accept(extractor);
    OnlineIndexUpdates lazyIndexUpdates = new OnlineIndexUpdates(neoStores.getNodeStore(), new PropertyLoader(neoStores), new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore()));
    lazyIndexUpdates.feed(extractor.propertyCommandsByNodeIds(), extractor.nodeCommandsById());
    return lazyIndexUpdates;
}
Also used : PropertyPhysicalToLogicalConverter(org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter) NodePropertyCommandsExtractor(org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor)

Aggregations

NodePropertyCommandsExtractor (org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor)2 Test (org.junit.Test)1 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)1 PropertyPhysicalToLogicalConverter (org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 SchemaRule (org.neo4j.storageengine.api.schema.SchemaRule)1