Search in sources :

Example 1 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class DatabaseAvailabilityIT method restartedDatabaseIsAvailable.

@Test
void restartedDatabaseIsAvailable() {
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
    DatabaseContext databaseContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
    Database database = databaseContext.database();
    executeTransactionOnDefaultDatabase();
    database.stop();
    assertThrows(DatabaseShutdownException.class, () -> this.database.beginTx());
    database.start();
    executeTransactionOnDefaultDatabase();
}
Also used : DatabaseContext(org.neo4j.dbms.database.DatabaseContext) Database(org.neo4j.kernel.database.Database) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 2 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class AbstractDatabaseManager method startDatabase.

protected void startDatabase(NamedDatabaseId namedDatabaseId, DB context) {
    try {
        log.info("Starting '%s'.", namedDatabaseId);
        Database database = context.database();
        database.start();
    } catch (Throwable t) {
        throw new DatabaseManagementException(format("An error occurred! Unable to start `%s`.", namedDatabaseId), t);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) Database(org.neo4j.kernel.database.Database)

Example 3 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class AbstractDatabaseManager method stopDatabase.

protected void stopDatabase(NamedDatabaseId namedDatabaseId, DB context) {
    try {
        log.info("Stopping '%s'.", namedDatabaseId);
        Database database = context.database();
        database.stop();
        log.info("Stopped '%s' successfully.", namedDatabaseId);
    } catch (Throwable t) {
        log.error("Error stopping '%s'.", namedDatabaseId);
        throw new DatabaseManagementException(format("An error occurred! Unable to stop `%s`.", namedDatabaseId), t);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) Database(org.neo4j.kernel.database.Database)

Example 4 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForNoTransactionLogs.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForNoTransactionLogs() throws IOException {
    // GIVEN
    Database database = databaseWithLogFilesContainingLowestTxId(noLogs());
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("Transaction log files stored on file store:").containsMessages(" - no transactions found").containsMessages(" - no checkpoints found");
}
Also used : Log(org.neo4j.logging.Log) Database(org.neo4j.kernel.database.Database) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 5 with Database

use of org.neo4j.kernel.database.Database in project neo4j by neo4j.

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs() throws Exception {
    // GIVEN
    long txLogLowVersion = 2;
    long txLogHighVersion = 10;
    long checkpointLogLowVersion = 0;
    long checkpointLogHighVersion = 3;
    StoreId storeId = new StoreId(12345);
    LogPosition checkpointLogPosition = new LogPosition(checkpointLogHighVersion, 34);
    Database database = databaseWithLogFilesContainingLowestTxId(logs(transactionLogsWithTransaction(txLogLowVersion, txLogHighVersion, 42), checkpointLogsWithLastCheckpoint(checkpointLogLowVersion, checkpointLogHighVersion, new CheckpointInfo(new LogEntryDetachedCheckpoint(KernelVersion.LATEST, checkpointLogPosition, 1234, storeId, "testing"), checkpointLogPosition))));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("existing transaction log versions " + txLogLowVersion + "-" + txLogHighVersion).containsMessages("existing checkpoint log versions " + checkpointLogLowVersion + "-" + checkpointLogHighVersion);
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) StoreId(org.neo4j.storageengine.api.StoreId) Log(org.neo4j.logging.Log) Database(org.neo4j.kernel.database.Database) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

Database (org.neo4j.kernel.database.Database)15 Test (org.junit.jupiter.api.Test)9 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 Log (org.neo4j.logging.Log)5 Dependencies (org.neo4j.collection.Dependencies)4 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 File (java.io.File)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1