Search in sources :

Example 11 with StoreFactory

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

the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.

@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
    // GIVEN a node with relationship group chain 2-->4-->10-->23
    File dir = new File("dir");
    fs.get().mkdirs(dir);
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
    try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
        RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
        RelationshipGroupRecord group_2 = group(0, 2);
        RelationshipGroupRecord group_4 = group(1, 4);
        RelationshipGroupRecord group_10 = group(2, 10);
        RelationshipGroupRecord group_23 = group(3, 23);
        link(group_2, group_4, group_10, group_23);
        store.updateRecord(group_2);
        store.updateRecord(group_4);
        store.updateRecord(group_10);
        store.updateRecord(group_23);
        RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
        NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
        // WHEN trying to find relationship group 7
        RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
        RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
        // THEN only groups 2, 4 and 10 should have been loaded
        InOrder verification = inOrder(store);
        verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        // it should also be reported as not found
        assertNull(result.group());
        // with group 4 as closes previous one
        assertEquals(group_4, result.closestPrevious().forReadingData());
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InOrder(org.mockito.InOrder) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectRecordAccess(org.neo4j.unsafe.batchinsert.DirectRecordAccess) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File) RelationshipGroupPosition(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter.RelationshipGroupPosition) Test(org.junit.Test)

Example 12 with StoreFactory

use of org.neo4j.kernel.impl.store.StoreFactory 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 13 with StoreFactory

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

the class StoreUpgraderTest method tracePageCacheAccessOnStoreUpgrade.

@ParameterizedTest
@MethodSource("versions")
void tracePageCacheAccessOnStoreUpgrade(RecordFormats formats) throws IOException {
    init(formats);
    fileSystem.deleteFile(databaseLayout.file(INTERNAL_LOG_FILE));
    StoreVersionCheck check = getVersionCheck(pageCache);
    var pageCacheTracer = new DefaultPageCacheTracer();
    newUpgrader(check, allowMigrateConfig, pageCache, pageCacheTracer).migrateIfNeeded(databaseLayout, false);
    assertThat(pageCacheTracer.hits()).isGreaterThan(0);
    assertThat(pageCacheTracer.pins()).isGreaterThan(0);
    assertThat(pageCacheTracer.unpins()).isGreaterThan(0);
    assertThat(pageCacheTracer.faults()).isGreaterThan(0);
    StoreFactory factory = new StoreFactory(databaseLayout, allowMigrateConfig, new ScanOnOpenOverwritingIdGeneratorFactory(fileSystem, databaseLayout.getDatabaseName()), pageCache, fileSystem, NullLogProvider.getInstance(), NULL, writable());
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        assertThat(neoStores.getMetaDataStore().getUpgradeTransaction()).isEqualTo(neoStores.getMetaDataStore().getLastCommittedTransaction());
        assertThat(neoStores.getMetaDataStore().getUpgradeTime()).isPositive();
    }
}
Also used : StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with StoreFactory

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

the class ConsistencyCheckingApplierTest method setUp.

@BeforeEach
void setUp() {
    Config config = Config.defaults(neo4j_home, directory.homePath());
    DatabaseLayout layout = DatabaseLayout.of(config);
    neoStores = new StoreFactory(layout, config, new DefaultIdGeneratorFactory(directory.getFileSystem(), immediate(), DEFAULT_DATABASE_NAME), pageCache, directory.getFileSystem(), NullLogProvider.getInstance(), PageCacheTracer.NULL, writable()).openAllNeoStores(true);
    RelationshipStore relationshipStore = neoStores.getRelationshipStore();
    checker = new ConsistencyCheckingApplier(relationshipStore, CursorContext.NULL);
    BatchContext batchContext = mock(BatchContext.class);
    when(batchContext.getLockGroup()).thenReturn(new LockGroup());
    applier = new NeoStoreTransactionApplier(CommandVersion.AFTER, neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE, 0, batchContext, CursorContext.NULL);
    appliers = new TransactionApplier[] { checker, applier };
}
Also used : LockGroup(org.neo4j.lock.LockGroup) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) ConsistencyCheckingApplier(org.neo4j.internal.recordstorage.ConsistencyCheckingApplierFactory.ConsistencyCheckingApplier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with StoreFactory

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

the class ApplyRecoveredTransactionsTest method before.

@BeforeEach
void before() {
    idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
    StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
    neoStores = storeFactory.openAllNeoStores(true);
}
Also used : DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)64 NeoStores (org.neo4j.kernel.impl.store.NeoStores)31 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)30 File (java.io.File)18 BeforeEach (org.junit.jupiter.api.BeforeEach)15 PageCache (org.neo4j.io.pagecache.PageCache)12 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Before (org.junit.Before)6 Test (org.junit.Test)6 Config (org.neo4j.configuration.Config)6 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 Config (org.neo4j.kernel.configuration.Config)6 LogProvider (org.neo4j.logging.LogProvider)6 NullLogProvider (org.neo4j.logging.NullLogProvider)6 ScanOnOpenOverwritingIdGeneratorFactory (org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory)5