Search in sources :

Example 11 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class TransactionLogFileTest method shouldVisitLogFile.

@Test
void shouldVisitLogFile() throws Exception {
    // GIVEN
    LogFiles logFiles = buildLogFiles();
    life.start();
    life.add(logFiles);
    LogFile logFile = logFiles.getLogFile();
    var transactionLogWriter = logFile.getTransactionLogWriter();
    var writer = transactionLogWriter.getChannel();
    LogPosition position = transactionLogWriter.getCurrentPosition();
    for (int i = 0; i < 5; i++) {
        writer.put((byte) i);
    }
    logFile.flush();
    // WHEN/THEN
    final AtomicBoolean called = new AtomicBoolean();
    logFile.accept(channel -> {
        for (int i = 0; i < 5; i++) {
            assertEquals((byte) i, channel.get());
        }
        called.set(true);
        return true;
    }, position);
    assertTrue(called.get());
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Example 12 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class TransactionLogFileTest method shouldForceLogChannel.

@Test
void shouldForceLogChannel() 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();
    logFile.forceAfterAppend(LogAppendEvent.NULL);
    assertEquals(1, capturingChannel.getFlushCounter().get() - flushesBefore);
    assertEquals(1, capturingChannel.getWriteAllCounter().get() - writesBefore);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Example 13 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class TransactionLogFileTest method shouldWaitForOngoingForceToCompleteBeforeForcingAgain.

@Test
void shouldWaitForOngoingForceToCompleteBeforeForcingAgain() throws Throwable {
    LogFiles logFiles = buildLogFiles();
    life.start();
    life.add(logFiles);
    LogFile logFile = logFiles.getLogFile();
    var capturingChannel = wrappingFileSystem.getCapturingChannel();
    ReentrantLock writeAllLock = capturingChannel.getWriteAllLock();
    var flushesBefore = capturingChannel.getFlushCounter().get();
    var writesBefore = capturingChannel.getWriteAllCounter().get();
    writeAllLock.lock();
    int executors = 10;
    var executorService = Executors.newFixedThreadPool(executors);
    try {
        var future = executorService.submit(() -> logFile.forceAfterAppend(LogAppendEvent.NULL));
        while (!writeAllLock.hasQueuedThreads()) {
            parkNanos(100);
        }
        writeAllLock.unlock();
        var future2 = executorService.submit(() -> logFile.forceAfterAppend(LogAppendEvent.NULL));
        Futures.getAll(List.of(future, future2));
    } finally {
        if (writeAllLock.isLocked()) {
            writeAllLock.unlock();
        }
        executorService.shutdownNow();
    }
    assertThat(capturingChannel.getWriteAllCounter().get() - writesBefore).isEqualTo(2);
    assertThat(capturingChannel.getFlushCounter().get() - flushesBefore).isEqualTo(2);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ReentrantLock(java.util.concurrent.locks.ReentrantLock) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Example 14 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class TransactionLogFileTest method closeChannelThrowExceptionOnAttemptToAppendTransactionLogRecords.

@Test
void closeChannelThrowExceptionOnAttemptToAppendTransactionLogRecords() throws IOException {
    LogFiles logFiles = buildLogFiles();
    life.start();
    life.add(logFiles);
    LogFile logFile = logFiles.getLogFile();
    var channel = logFile.getTransactionLogWriter().getChannel();
    life.shutdown();
    assertThrows(Throwable.class, () -> channel.put((byte) 7));
    assertThrows(Throwable.class, () -> channel.putInt(7));
    assertThrows(Throwable.class, () -> channel.putLong(7));
    assertThrows(Throwable.class, () -> channel.putDouble(7));
    assertThrows(Throwable.class, () -> channel.putFloat(7));
    assertThrows(Throwable.class, () -> channel.putShort((short) 7));
    assertThrows(Throwable.class, () -> channel.put(new byte[] { 1, 2, 3 }, 3));
    assertThrows(IllegalStateException.class, logFile::flush);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Test(org.junit.jupiter.api.Test)

Example 15 with LogFiles

use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.

the class TransactionLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.

@Test
void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
    // GIVEN
    LogFiles logFiles = buildLogFiles();
    // WHEN
    life.start();
    life.add(logFiles);
    life.shutdown();
    // THEN
    Path file = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.getTransactionLogsDirectory(), fileSystem).withLogEntryReader(logEntryReader()).build().getLogFile().getLogFileForVersion(1L);
    LogHeader header = readLogHeader(fileSystem, file, INSTANCE);
    assertEquals(1L, header.getLogVersion());
    assertEquals(2L, header.getLastCommittedTxId());
}
Also used : Path(java.nio.file.Path) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.jupiter.api.Test)

Aggregations

LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)61 Test (org.junit.jupiter.api.Test)33 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)21 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)16 Path (java.nio.file.Path)13 IOException (java.io.IOException)10 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)10 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 StoreChannel (org.neo4j.io.fs.StoreChannel)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 UncheckedIOException (java.io.UncheckedIOException)3