Search in sources :

Example 31 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeDifferentDirection.

@Test
public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeDifferentDirection() throws Exception {
    // GIVEN a node with a total of denseNodeThreshold-1 relationships
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "49");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    long nodeId = neoStores.getNodeStore().nextId();
    int typeA = 0;
    tx.nodeCreate(nodeId);
    tx.createRelationshipTypeToken("A", typeA);
    createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 24);
    createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 25);
    // here we're at the edge
    assertFalse(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    // WHEN creating the relationship that pushes us over the threshold
    createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 1);
    // THEN the node should have been converted into a dense node
    assertTrue(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 24, 26);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 32 with NeoStores

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

the class TransactionRecordStateTest method shouldExtractUpdateCommandsInCorrectOrder.

@Test
public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    long nodeId = 0, relId1 = 1, relId2 = 2, relId3 = 3;
    recordState.nodeCreate(nodeId);
    recordState.relCreate(relId1, 0, nodeId, nodeId);
    recordState.relCreate(relId2, 0, nodeId, nodeId);
    recordState.nodeAddProperty(nodeId, 0, 101);
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(recordState));
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeChangeProperty(nodeId, 0, 102);
    recordState.relCreate(relId3, 0, nodeId, nodeId);
    recordState.relAddProperty(relId1, 0, 123);
    // WHEN
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    // THEN
    Iterator<StorageCommand> commandIterator = commands.iterator();
    // added rel property
    assertCommand(commandIterator.next(), PropertyCommand.class);
    // created relationship relId3
    assertCommand(commandIterator.next(), RelationshipCommand.class);
    // rest is updates...
    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) 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 33 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeSameDirection.

@Test
public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeSameDirection() throws Exception {
    // GIVEN a node with a total of denseNodeThreshold-1 relationships
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "8");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    long nodeId = neoStores.getNodeStore().nextId();
    int typeA = 0;
    tx.nodeCreate(nodeId);
    tx.createRelationshipTypeToken("A", typeA);
    createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 8);
    // here we're at the edge
    assertFalse(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    // WHEN creating the relationship that pushes us over the threshold
    createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 1);
    // THEN the node should have been converted into a dense node
    assertTrue(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 9, 0);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 34 with NeoStores

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

the class TransactionRecordStateTest method movingBilaterallyOfTheDenseNodeThresholdIsConsistent.

@Test
public void movingBilaterallyOfTheDenseNodeThresholdIsConsistent() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "10");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    long nodeId = neoStores.getNodeStore().nextId();
    tx.nodeCreate(nodeId);
    int typeA = (int) neoStores.getRelationshipTypeTokenStore().nextId();
    tx.createRelationshipTypeToken("A", typeA);
    createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 20);
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(tx));
    tx = newTransactionRecordState(neoStores);
    int typeB = 1;
    tx.createRelationshipTypeToken("B", typeB);
    // WHEN
    // i remove enough relationships to become dense and remove enough to become not dense
    long[] relationshipsOfTypeB = createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 5);
    for (long relationshipToDelete : relationshipsOfTypeB) {
        tx.relDelete(relationshipToDelete);
    }
    PhysicalTransactionRepresentation ptx = transactionRepresentationOf(tx);
    apply(applier, ptx);
    // THEN
    // The dynamic label record in before should be the same id as in after, and should be in use
    final AtomicBoolean foundRelationshipGroupInUse = new AtomicBoolean();
    ptx.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitRelationshipGroupCommand(Command.RelationshipGroupCommand command) throws IOException {
            if (command.getAfter().inUse()) {
                if (!foundRelationshipGroupInUse.get()) {
                    foundRelationshipGroupInUse.set(true);
                } else {
                    fail();
                }
            }
            return false;
        }
    }));
    assertTrue("Did not create relationship group command", foundRelationshipGroupInUse.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NeoStores(org.neo4j.kernel.impl.store.NeoStores) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 35 with NeoStores

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

the class TransactionRecordStateTest method shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithManyTypes.

@Test
public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithManyTypes() throws Exception {
    // GIVEN a node with a total of denseNodeThreshold-1 relationships
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    long nodeId = neoStores.getNodeStore().nextId();
    int typeA = 0, typeB = 12, typeC = 600;
    tx.nodeCreate(nodeId);
    tx.createRelationshipTypeToken("A", typeA);
    long[] relationshipsCreatedAIncoming = createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 1);
    long[] relationshipsCreatedAOutgoing = createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 1);
    tx.createRelationshipTypeToken("B", typeB);
    long[] relationshipsCreatedBIncoming = createRelationships(neoStores, tx, nodeId, typeB, INCOMING, 1);
    long[] relationshipsCreatedBOutgoing = createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 1);
    tx.createRelationshipTypeToken("C", typeC);
    long[] relationshipsCreatedCIncoming = createRelationships(neoStores, tx, nodeId, typeC, INCOMING, 1);
    long[] relationshipsCreatedCOutgoing = createRelationships(neoStores, tx, nodeId, typeC, OUTGOING, 1);
    // WHEN
    tx.relDelete(relationshipsCreatedAIncoming[0]);
    // THEN
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 1, 0);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeB, 1, 1);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 1, 1);
    // WHEN
    tx.relDelete(relationshipsCreatedAOutgoing[0]);
    // THEN
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeA);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeB, 1, 1);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 1, 1);
    // WHEN
    tx.relDelete(relationshipsCreatedBIncoming[0]);
    // THEN
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeA);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeB, 1, 0);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 1, 1);
    // WHEN
    tx.relDelete(relationshipsCreatedBOutgoing[0]);
    // THEN
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeA);
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeB);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 1, 1);
    // WHEN
    tx.relDelete(relationshipsCreatedCIncoming[0]);
    // THEN
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeA);
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeB);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 1, 0);
    // WHEN
    tx.relDelete(relationshipsCreatedCOutgoing[0]);
    // THEN
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeA);
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeB);
    assertRelationshipGroupDoesNotExist(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), typeC);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) 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