Search in sources :

Example 11 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore 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)

Example 12 with GBPTreeCountsStore

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

the class OnlineIndexUpdatesTest method setUp.

@BeforeEach
void setUp() throws IOException {
    life = new LifeSupport();
    Config config = Config.defaults();
    NullLogProvider nullLogProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName()), pageCache, fileSystem, nullLogProvider, NULL, writable());
    neoStores = storeFactory.openAllNeoStores(true);
    GBPTreeCountsStore counts = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, immediate(), new CountsComputer(neoStores, pageCache, NULL, databaseLayout, INSTANCE, NullLog.getInstance()), writable(), NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1_000);
    life.add(wrapInLifecycle(counts));
    nodeStore = neoStores.getNodeStore();
    relationshipStore = neoStores.getRelationshipStore();
    PropertyStore propertyStore = neoStores.getPropertyStore();
    schemaCache = new SchemaCache(new StandardConstraintRuleAccessor(), index -> index);
    propertyPhysicalToLogicalConverter = new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore(), CursorContext.NULL);
    life.start();
    propertyCreator = new PropertyCreator(neoStores.getPropertyStore(), new PropertyTraverser(CursorContext.NULL), CursorContext.NULL, INSTANCE);
    recordAccess = new DirectRecordAccess<>(neoStores.getPropertyStore(), Loaders.propertyLoader(propertyStore, CursorContext.NULL));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) NO_NEXT_RELATIONSHIP(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Collections.singletonList(java.util.Collections.singletonList) NO_LABELS_FIELD(org.neo4j.kernel.impl.store.record.Record.NO_LABELS_FIELD) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NullLog(org.neo4j.logging.NullLog) PageCache(org.neo4j.io.pagecache.PageCache) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NODE(org.neo4j.common.EntityType.NODE) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) CountsStore(org.neo4j.counts.CountsStore) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) Values(org.neo4j.values.storable.Values) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) NO_NEXT_PROPERTY(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Iterator(java.util.Iterator) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) IOException(java.io.IOException) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.configuration.Config) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) NullLogProvider(org.neo4j.logging.NullLogProvider) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) BeforeEach(org.junit.jupiter.api.BeforeEach)

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