use of org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel in project neo4j by neo4j.
the class ReversedSingleFileTransactionCursorTest method writeTransactions.
private void writeTransactions(int transactionCount, int minTransactionSize, int maxTransactionSize) throws IOException {
FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
TransactionLogWriter writer = logFile.getTransactionLogWriter();
int previousChecksum = BASE_TX_CHECKSUM;
for (int i = 0; i < transactionCount; i++) {
previousChecksum = writer.append(tx(random.intBetween(minTransactionSize, maxTransactionSize)), ++txId, previousChecksum);
}
channel.prepareForFlush().flush();
// Don't close the channel, LogFile owns it
}
use of org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel in project neo4j by neo4j.
the class CorruptedLogsTruncatorTest method truncateLogWithCorruptionThatLooksLikePreAllocatedZeros.
@Test
void truncateLogWithCorruptionThatLooksLikePreAllocatedZeros() throws IOException {
life.start();
generateTransactionLogFiles(logFiles);
var logFile = logFiles.getLogFile();
long highestLogVersion = logFile.getHighestLogVersion();
long fileSizeBeforeAppend = Files.size(logFile.getHighestLogFile());
LogPosition endOfLogsPosition = new LogPosition(highestLogVersion, fileSizeBeforeAppend);
FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
for (int i = 0; i < RandomUtils.nextInt(100, 10240); i++) {
channel.putLong(0);
}
// corruption byte
channel.put((byte) 7);
for (int i = 0; i < RandomUtils.nextInt(10, 1024); i++) {
channel.putLong(0);
}
channel.prepareForFlush().flush();
long fileAfterZeroAppend = Files.size(logFile.getHighestLogFile());
assertNotEquals(fileSizeBeforeAppend, fileAfterZeroAppend);
logPruner.truncate(endOfLogsPosition);
assertEquals(TOTAL_NUMBER_OF_LOG_FILES, logFiles.logFiles().length);
assertEquals(fileSizeBeforeAppend, Files.size(logFile.getHighestLogFile()));
Path corruptedLogsDirectory = databaseDirectory.resolve(CORRUPTED_TX_LOGS_BASE_NAME);
assertTrue(Files.exists(corruptedLogsDirectory));
File[] files = corruptedLogsDirectory.toFile().listFiles();
assertNotNull(files);
assertEquals(1, files.length);
}
use of org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel 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.FlushablePositionAwareChecksumChannel 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.FlushablePositionAwareChecksumChannel in project neo4j by neo4j.
the class CorruptedLogsTruncatorTest method doNotTruncateLogWithPreAllocatedZeros.
@Test
void doNotTruncateLogWithPreAllocatedZeros() throws IOException {
life.start();
generateTransactionLogFiles(logFiles);
var logFile = logFiles.getLogFile();
long highestLogVersion = logFile.getHighestLogVersion();
long fileSizeBeforeAppend = Files.size(logFile.getHighestLogFile());
LogPosition endOfLogsPosition = new LogPosition(highestLogVersion, fileSizeBeforeAppend);
FlushablePositionAwareChecksumChannel channel = logFile.getTransactionLogWriter().getChannel();
for (int i = 0; i < RandomUtils.nextInt(100, 10240); i++) {
channel.putLong(0);
}
channel.prepareForFlush().flush();
long fileAfterZeroAppend = Files.size(logFile.getHighestLogFile());
assertNotEquals(fileSizeBeforeAppend, fileAfterZeroAppend);
logPruner.truncate(endOfLogsPosition);
assertEquals(TOTAL_NUMBER_OF_LOG_FILES, logFiles.logFiles().length);
assertEquals(fileAfterZeroAppend, Files.size(logFile.getHighestLogFile()));
assertNotEquals(fileSizeBeforeAppend, Files.size(logFile.getHighestLogFile()));
assertTrue(ArrayUtils.isEmpty(databaseDirectory.toFile().listFiles(File::isDirectory)));
}
Aggregations