Search in sources :

Example 51 with DatabaseLayout

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());
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.jupiter.api.Test)

Example 52 with DatabaseLayout

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());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 53 with DatabaseLayout

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());
}
Also used : Path(java.nio.file.Path) FileSystemException(java.nio.file.FileSystemException) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 54 with DatabaseLayout

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());
    }
}
Also used : FileLockException(org.neo4j.kernel.internal.locker.FileLockException) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Util.wrapIOException(org.neo4j.commandline.Util.wrapIOException) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 55 with DatabaseLayout

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);
}
Also used : Path(java.nio.file.Path) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Log(org.neo4j.logging.Log) LoggingMonitor(org.neo4j.kernel.api.index.LoggingMonitor) Config(org.neo4j.configuration.Config) Monitors(org.neo4j.monitoring.Monitors) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) PageCache(org.neo4j.io.pagecache.PageCache)

Aggregations

DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)108 Test (org.junit.jupiter.api.Test)66 Path (java.nio.file.Path)51 Config (org.neo4j.configuration.Config)35 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)24 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)19 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)17 PageCache (org.neo4j.io.pagecache.PageCache)17 IOException (java.io.IOException)16 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)16 Transaction (org.neo4j.graphdb.Transaction)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)9 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)9 CommandFailedException (org.neo4j.cli.CommandFailedException)8 ExecutionContext (org.neo4j.cli.ExecutionContext)8 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)8 Closeable (java.io.Closeable)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7