Search in sources :

Example 1 with CheckConsistencyConfig

use of org.neo4j.consistency.checking.full.CheckConsistencyConfig in project neo4j by neo4j.

the class CheckConsistencyCommandTest method passesOnCheckParameters.

@Test
public void passesOnCheckParameters() throws Exception {
    ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
    Path homeDir = testDir.directory("home").toPath();
    OutsideWorld outsideWorld = mock(OutsideWorld.class);
    CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(homeDir, testDir.directory("conf").toPath(), outsideWorld, consistencyCheckService);
    stub(consistencyCheckService.runFullConsistencyCheck(anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyBoolean(), anyObject(), any(CheckConsistencyConfig.class))).toReturn(ConsistencyCheckService.Result.success(null));
    checkConsistencyCommand.execute(new String[] { "--database=mydb", "--check-graph=false", "--check-indexes=false", "--check-label-scan-store=false", "--check-property-owners=true" });
    verify(consistencyCheckService).runFullConsistencyCheck(anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyBoolean(), anyObject(), eq(new CheckConsistencyConfig(false, false, false, true)));
}
Also used : Path(java.nio.file.Path) OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Test(org.junit.Test)

Example 2 with CheckConsistencyConfig

use of org.neo4j.consistency.checking.full.CheckConsistencyConfig in project neo4j by neo4j.

