Search in sources :

Example 11 with StoreId

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

the class DetachedCheckpointLogEntryParser method parse.

@Override
LogEntry parse(KernelVersion version, ReadableChecksumChannel channel, LogPositionMarker marker, CommandReaderFactory commandReaderFactory) throws IOException {
    long logVersion = channel.getLong();
    long byteOffset = channel.getLong();
    long checkpointTimeMillis = channel.getLong();
    StoreId storeId = new StoreId(channel.getLong(), channel.getLong(), channel.getLong(), channel.getLong(), channel.getLong());
    short reasonBytesLength = channel.getShort();
    byte[] bytes = new byte[MAX_DESCRIPTION_LENGTH];
    channel.get(bytes, MAX_DESCRIPTION_LENGTH);
    String reason = new String(bytes, 0, reasonBytesLength, UTF_8);
    channel.endChecksumAndValidate();
    return new LogEntryDetachedCheckpoint(version, new LogPosition(logVersion, byteOffset), checkpointTimeMillis, storeId, reason);
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 12 with StoreId

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

the class TransactionLogInitializerTest method shouldResetMetaDataStoreWithTransactionId.

@Test
void shouldResetMetaDataStoreWithTransactionId() throws Exception {
    // Given
    var metaStore = mock(MetadataProvider.class);
    var txn = new TransactionId(3, -1322858814, currentTimeMillis());
    when(metaStore.getStoreId()).thenReturn(new StoreId(versionStringToLong(LATEST_STORE_VERSION)));
    when(metaStore.getLastClosedTransaction()).thenReturn(new long[] { txn.transactionId(), 0, 1613 });
    when(metaStore.getLastCommittedTransaction()).thenReturn(txn);
    when(metaStore.getLastCommittedTransactionId()).thenReturn(txn.transactionId());
    when(metaStore.getLastClosedTransactionId()).thenReturn(txn.transactionId());
    DatabaseLayout databaseLayout = Neo4jLayout.of(testDirectory.homePath()).databaseLayout(DEFAULT_DATABASE_NAME);
    // When
    var initializer = new TransactionLogInitializer(testDirectory.getFileSystem(), metaStore, INSTANCE, PageCacheTracer.NULL);
    initializer.initializeEmptyLogFile(databaseLayout, databaseLayout.getTransactionLogsDirectory(), "LostFiles");
    // Then
    verify(metaStore).resetLastClosedTransaction(eq(txn.transactionId()), eq(txn.transactionId()), eq((long) CURRENT_FORMAT_LOG_HEADER_SIZE), eq(true), any());
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 13 with StoreId

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

the class DetachedCheckpointLogEntryParserTest method parseDetachedCheckpointRecord.

@Test
void parseDetachedCheckpointRecord() throws IOException {
    KernelVersion version = KernelVersion.V4_3_D4;
    var storeId = new StoreId(4, 5, 6, 7, 8);
    var channel = new InMemoryClosableChannel();
    int checkpointMillis = 3;
    String checkpointDescription = "checkpoint";
    byte[] bytes = Arrays.copyOf(checkpointDescription.getBytes(), 120);
    // For version confusion, please read LogEntryParserSetV4_3 comments
    var checkpoint = new LogEntryDetachedCheckpoint(version, new LogPosition(1, 2), checkpointMillis, storeId, checkpointDescription);
    channel.putLong(checkpoint.getLogPosition().getLogVersion()).putLong(checkpoint.getLogPosition().getByteOffset()).putLong(checkpointMillis).putLong(storeId.getCreationTime()).putLong(storeId.getRandomId()).putLong(storeId.getStoreVersion()).putLong(storeId.getUpgradeTime()).putLong(storeId.getUpgradeTxId()).putShort((short) checkpointDescription.getBytes().length).put(bytes, bytes.length);
    channel.putChecksum();
    var checkpointParser = LogEntryParserSets.parserSet(version).select(DETACHED_CHECK_POINT);
    LogEntry logEntry = checkpointParser.parse(version, channel, positionMarker, commandReader);
    assertEquals(checkpoint, logEntry);
}
Also used : KernelVersion(org.neo4j.kernel.KernelVersion) StoreId(org.neo4j.storageengine.api.StoreId) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 14 with StoreId

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

the class InlinedLogTailScanner method findLogTail.

protected LogTailInformation findLogTail() throws IOException {
    LogFile logFile = logFiles.getLogFile();
    final long highestLogVersion = logFile.getHighestLogVersion();
    long version = highestLogVersion;
    long versionToSearchForCommits = highestLogVersion;
    LogEntryStart latestStartEntry = null;
    long oldestStartEntryTransaction = NO_TRANSACTION_ID;
    long oldestVersionFound = -1;
    byte latestLogEntryVersion = 0;
    boolean startRecordAfterCheckpoint = false;
    boolean corruptedTransactionLogs = false;
    while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
        log.info("Scanning log file with version %d for checkpoint entries", version);
        oldestVersionFound = version;
        CheckpointInfo latestCheckPoint = null;
        StoreId storeId = StoreId.UNKNOWN;
        try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
            var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
            LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
            LogHeader logHeader = logFile.extractHeader(version);
            storeId = logHeader.getStoreId();
            LogEntry entry;
            long position = logHeader.getStartPosition().getByteOffset();
            long channelVersion = version;
            while (cursor.next()) {
                entry = cursor.get();
                // Collect data about latest checkpoint
                if (entry instanceof LogEntryInlinedCheckPoint) {
                    latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
                } else if (entry instanceof LogEntryCommit) {
                    if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
                        oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
                    }
                } else if (entry instanceof LogEntryStart) {
                    LogEntryStart startEntry = (LogEntryStart) entry;
                    if (version == versionToSearchForCommits) {
                        latestStartEntry = startEntry;
                    }
                    startRecordAfterCheckpoint = true;
                }
                // Collect data about latest entry version, only in first log file
                if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
                    latestLogEntryVersion = entry.getVersion().version();
                }
                position = channel.position();
                channelVersion = channel.getVersion();
            }
            verifyReaderPosition(version, logEntryReader.lastPosition());
        } catch (Error | ClosedByInterruptException e) {
            // These should not be parsing errors
            throw e;
        } catch (Throwable t) {
            monitor.corruptedLogFile(version, t);
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            corruptedTransactionLogs = true;
        }
        if (latestCheckPoint != null) {
            return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
        }
        version--;
        // if we have found no commits in the latest log, keep searching in the next one
        if (latestStartEntry == null) {
            versionToSearchForCommits--;
        }
    }
    return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) StoreId(org.neo4j.storageengine.api.StoreId) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 15 with StoreId

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

the class LogHeaderWriter method writeLogHeader.

public static void writeLogHeader(StoreChannel channel, LogHeader logHeader, MemoryTracker memoryTracker) throws IOException {
    try (var scopedBuffer = new HeapScopedBuffer(CURRENT_FORMAT_LOG_HEADER_SIZE, memoryTracker)) {
        var buffer = scopedBuffer.getBuffer();
        buffer.putLong(encodeLogVersion(logHeader.getLogVersion(), logHeader.getLogFormatVersion()));
        buffer.putLong(logHeader.getLastCommittedTxId());
        StoreId storeId = logHeader.getStoreId();
        buffer.putLong(storeId.getCreationTime());
        buffer.putLong(storeId.getRandomId());
        buffer.putLong(storeId.getStoreVersion());
        buffer.putLong(storeId.getUpgradeTime());
        buffer.putLong(storeId.getUpgradeTxId());
        buffer.putLong(0);
        buffer.flip();
        channel.writeAll(buffer);
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) StoreId(org.neo4j.storageengine.api.StoreId)

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