Search in sources :

Example 1 with FileLockException

use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.

the class LoadCommand method loadDump.

protected void loadDump() throws IOException {
    Config config = buildConfig();
    DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(database.name());
    ctx.fs().mkdirs(databaseLayout.databaseDirectory());
    ctx.fs().mkdirs(databaseLayout.getNeo4jLayout().transactionLogsRootDirectory());
    try (Closeable ignore = LockChecker.checkDatabaseLock(databaseLayout)) {
        deleteIfNecessary(databaseLayout, force);
        load(from, databaseLayout);
    } catch (FileLockException e) {
        throw new CommandFailedException("The database is in use. Stop database '" + database.name() + "' and try again.", e);
    } catch (IOException e) {
        wrapIOException(e);
    } catch (CannotWriteException e) {
        throw new CommandFailedException("You do not have permission to load the database.", e);
    }
    StoreVersionLoader.Result result = loader.getStoreVersion(ctx.fs(), config, databaseLayout);
    if (!result.isLatest) {
        ctx.err().printf("The loaded database is not on the latest format (current:%s, latest:%s). Set %s=true to enable migration.%n", result.currentFormatName, result.latestFormatName, GraphDatabaseSettings.allow_upgrade.name());
    }
}
Also used : FileLockException(org.neo4j.kernel.internal.locker.FileLockException) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Util.wrapIOException(org.neo4j.commandline.Util.wrapIOException) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 2 with FileLockException

use of org.neo4j.kernel.internal.locker.FileLockException 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 3 with FileLockException

use of org.neo4j.kernel.internal.locker.FileLockException 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 4 with FileLockException

use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.

the class StoreInfoCommand method printInfo.

private static String printInfo(FileSystemAbstraction fs, DatabaseLayout databaseLayout, PageCache pageCache, StorageEngineFactory storageEngineFactory, Config config, boolean structured, boolean failSilently) {
    var memoryTracker = EmptyMemoryTracker.INSTANCE;
    try (var ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
        var storeVersionCheck = storageEngineFactory.versionCheck(fs, databaseLayout, Config.defaults(), pageCache, NullLogService.getInstance(), PageCacheTracer.NULL);
        var storeVersion = storeVersionCheck.storeVersion(CursorContext.NULL).orElseThrow(() -> new CommandFailedException(format("Could not find version metadata in store '%s'", databaseLayout.databaseDirectory())));
        var versionInformation = storageEngineFactory.versionInformation(storeVersion);
        var recoveryRequired = checkRecoveryState(fs, databaseLayout, config, memoryTracker);
        var txIdStore = storageEngineFactory.readOnlyTransactionIdStore(fs, databaseLayout, pageCache, CursorContext.NULL);
        // Latest committed tx id found in metadata store. May be behind if recovery is required.
        var lastTxId = txIdStore.getLastCommittedTransactionId();
        var successorString = versionInformation.successor().map(StoreVersion::introductionNeo4jVersion).orElse(null);
        var storeInfo = StoreInfo.notInUseResult(databaseLayout.getDatabaseName(), storeVersion, versionInformation.introductionNeo4jVersion(), successorString, lastTxId, recoveryRequired);
        return storeInfo.print(structured);
    } catch (FileLockException e) {
        if (!failSilently) {
            throw new CommandFailedException(format("Failed to execute command as the database '%s' is in use. " + "Please stop it and try again.", databaseLayout.getDatabaseName()), e);
        }
        return StoreInfo.inUseResult(databaseLayout.getDatabaseName()).print(structured);
    } catch (CommandFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new CommandFailedException(format("Failed to execute command: '%s'.", e.getMessage()), e);
    }
}
Also used : FileLockException(org.neo4j.kernel.internal.locker.FileLockException) CommandFailedException(org.neo4j.cli.CommandFailedException) FileLockException(org.neo4j.kernel.internal.locker.FileLockException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Aggregations

CommandFailedException (org.neo4j.cli.CommandFailedException)4 FileLockException (org.neo4j.kernel.internal.locker.FileLockException)4 Closeable (java.io.Closeable)3 IOException (java.io.IOException)3 Config (org.neo4j.configuration.Config)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Path (java.nio.file.Path)1 Util.wrapIOException (org.neo4j.commandline.Util.wrapIOException)1 CannotWriteException (org.neo4j.commandline.dbms.CannotWriteException)1 ConsistencyCheckIncompleteException (org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException)1 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)1 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)1 Log4jLogProvider (org.neo4j.logging.log4j.Log4jLogProvider)1