Search in sources :

Example 1 with LogRotationMonitorAdapter

use of org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitorAdapter in project neo4j by neo4j.

the class TransactionLogFileIT method doNotScanDirectoryOnRotate.

@Test
@EnabledOnOs(OS.LINUX)
void doNotScanDirectoryOnRotate() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withTransactionIdStore(transactionIdStore).withLogVersionRepository(logVersionRepository).withStoreId(StoreId.UNKNOWN).build();
    life.add(logFiles);
    life.start();
    MutableLong rotationObservedVersion = new MutableLong();
    LogRotation logRotation = FileLogRotation.transactionLogRotation(logFiles, Clock.systemUTC(), new DatabaseHealth(NO_OP, NullLog.getInstance()), new LogRotationMonitorAdapter() {

        @Override
        public void startRotation(long currentLogVersion) {
            rotationObservedVersion.setValue(currentLogVersion);
        }
    });
    for (int i = 0; i < 6; i++) {
        for (Path path : logFiles.logFiles()) {
            FileUtils.deleteFile(path);
        }
        logRotation.rotateLogFile(LogAppendEvent.NULL);
    }
    assertEquals(5, rotationObservedVersion.getValue());
    assertEquals(6, logFiles.getLogFile().getCurrentLogVersion());
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) Path(java.nio.file.Path) MutableLong(org.apache.commons.lang3.mutable.MutableLong) FileLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogRotationMonitorAdapter(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitorAdapter) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Example 2 with LogRotationMonitorAdapter

use of org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitorAdapter in project neo4j by neo4j.

the class TestStartTransactionDuringLogRotation method setUp.

@BeforeEach
void setUp() throws InterruptedException {
    executor = Executors.newCachedThreadPool();
    startLogRotationLatch = new CountDownLatch(1);
    completeLogRotationLatch = new CountDownLatch(1);
    writerStopped = new AtomicBoolean();
    LogRotationMonitor rotationListener = new LogRotationMonitorAdapter() {

        @Override
        public void startRotation(long currentLogVersion) {
            startLogRotationLatch.countDown();
            try {
                completeLogRotationLatch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    };
    monitors.addMonitorListener(rotationListener);
    label = Label.label("Label");
    rotationFuture = t2.execute(forceLogRotation(database));
    // Waiting for the writer task to start a log rotation
    startLogRotationLatch.await();
// Then we should be able to start a transaction, though perhaps not be able to finish it.
// This is what the individual test methods will be doing.
// The test passes when transaction.close completes within the test timeout, that is, it didn't deadlock.
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogRotationMonitor(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor) CountDownLatch(java.util.concurrent.CountDownLatch) LogRotationMonitorAdapter(org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitorAdapter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LogRotationMonitorAdapter (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitorAdapter)2 Path (java.nio.file.Path)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)1 FileLogRotation (org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation)1 LogRotation (org.neo4j.kernel.impl.transaction.log.rotation.LogRotation)1 LogRotationMonitor (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor)1 DatabaseHealth (org.neo4j.monitoring.DatabaseHealth)1