Search in sources :

Example 11 with Database

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

the class TransactionRangeDiagnosticsTest method shouldLogNoCheckpointFoundForEmptyPresentCheckpointLog.

@Test
void shouldLogNoCheckpointFoundForEmptyPresentCheckpointLog() throws IOException {
    // GIVEN
    Database database = databaseWithLogFilesContainingLowestTxId(logs(transactionLogs -> {
    }, checkpointLogsWithLastCheckpoint(0, 0, null)));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("no transactions found").containsMessages("existing checkpoint log versions 0-0").containsMessages("no checkpoints found");
}
Also used : LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) Log(org.neo4j.logging.Log) Dependencies(org.neo4j.collection.Dependencies) LogAssertions.assertThat(org.neo4j.logging.LogAssertions.assertThat) KernelVersion(org.neo4j.kernel.KernelVersion) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Test(org.junit.jupiter.api.Test) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) TransactionLogFiles(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFiles) Database(org.neo4j.kernel.database.Database) CURRENT_FORMAT_LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) Optional(java.util.Optional) StoreId(org.neo4j.storageengine.api.StoreId) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) Path(java.nio.file.Path) Mockito.mock(org.mockito.Mockito.mock) Log(org.neo4j.logging.Log) Database(org.neo4j.kernel.database.Database) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 12 with Database

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

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsInSecondOldestLog.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInSecondOldestLog() throws Exception {
    // GIVEN
    long logVersion = 2;
    long prevLogLastTxId = 45;
    Database database = databaseWithLogFilesContainingLowestTxId(logWithTransactionsInNextToOldestLog(logVersion, prevLogLastTxId));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("oldest transaction " + (prevLogLastTxId + 1), "version " + (logVersion + 1)).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 13 with Database

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

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsInOldestLog.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInOldestLog() throws Exception {
    // GIVEN
    long logVersion = 2;
    long prevLogLastTxId = 45;
    Database database = databaseWithLogFilesContainingLowestTxId(logWithTransactions(logVersion, logVersion, prevLogLastTxId));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("oldest transaction " + (prevLogLastTxId + 1), "version " + logVersion).containsMessages("existing transaction log versions ").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 14 with Database

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

the class TransactionRangeDiagnosticsTest method databaseWithLogFilesContainingLowestTxId.

private static Database databaseWithLogFilesContainingLowestTxId(LogFiles files) {
    Dependencies dependencies = mock(Dependencies.class);
    when(dependencies.resolveDependency(LogFiles.class)).thenReturn(files);
    Database database = mock(Database.class);
    when(database.getDependencyResolver()).thenReturn(dependencies);
    return database;
}
Also used : Database(org.neo4j.kernel.database.Database) Dependencies(org.neo4j.collection.Dependencies)

Example 15 with Database

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

the class DefaultDatabaseManager method upgradeDatabase.

@Override
public synchronized void upgradeDatabase(NamedDatabaseId namedDatabaseId) throws DatabaseNotFoundException {
    StandaloneDatabaseContext context = getDatabaseContext(namedDatabaseId).orElseThrow(() -> new DatabaseNotFoundException("Database not found: " + namedDatabaseId));
    Database database = context.database();
    log.info("Upgrading '%s'.", namedDatabaseId);
    // Clear any failed state, e.g. due to format being too old on startup.
    context.fail(null);
    try {
        database.upgrade(true);
    } catch (Throwable throwable) {
        String message = "Failed to upgrade " + namedDatabaseId;
        context.fail(throwable);
        throw new DatabaseManagementException(message, throwable);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) Database(org.neo4j.kernel.database.Database)

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