Search in sources :

Example 46 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) throws IOException {
    cleanupCountsForRebuilding();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache, fs, NullLogProvider.getInstance());
    try (Lifespan life = new Lifespan();
        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);
        CountsTracker countsTracker = createCountsTracker();
        life.add(countsTracker.setInitializer(countsComputer));
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 47 with StoreFactory

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

the class StoreMigratorIT method shouldBeAbleToResumeMigrationOnMoving.

@Test
public void shouldBeAbleToResumeMigrationOnMoving() throws Exception {
    // GIVEN a legacy database
    File storeDirectory = directory.graphDbDir();
    File prepare = directory.directory("prepare");
    MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, storeDirectory, prepare);
    // and a state of the migration saying that it has done the actual migration
    LogService logService = NullLogService.getInstance();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fs), selectFormat());
    String versionToMigrateFrom = upgradableDatabase.checkUpgradeable(storeDirectory).storeVersion();
    SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
    StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
    File migrationDir = new File(storeDirectory, StoreUpgrader.MIGRATION_DIRECTORY);
    fs.mkdirs(migrationDir);
    migrator.migrate(storeDirectory, migrationDir, progressMonitor.startSection("section"), versionToMigrateFrom, upgradableDatabase.currentVersion());
    // WHEN simulating resuming the migration
    progressMonitor = new SilentMigrationProgressMonitor();
    migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
    migrator.moveMigratedFiles(migrationDir, storeDirectory, versionToMigrateFrom, upgradableDatabase.currentVersion());
    // THEN starting the new store should be successful
    StoreFactory storeFactory = new StoreFactory(storeDirectory, pageCache, fs, logService.getInternalLogProvider());
    storeFactory.openAllNeoStores().close();
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 48 with StoreFactory

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

the class StoreMigratorIT method shouldBeAbleToResumeMigrationOnRebuildingCounts.

@Test
public void shouldBeAbleToResumeMigrationOnRebuildingCounts() throws Exception {
    // GIVEN a legacy database
    File storeDirectory = directory.graphDbDir();
    File prepare = directory.directory("prepare");
    MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, storeDirectory, prepare);
    // and a state of the migration saying that it has done the actual migration
    LogService logService = NullLogService.getInstance();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fs), selectFormat());
    String versionToMigrateFrom = upgradableDatabase.checkUpgradeable(storeDirectory).storeVersion();
    SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
    StoreMigrator migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
    File migrationDir = new File(storeDirectory, StoreUpgrader.MIGRATION_DIRECTORY);
    fs.mkdirs(migrationDir);
    migrator.migrate(storeDirectory, migrationDir, progressMonitor.startSection("section"), versionToMigrateFrom, upgradableDatabase.currentVersion());
    migrator.moveMigratedFiles(migrationDir, storeDirectory, versionToMigrateFrom, upgradableDatabase.currentVersion());
    // WHEN simulating resuming the migration
    progressMonitor = new SilentMigrationProgressMonitor();
    migrator = new StoreMigrator(fs, pageCache, CONFIG, logService, schemaIndexProvider);
    migrator.rebuildCounts(storeDirectory, versionToMigrateFrom, upgradableDatabase.currentVersion());
    // THEN starting the new store should be successful
    StoreFactory storeFactory = new StoreFactory(storeDirectory, pageCache, fs, logService.getInternalLogProvider());
    storeFactory.openAllNeoStores().close();
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 49 with StoreFactory

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

the class RecordStorageEngineFactory method loadSchemaRules.

@Override
public List<SchemaRule> loadSchemaRules(FileSystemAbstraction fs, PageCache pageCache, Config config, DatabaseLayout databaseLayout, CursorContext cursorContext) {
    StoreFactory factory = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.nullLogProvider(), PageCacheTracer.NULL, readOnly());
    try (NeoStores stores = factory.openNeoStores(false, StoreType.SCHEMA, StoreType.PROPERTY_KEY_TOKEN, StoreType.PROPERTY)) {
        stores.start(cursorContext);
        TokenHolders tokenHolders = tokenHoldersForSchemaStore(stores, new ReadOnlyTokenCreator(), cursorContext);
        List<SchemaRule> rules = new ArrayList<>();
        new SchemaStorage(stores.getSchemaStore(), tokenHolders, () -> KernelVersion.LATEST).getAll(cursorContext).forEach(rules::add);
        return rules;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.internal.schema.SchemaRule) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) TokenHolders(org.neo4j.token.TokenHolders) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator)

Example 50 with StoreFactory

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

the class StoreUpgraderTest method verifyStoreUpgradedWithin.

private void verifyStoreUpgradedWithin(long duration, TimeUnit unit) {
    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();
        long minuteAgo = System.currentTimeMillis() - unit.toMillis(duration);
        assertThat(neoStores.getMetaDataStore().getUpgradeTime()).isGreaterThan(minuteAgo);
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory)

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