use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LabelsAcceptanceTest method oversteppingMaxNumberOfLabelsShouldFailGracefully.
@Test
void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws IOException {
JobScheduler scheduler = JobSchedulerFactory.createScheduler();
try (EphemeralFileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();
Lifespan lifespan = new Lifespan(scheduler);
PageCache pageCache = new MuninnPageCache(swapper(fileSystem), scheduler, MuninnPageCache.config(1_000))) {
// Given
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependencies(createIdContextFactoryWithMaxedOutLabelTokenIds(fileSystem, scheduler));
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(fileSystem).noOpSystemGraphInitializer().setExternalDependencies(dependencies).impermanent().build();
GraphDatabaseService graphDatabase = managementService.database(DEFAULT_DATABASE_NAME);
// When
try (Transaction tx = graphDatabase.beginTx()) {
assertThrows(ConstraintViolationException.class, () -> tx.createNode().addLabel(Labels.MY_LABEL));
}
managementService.shutdown();
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class RecoveryWithTokenIndexesIT method recoverDatabaseWithTokenIndexes.
@ParameterizedTest(name = "{0}")
@MethodSource("arguments")
void recoverDatabaseWithTokenIndexes(String name, boolean checkpointIndexes) throws Throwable {
config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).build();
EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
GraphDatabaseService db = startDatabase(fs);
IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
if (checkpointIndexes) {
// Checkpoint to not make index creation part of the recovery.
checkPoint(db);
}
int numberOfEntities = 10;
for (int i = 0; i < numberOfEntities; i++) {
createEntities(db);
}
// Don't flush/checkpoint before taking the snapshot, to make the indexes need to recover (clean crash generation)
EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
managementService.shutdown();
fs.close();
try (PageCache cache = pageCacheExtension.getPageCache(crashedFs)) {
DatabaseLayout layout = DatabaseLayout.of(config);
recoverDatabase(layout, crashedFs, cache);
}
db = startDatabase(crashedFs);
// Verify that the default token indexes still exist
IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
awaitIndexesOnline(db);
try (Transaction tx = db.beginTx()) {
assertEquals(numberOfEntities, tx.findNodes(label).stream().count());
assertEquals(numberOfEntities, tx.findRelationships(type).stream().count());
}
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestLogPruning method newDb.
private GraphDatabaseAPI newDb(String logPruning, int rotateEveryNTransactions) {
this.rotateEveryNTransactions = rotateEveryNTransactions;
fs = new EphemeralFileSystemAbstraction();
TestDatabaseManagementServiceBuilder gdf = new TestDatabaseManagementServiceBuilder();
gdf.setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs));
DatabaseManagementServiceBuilder builder = gdf.impermanent();
builder.setConfig(keep_logical_logs, logPruning);
managementService = builder.build();
this.db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
files = db.getDependencyResolver().resolveDependency(LogFiles.class);
return db;
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseRecoveryIT method shouldSeeSameIndexUpdatesDuringRecoveryAsFromNormalIndexApplication.
@Test
void shouldSeeSameIndexUpdatesDuringRecoveryAsFromNormalIndexApplication() throws Exception {
// Previously indexes weren't really participating in recovery, instead there was an after-phase
// where nodes that was changed during recovery were reindexed. Do be able to do this reindexing
// the index had to support removing arbitrary entries based on node id alone. Lucene can do this,
// but at least at the time of writing this not the native index. For this the recovery process
// was changed to rewind neostore back to how it looked at the last checkpoint and then replay
// transactions from that point, including indexes. This test verifies that there's no mismatch
// between applying transactions normally and recovering them after a crash, index update wise.
// given
Path storeDir = directory.absolutePath();
EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
UpdateCapturingIndexProvider updateCapturingIndexProvider = new UpdateCapturingIndexProvider(IndexProvider.EMPTY, new HashMap<>());
GraphDatabaseAPI db = startDatabase(storeDir, fs, updateCapturingIndexProvider);
Label label = TestLabels.LABEL_ONE;
String key1 = "key1";
String key2 = "key2";
try (Transaction tx = db.beginTx()) {
tx.schema().indexFor(label).on(key1).create();
tx.schema().indexFor(label).on(key1).on(key2).create();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(10, SECONDS);
tx.commit();
}
checkPoint(db);
produceRandomNodePropertyAndLabelUpdates(db, random.intBetween(20, 40), label, key1, key2);
checkPoint(db);
Map<Long, Collection<IndexEntryUpdate<?>>> updatesAtLastCheckPoint = updateCapturingIndexProvider.snapshot();
// when
produceRandomNodePropertyAndLabelUpdates(db, random.intBetween(40, 100), label, key1, key2);
// Snapshot
flush(db);
EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
Map<Long, Collection<IndexEntryUpdate<?>>> updatesAtCrash = updateCapturingIndexProvider.snapshot();
// Crash and start anew
UpdateCapturingIndexProvider recoveredUpdateCapturingIndexProvider = new UpdateCapturingIndexProvider(IndexProvider.EMPTY, updatesAtLastCheckPoint);
long lastCommittedTxIdBeforeRecovered = lastCommittedTxId(db);
managementService.shutdown();
fs.close();
db = startDatabase(storeDir, crashedFs, recoveredUpdateCapturingIndexProvider);
long lastCommittedTxIdAfterRecovered = lastCommittedTxId(db);
Map<Long, Collection<IndexEntryUpdate<?>>> updatesAfterRecovery = recoveredUpdateCapturingIndexProvider.snapshot();
// then
assertEquals(lastCommittedTxIdBeforeRecovered, lastCommittedTxIdAfterRecovered);
assertSameUpdates(updatesAtCrash, updatesAfterRecovery);
managementService.shutdown();
crashedFs.close();
}
use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class AuthProceduresIT method setup.
@BeforeEach
void setup() throws InvalidAuthTokenException {
fs = new EphemeralFileSystemAbstraction();
DatabaseManagementServiceBuilder graphDatabaseFactory = new TestDatabaseManagementServiceBuilder().setFileSystem(fs).impermanent().setConfig(GraphDatabaseSettings.auth_enabled, true);
managementService = graphDatabaseFactory.build();
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
systemDb = (GraphDatabaseAPI) managementService.database(SYSTEM_DATABASE_NAME);
authManager = db.getDependencyResolver().resolveDependency(BasicSystemGraphRealm.class);
assertSuccess(login("neo4j", "neo4j"), "ALTER CURRENT USER SET PASSWORD FROM 'neo4j' TO 'temp'");
assertSuccess(login("neo4j", "temp"), "ALTER CURRENT USER SET PASSWORD FROM 'temp' TO 'neo4j'");
admin = login("neo4j", "neo4j");
}
Aggregations