Search in sources :

Example 36 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldExtractCreatedCommandsInCorrectOrder.

@Test
public void shouldExtractCreatedCommandsInCorrectOrder() throws Throwable {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId = 0, relId = 1;
    recordState.nodeCreate(nodeId);
    recordState.relCreate(relId++, 0, nodeId, nodeId);
    recordState.relCreate(relId, 0, nodeId, nodeId);
    recordState.nodeAddProperty(nodeId, 0, 101);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    assertCommand(commandIterator.next(), PropertyCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    assertCommand(commandIterator.next(), NodeCommand.class);
    assertFalse(commandIterator.hasNext());
}
Also used : NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 37 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.

@Test
public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 1;
    recordState.nodeCreate(nodeId);
    int propertyKey = 1;
    Object value = 5;
    // WHEN
    recordState.nodeAddProperty(nodeId, propertyKey, value);
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    PropertyCommand propertyCommand = singlePropertyCommand(commands);
    // THEN
    PropertyRecord before = propertyCommand.getBefore();
    assertFalse(before.inUse());
    assertFalse(before.iterator().hasNext());
    PropertyRecord after = propertyCommand.getAfter();
    assertTrue(after.inUse());
    assertEquals(1, count(after));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) Test(org.junit.Test)

Example 38 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNode.

@Test
public void shouldDeleteDynamicLabelsForDeletedNode() throws Throwable {
    // GIVEN a store that has got a node with a dynamic label record
    NeoStores store = neoStoresRule.open();
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    AtomicLong nodeId = new AtomicLong();
    AtomicLong dynamicLabelRecordId = new AtomicLong();
    apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
    // WHEN applying a transaction where the node is deleted
    apply(applier, transaction(deleteNode(store, nodeId.get())));
    // THEN the dynamic label record should also be deleted
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NeoStores(org.neo4j.kernel.impl.store.NeoStores) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.Test)

Example 39 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores 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 40 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx.

@Test
public void shouldIgnoreRelationshipGroupCommandsForGroupThatIsCreatedAndDeletedInThisTx() throws Exception {
    /*
         * This test verifies that there are no transaction commands generated for a state diff that contains a
         * relationship group that is created and deleted in this tx. This case requires special handling because
         * relationship groups can be created and then deleted from disjoint code paths. Look at
         * TransactionRecordState.extractCommands() for more details.
         *
         * The test setup looks complicated but all it does is mock properly a NeoStoreTransactionContext to
         * return an Iterable<RecordSet< that contains a RelationshipGroup record which has been created in this
         * tx and also is set notInUse.
         */
    // Given:
    // - dense node threshold of 5
    // - node with 4 rels of type A and 1 rel of type B
    NeoStores neoStore = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "5");
    int A = 0, B = 1;
    TransactionRecordState state = newTransactionRecordState(neoStore);
    state.nodeCreate(0);
    state.relCreate(0, A, 0, 0);
    state.relCreate(1, A, 0, 0);
    state.relCreate(2, A, 0, 0);
    state.relCreate(3, A, 0, 0);
    state.relCreate(4, B, 0, 0);
    apply(neoStore, state);
    // When doing a tx where a relationship of type A for the node is create and rel of type B is deleted
    state = newTransactionRecordState(neoStore);
    // here this node should be converted to dense and the groups should be created
    state.relCreate(5, A, 0, 0);
    // here the group B should be delete
    state.relDelete(4);
    // Then
    Collection<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands);
    RelationshipGroupCommand group = singleRelationshipGroupCommand(commands);
    assertEquals(A, group.getAfter().getType());
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)77 Test (org.junit.Test)48 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)17 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)14 NodeStore (org.neo4j.kernel.impl.store.NodeStore)12 File (java.io.File)11 Transaction (org.neo4j.graphdb.Transaction)11 ArrayList (java.util.ArrayList)9 PageCache (org.neo4j.io.pagecache.PageCache)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 Node (org.neo4j.graphdb.Node)8 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)8 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)7 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)6 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)5 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)5