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);
}
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();
}
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());
}
}
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();
}
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);
}
}
}
Aggregations