use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class RecoveryRequiredCheckerTest method recoverBrokenStoreWithConfig.
private void recoverBrokenStoreWithConfig(Config config) throws IOException {
try (EphemeralFileSystemAbstraction ephemeralFs = createSomeDataAndCrash(storeDir, config);
PageCache pageCache = pageCacheExtension.getPageCache(ephemeralFs)) {
RecoveryRequiredChecker recoveryChecker = getRecoveryChecker(ephemeralFs, pageCache, storageEngineFactory, config);
assertThat(recoveryChecker.isRecoveryRequiredAt(DatabaseLayout.of(config), INSTANCE)).isEqualTo(true);
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(ephemeralFs).setConfig(config).build();
managementService.shutdown();
assertThat(recoveryChecker.isRecoveryRequiredAt(databaseLayout, INSTANCE)).isEqualTo(false);
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class IndexedIdGeneratorRecoverabilityTest method simpleCrashTest.
@Test
void simpleCrashTest() throws Exception {
final EphemeralFileSystemAbstraction snapshot;
final long id1;
final long id2;
try (IdGenerator freelist = instantiateFreelist()) {
id1 = freelist.nextId(NULL);
id2 = freelist.nextId(NULL);
markUsed(freelist, id1, id2);
freelist.checkpoint(NULL);
markDeleted(freelist, id1, id2);
pageCache.flushAndForce();
snapshot = fs.snapshot();
}
try (PageCache newPageCache = getPageCache(snapshot);
IdGenerator freelist = instantiateFreelist()) {
markDeleted(freelist, id1, id2);
// Recovery is completed ^^^
freelist.start(NO_FREE_IDS, NULL);
markFree(freelist, id1, id2);
final ImmutableLongSet reused = LongSets.immutable.of(freelist.nextId(NULL), freelist.nextId(NULL));
assertEquals(LongSets.immutable.of(id1, id2), reused, "IDs are not reused");
} finally {
snapshot.close();
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method createIndex.
@BeforeAll
void createIndex() throws Exception {
final EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
fs.mkdirs(neo4jHome);
dbmsAction(neo4jHome, fs, NATIVE_BTREE10, // Data
db -> {
indexWithStringData(db, label);
databaseLayout = ((GraphDatabaseAPI) db).databaseLayout();
}, // Config
builder -> {
});
sourceSnapshot = fs.snapshot();
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class PageCacheSlowTest method mustNotRunOutOfSwapperAllocationSpace.
@Test
void mustNotRunOutOfSwapperAllocationSpace() throws Exception {
assumeTrue(fs instanceof EphemeralFileSystemAbstraction, "This test is file system agnostic, and too slow on a real file system");
configureStandardPageCache();
profiler.profile();
Path file = file("a");
int iterations = Short.MAX_VALUE * 3;
for (int i = 0; i < iterations; i++) {
try (PagedFile pagedFile = pageCache.map(file, filePageSize, DEFAULT_DATABASE_NAME)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
assertTrue(cursor.next());
}
}
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class SchemaAcceptanceTest method crashDuringIndexPopulationOfConstraint.
/**
* This test describes a problem where if you crash during index population
* when creating a constraint the constraint will never be created but the
* index will and after next startup only the index will be there.
*
* We need to specifically drop the index in separate transaction to be
* able to create the constraint again.
*
* A better behaviour would be that the index is never created and is not
* present after crash.
*/
@Test
void crashDuringIndexPopulationOfConstraint() throws InterruptedException {
// Given
trapPopulation.set(true);
otherThreadRule.execute(() -> {
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
tx.commit();
}
return null;
});
// When
// Crashing during index population of index backing a constraint
populationScanFinished.await();
EphemeralFileSystemAbstraction crash = fs.snapshot();
populationScanFinished.release();
// Then
// On next startup
controller.restartDbms(builder -> {
builder.setFileSystem(crash);
return builder;
});
// the index is online but constraint is missing... which is sub-optimal
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(1, TimeUnit.HOURS);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
Iterable<ConstraintDefinition> constraints = tx.schema().getConstraints();
Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
assertThat(count(constraints)).isEqualTo(0);
assertThat(count(indexes)).isEqualTo(1);
indexes.forEach(index -> assertThat(getIndexState(tx, index)).isEqualTo(ONLINE));
tx.commit();
}
// and we cannot drop the constraint because it was never created
{
QueryExecutionException e = assertThrows(QueryExecutionException.class, () -> {
try (Transaction tx = db.beginTx()) {
tx.execute("DROP CONSTRAINT `" + nameA + "`");
tx.commit();
}
});
assertThat(e).hasRootCauseInstanceOf(NoSuchConstraintException.class);
}
// and we cannot re-create the constraint because index is blocking us
{
ConstraintViolationException e = assertThrows(ConstraintViolationException.class, () -> {
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
tx.commit();
}
});
assertThat(e).hasRootCauseInstanceOf(IndexWithNameAlreadyExistsException.class);
}
// dropping the index in separate transaction
try (Transaction tx = db.beginTx()) {
tx.schema().getIndexByName(nameA).drop();
tx.commit();
}
// we can finally create the constraint again.
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
Iterable<ConstraintDefinition> constraints = tx.schema().getConstraints();
Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
assertThat(count(constraints)).isEqualTo(1);
assertThat(count(indexes)).isEqualTo(1);
indexes.forEach(index -> assertThat(getIndexState(tx, index)).isEqualTo(ONLINE));
tx.commit();
}
}
Aggregations