Search in sources :

Example 1 with ProgressMonitorFactory

use of org.neo4j.internal.helpers.progress.ProgressMonitorFactory in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method shouldReportProgress.

@Test
void shouldReportProgress() throws Exception {
    Writer writer = new StringWriter();
    ProgressMonitorFactory factory = ProgressMonitorFactory.textual(writer);
    ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), factory);
    assertTrue(result.isSuccessful(), "Expected new database to be clean.");
    assertTrue(writer.toString().contains("Index structure consistency check"));
}
Also used : StringWriter(java.io.StringWriter) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.jupiter.api.Test)

Example 2 with ProgressMonitorFactory

use of org.neo4j.internal.helpers.progress.ProgressMonitorFactory 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

ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Test (org.junit.jupiter.api.Test)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 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