Search in sources :

Example 6 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class LogHeaderReader method readLogHeader.

/**
 * Reads the header of a log. Data will be read from {@code channel} using supplied {@code buffer}
 * as to allow more controlled allocation.
 *
 * @param buffer {@link ByteBuffer} to read into. Passed in to allow control over allocation.
 * @param channel {@link ReadableByteChannel} to read from, typically a channel over a file containing the data.
 * @param strict if {@code true} then will fail with {@link IncompleteLogHeaderException} on incomplete
 * header, i.e. if there's not enough data in the channel to even read the header. If {@code false} then
 * the return value will instead be {@code null}.
 * @param fileForAdditionalErrorInformationOrNull when in {@code strict} mode the exception can be
 * amended with information about which file the channel represents, if any. Purely for better forensics
 * ability.
 * @return {@link LogHeader} containing the log header data from the {@code channel}.
 * @throws IOException if unable to read from {@code channel}
 * @throws IncompleteLogHeaderException if {@code strict} and not enough data could be read
 */
public static LogHeader readLogHeader(ByteBuffer buffer, ReadableByteChannel channel, boolean strict, Path fileForAdditionalErrorInformationOrNull) throws IOException {
    // Decode first part of the header that contains the version
    if (!safeRead(buffer, channel, LOG_HEADER_VERSION_SIZE, strict, fileForAdditionalErrorInformationOrNull)) {
        return null;
    }
    long encodedLogVersions = buffer.getLong();
    if (encodedLogVersions == 0) {
        // Since the format version is a non-zero number, we know we are reading a pre-allocated file
        return null;
    }
    byte logFormatVersion = decodeLogFormatVersion(encodedLogVersions);
    long logVersion = decodeLogVersion(encodedLogVersions);
    // The header's total length differs from versions
    if (logFormatVersion == LOG_VERSION_3_5) {
        if (!safeRead(buffer, channel, Long.BYTES, strict, fileForAdditionalErrorInformationOrNull)) {
            return null;
        }
        long previousCommittedTx = buffer.getLong();
        return new LogHeader(logFormatVersion, logVersion, previousCommittedTx, LOG_HEADER_SIZE_3_5);
    }
    if (logFormatVersion == LOG_VERSION_4_0) {
        if (!safeRead(buffer, channel, LOG_HEADER_SIZE_4_0 - LOG_HEADER_VERSION_SIZE, strict, fileForAdditionalErrorInformationOrNull)) {
            return null;
        }
        long previousCommittedTx = buffer.getLong();
        StoreId storeId = new StoreId(buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong());
        // reserved
        buffer.getLong();
        return new LogHeader(logFormatVersion, logVersion, previousCommittedTx, storeId, LOG_HEADER_SIZE_4_0);
    }
    throw new IOException("Unrecognized transaction log format version: " + logFormatVersion);
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) IOException(java.io.IOException)

Example 7 with StoreId

use of org.neo4j.storageengine.api.StoreId 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)

Example 8 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class CheckpointInfoTest method checkpointInfoOfLegacyCheckpointEntry.

@Test
void checkpointInfoOfLegacyCheckpointEntry() {
    var logPosition = new LogPosition(0, 1);
    StoreId storeId = new StoreId(1, 2, 3, 4, 5);
    LogPosition position = new LogPosition(1, 2);
    var checkpointInfo = new CheckpointInfo(new LogEntryInlinedCheckPoint(logPosition), storeId, position);
    assertSame(logPosition, checkpointInfo.getTransactionLogPosition());
    assertSame(storeId, checkpointInfo.storeId());
    assertSame(position, checkpointInfo.getCheckpointEntryPosition());
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 9 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class MetaDataStore method initialiseNewStoreFile.

@Override
protected void initialiseNewStoreFile(CursorContext cursorContext) throws IOException {
    super.initialiseNewStoreFile(cursorContext);
    long storeVersionAsLong = MetaDataStore.versionStringToLong(storeVersion);
    StoreId storeId = new StoreId(storeVersionAsLong);
    setCreationTime(storeId.getCreationTime(), cursorContext);
    setRandomNumber(storeId.getRandomId(), cursorContext);
    // If metaDataStore.creationTime == metaDataStore.upgradeTime && metaDataStore.upgradeTransactionId == BASE_TX_ID
    // then store has never been upgraded
    setUpgradeTime(storeId.getCreationTime(), cursorContext);
    setUpgradeTransaction(BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, cursorContext);
    setCurrentLogVersion(0, cursorContext);
    setLastCommittedAndClosedTransactionId(BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, BASE_TX_LOG_BYTE_OFFSET, BASE_TX_LOG_VERSION, cursorContext);
    setStoreVersion(storeVersionAsLong, cursorContext);
    setLatestConstraintIntroducingTx(0, cursorContext);
    setExternalStoreUUID(UUID.randomUUID(), cursorContext);
    setCheckpointLogVersion(0, cursorContext);
    setKernelVersion(KernelVersion.LATEST, cursorContext);
    setDatabaseIdUuid(NOT_INITIALIZED_UUID, cursorContext);
    flush(cursorContext);
}
Also used : ExternalStoreId(org.neo4j.storageengine.api.ExternalStoreId) StoreId(org.neo4j.storageengine.api.StoreId)

Example 10 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class DetachedCheckpointLogEntryWriterTest method writeCheckpoint.

private static void writeCheckpoint(DetachedCheckpointLogEntryWriter checkpointLogEntryWriter, String reason) throws IOException {
    var storeId = new StoreId(3, 4, 5, 6, 7);
    LogPosition logPosition = new LogPosition(1, 2);
    checkpointLogEntryWriter.writeCheckPointEntry(logPosition, Instant.ofEpochMilli(1), storeId, reason);
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

StoreId (org.neo4j.storageengine.api.StoreId)20 Test (org.junit.jupiter.api.Test)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 ExternalStoreId (org.neo4j.storageengine.api.ExternalStoreId)3 Path (java.nio.file.Path)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)2 LogEntryDetachedCheckpoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint)2 LogEntryInlinedCheckPoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint)2 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)2 TransactionId (org.neo4j.storageengine.api.TransactionId)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongSupplier (java.util.function.LongSupplier)1 UnsatisfiedDependencyException (org.neo4j.exceptions.UnsatisfiedDependencyException)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1