use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RecoveryStartInformationProvider method get.
/**
* Find the log position to start recovery from
*
* @return {@link LogPosition#UNSPECIFIED} if there is no need to recover otherwise the {@link LogPosition} to
* start recovery from
* @throws IOException if log files cannot be read
*/
@Override
public RecoveryStartInformation get() {
LogTailInformation logTailInformation = logFiles.getTailInformation();
CheckpointInfo lastCheckPoint = logTailInformation.lastCheckPoint;
long txIdAfterLastCheckPoint = logTailInformation.firstTxIdAfterLastCheckPoint;
if (!logTailInformation.isRecoveryRequired()) {
monitor.noCommitsAfterLastCheckPoint(lastCheckPoint != null ? lastCheckPoint.getTransactionLogPosition() : null);
return NO_RECOVERY_REQUIRED;
}
if (logTailInformation.logsMissing()) {
return MISSING_LOGS;
}
if (logTailInformation.commitsAfterLastCheckpoint()) {
if (lastCheckPoint == null) {
long lowestLogVersion = logFiles.getLogFile().getLowestLogVersion();
if (lowestLogVersion != INITIAL_LOG_VERSION) {
throw new UnderlyingStorageException("No check point found in any log file from version " + lowestLogVersion + " to " + logTailInformation.currentLogVersion);
}
monitor.noCheckPointFound();
LogPosition position = tryExtractHeaderSize();
return createRecoveryInformation(position, new LogPosition(INITIAL_LOG_VERSION, CURRENT_FORMAT_LOG_HEADER_SIZE), txIdAfterLastCheckPoint);
}
LogPosition transactionLogPosition = lastCheckPoint.getTransactionLogPosition();
monitor.commitsAfterLastCheckPoint(transactionLogPosition, txIdAfterLastCheckPoint);
return createRecoveryInformation(transactionLogPosition, lastCheckPoint.getCheckpointEntryPosition(), txIdAfterLastCheckPoint);
} else {
throw new UnderlyingStorageException("Fail to determine recovery information Log tail info: " + logTailInformation);
}
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CorruptedLogsTruncator method truncateLogFiles.
private void truncateLogFiles(long recoveredTransactionLogVersion, long recoveredTransactionOffset, Optional<CheckpointInfo> corruptCheckpoint) throws IOException {
LogFile transactionLogFile = logFiles.getLogFile();
truncateFilesFromVersion(recoveredTransactionLogVersion, recoveredTransactionOffset, transactionLogFile.getHighestLogVersion(), transactionLogFile::getLogFileForVersion);
if (corruptCheckpoint.isPresent()) {
LogPosition checkpointPosition = corruptCheckpoint.get().getCheckpointEntryPosition();
CheckpointFile checkpointFile = logFiles.getCheckpointFile();
truncateFilesFromVersion(checkpointPosition.getLogVersion(), checkpointPosition.getByteOffset(), checkpointFile.getCurrentDetachedLogVersion(), checkpointFile::getDetachedCheckpointFileForVersion);
}
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CorruptedLogsTruncator method backupCorruptedContent.
private void backupCorruptedContent(long recoveredTransactionLogVersion, long recoveredTransactionOffset, Optional<CheckpointInfo> corruptCheckpoint) throws IOException {
Path corruptedLogArchive = getArchiveFile(recoveredTransactionLogVersion, recoveredTransactionOffset);
try (ZipOutputStream recoveryContent = new ZipOutputStream(fs.openAsOutputStream(corruptedLogArchive, false));
var bufferScope = new HeapScopedBuffer(1, MebiByte, memoryTracker)) {
LogFile transactionLogFile = logFiles.getLogFile();
copyLogsContent(recoveredTransactionLogVersion, recoveredTransactionOffset, transactionLogFile.getHighestLogVersion(), recoveryContent, bufferScope, transactionLogFile::getLogFileForVersion);
if (corruptCheckpoint.isPresent()) {
LogPosition checkpointPosition = corruptCheckpoint.get().getCheckpointEntryPosition();
CheckpointFile checkpointFile = logFiles.getCheckpointFile();
copyLogsContent(checkpointPosition.getLogVersion(), checkpointPosition.getByteOffset(), checkpointFile.getCurrentDetachedLogVersion(), recoveryContent, bufferScope, checkpointFile::getDetachedCheckpointFileForVersion);
}
}
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CorruptedLogsTruncator method findFirstCorruptDetachedCheckpoint.
private Optional<CheckpointInfo> findFirstCorruptDetachedCheckpoint(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
List<CheckpointInfo> detachedCheckpoints = logFiles.getCheckpointFile().getReachableDetachedCheckpoints();
for (CheckpointInfo checkpoint : detachedCheckpoints) {
LogPosition transactionLogPosition = checkpoint.getTransactionLogPosition();
long logVersion = transactionLogPosition.getLogVersion();
if (logVersion > recoveredTransactionLogVersion || (logVersion == recoveredTransactionLogVersion && transactionLogPosition.getByteOffset() > recoveredTransactionOffset)) {
return Optional.of(checkpoint);
}
}
return Optional.empty();
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition 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());
}
Aggregations