use of org.neo4j.kernel.impl.transaction.log.files.LogFile 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.LogFile in project neo4j by neo4j.
the class TransactionLogFileTest method shouldReadOlderLogs.
@Test
void shouldReadOlderLogs() throws Exception {
// GIVEN
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
// WHEN
LogFile logFile = logFiles.getLogFile();
TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
var writer = logWriter.getChannel();
LogPosition position1 = logWriter.getCurrentPosition();
int intValue = 45;
long longValue = 4854587;
byte[] someBytes = someBytes(40);
writer.putInt(intValue);
writer.putLong(longValue);
writer.put(someBytes, someBytes.length);
logFile.flush();
LogPosition position2 = logWriter.getCurrentPosition();
long longValue2 = 123456789L;
writer.putLong(longValue2);
writer.put(someBytes, someBytes.length);
logFile.flush();
// THEN
try (ReadableChannel reader = logFile.getReader(position1)) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
try (ReadableChannel reader = logFile.getReader(position2)) {
assertEquals(longValue2, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class TransactionLogFileTest method shouldWriteSomeDataIntoTheLog.
@Test
void shouldWriteSomeDataIntoTheLog() throws Exception {
// GIVEN
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
// WHEN
LogFile logFile = logFiles.getLogFile();
TransactionLogWriter transactionLogWriter = logFile.getTransactionLogWriter();
var channel = transactionLogWriter.getChannel();
LogPosition currentPosition = transactionLogWriter.getCurrentPosition();
int intValue = 45;
long longValue = 4854587;
channel.putInt(intValue);
channel.putLong(longValue);
logFile.flush();
// THEN
try (ReadableChannel reader = logFile.getReader(currentPosition)) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class TransactionLogFileTest method shouldBatchUpMultipleWaitingForceRequests.
@Test
void shouldBatchUpMultipleWaitingForceRequests() throws Throwable {
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var capturingChannel = wrappingFileSystem.getCapturingChannel();
var flushesBefore = capturingChannel.getFlushCounter().get();
var writesBefore = capturingChannel.getWriteAllCounter().get();
ReentrantLock writeAllLock = capturingChannel.getWriteAllLock();
writeAllLock.lock();
int executors = 10;
var executorService = Executors.newFixedThreadPool(executors);
try {
List<Future<?>> futures = Stream.iterate(0, i -> i + 1).limit(executors).map(v -> executorService.submit(() -> logFile.forceAfterAppend(LogAppendEvent.NULL))).collect(toList());
while (!writeAllLock.hasQueuedThreads()) {
parkNanos(100);
}
writeAllLock.unlock();
assertThat(futures).hasSize(executors);
Futures.getAll(futures);
} finally {
if (writeAllLock.isLocked()) {
writeAllLock.unlock();
}
executorService.shutdownNow();
}
assertThat(capturingChannel.getFlushCounter().get() - flushesBefore).isLessThanOrEqualTo(executors);
assertThat(capturingChannel.getWriteAllCounter().get() - writesBefore).isLessThanOrEqualTo(executors);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class AbstractLogTailScannerTest method logFile.
LogCreator logFile(Entry... entries) {
return (logVersion, positions) -> {
try {
AtomicLong lastTxId = new AtomicLong();
logVersionRepository.setCurrentLogVersion(logVersion, NULL);
logVersionRepository.setCheckpointLogVersion(logVersion, NULL);
LifeSupport logFileLife = new LifeSupport();
logFileLife.start();
logFileLife.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var checkpointFile = logFiles.getCheckpointFile();
int previousChecksum = BASE_TX_CHECKSUM;
try {
TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
LogEntryWriter writer = logWriter.getWriter();
for (Entry entry : entries) {
LogPosition currentPosition = logWriter.getCurrentPosition();
positions.put(entry, currentPosition);
if (entry instanceof StartEntry) {
writer.writeStartEntry(0, 0, previousChecksum, new byte[0]);
} else if (entry instanceof CommitEntry) {
CommitEntry commitEntry = (CommitEntry) entry;
previousChecksum = writer.writeCommitEntry(commitEntry.txId, 0);
lastTxId.set(commitEntry.txId);
} else if (entry instanceof CheckPointEntry) {
CheckPointEntry checkPointEntry = (CheckPointEntry) entry;
Entry target = checkPointEntry.withPositionOfEntry;
LogPosition logPosition = target != null ? positions.get(target) : currentPosition;
assert logPosition != null : "No registered log position for " + target;
writeCheckpoint(writer, checkpointFile, logPosition);
} else if (entry instanceof PositionEntry) {
// Don't write anything, this entry is just for registering a position so that
// another CheckPointEntry can refer to it
} else {
throw new IllegalArgumentException("Unknown entry " + entry);
}
}
} finally {
logFileLife.shutdown();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
Aggregations