use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method shouldNotCheckIndexStructureIfConfiguredNotToEvenIfCheckingIndexes.
@Test
void shouldNotCheckIndexStructureIfConfiguredNotToEvenIfCheckingIndexes() throws Exception {
MutableObject<Long> targetNode = new MutableObject<>();
Path[] indexFiles = schemaIndexFiles();
corruptIndexes(readOnly(), (tree, inspection) -> {
targetNode.setValue(inspection.getRootNode());
tree.unsafe(GBPTreeCorruption.addFreelistEntry(5), CursorContext.NULL);
}, indexFiles);
ConsistencyFlags flags = new ConsistencyFlags(true, true, false);
ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), flags);
assertTrue(result.isSuccessful(), "Expected store to be consistent when not checking indexes.");
}
use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method corruptionInIdGenerator.
@Test
void corruptionInIdGenerator() throws Exception {
MutableObject<Long> rootNode = new MutableObject<>();
Path[] idStoreFiles = idStoreFiles();
final LayoutBootstrapper countsLayoutBootstrapper = (indexFile, pageCache, meta) -> new CountsLayout();
corruptIndexes(fs, readOnly(), (tree, inspection) -> {
rootNode.setValue(inspection.getRootNode());
tree.unsafe(pageSpecificCorruption(rootNode.getValue(), GBPTreeCorruption.broken(GBPTreePointerType.leftSibling())), CursorContext.NULL);
}, idStoreFiles);
ConsistencyFlags flags = new ConsistencyFlags(false, false, true);
ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), flags);
assertFalse(result.isSuccessful());
assertResultContainsMessage(result, "Index inconsistency: Broken pointer found in tree node " + rootNode.getValue() + ", pointerType='left sibling'");
assertResultContainsMessage(result, "Number of inconsistent ID_STORE records: " + idStoreFiles.length);
}
use of org.neo4j.consistency.checking.full.ConsistencyFlags in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method shouldCheckIndexStructureEvenIfNotCheckingIndexes.
@Test
void shouldCheckIndexStructureEvenIfNotCheckingIndexes() throws Exception {
MutableObject<Long> targetNode = new MutableObject<>();
Path[] indexFiles = schemaIndexFiles();
corruptIndexes(readOnly(), (tree, inspection) -> {
targetNode.setValue(inspection.getRootNode());
tree.unsafe(pageSpecificCorruption(targetNode.getValue(), GBPTreeCorruption.notATreeNode()), CursorContext.NULL);
}, indexFiles);
ConsistencyFlags flags = new ConsistencyFlags(true, false, true);
ConsistencyCheckService.Result result = runConsistencyCheck(NullLogProvider.getInstance(), flags);
assertFalse(result.isSuccessful(), "Expected store to be inconsistent when checking index structure.");
assertResultContainsMessage(result, "Page: " + targetNode.getValue() + " is not a tree node page");
}
use of org.neo4j.consistency.checking.full.ConsistencyFlags 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);
}
}
Aggregations