use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class AbstractInProcessNeo4jBuilder method build.
@Override
public InProcessNeo4j build() {
Path userLogFile = serverFolder.resolve("neo4j.log");
Path internalLogFile = serverFolder.resolve("debug.log");
config.set(ServerSettings.third_party_packages, unmanagedExtentions.toList());
config.set(GraphDatabaseSettings.store_internal_log_path, internalLogFile.toAbsolutePath());
var certificates = serverFolder.resolve("certificates");
if (disabledServer) {
config.set(HttpConnector.enabled, false);
config.set(HttpsConnector.enabled, false);
}
Config dbConfig = config.build();
if (dbConfig.get(HttpsConnector.enabled) || dbConfig.get(BoltConnector.enabled) && dbConfig.get(BoltConnector.encryption_level) != BoltConnector.EncryptionLevel.DISABLED) {
SelfSignedCertificateFactory.create(certificates);
List<SslPolicyConfig> policies = List.of(SslPolicyConfig.forScope(HTTPS), SslPolicyConfig.forScope(BOLT));
for (SslPolicyConfig policy : policies) {
config.set(policy.enabled, Boolean.TRUE);
config.set(policy.base_directory, certificates);
config.set(policy.trust_all, true);
config.set(policy.client_auth, ClientAuth.NONE);
}
dbConfig = config.build();
}
Neo4jLoggerContext loggerContext = LogConfig.createBuilder(new DefaultFileSystemAbstraction(), userLogFile, Level.INFO).withTimezone(dbConfig.get(db_timezone)).build();
var userLogProvider = new Log4jLogProvider(loggerContext);
GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider);
dependencies = dependencies.extensions(buildExtensionList(dependencies));
var managementService = createNeo(dbConfig, dependencies);
InProcessNeo4j controls = new InProcessNeo4j(serverFolder, userLogFile, internalLogFile, managementService, dbConfig, userLogProvider);
controls.start();
try {
fixtures.applyTo(controls);
} catch (Exception e) {
controls.close();
throw e;
}
return controls;
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method multipleCorruptionsInFusionIndex.
@Test
void multipleCorruptionsInFusionIndex() throws Exception {
// Because NATIVE30 provider use Lucene internally we can not use the snapshot from ephemeral file system because
// lucene will not use it to store the files. Therefor we use a default file system together with TestDirectory
// for cleanup.
final DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
final TestDirectory testDirectory = TestDirectory.testDirectory(fs);
testDirectory.prepareDirectory(ConsistencyCheckWithCorruptGBPTreeIT.class, "multipleCorruptionsInFusionIndex");
try {
final Path neo4jHome = testDirectory.homePath();
dbmsAction(neo4jHome, fs, NATIVE30, db -> {
Label label = Label.label("label2");
indexWithNumberData(db, label);
}, builder -> {
});
DatabaseLayout layout = DatabaseLayout.of(Config.defaults(neo4j_home, neo4jHome));
final Path[] indexFiles = schemaIndexFiles(fs, layout.databaseDirectory(), NATIVE30);
final List<Path> files = corruptIndexes(fs, readOnly(), (tree, inspection) -> {
long leafNode = inspection.getLeafNodes().get(1);
long internalNode = inspection.getInternalNodes().get(0);
tree.unsafe(pageSpecificCorruption(leafNode, GBPTreeCorruption.rightSiblingPointToNonExisting()), CursorContext.NULL);
tree.unsafe(pageSpecificCorruption(internalNode, GBPTreeCorruption.setChild(0, internalNode)), CursorContext.NULL);
}, indexFiles);
assertTrue(files.size() > 0, "Expected number of corrupted files to be more than one.");
ConsistencyCheckService.Result result = runConsistencyCheck(fs, neo4jHome, layout, NullLogProvider.getInstance(), NONE, DEFAULT);
for (Path file : files) {
assertResultContainsMessage(fs, result, "Index will be excluded from further consistency checks. Index file: " + file.toAbsolutePath());
}
} finally {
testDirectory.cleanup();
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction 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);
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.
@Test
void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
// given
// create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// mess up the version in the metadatastore
String badStoreVersion = "bad";
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion), databaseLayout.getDatabaseName(), NULL);
}
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(GraphDatabaseSettings.allow_upgrade, true).build();
GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
Optional<Throwable> upgradeException = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
assertTrue(upgradeException.isPresent());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseStartupTest method startDatabaseWithWrongTransactionFilesShouldFail.
@Test
void startDatabaseWithWrongTransactionFilesShouldFail() throws IOException {
// Create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
DatabaseLayout databaseLayout = db.databaseLayout();
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// Change store id component
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
long newTime = System.currentTimeMillis() + 1;
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.TIME, newTime, databaseLayout.getDatabaseName(), NULL);
}
// Try to start
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
try {
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
assertFalse(db.isAvailable(10));
DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
assertTrue(cause.isPresent());
assertTrue(cause.get().getCause().getMessage().contains("Mismatching store id"));
} finally {
managementService.shutdown();
}
}
Aggregations