Search in sources :

Example 6 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    RelationshipType[] relTypes = null;
    int[] relTypeIds = null;
    Node[] nodes = null;
    Relationship[] rels = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        relTypes = createRelationShipTypes(2);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]) };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[1], relTypes[0]), nodes[1].createRelationshipTo(nodes[0], relTypes[1]) };
        rels[0].delete();
        tx.commit();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore()) {
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
        softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(0);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("()-[]->()").isEqualTo(rels.length - 1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 7 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method rebuildCounts.

private void rebuildCounts(long lastCommittedTransactionId, ProgressReporter progressReporter) throws IOException {
    cleanupCountsForRebuilding();
    IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    StoreFactory storeFactory = new StoreFactory(databaseLayout, CONFIG, idGenFactory, pageCache, fileSystem, LOG_PROVIDER, PageCacheTracer.NULL, writable());
    try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
        int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
        CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId, NumberArrayFactories.AUTO_WITHOUT_PAGECACHE, databaseLayout, progressReporter, PageCacheTracer.NULL, INSTANCE);
        try (GBPTreeCountsStore countsStore = createCountsStore(countsComputer)) {
            countsStore.start(NULL, INSTANCE);
            countsStore.checkpoint(NULL);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) IOException(java.io.IOException) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory)

Example 8 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class BatchInsertTest method shouldBuildCorrectCountsStoreOnIncrementalImport.

@Test
void shouldBuildCorrectCountsStoreOnIncrementalImport() throws Exception {
    // given
    Label label = Label.label("Person");
    int denseNodeThreshold = dense_node_threshold.defaultValue();
    for (int r = 0; r < 3; r++) {
        // when
        BatchInserter inserter = newBatchInserter(denseNodeThreshold);
        try {
            for (int i = 0; i < 100; i++) {
                inserter.createNode(null, label);
            }
        } finally {
            inserter.shutdown();
        }
        // then
        try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fs, RecoveryCleanupWorkCollector.immediate(), new CountsBuilder() {

            @Override
            public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
                throw new UnsupportedOperationException("Should not be required");
            }

            @Override
            public long lastCommittedTxId() {
                return TransactionIdStore.BASE_TX_ID;
            }
        }, readOnly(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1000)) {
            countsStore.start(NULL, INSTANCE);
            assertEquals((r + 1) * 100, countsStore.nodeCount(0, NULL));
        }
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) Label(org.neo4j.graphdb.Label) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) CountsAccessor(org.neo4j.counts.CountsAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsBuilder(org.neo4j.internal.counts.CountsBuilder) MemoryTracker(org.neo4j.memory.MemoryTracker) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 9 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class BatchingNeoStores method buildCountsStore.

public void buildCountsStore(CountsBuilder builder, PageCacheTracer cacheTracer, CursorContext cursorContext, MemoryTracker memoryTracker) {
    try {
        deleteCountsStore();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), builder, writable(), cacheTracer, GBPTreeCountsStore.NO_MONITOR, databaseName, neo4jConfig.get(counts_store_max_cached_entries))) {
        countsStore.start(cursorContext, memoryTracker);
        countsStore.checkpoint(cursorContext);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 10 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method skipPopulationWhenNodeAndRelationshipStoresAreEmpty.

@Test
void skipPopulationWhenNodeAndRelationshipStoresAreEmpty() throws IOException {
    DatabaseManagementService managementService = dbBuilder.build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    InvocationTrackingProgressReporter progressReporter = new InvocationTrackingProgressReporter();
    rebuildCounts(lastCommittedTransactionId, progressReporter);
    try (GBPTreeCountsStore store = createCountsStore(matchingBuilder(lastCommittedTransactionId))) {
        store.start(NULL, INSTANCE);
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        store.accept(new AssertEmptyCountStoreVisitor(), NULL);
    }
    softly.assertThat(progressReporter.isCompleteInvoked()).as("Complete").isTrue();
    softly.assertThat(progressReporter.isStartInvoked()).as("Start").isFalse();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)12 Test (org.junit.jupiter.api.Test)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)7 Label (org.neo4j.graphdb.Label)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 Node (org.neo4j.graphdb.Node)5 Transaction (org.neo4j.graphdb.Transaction)5 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 IOException (java.io.IOException)3 Relationship (org.neo4j.graphdb.Relationship)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 CountsAccessor (org.neo4j.counts.CountsAccessor)2 CountsBuilder (org.neo4j.internal.counts.CountsBuilder)2 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)2 CountsComputer (org.neo4j.kernel.impl.store.CountsComputer)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)2