Search in sources :

Example 71 with DefaultFileSystemAbstraction

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

the class DumpCommand method execute.

@Override
public void execute() {
    var databaseName = database.name();
    Path archive = buildArchivePath(databaseName, to.toAbsolutePath());
    var memoryTracker = EmptyMemoryTracker.INSTANCE;
    Config config = CommandHelpers.buildConfig(ctx, allowCommandExpansion);
    DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(databaseName);
    try {
        Validators.CONTAINS_EXISTING_DATABASE.validate(databaseLayout.databaseDirectory());
    } catch (IllegalArgumentException e) {
        throw new CommandFailedException("Database does not exist: " + databaseName, e);
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        if (fileSystem.fileExists(databaseLayout.file(StoreUpgrader.MIGRATION_DIRECTORY))) {
            throw new CommandFailedException("Store migration folder detected - A dump can not be taken during a store migration. Make sure " + "store migration is completed before trying again.");
        }
    } catch (IOException e) {
        wrapIOException(e);
    }
    try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
        checkDbState(databaseLayout, config, memoryTracker);
        dump(databaseLayout, archive);
    } catch (FileLockException e) {
        throw new CommandFailedException("The database is in use. Stop database '" + databaseName + "' and try again.", e);
    } catch (IOException e) {
        wrapIOException(e);
    } catch (CannotWriteException e) {
        throw new CommandFailedException("You do not have permission to dump the database.", e);
    }
}
Also used : Path(java.nio.file.Path) 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) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 72 with DefaultFileSystemAbstraction

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

the class Recovery method performRecovery.

/**
 * Performs recovery of database described by provided layout.
 * Transaction logs should be located in their default location.
 * If recovery is not required nothing will be done to the the database or logs.
 * Note: used by external tools.
 * @param databaseLayout database to recover layout.
 * @param tracers underlying events tracers.
 * @throws IOException on any unexpected I/O exception encountered during recovery.
 */
public static void performRecovery(DatabaseLayout databaseLayout, DatabaseTracers tracers, MemoryTracker memoryTracker) throws Exception {
    requireNonNull(databaseLayout);
    Config config = defaults();
    try (DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
        PageCache pageCache = getPageCache(config, fs, jobScheduler)) {
        performRecovery(fs, pageCache, tracers, config, databaseLayout, memoryTracker);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.configuration.Config) DatabasePageCache(org.neo4j.dbms.database.DatabasePageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Example 73 with DefaultFileSystemAbstraction

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

the class Recovery method isRecoveryRequired.

/**
 * Check if recovery is required for a store described by provided layout.
 * Custom root location for transaction logs can be provided using {@link GraphDatabaseSettings#transaction_logs_root_path} config setting value.
 * @param databaseLayout layout of database to check for recovery
 * @param config custom configuration
 * @return true if recovery is required, false otherwise.
 * @throws IOException on any unexpected I/O exception encountered during recovery.
 */
public static boolean isRecoveryRequired(DatabaseLayout databaseLayout, Config config, MemoryTracker memoryTracker) throws Exception {
    requireNonNull(databaseLayout);
    requireNonNull(config);
    try (DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        return isRecoveryRequired(fs, databaseLayout, config, memoryTracker);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction)

Example 74 with DefaultFileSystemAbstraction

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

the class NeoBootstrapper method setupLogging.

private static Log4jLogProvider setupLogging(Config config) {
    LogConfig.Builder builder = LogConfig.createBuilder(new DefaultFileSystemAbstraction(), config.get(GraphDatabaseSettings.store_user_log_path), config.get(GraphDatabaseSettings.store_internal_log_level)).withTimezone(config.get(GraphDatabaseSettings.db_timezone)).withFormat(config.get(GraphDatabaseSettings.store_user_log_format)).withCategory(false).withRotation(config.get(GraphDatabaseSettings.store_user_log_rotation_threshold), config.get(GraphDatabaseSettings.store_user_log_max_archives));
    if (config.get(GraphDatabaseSettings.store_user_log_to_stdout)) {
        builder.logToSystemOut();
    }
    Neo4jLoggerContext ctx = builder.build();
    Log4jLogProvider userLogProvider = new Log4jLogProvider(ctx);
    JULBridge.resetJUL();
    Logger.getLogger("").setLevel(Level.WARNING);
    JULBridge.forwardTo(userLogProvider);
    JettyLogBridge.setLogProvider(userLogProvider);
    return userLogProvider;
}
Also used : Neo4jLoggerContext(org.neo4j.logging.log4j.Neo4jLoggerContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) LogConfig(org.neo4j.logging.log4j.LogConfig)

Example 75 with DefaultFileSystemAbstraction

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

the class BatchInserters method inserter.

/**
 * Get a {@link BatchInserter} given a store directory.
 *
 * @param databaseLayout directory where particular neo4j database is located
 * @return a new {@link BatchInserter}
 * @throws IOException if there is an IO error
 */
public static BatchInserter inserter(DatabaseLayout databaseLayout) throws IOException {
    DefaultFileSystemAbstraction fileSystem = createFileSystem();
    BatchInserter batchInserter = inserter(databaseLayout, fileSystem, Config.defaults());
    return new FileSystemClosingBatchInserter(batchInserter, fileSystem);
}
Also used : FileSystemClosingBatchInserter(org.neo4j.batchinsert.internal.FileSystemClosingBatchInserter) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemClosingBatchInserter(org.neo4j.batchinsert.internal.FileSystemClosingBatchInserter)

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