Search in sources :

Example 6 with DatabaseLayout

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

the class LegacyTransactionLogsLocatorTest method transactionLogsDirectoryEqualsToDatabaseDirectoryForSystemDatabase.

@Test
void transactionLogsDirectoryEqualsToDatabaseDirectoryForSystemDatabase() {
    Path customDirectory = testDirectory.directory("customDirectory");
    Config config = Config.defaults(GraphDatabaseInternalSettings.logical_logs_location, customDirectory.toAbsolutePath());
    DatabaseLayout systemDbLayout = neo4jLayout.databaseLayout(GraphDatabaseSettings.SYSTEM_DATABASE_NAME);
    LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(config, systemDbLayout);
    assertEquals(systemDbLayout.databaseDirectory(), logsLocator.getTransactionLogsDirectory());
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 7 with DatabaseLayout

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

the class Neo4jLayoutSupportExtensionTest method shouldUseDefaultConfig.

@Test
void shouldUseDefaultConfig() {
    Config defaultConfig = Config.defaults(neo4j_home, testDirectory.homePath());
    Neo4jLayout defaultNeo4jLayout = Neo4jLayout.of(defaultConfig);
    DatabaseLayout defaultDatabaseLayout = defaultNeo4jLayout.databaseLayout(defaultConfig.get(default_database));
    assertEquals(defaultNeo4jLayout.homeDirectory(), neo4jLayout.homeDirectory());
    assertEquals(defaultNeo4jLayout.databasesDirectory(), neo4jLayout.databasesDirectory());
    assertEquals(defaultNeo4jLayout.transactionLogsRootDirectory(), neo4jLayout.transactionLogsRootDirectory());
    assertEquals(defaultDatabaseLayout.databaseDirectory(), databaseLayout.databaseDirectory());
    assertEquals(defaultDatabaseLayout.getTransactionLogsDirectory(), databaseLayout.getTransactionLogsDirectory());
}
Also used : Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) Test(org.junit.jupiter.api.Test)

Example 8 with DatabaseLayout

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

the class FulltextProceduresTest method checkDatabaseConsistency.

private void checkDatabaseConsistency() {
    DatabaseLayout layout = db.databaseLayout();
    controller.restartDbms(b -> {
        try {
            ConsistencyCheckService cc = new ConsistencyCheckService();
            ConsistencyCheckService.Result result = cc.runFullConsistencyCheck(layout, Config.defaults(), ProgressMonitorFactory.NONE, NullLogProvider.nullLogProvider(), false, ConsistencyFlags.DEFAULT);
            if (!result.isSuccessful()) {
                Files.lines(result.reportFile()).forEach(System.out::println);
            }
            assertTrue(result.isSuccessful());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return b;
    });
}
Also used : DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) RepeatedPropertyInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedPropertyInSchemaException) RepeatedLabelInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedLabelInSchemaException) RepeatedRelationshipTypeInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedRelationshipTypeInSchemaException) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 9 with DatabaseLayout

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

the class DatabaseStartupTest method startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure.

@Test
void startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure() 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();
    fs.deleteRecursively(databaseLayout.databaseDirectory());
    // 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());
        assertThat(cause.get()).hasStackTraceContaining("Fail to start '" + db.databaseId() + "' since transaction logs were found, while database ");
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 10 with DatabaseLayout

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

the class CommunitySystemDatabaseIT method systemAndDefaultDatabasesAreConsistentAfterShutdown.

@Test
void systemAndDefaultDatabasesAreConsistentAfterShutdown() throws ConsistencyCheckIncompleteException {
    int systemDatabaseTransactions = 100;
    int defaultDatabaseTransactions = 15;
    DatabaseLayout systemDatabaseLayout = systemDb.databaseLayout();
    DatabaseLayout defaultDbLayout = defaultDb.databaseLayout();
    for (int i = 0; i < systemDatabaseTransactions; i++) {
        try (Transaction transaction = systemDb.beginTx()) {
            Node nodeA = transaction.createNode();
            Node nodeB = transaction.createNode();
            nodeA.createRelationshipTo(nodeB, RelationshipType.withName(valueOf(i)));
            transaction.commit();
        }
    }
    for (int i = 0; i < defaultDatabaseTransactions; i++) {
        try (Transaction transaction = defaultDb.beginTx()) {
            transaction.createNode(label(valueOf(i)));
            transaction.commit();
        }
    }
    managementService.shutdown();
    ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
    assertTrue(runConsistencyCheck(systemDatabaseLayout, consistencyCheckService).isSuccessful());
    assertTrue(runConsistencyCheck(defaultDbLayout, consistencyCheckService).isSuccessful());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.jupiter.api.Test)

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