use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class CorruptedLogsTruncatorTest method generateTransactionLogFiles.
private static void generateTransactionLogFiles(LogFiles logFiles) throws IOException {
LogFile logFile = logFiles.getLogFile();
FlushablePositionAwareChecksumChannel writer = logFile.getTransactionLogWriter().getChannel();
for (byte i = 0; i < 107; i++) {
writer.put(i);
writer.prepareForFlush();
if (logFile.rotationNeeded()) {
logFile.rotate();
}
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class DumpCommandIT method databaseThatRequireRecoveryIsNotDumpable.
@Test
void databaseThatRequireRecoveryIsNotDumpable() throws IOException {
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, testDirectory.getFileSystem()).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).withStoreId(StoreId.UNKNOWN).build();
try (Lifespan ignored = new Lifespan(logFiles)) {
LogFile logFile = logFiles.getLogFile();
LogEntryWriter writer = logFile.getTransactionLogWriter().getWriter();
writer.writeStartEntry(0x123456789ABCDEFL, logFile.getLogFileInformation().getLastEntryId() + 1, BASE_TX_CHECKSUM, new byte[] { 0 });
}
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
assertThat(commandFailed.getMessage()).startsWith("Active logical log detected, this might be a source of inconsistencies.");
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method addCorruptedCommandsToLastLogFile.
private void addCorruptedCommandsToLastLogFile(LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository(logFiles);
LogFiles internalLogFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(versionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withCommandReaderFactory(StorageEngineFactory.defaultStorageEngine().commandReaderFactory()).build();
try (Lifespan lifespan = new Lifespan(internalLogFiles)) {
LogFile transactionLogFile = internalLogFiles.getLogFile();
LogEntryWriter<FlushablePositionAwareChecksumChannel> realLogEntryWriter = transactionLogFile.getTransactionLogWriter().getWriter();
LogEntryWriter<FlushablePositionAwareChecksumChannel> wrappedLogEntryWriter = logEntryWriterWrapper.wrap(realLogEntryWriter);
StaticLogEntryWriterFactory<FlushablePositionAwareChecksumChannel> factory = new StaticLogEntryWriterFactory<>(wrappedLogEntryWriter);
TransactionLogWriter writer = new TransactionLogWriter(realLogEntryWriter.getChannel(), factory);
List<StorageCommand> commands = new ArrayList<>();
commands.add(new Command.PropertyCommand(new PropertyRecord(1), new PropertyRecord(2)));
commands.add(new Command.NodeCommand(new NodeRecord(2), new NodeRecord(3)));
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
transaction.setHeader(new byte[0], 0, 0, 0, 0, ANONYMOUS);
writer.append(transaction, 1000, BASE_TX_CHECKSUM);
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile 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.files.LogFile 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.");
}
Aggregations