use of org.neo4j.kernel.impl.transaction.log.files.LogTailInformation in project neo4j by neo4j.
the class RecoveryStartInformationProviderTest method shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero.
@Test
void shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero() {
// given
long oldestLogVersionFound = 1L;
when(logFile.getLowestLogVersion()).thenReturn(oldestLogVersionFound);
when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(true, 10L, false, currentLogVersion, LATEST.version()));
// when
UnderlyingStorageException storageException = assertThrows(UnderlyingStorageException.class, () -> new RecoveryStartInformationProvider(logFiles, monitor).get());
final String expectedMessage = "No check point found in any log file from version " + oldestLogVersionFound + " to " + logVersion;
assertEquals(expectedMessage, storageException.getMessage());
}
use of org.neo4j.kernel.impl.transaction.log.files.LogTailInformation in project neo4j by neo4j.
the class RecoveryStartInformationProviderTest method shouldReturnUnspecifiedIfThereIsNoNeedForRecovery.
@Test
void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() {
// given
when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(false, NO_TRANSACTION_ID, false, currentLogVersion, LATEST.version()));
// when
RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
// then
verify(monitor).noCommitsAfterLastCheckPoint(null);
assertEquals(LogPosition.UNSPECIFIED, recoveryStartInformation.getTransactionLogPosition());
assertEquals(LogPosition.UNSPECIFIED, recoveryStartInformation.getCheckpointPosition());
assertEquals(NO_TRANSACTION_ID, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint());
assertFalse(recoveryStartInformation.isRecoveryRequired());
}
use of org.neo4j.kernel.impl.transaction.log.files.LogTailInformation in project neo4j by neo4j.
the class RecoveryStartInformationProviderTest method shouldReturnLogPositionToRecoverFromIfNeeded.
@Test
void shouldReturnLogPositionToRecoverFromIfNeeded() {
// given
LogPosition txPosition = new LogPosition(1L, 4242);
LogPosition checkpointPosition = new LogPosition(2, 4);
when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(new CheckpointInfo(txPosition, StoreId.UNKNOWN, checkpointPosition), true, 10L, false, currentLogVersion, LATEST.version(), StoreId.UNKNOWN));
// when
RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
// then
verify(monitor).commitsAfterLastCheckPoint(txPosition, 10L);
assertEquals(txPosition, recoveryStartInformation.getTransactionLogPosition());
assertEquals(checkpointPosition, recoveryStartInformation.getCheckpointPosition());
assertEquals(10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint());
assertTrue(recoveryStartInformation.isRecoveryRequired());
}
use of org.neo4j.kernel.impl.transaction.log.files.LogTailInformation 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);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogTailInformation in project neo4j by neo4j.
the class AbstractLogTailScannerTest method latestLogFileContainingACheckPointOnly.
@ParameterizedTest
@MethodSource("params")
void latestLogFileContainingACheckPointOnly(int startLogVersion, int endLogVersion) {
// given
setupLogFiles(endLogVersion, logFile(checkPoint()));
// when
LogTailInformation logTailInformation = logFiles.getTailInformation();
// then
assertLatestCheckPoint(true, false, NO_TRANSACTION_ID, false, logTailInformation);
}
Aggregations