Search in sources :

Example 1 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class CheckTxLogs method validateCheckPoints.

boolean validateCheckPoints(PhysicalLogFiles logFiles, InconsistenciesHandler handler) throws IOException {
    final long lowestLogVersion = logFiles.getLowestLogVersion();
    final long highestLogVersion = logFiles.getHighestLogVersion();
    boolean success = true;
    try (PrimitiveLongLongMap logFileSizes = Primitive.offHeapLongLongMap()) {
        for (long i = lowestLogVersion; i <= highestLogVersion; i++) {
            logFileSizes.put(i, fs.getFileSize(logFiles.getLogFileForVersion(i)));
        }
        LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles);
        while (logEntryCursor.next()) {
            LogEntry logEntry = logEntryCursor.get();
            if (logEntry instanceof CheckPoint) {
                LogPosition logPosition = logEntry.<CheckPoint>as().getLogPosition();
                // if the file has been pruned we cannot validate the check point
                if (logPosition.getLogVersion() >= lowestLogVersion) {
                    long size = logFileSizes.get(logPosition.getLogVersion());
                    if (logPosition.getByteOffset() < 0 || size < 0 || logPosition.getByteOffset() > size) {
                        long currentLogVersion = logEntryCursor.getCurrentLogVersion();
                        handler.reportInconsistentCheckPoint(currentLogVersion, logPosition, size);
                        success = false;
                    }
                }
            }
        }
    }
    return success;
}
Also used : PrimitiveLongLongMap(org.neo4j.collection.primitive.PrimitiveLongLongMap) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class CheckTxLogsTest method writeCheckPoint.

private void writeCheckPoint(File log, long logVersion, long byteOffset) throws IOException {
    LogPosition logPosition = new LogPosition(logVersion, byteOffset);
    writeContent(log, (txWriter) -> txWriter.checkPoint(logPosition));
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 3 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class CheckTxLogsTest method shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile.

@Test
public void shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile() throws Exception {
    // given
    ensureLogExists(logFile(1));
    writeCheckPoint(logFile(2), 1, 42);
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // when
    checker.validateCheckPoints(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler);
    // then
    assertEquals(1, handler.checkPointInconsistencies.size());
    assertEquals(2, handler.checkPointInconsistencies.get(0).logVersion);
    assertEquals(new LogPosition(1, 42), handler.checkPointInconsistencies.get(0).logPosition);
    assertEquals(LOG_HEADER_SIZE, handler.checkPointInconsistencies.get(0).size);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 4 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class TransactionLogCatchUpWriter method close.

@Override
public synchronized void close() throws IOException {
    if (asPartOfStoreCopy) {
        /* A checkpoint which points to the beginning of the log file, meaning that
            all the streamed transactions will be applied as part of recovery. */
        long logVersion = logFiles.getHighestLogVersion();
        writer.checkPoint(new LogPosition(logVersion, LOG_HEADER_SIZE));
        // * comment copied from old StoreCopyClient *
        // since we just create new log and put checkpoint into it with offset equals to
        // LOG_HEADER_SIZE we need to update last transaction offset to be equal to this newly defined max
        // offset otherwise next checkpoint that use last transaction offset will be created for non
        // existing offset that is in most of the cases bigger than new log size.
        // Recovery will treat that as last checkpoint and will not try to recover store till new
        // last closed transaction offset will not overcome old one. Till that happens it will be
        // impossible for recovery process to restore the store
        File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
        MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, LOG_HEADER_SIZE);
    }
    lifespan.close();
    if (lastTxId != -1) {
        File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
        MetaDataStore.setRecord(pageCache, neoStoreFile, LAST_TRANSACTION_ID, lastTxId);
    }
}
Also used : File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 5 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.

the class RaftLogMetadataCacheTest method shouldRemoveUpTo.

@Test
public void shouldRemoveUpTo() throws Exception {
    // given
    int cacheSize = 100;
    RaftLogMetadataCache cache = new RaftLogMetadataCache(cacheSize);
    for (int i = 0; i < cacheSize; i++) {
        cache.cacheMetadata(i, i, new LogPosition(i, i));
    }
    // when
    int upTo = 30;
    cache.removeUpTo(upTo);
    // then
    long i = 0;
    for (; i <= upTo; i++) {
        assertNull(cache.getMetadata(i));
    }
    for (; i < cacheSize; i++) {
        RaftLogMetadataCache.RaftLogEntryMetadata metadata = cache.getMetadata(i);
        assertNotNull(metadata);
        assertEquals(i, metadata.getEntryTerm());
    }
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Aggregations

LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)115 Test (org.junit.jupiter.api.Test)50 File (java.io.File)16 Test (org.junit.Test)16 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)15 Path (java.nio.file.Path)14 IOException (java.io.IOException)11 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)10 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)10 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)10 StoreId (org.neo4j.storageengine.api.StoreId)10 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)9 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)8 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)8 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)7