Search in sources :

Example 41 with NeoStores

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

the class TransactionRecordStateTest method shouldExtractDeleteCommandsInCorrectOrder.

@Test
public void shouldExtractDeleteCommandsInCorrectOrder() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId1 = 0, nodeId2 = 1, relId1 = 1, relId2 = 2, relId4 = 10;
    recordState.nodeCreate(nodeId1);
    recordState.nodeCreate(nodeId2);
    recordState.relCreate(relId1, 0, nodeId1, nodeId1);
    recordState.relCreate(relId2, 0, nodeId1, nodeId1);
    recordState.relCreate(relId4, 1, nodeId1, nodeId1);
    recordState.nodeAddProperty(nodeId1, 0, 101);
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(recordState));
    recordState = newTransactionRecordState(neoStores);
    recordState.relDelete(relId4);
    recordState.nodeDelete(nodeId2);
    recordState.nodeRemoveProperty(nodeId1, 0);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    // updated rel group to not point to the deleted one below
    assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
    // updated node to point to the group after the deleted one
    assertCommand(commandIterator.next(), NodeCommand.class);
    // rest is deletions below...
    assertCommand(commandIterator.next(), PropertyCommand.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) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) ArrayList(java.util.ArrayList) 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 42 with NeoStores

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

the class TransactionRecordStateTest method shouldSortRelationshipGroups.

@Test
public void shouldSortRelationshipGroups() throws Throwable {
    // GIVEN
    int type5 = 5, type10 = 10, type15 = 15;
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        neoStores.getRelationshipTypeTokenStore().setHighId(16);
        recordState.createRelationshipTypeToken("5", type5);
        recordState.createRelationshipTypeToken("10", type10);
        recordState.createRelationshipTypeToken("15", type15);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
    }
    long nodeId = neoStores.getNodeStore().nextId();
    {
        long otherNode1Id = neoStores.getNodeStore().nextId();
        long otherNode2Id = neoStores.getNodeStore().nextId();
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        recordState.nodeCreate(nodeId);
        recordState.nodeCreate(otherNode1Id);
        recordState.nodeCreate(otherNode2Id);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode1Id);
        // This relationship will cause the switch to dense
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode2Id);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // Just a little validation of assumptions
        assertRelationshipGroupsInOrder(neoStores, nodeId, type10);
    }
    // WHEN inserting a relationship of type 5
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        long otherNodeId = neoStores.getNodeStore().nextId();
        recordState.nodeCreate(otherNodeId);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // THEN that group should end up first in the chain
        assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10);
    }
    // WHEN inserting a relationship of type 15
    {
        TransactionRecordState recordState = newTransactionRecordState(neoStores);
        long otherNodeId = neoStores.getNodeStore().nextId();
        recordState.nodeCreate(otherNodeId);
        recordState.relCreate(neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId);
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
        apply(applier, transaction(recordState));
        // THEN that group should end up last in the chain
        assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10, type15);
    }
}
Also used : 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) Test(org.junit.Test)

Example 43 with NeoStores

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

the class WriteTransactionCommandOrderingTest method injectAllPossibleCommands.

