use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class RollbackIdLeakIT method nonClean.
private DbRestarter nonClean() {
return new DbRestarter() {
private DatabaseManagementService dbms;
private EphemeralFileSystemAbstraction fsSnapshot;
@Override
public GraphDatabaseService start() {
return start(fs);
}
@Override
public GraphDatabaseService restart() {
fsSnapshot = fs.snapshot();
dbms.shutdown();
return start(fsSnapshot);
}
@Override
public void close() throws IOException {
dbms.shutdown();
fsSnapshot.close();
}
private GraphDatabaseService start(EphemeralFileSystemAbstraction fs) {
dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(fs).build();
return dbms.database(DEFAULT_DATABASE_NAME);
}
};
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class RandomPageCacheTestHarness method runIteration.
@SuppressWarnings("unchecked")
private void runIteration(long timeout, TimeUnit unit) throws Exception {
assert filePageSize % recordFormat.getRecordSize() == 0 : "File page size must be a multiple of the record size";
if (!fixedRandomSeed) {
randomSeed = ThreadLocalRandom.current().nextLong();
}
FileSystemAbstraction fs = this.fs;
Path[] files = buildFileNames();
RandomAdversary adversary = new RandomAdversary(mischiefRate, failureRate, errorRate);
adversary.setProbabilityFactor(0.0);
if (useAdversarialIO) {
adversary.setSeed(randomSeed);
fs = new AdversarialFileSystemAbstraction(adversary, fs);
}
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
JobScheduler jobScheduler = new ThreadPoolJobScheduler();
MuninnPageCache cache = new MuninnPageCache(swapperFactory, jobScheduler, MuninnPageCache.config(cachePageCount).pageCacheTracer(tracer));
if (filePageSize == 0) {
filePageSize = cache.pageSize();
}
cache.setPrintExceptionsOnClose(false);
Map<Path, PagedFile> fileMap = new HashMap<>(files.length);
for (int i = 0; i < Math.min(files.length, initialMappedFiles); i++) {
Path file = files[i];
fileMap.put(file, cache.map(file, filePageSize, DEFAULT_DATABASE_NAME));
}
plan = plan(cache, files, fileMap);
AtomicBoolean stopSignal = new AtomicBoolean();
Callable<Void> planRunner = new PlanRunner(plan, stopSignal, profiler);
Future<Void>[] futures = new Future[concurrencyLevel];
for (int i = 0; i < concurrencyLevel; i++) {
futures[i] = executorService.submit(planRunner);
}
if (preparation != null) {
preparation.run(cache, this.fs, plan.getFilesTouched());
}
adversary.setProbabilityFactor(1.0);
plan.start();
long deadlineMillis = System.currentTimeMillis() + unit.toMillis(timeout);
long now;
try {
for (Future<Void> future : futures) {
now = System.currentTimeMillis();
if (deadlineMillis < now) {
throw new TimeoutException();
}
future.get(deadlineMillis - now, TimeUnit.MILLISECONDS);
}
adversary.setProbabilityFactor(0.0);
runVerificationPhase(cache);
} finally {
stopSignal.set(true);
adversary.setProbabilityFactor(0.0);
try {
for (Future<Void> future : futures) {
future.get(10, TimeUnit.SECONDS);
}
} catch (InterruptedException | TimeoutException e) {
for (Future<Void> future : futures) {
future.cancel(true);
}
throw new RuntimeException(e);
}
try {
plan.close();
cache.close();
jobScheduler.close();
if (this.fs instanceof EphemeralFileSystemAbstraction) {
this.fs.close();
this.fs = new EphemeralFileSystemAbstraction();
} else {
for (Path file : files) {
Files.delete(file);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class SingleFilePageSwapperTest method setUp.
@BeforeEach
void setUp() {
path = Path.of("file").normalize();
ephemeralFileSystem = new EphemeralFileSystemAbstraction();
fileSystem = new DefaultFileSystemAbstraction();
threadRegistryFactory = new ThreadRegistryFactory();
operationExecutor = Executors.newSingleThreadExecutor(threadRegistryFactory);
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.
/**
* Reading a node command might leave a node record which referred to
* labels in one or more dynamic records as marked as heavy even if that
* node already had references to dynamic records, changed in a transaction,
* but had no labels on that node changed within that same transaction.
* Now defensively only marks as heavy if there were one or more dynamic
* records provided when providing the record object with the label field
* value. This would give the opportunity to load the dynamic records the
* next time that record would be ensured heavy.
*/
@Test
void shouldRecoverNodeWithDynamicLabelRecords() {
// GIVEN
managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(filesystem).impermanent().build();
database = managementService.database(DEFAULT_DATABASE_NAME);
Node node;
Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
try (Transaction tx = database.beginTx()) {
node = tx.createNode(labels);
tx.commit();
}
// WHEN
try (Transaction tx = database.beginTx()) {
node = tx.getNodeById(node.getId());
node.setProperty("prop", "value");
tx.commit();
}
EphemeralFileSystemAbstraction snapshot = filesystem.snapshot();
managementService.shutdown();
managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(snapshot).impermanent().build();
database = managementService.database(DEFAULT_DATABASE_NAME);
// THEN
try (Transaction tx = database.beginTx()) {
node = tx.getNodeById(node.getId());
for (Label label : labels) {
assertTrue(node.hasLabel(label));
}
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class RecoveryRequiredCheckerTest method createSomeDataAndCrash.
private static EphemeralFileSystemAbstraction createSomeDataAndCrash(Path store, Config config) throws IOException {
try (EphemeralFileSystemAbstraction ephemeralFs = new EphemeralFileSystemAbstraction()) {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(store).setFileSystem(ephemeralFs).setConfig(config).build();
final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
EphemeralFileSystemAbstraction snapshot = ephemeralFs.snapshot();
managementService.shutdown();
return snapshot;
}
}
Aggregations