use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionRangeDiagnosticsTest method logWithTransactionsInNextToOldestLog.
private static LogFiles logWithTransactionsInNextToOldestLog(long logVersion, long prevLogLastTxId) throws IOException {
LogFiles files = logWithTransactions(logVersion, logVersion + 1, prevLogLastTxId);
var logFile = files.getLogFile();
when(logFile.hasAnyEntries(logVersion)).thenReturn(false);
return files;
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class LogPruningTest method setUp.
@BeforeEach
void setUp() {
fs = mock(FileSystemAbstraction.class);
logFiles = mock(LogFiles.class);
LogFile logFile = mock(LogFile.class);
when(logFiles.getLogFile()).thenReturn(logFile);
when(logFiles.getCheckpointFile()).thenReturn(mock(CheckpointFile.class));
doAnswer(inv -> Path.of(String.valueOf(inv.getArguments()[0]))).when(logFile).getLogFileForVersion(anyLong());
logProvider = new AssertableLogProvider();
clock = mock(SystemNanoClock.class);
factory = mock(LogPruneStrategyFactory.class);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.
@Test
void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
// GIVEN
LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).withLogEntryReader(logEntryReader()).withStoreId(StoreId.UNKNOWN).build();
life.add(logFiles);
final AtomicBoolean end = new AtomicBoolean();
AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
TransactionIdStore txIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
monitoring.setLogFile(logFiles.getLogFile());
Health health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogRotation rotation = transactionLogRotation(logFiles, Clock.systemUTC(), health, monitoring);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, health));
// WHEN
Race race = new Race();
for (int i = 0; i < 4; i++) {
race.addContestant(() -> {
while (!end.get()) {
try {
appender.append(new TransactionToApply(sillyTransaction(1_000), CursorContext.NULL), LogAppendEvent.NULL);
} catch (Exception e) {
e.printStackTrace(System.out);
end.set(true);
fail(e.getMessage(), e);
}
}
});
}
race.addContestant(endAfterMax(250, MILLISECONDS, end, monitoring));
race.go();
// THEN
assertTrue(monitoring.numberOfRotations() > 0);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method skipLogFileWithoutHeader.
@Test
void skipLogFileWithoutHeader() throws IOException {
LogFiles logFiles = buildLogFiles();
life.add(logFiles);
life.start();
// simulate new file without header presence
logVersionRepository.incrementAndGetVersion(NULL);
fileSystem.write(logFiles.getLogFile().getLogFileForVersion(logVersionRepository.getCurrentLogVersion())).close();
transactionIdStore.transactionCommitted(5L, 5, 5L, NULL);
PhysicalLogicalTransactionStore.LogVersionLocator versionLocator = new PhysicalLogicalTransactionStore.LogVersionLocator(4L);
logFiles.getLogFile().accept(versionLocator);
LogPosition logPosition = versionLocator.getLogPosition();
assertEquals(1, logPosition.getLogVersion());
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method shouldCloseChannelInFailedAttemptToReadHeaderAfterOpen.
@Test
void shouldCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception {
// GIVEN a file which returns 1/2 log header size worth of bytes
FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withTransactionIdStore(transactionIdStore).withLogVersionRepository(logVersionRepository).withLogEntryReader(logEntryReader()).build();
int logVersion = 0;
Path logFile = logFiles.getLogFile().getLogFileForVersion(logVersion);
StoreChannel channel = mock(StoreChannel.class);
when(channel.read(any(ByteBuffer.class))).thenReturn(CURRENT_FORMAT_LOG_HEADER_SIZE / 2);
when(fs.fileExists(logFile)).thenReturn(true);
when(fs.read(eq(logFile))).thenReturn(channel);
// WHEN
assertThrows(IncompleteLogHeaderException.class, () -> logFiles.getLogFile().openForVersion(logVersion));
verify(channel).close();
}
Aggregations