Search in sources :

Example 1 with CountsBuilder

use of org.neo4j.internal.counts.CountsBuilder 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 2 with CountsBuilder

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

the class BatchingNeoStoresTest method shouldRebuildCountsStoreEvenIfExistsInEmptyDb.

@Test
void shouldRebuildCountsStoreEvenIfExistsInEmptyDb() throws IOException {
    // given
    try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), CountsBuilder.EMPTY, writable(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, DEFAULT_DATABASE_NAME, 1_000)) {
        countsStore.start(NULL, INSTANCE);
        countsStore.checkpoint(NULL);
    }
    // when
    try (BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache(fileSystem, pageCache, PageCacheTracer.NULL, databaseLayout, LATEST_RECORD_FORMATS, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults(), INSTANCE)) {
        stores.createNew();
        stores.buildCountsStore(new CountsBuilder() {

            @Override
            public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
                updater.incrementNodeCount(1, 10);
                updater.incrementNodeCount(2, 20);
                updater.incrementRelationshipCount(ANY_LABEL, 1, 2, 30);
                updater.incrementRelationshipCount(1, 2, ANY_LABEL, 50);
            }

            @Override
            public long lastCommittedTxId() {
                return BASE_TX_ID + 1;
            }
        }, PageCacheTracer.NULL, NULL, INSTANCE);
    }
    // then
    try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), CountsBuilder.EMPTY, writable(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, DEFAULT_DATABASE_NAME, 1_000)) {
        assertEquals(10, countsStore.nodeCount(1, NULL));
        assertEquals(20, countsStore.nodeCount(2, NULL));
        assertEquals(30, countsStore.relationshipCount(ANY_LABEL, 1, 2, NULL));
        assertEquals(50, countsStore.relationshipCount(1, 2, ANY_LABEL, NULL));
    }
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 CountsAccessor (org.neo4j.counts.CountsAccessor)2 CountsBuilder (org.neo4j.internal.counts.CountsBuilder)2 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 MemoryTracker (org.neo4j.memory.MemoryTracker)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 BatchInserter (org.neo4j.batchinsert.BatchInserter)1 Label (org.neo4j.graphdb.Label)1