Search in sources :

Example 76 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class AbstractInProcessNeo4jBuilder method build.

@Override
public InProcessNeo4j build() {
    Path userLogFile = serverFolder.resolve("neo4j.log");
    Path internalLogFile = serverFolder.resolve("debug.log");
    config.set(ServerSettings.third_party_packages, unmanagedExtentions.toList());
    config.set(GraphDatabaseSettings.store_internal_log_path, internalLogFile.toAbsolutePath());
    var certificates = serverFolder.resolve("certificates");
    if (disabledServer) {
        config.set(HttpConnector.enabled, false);
        config.set(HttpsConnector.enabled, false);
    }
    Config dbConfig = config.build();
    if (dbConfig.get(HttpsConnector.enabled) || dbConfig.get(BoltConnector.enabled) && dbConfig.get(BoltConnector.encryption_level) != BoltConnector.EncryptionLevel.DISABLED) {
        SelfSignedCertificateFactory.create(certificates);
        List<SslPolicyConfig> policies = List.of(SslPolicyConfig.forScope(HTTPS), SslPolicyConfig.forScope(BOLT));
        for (SslPolicyConfig policy : policies) {
            config.set(policy.enabled, Boolean.TRUE);
            config.set(policy.base_directory, certificates);
            config.set(policy.trust_all, true);
            config.set(policy.client_auth, ClientAuth.NONE);
        }
        dbConfig = config.build();
    }
    Neo4jLoggerContext loggerContext = LogConfig.createBuilder(new DefaultFileSystemAbstraction(), userLogFile, Level.INFO).withTimezone(dbConfig.get(db_timezone)).build();
    var userLogProvider = new Log4jLogProvider(loggerContext);
    GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider);
    dependencies = dependencies.extensions(buildExtensionList(dependencies));
    var managementService = createNeo(dbConfig, dependencies);
    InProcessNeo4j controls = new InProcessNeo4j(serverFolder, userLogFile, internalLogFile, managementService, dbConfig, userLogProvider);
    controls.start();
    try {
        fixtures.applyTo(controls);
    } catch (Exception e) {
        controls.close();
        throw e;
    }
    return controls;
}
Also used : Path(java.nio.file.Path) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) Neo4jLoggerContext(org.neo4j.logging.log4j.Neo4jLoggerContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) Config(org.neo4j.configuration.Config) LogConfig(org.neo4j.logging.log4j.LogConfig) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) GraphDatabaseDependencies(org.neo4j.graphdb.facade.GraphDatabaseDependencies) IOException(java.io.IOException)

Example 77 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method multipleCorruptionsInFusionIndex.

@Test
void multipleCorruptionsInFusionIndex() throws Exception {
    // Because NATIVE30 provider use Lucene internally we can not use the snapshot from ephemeral file system because
    // lucene will not use it to store the files. Therefor we use a default file system together with TestDirectory
    // for cleanup.
    final DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
    final TestDirectory testDirectory = TestDirectory.testDirectory(fs);
    testDirectory.prepareDirectory(ConsistencyCheckWithCorruptGBPTreeIT.class, "multipleCorruptionsInFusionIndex");
    try {
        final Path neo4jHome = testDirectory.homePath();
        dbmsAction(neo4jHome, fs, NATIVE30, db -> {
            Label label = Label.label("label2");
            indexWithNumberData(db, label);
        }, builder -> {
        });
        DatabaseLayout layout = DatabaseLayout.of(Config.defaults(neo4j_home, neo4jHome));
        final Path[] indexFiles = schemaIndexFiles(fs, layout.databaseDirectory(), NATIVE30);
        final List<Path> files = corruptIndexes(fs, readOnly(), (tree, inspection) -> {
            long leafNode = inspection.getLeafNodes().get(1);
            long internalNode = inspection.getInternalNodes().get(0);
            tree.unsafe(pageSpecificCorruption(leafNode, GBPTreeCorruption.rightSiblingPointToNonExisting()), CursorContext.NULL);
            tree.unsafe(pageSpecificCorruption(internalNode, GBPTreeCorruption.setChild(0, internalNode)), CursorContext.NULL);
        }, indexFiles);
        assertTrue(files.size() > 0, "Expected number of corrupted files to be more than one.");
        ConsistencyCheckService.Result result = runConsistencyCheck(fs, neo4jHome, layout, NullLogProvider.getInstance(), NONE, DEFAULT);
        for (Path file : files) {
            assertResultContainsMessage(fs, result, "Index will be excluded from further consistency checks. Index file: " + file.toAbsolutePath());
        }
    } finally {
        testDirectory.cleanup();
    }
}
Also used : Path(java.nio.file.Path) TestDirectory(org.neo4j.test.rule.TestDirectory) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Label(org.neo4j.graphdb.Label) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 78 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class CheckConsistencyCommand method execute.