private TransactionRecordState injectAllPossibleCommands() {
    RecordChangeSet recordChangeSet = mock(RecordChangeSet.class);
    RecordChanges<Integer, LabelTokenRecord, Void> labelTokenChanges = mock(RecordChanges.class);
    RecordChanges<Integer, RelationshipTypeTokenRecord, Void> relationshipTypeTokenChanges = mock(RecordChanges.class);
    RecordChanges<Integer, PropertyKeyTokenRecord, Void> propertyKeyTokenChanges = mock(RecordChanges.class);
    RecordChanges<Long, NodeRecord, Void> nodeRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, RelationshipRecord, Void> relationshipRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, PropertyRecord, PrimitiveRecord> propertyRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, RelationshipGroupRecord, Integer> relationshipGroupChanges = mock(RecordChanges.class);
    RecordChanges<Long, SchemaRecord, SchemaRule> schemaRuleChanges = mock(RecordChanges.class);
    when(recordChangeSet.getLabelTokenChanges()).thenReturn(labelTokenChanges);
    when(recordChangeSet.getRelationshipTypeTokenChanges()).thenReturn(relationshipTypeTokenChanges);
    when(recordChangeSet.getPropertyKeyTokenChanges()).thenReturn(propertyKeyTokenChanges);
    when(recordChangeSet.getNodeRecords()).thenReturn(nodeRecordChanges);
    when(recordChangeSet.getRelRecords()).thenReturn(relationshipRecordChanges);
    when(recordChangeSet.getPropertyRecords()).thenReturn(propertyRecordChanges);
    when(recordChangeSet.getRelGroupRecords()).thenReturn(relationshipGroupChanges);
    when(recordChangeSet.getSchemaRuleChanges()).thenReturn(schemaRuleChanges);
    List<RecordProxy<Long, NodeRecord, Void>> nodeChanges = new LinkedList<>();
    RecordChange<Long, NodeRecord, Void> deletedNode = mock(RecordChange.class);
    when(deletedNode.getBefore()).thenReturn(inUseNode());
    when(deletedNode.forReadingLinkage()).thenReturn(missingNode());
    nodeChanges.add(deletedNode);
    RecordChange<Long, NodeRecord, Void> createdNode = mock(RecordChange.class);
    when(createdNode.getBefore()).thenReturn(missingNode());
    when(createdNode.forReadingLinkage()).thenReturn(createdNode());
    nodeChanges.add(createdNode);
    RecordChange<Long, NodeRecord, Void> updatedNode = mock(RecordChange.class);
    when(updatedNode.getBefore()).thenReturn(inUseNode());
    when(updatedNode.forReadingLinkage()).thenReturn(inUseNode());
    nodeChanges.add(updatedNode);
    when(nodeRecordChanges.changes()).thenReturn(nodeChanges);
    when(nodeRecordChanges.changeSize()).thenReturn(3);
    when(recordChangeSet.changeSize()).thenReturn(3);
    when(labelTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, LabelTokenRecord, Void>>emptyList());
    when(relationshipTypeTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, RelationshipTypeTokenRecord, Void>>emptyList());
    when(propertyKeyTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, PropertyKeyTokenRecord, Void>>emptyList());
    when(relationshipRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipRecord, Void>>emptyList());
    when(propertyRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, PropertyRecord, PrimitiveRecord>>emptyList());
    when(relationshipGroupChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipGroupRecord, Integer>>emptyList());
    when(schemaRuleChanges.changes()).thenReturn(Collections.<RecordProxy<Long, SchemaRecord, SchemaRule>>emptyList());
    NeoStores neoStores = mock(NeoStores.class);
    when(neoStores.getNodeStore()).thenReturn(mock(NodeStore.class));
    when(neoStores.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
    when(neoStores.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
    return new TransactionRecordState(neoStores, mock(IntegrityValidator.class), recordChangeSet, 0, null, null, null, null, null);
}
Also used : RelationshipTypeTokenRecord(org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) RecordProxy(org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) LinkedList(java.util.LinkedList) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore)

Example 44 with NeoStores

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

the class RelationshipCreatorTest method shouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode.

@Test
public void shouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode() throws Exception {
    // GIVEN
    long nodeId = createNodeWithRelationships(DENSE_NODE_THRESHOLD);
    NeoStores neoStores = flipToNeoStores();
    Tracker tracker = new Tracker(neoStores);
    RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(neoStores.getRelationshipGroupStore());
    RelationshipCreator relationshipCreator = new RelationshipCreator(groupGetter, 5);
    // WHEN
    relationshipCreator.relationshipCreate(idGeneratorFactory.get(IdType.RELATIONSHIP).nextId(), 0, nodeId, nodeId, tracker, tracker);
    // THEN
    assertEquals(tracker.relationshipLocksAcquired.size(), tracker.changedRelationships.size());
    assertFalse(tracker.relationshipLocksAcquired.isEmpty());
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 45 with NeoStores

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

the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.

@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
    // GIVEN a node with relationship group chain 2-->4-->10-->23
    File dir = new File("dir");
    fs.get().mkdirs(dir);
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
    try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
        RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
        RelationshipGroupRecord group_2 = group(0, 2);
        RelationshipGroupRecord group_4 = group(1, 4);
        RelationshipGroupRecord group_10 = group(2, 10);
        RelationshipGroupRecord group_23 = group(3, 23);
        link(group_2, group_4, group_10, group_23);
        store.updateRecord(group_2);
        store.updateRecord(group_4);
        store.updateRecord(group_10);
        store.updateRecord(group_23);
        RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
        NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
        // WHEN trying to find relationship group 7
        RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
        RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
        // THEN only groups 2, 4 and 10 should have been loaded
        InOrder verification = inOrder(store);
        verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        // it should also be reported as not found
        assertNull(result.group());
        // with group 4 as closes previous one
        assertEquals(group_4, result.closestPrevious().forReadingData());
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InOrder(org.mockito.InOrder) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectRecordAccess(org.neo4j.unsafe.batchinsert.DirectRecordAccess) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File) RelationshipGroupPosition(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter.RelationshipGroupPosition) 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