Search in sources :

Example 66 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class DatabaseFileListingTest method createIndexDbFile.

private void createIndexDbFile() throws IOException {
    DatabaseLayout databaseLayout = db.databaseLayout();
    final Path indexFile = databaseLayout.file("index.db");
    if (Files.notExists(indexFile)) {
        Files.createFile(indexFile);
    }
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 67 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class IdGeneratorMigrator method createEmptyPlaceHolderStoreFiles.

private Set<Path> createEmptyPlaceHolderStoreFiles(DatabaseLayout layout, RecordFormats format) {
    Set<Path> createdStores = new HashSet<>();
    StoreType[] storesToCreate = Stream.of(StoreType.values()).filter(t -> {
        Path file = layout.file(t.getDatabaseFile());
        boolean exists = fileSystem.fileExists(file);
        if (!exists) {
            createdStores.add(file);
        }
        return !exists;
    }).toArray(StoreType[]::new);
    createStoreFactory(layout, format, new ScanOnOpenReadOnlyIdGeneratorFactory()).openNeoStores(true, storesToCreate).close();
    return createdStores;
}
Also used : Path(java.nio.file.Path) StoreType(org.neo4j.kernel.impl.store.StoreType) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) ProgressReporter(org.neo4j.common.ProgressReporter) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Config(org.neo4j.configuration.Config) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ArrayList(java.util.ArrayList) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) HashSet(java.util.HashSet) ScanOnOpenReadOnlyIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Iterables(org.neo4j.internal.helpers.collection.Iterables) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) Path(java.nio.file.Path) AbstractStoreMigrationParticipant(org.neo4j.storageengine.migration.AbstractStoreMigrationParticipant) DatabaseFile(org.neo4j.io.layout.DatabaseFile) PageCache(org.neo4j.io.pagecache.PageCache) OpenOption(java.nio.file.OpenOption) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) Set(java.util.Set) RecordFormatSelector.selectForVersion(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForVersion) GBPTREE_ID_FILES(org.neo4j.kernel.impl.store.format.RecordStorageCapability.GBPTREE_ID_FILES) IOException(java.io.IOException) MOVE(org.neo4j.kernel.impl.storemigration.FileOperation.MOVE) StoreMigratorFileOperation.fileOperation(org.neo4j.kernel.impl.storemigration.StoreMigratorFileOperation.fileOperation) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) IdType(org.neo4j.internal.id.IdType) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) List(java.util.List) Stream(java.util.stream.Stream) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreType(org.neo4j.kernel.impl.store.StoreType) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ScanOnOpenReadOnlyIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory) HashSet(java.util.HashSet)

Example 68 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist.

@Test
void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist() throws IOException {
    Path archive = testDirectory.file("the-archive.dump");
    Path txLogsDestination = Paths.get(testDirectory.absolutePath().toString(), "subdir", "txLogs");
    Config config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).set(transaction_logs_root_path, txLogsDestination.toAbsolutePath()).set(default_database, "destination").build();
    DatabaseLayout databaseLayout = DatabaseLayout.of(config);
    fileSystem.deleteRecursively(txLogsDestination);
    NoSuchFileException noSuchFileException = assertThrows(NoSuchFileException.class, () -> new Loader().load(archive, databaseLayout));
    assertEquals(txLogsDestination.toString(), noSuchFileException.getMessage());
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.jupiter.api.Test)

Example 69 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable() throws IOException {
    Path archive = testDirectory.file("the-archive.dump");
    Path destination = testDirectory.directory("subdir/the-destination");
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(destination);
    Path parentPath = databaseLayout.databaseDirectory().getParent();
    try (Closeable ignored = withPermissions(parentPath, emptySet())) {
        AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Loader().load(archive, databaseLayout));
        assertEquals(parentPath.toString(), exception.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) 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 70 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class ArchiveTest method shouldExcludeWholeDirectoriesMatchedByTheExclusionPredicate.

@ParameterizedTest
@EnumSource(CompressionFormat.class)
void shouldExcludeWholeDirectoriesMatchedByTheExclusionPredicate(CompressionFormat compressionFormat) throws IOException, IncorrectFormat {
    Path directory = testDirectory.directory("a-directory");
    Path subdir = directory.resolve("subdir");
    Files.createDirectories(subdir);
    Files.write(subdir.resolve("a-file"), new byte[0]);
    Path archive = testDirectory.file("the-archive.dump");
    new Dumper().dump(directory, directory, archive, compressionFormat, path -> path.getFileName().toString().equals("subdir"));
    Path txLogsRoot = testDirectory.directory("txLogsRoot");
    DatabaseLayout databaseLayout = layoutWithCustomTxRoot(txLogsRoot, "the-new-directory");
    new Loader().load(archive, databaseLayout);
    Path expectedOutput = testDirectory.directory("expected-output");
    Files.createDirectories(expectedOutput);
    assertEquals(describeRecursively(expectedOutput), describeRecursively(databaseLayout.databaseDirectory()));
}
Also used : Path(java.nio.file.Path) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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