Search in sources :

Example 1 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class SchemaIndexAcceptanceTest method crashAndRestart.

private void crashAndRestart() {
    EphemeralFileSystemAbstraction crashSnapshot = fs.snapshot();
    managementService.shutdown();
    db = newDb(crashSnapshot);
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction)

Example 2 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class BatchingTransactionAppenderConcurrencyTest method shouldHaveAllConcurrentAppendersSeePanic.

/*
     * There was an issue where if multiple concurrent appending threads did append and they moved on
     * to await a force, where the force would fail and the one doing the force would raise a panic...
     * the other threads may not notice the panic and move on to mark those transactions as committed
     * and notice the panic later (which would be too late).
     */
@Test
void shouldHaveAllConcurrentAppendersSeePanic() throws Throwable {
    // GIVEN
    Adversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), failMethod(TransactionLogFile.class, "force"));
    EphemeralFileSystemAbstraction efs = new EphemeralFileSystemAbstraction();
    FileSystemAbstraction fs = new AdversarialFileSystemAbstraction(adversary, efs);
    life.add(new FileSystemLifecycleAdapter(fs));
    DatabaseHealth databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogVersionRepository(logVersionRepository).withTransactionIdStore(transactionIdStore).withDatabaseHealth(databaseHealth).withLogEntryReader(new VersionAwareLogEntryReader(new TestCommandReaderFactory())).withStoreId(StoreId.UNKNOWN).build();
    life.add(logFiles);
    final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, databaseHealth));
    life.start();
    // WHEN
    int numberOfAppenders = 10;
    final CountDownLatch trap = new CountDownLatch(numberOfAppenders);
    final LogAppendEvent beforeForceTrappingEvent = new LogAppendEvent.Empty() {

        @Override
        public LogForceWaitEvent beginLogForceWait() {
            trap.countDown();
            awaitLatch(trap);
            return super.beginLogForceWait();
        }
    };
    Race race = new Race();
    for (int i = 0; i < numberOfAppenders; i++) {
        race.addContestant(() -> {
            // Good, we know that this test uses an adversarial file system which will throw
            // an exception in LogFile#force, and since all these transactions
            // will append and be forced in the same batch, where the force will fail then
            // all these transactions should fail. If there's any transaction not failing then
            // it just didn't notice the panic, which would be potentially hazardous.
            assertThrows(IOException.class, () -> appender.append(tx(), beforeForceTrappingEvent));
        });
    }
    // THEN perform the race. The relevant assertions are made inside the contestants.
    race.go();
}
Also used : FileSystemLifecycleAdapter(org.neo4j.io.fs.FileSystemLifecycleAdapter) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) CountingAdversary(org.neo4j.adversaries.CountingAdversary) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ClassGuardedAdversary(org.neo4j.adversaries.ClassGuardedAdversary) TransactionLogFile(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFile) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) TransactionLogFiles(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFiles) DatabasePanicEventGenerator(org.neo4j.kernel.monitoring.DatabasePanicEventGenerator) TestCommandReaderFactory(org.neo4j.kernel.impl.api.TestCommandReaderFactory) CountDownLatch(java.util.concurrent.CountDownLatch) LogAppendEvent(org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent) Race(org.neo4j.test.Race) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) Adversary(org.neo4j.adversaries.Adversary) CountingAdversary(org.neo4j.adversaries.CountingAdversary) ClassGuardedAdversary(org.neo4j.adversaries.ClassGuardedAdversary) Test(org.junit.jupiter.api.Test)

Example 3 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class ChannelOutputStreamTest method shouldStoreAByteAtBoundary.

@Test
void shouldStoreAByteAtBoundary() throws Exception {
    try (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) {
        Path workFile = testDirectory.file("a");
        fs.mkdirs(testDirectory.homePath());
        OutputStream out = fs.openAsOutputStream(workFile, false);
        // When I write a byte[] that is larger than the internal buffer in
        // ChannelOutputStream..
        byte[] b = new byte[8097];
        b[b.length - 1] = 7;
        out.write(b);
        out.flush();
        // Then it should get cleanly written and be readable
        InputStream in = fs.openAsInputStream(workFile);
        in.skip(8096);
        assertEquals(7, in.read());
    }
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Test(org.junit.jupiter.api.Test)

Example 4 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class EphemeralFileSystemRule method clear.

public void clear() throws Exception {
    fs.close();
    fs = new EphemeralFileSystemAbstraction();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction)

Example 5 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldCorrectlyDecideToAwaitMergeDependingOnProgress.

@Test
void shouldCorrectlyDecideToAwaitMergeDependingOnProgress() throws Throwable {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
    boolean closed = false;
    try {
        populator.add(batchOfUpdates(), NULL);
        // when
        Race race = new Race();
        race.addContestant(throwing(() -> populator.scanCompleted(nullInstance, populationWorkScheduler, NULL)));
        race.addContestant(throwing(() -> populator.close(false, NULL)));
        race.go();
        closed = true;
        // then regardless of who wins (close/merge) after close call returns no files should still be mapped
        EphemeralFileSystemAbstraction ephemeralFileSystem = (EphemeralFileSystemAbstraction) fs;
        ephemeralFileSystem.assertNoOpenFiles();
    } finally {
        if (!closed) {
            populator.close(true, NULL);
        }
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) Race(org.neo4j.test.Race) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)30 Test (org.junit.jupiter.api.Test)17 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 PageCache (org.neo4j.io.pagecache.PageCache)9 Path (java.nio.file.Path)7 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)7 Transaction (org.neo4j.graphdb.Transaction)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)2 Dependencies (org.neo4j.collection.Dependencies)2 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)2 Label (org.neo4j.graphdb.Label)2 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2