Search in sources :

Example 1 with CannotWriteException

use of org.neo4j.commandline.dbms.CannotWriteException 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)

Aggregations

Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 CommandFailedException (org.neo4j.cli.CommandFailedException)1 CannotWriteException (org.neo4j.commandline.dbms.CannotWriteException)1 Config (org.neo4j.configuration.Config)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 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 FileLockException (org.neo4j.kernel.internal.locker.FileLockException)1 Log4jLogProvider (org.neo4j.logging.log4j.Log4jLogProvider)1