the class CheckConsistencyCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final String database;
    final boolean verbose;
    final Optional<Path> additionalConfigFile;
    final Path reportDir;
    final Optional<Path> backupPath;
    final boolean checkGraph;
    final boolean checkIndexes;
    final boolean checkLabelScanStore;
    final boolean checkPropertyOwners;
    try {
        database = arguments.parse("database", args);
        backupPath = arguments.parseOptionalPath("backup", args);
        verbose = arguments.parseBoolean("verbose", args);
        additionalConfigFile = arguments.parseOptionalPath("additional-config", args);
        reportDir = arguments.parseOptionalPath("report-dir", args).orElseThrow(() -> new IllegalArgumentException("report-dir must be a valid path"));
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    if (backupPath.isPresent()) {
        if (arguments.has("database", args)) {
            throw new IncorrectUsage("Only one of '--database' and '--backup' can be specified.");
        }
        if (!backupPath.get().toFile().isDirectory()) {
            throw new CommandFailed(format("Specified backup should be a directory: %s", backupPath.get()));
        }
    }
    Config config = loadNeo4jConfig(homeDir, configDir, database, loadAdditionalConfig(additionalConfigFile));
    try {
        // We can remove the loading from config file in 4.0
        if (arguments.has(CHECK_GRAPH, args)) {
            checkGraph = arguments.parseBoolean(CHECK_GRAPH, args);
        } else {
            checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
        }
        if (arguments.has(CHECK_INDEXES, args)) {
            checkIndexes = arguments.parseBoolean(CHECK_INDEXES, args);
        } else {
            checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
        }
        if (arguments.has(CHECK_LABEL_SCAN_STORE, args)) {
            checkLabelScanStore = arguments.parseBoolean(CHECK_LABEL_SCAN_STORE, args);
        } else {
            checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
        }
        if (arguments.has(CHECK_PROPERTY_OWNERS, args)) {
            checkPropertyOwners = arguments.parseBoolean(CHECK_PROPERTY_OWNERS, args);
        } else {
            checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
        }
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        File storeDir = backupPath.map(Path::toFile).orElse(config.get(database_path));
        checkDbState(storeDir, config);
        ConsistencyCheckService.Result consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(storeDir, config, ProgressMonitorFactory.textual(System.err), FormattedLogProvider.toOutputStream(System.out), fileSystem, verbose, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
        if (!consistencyCheckResult.isSuccessful()) {
            throw new CommandFailed(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
        }
    } catch (ConsistencyCheckIncompleteException | IOException e) {
        throw new CommandFailed("Consistency checking failed." + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) OptionalCanonicalPath(org.neo4j.commandline.arguments.common.OptionalCanonicalPath) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) File(java.io.File)

Example 3 with CheckConsistencyConfig

use of org.neo4j.consistency.checking.full.CheckConsistencyConfig in project neo4j by neo4j.

the class ConsistencyCheckTool method run.

ConsistencyCheckService.Result run(String... args) throws ToolFailureException, IOException {
    Args arguments = Args.withFlags(VERBOSE).parse(args);
    File storeDir = determineStoreDirectory(arguments);
    Config tuningConfiguration = readConfiguration(arguments);
    boolean verbose = isVerbose(arguments);
    checkDbState(storeDir, tuningConfiguration);
    LogProvider logProvider = FormattedLogProvider.toOutputStream(System.out);
    try {
        return consistencyCheckService.runFullConsistencyCheck(storeDir, tuningConfiguration, ProgressMonitorFactory.textual(System.err), logProvider, fs, verbose, new CheckConsistencyConfig(tuningConfiguration));
    } catch (ConsistencyCheckIncompleteException e) {
        throw new ToolFailureException("Check aborted due to exception", e);
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) Args(org.neo4j.helpers.Args) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) File(java.io.File)

Example 4 with CheckConsistencyConfig

use of org.neo4j.consistency.checking.full.CheckConsistencyConfig in project neo4j by neo4j.

the class OnlineBackupCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final HostnamePort address;
    final Path folder;
    final String name;
    final boolean fallbackToFull;
    final boolean doConsistencyCheck;
    final Optional<Path> additionalConfig;
    final Path reportDir;
    final long timeout;
    final boolean checkGraph;
    final boolean checkIndexes;
    final boolean checkLabelScanStore;
    final boolean checkPropertyOwners;
    try {
        address = toHostnamePort(new HostnamePort("localhost", 6362)).apply(arguments.parse("from", args));
        folder = arguments.parseMandatoryPath("backup-dir", args);
        name = arguments.parse("name", args);
        fallbackToFull = arguments.parseBoolean("fallback-to-full", args);
        doConsistencyCheck = arguments.parseBoolean("check-consistency", args);
        timeout = parseTimeout(args);
        additionalConfig = arguments.parseOptionalPath("additional-config", args);
        reportDir = arguments.parseOptionalPath("cc-report-dir", args).orElseThrow(() -> new IllegalArgumentException("cc-report-dir must be a path"));
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    // Make sure destination exists
    if (!outsideWorld.fileSystem().isDirectory(folder.toFile())) {
        throw new CommandFailed(String.format("Directory '%s' does not exist.", folder));
    }
    if (!outsideWorld.fileSystem().isDirectory(reportDir.toFile())) {
        throw new CommandFailed(String.format("Directory '%s' does not exist.", reportDir));
    }
    File destination = folder.resolve(name).toFile();
    Config config = loadConfig(additionalConfig);
    boolean done = false;
    try {
        // We can remove the loading from config file in 4.0
        if (arguments.has("cc-graph", args)) {
            checkGraph = arguments.parseBoolean("cc-graph", args);
        } else {
            checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
        }
        if (arguments.has("cc-indexes", args)) {
            checkIndexes = arguments.parseBoolean("cc-indexes", args);
        } else {
            checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
        }
        if (arguments.has("cc-label-scan-store", args)) {
            checkLabelScanStore = arguments.parseBoolean("cc-label-scan-store", args);
        } else {
            checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
        }
        if (arguments.has("cc-property-owners", args)) {
            checkPropertyOwners = arguments.parseBoolean("cc-property-owners", args);
        } else {
            checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
        }
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    File[] listFiles = outsideWorld.fileSystem().listFiles(destination);
    if (listFiles != null && listFiles.length > 0) {
        outsideWorld.stdOutLine("Destination is not empty, doing incremental backup...");
        try {
            backupService.doIncrementalBackup(address.getHost(), address.getPort(), destination, timeout, config);
            done = true;
        } catch (Exception e) {
            if (fallbackToFull) {
                outsideWorld.stdErrLine("Incremental backup failed: " + e.getMessage());
                String renamed = renameExistingBackup(folder, name);
                outsideWorld.stdErrLine(String.format("Old backup renamed to '%s'.", renamed));
            } else {
                throw new CommandFailed("Backup failed: " + e.getMessage(), e);
            }
        }
    }
    if (!done) {
        outsideWorld.stdOutLine("Doing full backup...");
        try {
            backupService.doFullBackup(address.getHost(), address.getPort(), destination, ConsistencyCheck.NONE, config, timeout, false);
        } catch (Exception e) {
            throw new CommandFailed("Backup failed: " + e.getMessage(), e);
        }
    }
    if (doConsistencyCheck) {
        try {
            outsideWorld.stdOutLine("Doing consistency check...");
            ConsistencyCheckService.Result ccResult = consistencyCheckService.runFullConsistencyCheck(destination, config, ProgressMonitorFactory.textual(outsideWorld.errorStream()), FormattedLogProvider.toOutputStream(outsideWorld.outStream()), outsideWorld.fileSystem(), false, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
            if (!ccResult.isSuccessful()) {
                throw new CommandFailed(String.format("Inconsistencies found. See '%s' for details.", ccResult.reportFile()), STATUS_CC_INCONSISTENT);
            }
        } catch (Throwable e) {
            if (e instanceof CommandFailed) {
                throw (CommandFailed) e;
            }
            throw new CommandFailed("Failed to do consistency check on backup: " + e.getMessage(), e, STATUS_CC_ERROR);
        }
    }
    outsideWorld.stdOutLine("Backup complete.");
}
Also used : Path(java.nio.file.Path) OptionalCanonicalPath(org.neo4j.commandline.arguments.common.OptionalCanonicalPath) MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) Converters.toHostnamePort(org.neo4j.kernel.impl.util.Converters.toHostnamePort) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File)

Example 5 with CheckConsistencyConfig

use of org.neo4j.consistency.checking.full.CheckConsistencyConfig in project neo4j by neo4j.

the class OnlineBackupCommandTest method shouldPassOnCCParameters.

@Test
public void shouldPassOnCCParameters() throws Exception {
    execute("--check-consistency=true", backupDir(), "--name=mybackup", "--cc-graph=false", "--cc-indexes=false", "--cc-label-scan-store=false", "--cc-property-owners=true");
    verify(backupService).doFullBackup(any(), anyInt(), any(), any(), any(), anyLong(), anyBoolean());
    verify(consistencyCheckService).runFullConsistencyCheck(any(), any(), any(), any(), any(), anyBoolean(), eq(new File(".").getCanonicalFile()), eq(new CheckConsistencyConfig(false, false, false, true)));
}
Also used : CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) File(java.io.File) Test(org.junit.Test)

Aggregations

CheckConsistencyConfig (org.neo4j.consistency.checking.full.CheckConsistencyConfig)6 File (java.io.File)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 Config (org.neo4j.kernel.configuration.Config)3 IOException (java.io.IOException)2 CommandFailed (org.neo4j.commandline.admin.CommandFailed)2 IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)2 OptionalCanonicalPath (org.neo4j.commandline.arguments.common.OptionalCanonicalPath)2 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 ConsistencyCheckIncompleteException (org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Cluster (org.neo4j.causalclustering.discovery.Cluster)1 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)1 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)1 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)1 MandatoryCanonicalPath (org.neo4j.commandline.arguments.common.MandatoryCanonicalPath)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1