Search in sources :

Example 91 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertRemovedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    int nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, transactionRepresentationOf(recordState));
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
    recordState.nodeRemoveProperty(nodeId, property2.propertyKeyId());
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId).removed(property1.propertyKeyId(), property1.value()).removed(property2.propertyKeyId(), property2.value()).build();
    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 92 with NeoStores

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

the class TransactionRecordStateTest method shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType.

@Test
public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType() throws Exception {
    // GIVEN a node with a total of denseNodeThreshold-1 relationships
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "13");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    int nodeId = (int) neoStores.getNodeStore().nextId(), typeA = 0;
    tx.nodeCreate(nodeId);
    tx.createRelationshipTypeToken("A", typeA);
    long[] relationshipsCreated = createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 15);
    //WHEN
    tx.relDelete(relationshipsCreated[0]);
    // THEN the node should have been converted into a dense node
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 0, 14);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 93 with NeoStores

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

the class CsvInputBatchImportIT method verifyImportedData.

// ======================================================
// Below is code for verifying the imported data
// ======================================================
private void verifyImportedData(List<InputNode> nodeData, List<InputRelationship> relationshipData) {
    // Build up expected data for the verification below
    Map<String, InputNode> /*id*/
    expectedNodes = new HashMap<>();
    Map<String, String[]> expectedNodeNames = new HashMap<>();
    Map<String, Map<String, Map<String, AtomicInteger>>> /*end node name*/
    expectedRelationships = new AutoCreatingHashMap<>(nested(String.class, nested(String.class, values(AtomicInteger.class))));
    Map<String, AtomicLong> expectedNodeCounts = new AutoCreatingHashMap<>(values(AtomicLong.class));
    Map<String, Map<String, Map<String, AtomicLong>>> expectedRelationshipCounts = new AutoCreatingHashMap<>(nested(String.class, nested(String.class, values(AtomicLong.class))));
    buildUpExpectedData(nodeData, relationshipData, expectedNodes, expectedNodeNames, expectedRelationships, expectedNodeCounts, expectedRelationshipCounts);
    // Do the verification
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(directory.graphDbDir());
    try (Transaction tx = db.beginTx()) {
        // Verify nodes
        for (Node node : db.getAllNodes()) {
            String name = (String) node.getProperty("name");
            String[] labels = expectedNodeNames.remove(name);
            assertEquals(asSet(labels), names(node.getLabels()));
        }
        assertEquals(0, expectedNodeNames.size());
        // Verify relationships
        for (Relationship relationship : db.getAllRelationships()) {
            String startNodeName = (String) relationship.getStartNode().getProperty("name");
            Map<String, Map<String, AtomicInteger>> inner = expectedRelationships.get(startNodeName);
            String endNodeName = (String) relationship.getEndNode().getProperty("name");
            Map<String, AtomicInteger> innerInner = inner.get(endNodeName);
            String type = relationship.getType().name();
            int countAfterwards = innerInner.get(type).decrementAndGet();
            assertThat(countAfterwards, greaterThanOrEqualTo(0));
            if (countAfterwards == 0) {
                innerInner.remove(type);
                if (innerInner.isEmpty()) {
                    inner.remove(endNodeName);
                    if (inner.isEmpty()) {
                        expectedRelationships.remove(startNodeName);
                    }
                }
            }
        }
        assertEquals(0, expectedRelationships.size());
        // Verify counts, TODO how to get counts store other than this way?
        NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
        Function<String, Integer> labelTranslationTable = translationTable(neoStores.getLabelTokenStore(), ReadOperations.ANY_LABEL);
        for (Pair<Integer, Long> count : allNodeCounts(labelTranslationTable, expectedNodeCounts)) {
            assertEquals("Label count mismatch for label " + count.first(), count.other().longValue(), neoStores.getCounts().nodeCount(count.first().intValue(), newDoubleLongRegister()).readSecond());
        }
        Function<String, Integer> relationshipTypeTranslationTable = translationTable(neoStores.getRelationshipTypeTokenStore(), ReadOperations.ANY_RELATIONSHIP_TYPE);
        for (Pair<RelationshipCountKey, Long> count : allRelationshipCounts(labelTranslationTable, relationshipTypeTranslationTable, expectedRelationshipCounts)) {
            RelationshipCountKey key = count.first();
            assertEquals("Label count mismatch for label " + key, count.other().longValue(), neoStores.getCounts().relationshipCount(key.startLabel, key.type, key.endLabel, newDoubleLongRegister()).readSecond());
        }
        tx.success();
    } finally {
        db.shutdown();
    }
}
Also used : AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Node(org.neo4j.graphdb.Node) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.neo4j.graphdb.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap)

Example 94 with NeoStores

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

the class CountsStoreRecoveryTest method flushNeoStoreOnly.

private void flushNeoStoreOnly() throws Exception {
    NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    MetaDataStore metaDataStore = neoStores.getMetaDataStore();
    metaDataStore.flush();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 95 with NeoStores

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

the class StoreUpgraderTest method upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId.

@Test
public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Exception {
    // Given
    fileSystem.deleteFile(new File(dbDirectory, StoreLogService.INTERNAL_LOG_NAME));
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    // When
    newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache).migrateIfNeeded(dbDirectory);
    // Then
    StoreFactory factory = new StoreFactory(dbDirectory, pageCache, fileSystem, NullLogProvider.getInstance());
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        assertThat(neoStores.getMetaDataStore().getUpgradeTransaction(), equalTo(neoStores.getMetaDataStore().getLastCommittedTransaction()));
        assertThat(neoStores.getMetaDataStore().getUpgradeTime(), not(equalTo(MetaDataStore.FIELD_NOT_INITIALIZED)));
        long minuteAgo = System.currentTimeMillis() - MINUTES.toMillis(1);
        assertThat(neoStores.getMetaDataStore().getUpgradeTime(), greaterThan(minuteAgo));
    }
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) NeoStores(org.neo4j.kernel.impl.store.NeoStores) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) MigrationTestUtils.truncateFile(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.truncateFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)122 Test (org.junit.Test)46 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)32 Test (org.junit.jupiter.api.Test)25 ArrayList (java.util.ArrayList)17 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)16 PageCache (org.neo4j.io.pagecache.PageCache)16 NodeStore (org.neo4j.kernel.impl.store.NodeStore)15 Transaction (org.neo4j.graphdb.Transaction)14 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)13 File (java.io.File)11 IOException (java.io.IOException)11 Node (org.neo4j.graphdb.Node)11 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)11 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)9 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9