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)));
}
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);
}
}
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);
}
}
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.");
}
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)));
}
Aggregations