use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class DegreesRebuildFromStoreTest method skipNotUsedRecordsOnDegreeStoreRebuild.
@Test
void skipNotUsedRecordsOnDegreeStoreRebuild() throws Exception {
// given a dataset containing mixed sparse and dense nodes with relationships in random directions,
// where some chains have been marked as having external degrees
int denseThreshold = dense_node_threshold.defaultValue();
DatabaseLayout layout = DatabaseLayout.ofFlat(directory.homePath());
int[] relationshipTypes;
MutableLongLongMap expectedDegrees = LongLongMaps.mutable.empty();
try (Lifespan life = new Lifespan()) {
RecordStorageEngine storageEngine = openStorageEngine(layout, denseThreshold);
relationshipTypes = createRelationshipTypes(storageEngine);
life.add(storageEngine);
generateData(storageEngine, denseThreshold, relationshipTypes);
storageEngine.relationshipGroupDegreesStore().accept((groupId, direction, degree) -> expectedDegrees.put(combinedKeyOnGroupAndDirection(groupId, direction), degree), NULL);
assertThat(expectedDegrees.isEmpty()).isFalse();
RelationshipGroupStore groupStore = storageEngine.testAccessNeoStores().getRelationshipGroupStore();
long highId = groupStore.getHighId();
assertThat(highId).isGreaterThan(1);
for (int i = 10; i < highId; i++) {
RelationshipGroupRecord record = groupStore.getRecord(i, new RelationshipGroupRecord(i), RecordLoad.ALWAYS, NULL);
record.setInUse(false);
groupStore.updateRecord(record, NULL);
}
storageEngine.flushAndForce(NULL);
}
// when
directory.getFileSystem().deleteFile(layout.relationshipGroupDegreesStore());
try (Lifespan life = new Lifespan()) {
RecordStorageEngine storageEngine = assertDoesNotThrow(() -> life.add(openStorageEngine(layout, denseThreshold)));
// then
storageEngine.relationshipGroupDegreesStore().accept((groupId, direction, degree) -> {
long key = combinedKeyOnGroupAndDirection(groupId, direction);
assertThat(expectedDegrees.containsKey(key)).isTrue();
long expectedDegree = expectedDegrees.get(key);
expectedDegrees.remove(key);
assertThat(degree).isEqualTo(expectedDegree);
}, NULL);
assertThat(expectedDegrees.size()).isGreaterThan(0);
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class CompositeDatabaseAvailabilityGuardTest method stopOfAvailabilityGuardDeregisterItInCompositeParent.
@Test
void stopOfAvailabilityGuardDeregisterItInCompositeParent() throws Exception {
int initialGuards = compositeGuard.getGuards().size();
DatabaseAvailabilityGuard firstGuard = createDatabaseAvailabilityGuard(randomNamedDatabaseId(), mockClock, compositeGuard);
DatabaseAvailabilityGuard secondGuard = createDatabaseAvailabilityGuard(randomNamedDatabaseId(), mockClock, compositeGuard);
firstGuard.start();
secondGuard.start();
assertEquals(2, countNewGuards(initialGuards));
new Lifespan(firstGuard).close();
assertEquals(1, countNewGuards(initialGuards));
new Lifespan(secondGuard).close();
assertEquals(0, countNewGuards(initialGuards));
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class SetInitialPasswordCommand method realUsersExist.
private boolean realUsersExist(Config config) {
boolean result = false;
Path authFile = CommunitySecurityModule.getUserRepositoryFile(config);
if (ctx.fs().fileExists(authFile)) {
result = true;
// Check if it only contains the default neo4j user
FileUserRepository userRepository = new FileUserRepository(ctx.fs(), authFile, NullLogProvider.getInstance());
try (Lifespan life = new Lifespan(userRepository)) {
ListSnapshot<User> users = userRepository.getSnapshot();
if (users.values().size() == 1) {
User user = users.values().get(0);
if (INITIAL_USER_NAME.equals(user.name()) && user.credentials().matchesPassword(UTF8.encode(INITIAL_PASSWORD))) {
// We allow overwriting an unmodified default neo4j user
result = false;
}
}
} catch (IOException e) {
// Do not allow overwriting if we had a problem reading the file
}
}
return result;
}
Aggregations