use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class LogPositionMarkerTest method shouldReturnTheMarkedPosition.
@Test
void shouldReturnTheMarkedPosition() {
// given
final LogPositionMarker marker = new LogPositionMarker();
// when
marker.mark(1, 2);
final LogPosition logPosition = marker.newPosition();
// given
assertEquals(new LogPosition(1, 2), logPosition);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.
private LogPosition getLastReadablePosition(Path logFile) throws IOException {
VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
LogFile txLogFile = logFiles.getLogFile();
long logVersion = txLogFile.getLogVersion(logFile);
LogPosition startPosition = txLogFile.extractHeader(logVersion).getStartPosition();
try (ReadableLogChannel reader = openTransactionFileChannel(logVersion, startPosition)) {
while (entryReader.readLogEntry(reader) != null) {
// scroll to the end of readable entries
}
} catch (IncompleteLogHeaderException e) {
return new LogPosition(logVersion, 0);
}
return entryReader.lastPosition();
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled.
@Test
void startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransaction(database);
managementService.shutdown();
long originalLogDataLength;
Path firstLogFile;
try (Lifespan lifespan = new Lifespan(logFiles)) {
LogFile logFile = logFiles.getLogFile();
LogPosition readablePosition = getLastReadablePosition(logFile);
firstLogFile = logFiles.getLogFile().getHighestLogFile();
originalLogDataLength = readablePosition.getByteOffset();
logFile.rotate();
// append zeros in the end of previous file causing illegal suffix
try (StoreFileChannel writeChannel = fileSystem.write(firstLogFile)) {
writeChannel.position(writeChannel.size());
for (int i = 0; i < 10; i++) {
writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
}
}
}
startStopDbRecoveryOfCorruptedLogs();
assertEquals(originalLogDataLength, fileSystem.getFileSize(firstLogFile));
assertThat(logProvider).containsMessages("Recovery required from position LogPosition{logVersion=0, byteOffset=" + (996 + txOffsetAfterStart) + "}").assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessage("Transaction log files with version 0 has 50 unreadable bytes. Was able to read upto " + (996 + txOffsetAfterStart) + " but " + (1046 + txOffsetAfterStart) + " is available.");
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.
private LogPosition getLastReadablePosition(LogFile logFile) throws IOException {
VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
LogPosition startPosition = logFile.extractHeader(logFiles.getLogFile().getHighestLogVersion()).getStartPosition();
try (ReadableLogChannel reader = logFile.getReader(startPosition)) {
while (entryReader.readLogEntry(reader) != null) {
// scroll to the end of readable entries
}
}
return entryReader.lastPosition();
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckpointLogFileRotationIT method rotateCheckpointLogFiles.
@Test
void rotateCheckpointLogFiles() throws IOException {
var checkpointFile = logFiles.getCheckpointFile();
var checkpointAppender = checkpointFile.getCheckpointAppender();
LogPosition logPosition = new LogPosition(1000, 12345);
var reason = "checkpoint for rotation test";
for (int i = 0; i < 105; i++) {
checkpointAppender.checkPoint(NULL, logPosition, Instant.now(), reason);
}
var matchedFiles = checkpointFile.getDetachedCheckpointFiles();
assertThat(matchedFiles).hasSize(22);
for (var fileWithCheckpoints : matchedFiles) {
assertThat(fileWithCheckpoints).satisfies(new Condition<>() {
@Override
public boolean matches(Path file) {
long length = file.toFile().length();
return length == kibiBytes(1) || length == CURRENT_FORMAT_LOG_HEADER_SIZE;
}
});
}
}
Aggregations