use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class ConstraintRecoveryIT method shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails.
@Test
void shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails() {
// given
Path pathToDb = testDirectory.homePath();
TestDatabaseManagementServiceBuilder dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
dbFactory.setFileSystem(fs);
final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
final AtomicBoolean monitorCalled = new AtomicBoolean(false);
Monitors monitors = new Monitors();
monitors.addMonitorListener(new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanComplete() {
monitorCalled.set(true);
db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush(NULL);
storeInNeedOfRecovery[0] = fs.snapshot();
}
});
dbFactory.setMonitors(monitors);
// This test relies on behaviour that is specific to the Lucene populator, where uniqueness is controlled
// after index has been populated, which is why we're using NATIVE20 and index booleans (they end up in Lucene)
DatabaseManagementService managementService = configure(dbFactory.impermanent().setConfig(default_schema_provider, NATIVE30.providerName())).build();
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < 2; i++) {
tx.createNode(LABEL).setProperty(KEY, "true");
}
tx.commit();
}
assertThrows(ConstraintViolationException.class, () -> {
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(LABEL).assertPropertyIsUnique(KEY).create();
}
});
managementService.shutdown();
assertTrue(monitorCalled.get());
// when
dbFactory = new TestDatabaseManagementServiceBuilder(pathToDb);
dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
DatabaseManagementService secondManagementService = configure(dbFactory.impermanent()).build();
db = (GraphDatabaseAPI) secondManagementService.database(DEFAULT_DATABASE_NAME);
// then
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
}
try (Transaction transaction = db.beginTx()) {
assertEquals(2, Iterables.count(transaction.getAllNodes()));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(tx.schema().getConstraints())));
}
try (Transaction tx = db.beginTx()) {
IndexDefinition orphanedConstraintIndex = single(tx.schema().getIndexes(LABEL));
assertEquals(LABEL.name(), single(orphanedConstraintIndex.getLabels()).name());
assertEquals(KEY, single(orphanedConstraintIndex.getPropertyKeys()));
}
secondManagementService.shutdown();
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseRecoveryIT method shouldSeeTheSameRecordsAtCheckpointAsAfterReverseRecovery.
@Test
void shouldSeeTheSameRecordsAtCheckpointAsAfterReverseRecovery() throws Exception {
// given
EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(fs).impermanent().build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
produceRandomGraphUpdates(db, 100);
checkPoint(db);
EphemeralFileSystemAbstraction checkPointFs = fs.snapshot();
// when
produceRandomGraphUpdates(db, 100);
flush(db);
EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
managementService.shutdown();
fs.close();
Dependencies dependencies = new Dependencies();
Monitors monitors;
AtomicReference<EphemeralFileSystemAbstraction> reversedFs;
try (PageCache pageCache = pageCacheExtension.getPageCache(crashedFs)) {
dependencies.satisfyDependencies(pageCache);
monitors = new Monitors();
reversedFs = new AtomicReference<>();
monitors.addMonitorListener(new RecoveryMonitor() {
@Override
public void reverseStoreRecoveryCompleted(long checkpointTxId) {
try {
// Flush the page cache which will fished out of the GlobalModule at the point of constructing the database
pageCache.flushAndForce();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
// The stores should now be equal in content to the db as it was right after the checkpoint.
// Grab a snapshot so that we can compare later.
reversedFs.set(crashedFs.snapshot());
}
});
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(crashedFs).setExternalDependencies(dependencies).setMonitors(monitors).impermanent().build();
managementService.shutdown();
}
// then
fs.close();
try {
// Here we verify that the neostore contents, record by record are exactly the same when comparing
// the store as it was right after the checkpoint with the store as it was right after reverse recovery completed.
assertSameStoreContents(checkPointFs, reversedFs.get(), databaseLayout);
} finally {
IOUtils.closeAll(checkPointFs, reversedFs.get());
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestTxEntries method testStartEntryWrittenOnceOnRollback.
@Test
void testStartEntryWrittenOnceOnRollback() {
Path storeDir = testDirectory.homePath();
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(fs).impermanent().build();
final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
createSomeTransactions(db);
EphemeralFileSystemAbstraction snapshot = fs.snapshot();
managementService.shutdown();
managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(snapshot).impermanent().build();
managementService.shutdown();
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class KernelRecoveryTest method shouldHandleWritesProperlyAfterRecovery.
@Test
void shouldHandleWritesProperlyAfterRecovery() throws Exception {
// Given
GraphDatabaseService db = newDB(fileSystem, "main");
// We don't want to include any transactions that may have run on start-up since they
// will have run on start-up of rebuilt db already.
long txIdToExtractFrom = getLastClosedTransactionId((GraphDatabaseAPI) db) + 1;
long node1 = createNode(db, "k", "v1");
// And given the power goes out
List<TransactionRepresentation> transactions = new ArrayList<>();
long node2;
try (EphemeralFileSystemAbstraction crashedFs = fileSystem.snapshot()) {
managementService.shutdown();
db = newDB(crashedFs, "main");
node2 = createNode(db, "k", "v2");
extractTransactions((GraphDatabaseAPI) db, transactions, txIdToExtractFrom);
managementService.shutdown();
}
// Then both those nodes should be there, i.e. they are properly there in the log
GraphDatabaseService rebuilt = newDB(fileSystem, "rebuilt");
applyTransactions(transactions, (GraphDatabaseAPI) rebuilt);
try (Transaction tx = rebuilt.beginTx()) {
assertEquals("v1", tx.getNodeById(node1).getProperty("k"));
assertEquals("v2", tx.getNodeById(node2).getProperty("k"));
tx.commit();
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class EphemeralFileSystemRule method snapshot.
public EphemeralFileSystemAbstraction snapshot(Runnable action) throws Exception {
EphemeralFileSystemAbstraction snapshot = fs.snapshot();
try {
action.run();
} finally {
fs.close();
fs = snapshot;
}
return fs;
}
Aggregations