@Override
public void execute() {
    options.warnOnUsageOfDeprecatedOptions(spec, ctx);
    if (target.backup != null) {
        target.backup = target.backup.toAbsolutePath();
        if (!Files.isDirectory(target.backup)) {
            throw new CommandFailedException("Report directory path doesn't exist or not a directory: " + target.backup);
        }
    }
    Config config = loadNeo4jConfig(ctx.homeDir(), ctx.confDir(), additionalConfig);
    var memoryTracker = EmptyMemoryTracker.INSTANCE;
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        DatabaseLayout databaseLayout = Optional.ofNullable(target.backup).map(DatabaseLayout::ofFlat).orElseGet(() -> Neo4jLayout.of(config).databaseLayout(target.database.name()));
        checkDatabaseExistence(databaseLayout);
        try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
            checkDbState(databaseLayout, config, memoryTracker);
            // Only output progress indicator if a console receives the output
            ProgressMonitorFactory progressMonitorFactory = ProgressMonitorFactory.NONE;
            if (System.console() != null) {
                progressMonitorFactory = ProgressMonitorFactory.textual(System.out);
            }
            ConsistencyCheckService.Result consistencyCheckResult;
            try (Log4jLogProvider logProvider = Util.configuredLogProvider(config, System.out)) {
                consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, progressMonitorFactory, logProvider, fileSystem, verbose, options.getReportDir().normalize(), new ConsistencyFlags(options.isCheckGraph(), options.isCheckIndexes(), options.isCheckIndexStructure()));
            }
            if (!consistencyCheckResult.isSuccessful()) {
                throw new CommandFailedException(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
            }
        } catch (FileLockException e) {
            throw new CommandFailedException("The database is in use. Stop database '" + databaseLayout.getDatabaseName() + "' and try again.", e);
        } catch (CannotWriteException e) {
            throw new CommandFailedException("You do not have permission to check database consistency.", e);
        }
    } catch (ConsistencyCheckIncompleteException | IOException e) {
        throw new CommandFailedException("Consistency checking failed." + e.getMessage(), e);
    }
}
Also used : CannotWriteException(org.neo4j.commandline.dbms.CannotWriteException) FileLockException(org.neo4j.kernel.internal.locker.FileLockException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Closeable(java.io.Closeable) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 79 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.

@Test
void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
    // given
    // create a store
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    managementService.shutdown();
    // mess up the version in the metadatastore
    String badStoreVersion = "bad";
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
        PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
        MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion), databaseLayout.getDatabaseName(), NULL);
    }
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(GraphDatabaseSettings.allow_upgrade, true).build();
    GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
        DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
        Optional<Throwable> upgradeException = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
        assertTrue(upgradeException.isPresent());
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Example 80 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class DatabaseStartupTest method startDatabaseWithWrongTransactionFilesShouldFail.

@Test
void startDatabaseWithWrongTransactionFilesShouldFail() throws IOException {
    // Create a store
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DatabaseLayout databaseLayout = db.databaseLayout();
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    managementService.shutdown();
    // Change store id component
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
        PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
        long newTime = System.currentTimeMillis() + 1;
        MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.TIME, newTime, databaseLayout.getDatabaseName(), NULL);
    }
    // Try to start
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    try {
        db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
        assertFalse(db.isAvailable(10));
        DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
        assertTrue(cause.isPresent());
        assertTrue(cause.get().getCause().getMessage().contains("Mismatching store id"));
    } finally {
        managementService.shutdown();
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)82 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)43 File (java.io.File)24 Path (java.nio.file.Path)21 PageCache (org.neo4j.io.pagecache.PageCache)21 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)13 IOException (java.io.IOException)12 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)11 Config (org.neo4j.kernel.configuration.Config)11 Config (org.neo4j.configuration.Config)9 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)7 Transaction (org.neo4j.graphdb.Transaction)7 PrintStream (java.io.PrintStream)6 Before (org.junit.Before)6 CommandFailed (org.neo4j.commandline.admin.CommandFailed)6 Args (org.neo4j.helpers.Args)6 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)6 JobScheduler (org.neo4j.scheduler.JobScheduler)6