use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist.
@Test
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist() {
Path archive = testDirectory.file("the-archive.dump");
Path destination = Paths.get(testDirectory.absolutePath().toString(), "subdir", "the-destination");
DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(destination);
NoSuchFileException noSuchFileException = assertThrows(NoSuchFileException.class, () -> new Loader().load(archive, databaseLayout));
assertEquals(destination.getParent().toString(), noSuchFileException.getMessage());
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class LoaderTest method shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable.
@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable() throws IOException {
Path archive = testDirectory.file("the-archive.dump");
Path txLogsDirectory = testDirectory.directory("subdir", "txLogs");
Config config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).set(transaction_logs_root_path, txLogsDirectory.toAbsolutePath()).set(default_database, "destination").build();
DatabaseLayout databaseLayout = DatabaseLayout.of(config);
Path txLogsRoot = databaseLayout.getTransactionLogsDirectory().getParent();
try (Closeable ignored = withPermissions(txLogsRoot, emptySet())) {
AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Loader().load(archive, databaseLayout));
assertEquals(txLogsRoot.toString(), exception.getMessage());
}
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsAFile.
@Test
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsAFile() throws IOException {
Path archive = testDirectory.file("the-archive.dump");
Path destination = Paths.get(testDirectory.absolutePath().toString(), "subdir", "the-destination");
Files.write(destination.getParent(), new byte[0]);
DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(destination);
FileSystemException exception = assertThrows(FileSystemException.class, () -> new Loader().load(archive, databaseLayout));
assertEquals(destination.getParent() + ": Not a directory", exception.getMessage());
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class LoadCommand method loadDump.
protected void loadDump() throws IOException {
Config config = buildConfig();
DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(database.name());
ctx.fs().mkdirs(databaseLayout.databaseDirectory());
ctx.fs().mkdirs(databaseLayout.getNeo4jLayout().transactionLogsRootDirectory());
try (Closeable ignore = LockChecker.checkDatabaseLock(databaseLayout)) {
deleteIfNecessary(databaseLayout, force);
load(from, databaseLayout);
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + database.name() + "' and try again.", e);
} catch (IOException e) {
wrapIOException(e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to load the database.", e);
}
StoreVersionLoader.Result result = loader.getStoreVersion(ctx.fs(), config, databaseLayout);
if (!result.isLatest) {
ctx.err().printf("The loaded database is not on the latest format (current:%s, latest:%s). Set %s=true to enable migration.%n", result.currentFormatName, result.latestFormatName, GraphDatabaseSettings.allow_upgrade.name());
}
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class AbstractIndexProviderFactory method newInstance.
@Override
public IndexProvider newInstance(ExtensionContext context, Dependencies dependencies) {
PageCache pageCache = dependencies.pageCache();
Path databaseDir = context.directory();
FileSystemAbstraction fs = dependencies.fileSystem();
Log log = dependencies.getLogService().getInternalLogProvider().getLog(loggingClass());
Monitors monitors = dependencies.monitors();
String monitorTag = descriptor().toString();
monitors.addMonitorListener(new LoggingMonitor(log), monitorTag);
Config config = dependencies.getConfig();
var readOnlyChecker = dependencies.readOnlyChecker();
if (OperationalMode.SINGLE != context.dbmsInfo().operationalMode) {
// if running as part of cluster indexes should be writable to allow catchup process to accept transactions
readOnlyChecker = DatabaseReadOnlyChecker.writable();
}
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = dependencies.recoveryCleanupWorkCollector();
PageCacheTracer pageCacheTracer = dependencies.pageCacheTracer();
DatabaseLayout databaseLayout = dependencies.databaseLayout();
return internalCreate(pageCache, databaseDir, fs, monitors, monitorTag, config, readOnlyChecker, recoveryCleanupWorkCollector, databaseLayout, pageCacheTracer);
}
Aggregations