use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class HighAvailabilityModeSwitcher method switchToMaster.
private void switchToMaster() {
final CancellationHandle cancellationHandle = new CancellationHandle();
startModeSwitching(() -> {
if (currentTargetState != HighAvailabilityMemberState.TO_MASTER) {
return;
}
// We just got scheduled. Maybe we are already obsolete - test
if (cancellationHandle.cancellationRequested()) {
msgLog.info("Switch to master cancelled on start.");
return;
}
componentSwitcher.switchToMaster();
if (cancellationHandle.cancellationRequested()) {
msgLog.info("Switch to master cancelled before ha communication started.");
return;
}
haCommunicationLife.shutdown();
haCommunicationLife = new LifeSupport();
try {
masterHaURI = switchToMaster.switchToMaster(haCommunicationLife, me);
canAskForElections.set(true);
} catch (Throwable e) {
msgLog.error("Failed to switch to master", e);
// Since this master switch failed, elect someone else
election.demote(instanceId);
}
}, cancellationHandle);
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class StoreMigratorTestUtil method buildClusterWithMasterDirIn.
public static ClusterManager.ManagedCluster buildClusterWithMasterDirIn(FileSystemAbstraction fs, final File legacyStoreDir, LifeSupport life, final Map<String, String> sharedConfig) throws Throwable {
File haRootDir = new File(legacyStoreDir.getParentFile(), "ha-migration");
fs.deleteRecursively(haRootDir);
ClusterManager clusterManager = new ClusterManager.Builder(haRootDir).withStoreDirInitializer((serverId, storeDir) -> {
if (// Initialize dir only for master, others will copy store from it
serverId == 1) {
FileUtils.copyRecursively(legacyStoreDir, storeDir);
}
}).withCluster(clusterOfSize(3)).withSharedConfig(sharedConfig).build();
life.add(clusterManager);
life.start();
return clusterManager.getCluster();
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class ShutdownOnIndexUpdateIT method shutdownWhileFinishingTransactionWithIndexUpdates.
@Test
public void shutdownWhileFinishingTransactionWithIndexUpdates() throws Exception {
GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
createConstraint(database);
waitIndexesOnline(database);
try (Transaction transaction = database.beginTx()) {
Node node = database.createNode(constraintIndexLabel);
node.setProperty(UNIQUE_PROPERTY_NAME, indexProvider.getAndIncrement());
DependencyResolver dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
NeoStoreDataSource dataSource = dependencyResolver.resolveDependency(NeoStoreDataSource.class);
LifeSupport dataSourceLife = dataSource.getLife();
TransactionCloseListener closeListener = new TransactionCloseListener(transaction);
dataSourceLife.addLifecycleListener(closeListener);
dataSource.stop();
assertTrue("Transaction should be closed and no exception should be thrown.", closeListener.isTransactionClosed());
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method shouldOpenCleanStore.
@Test
public void shouldOpenCleanStore() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache(1000);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
LifeSupport life = new LifeSupport();
PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
try {
// WHEN
life.start();
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class EnterpriseSecurityModule method setup.
@Override
public void setup(Dependencies dependencies) throws KernelException {
Config config = dependencies.config();
Procedures procedures = dependencies.procedures();
LogProvider logProvider = dependencies.logService().getUserLogProvider();
JobScheduler jobScheduler = dependencies.scheduler();
FileSystemAbstraction fileSystem = dependencies.fileSystem();
LifeSupport life = dependencies.lifeSupport();
SecurityLog securityLog = SecurityLog.create(config, dependencies.logService().getInternalLog(GraphDatabaseFacade.class), fileSystem, jobScheduler);
life.add(securityLog);
boolean allowTokenCreate = config.get(SecuritySettings.allow_publisher_create_token);
PredefinedRolesBuilder.setAllowPublisherTokenCreate(allowTokenCreate);
procedures.writerCreateToken(allowTokenCreate);
EnterpriseAuthAndUserManager authManager = newAuthManager(config, logProvider, securityLog, fileSystem, jobScheduler);
life.add(dependencies.dependencySatisfier().satisfyDependency(authManager));
// Register procedures
procedures.registerComponent(SecurityLog.class, (ctx) -> securityLog, false);
procedures.registerComponent(EnterpriseAuthManager.class, ctx -> authManager, false);
procedures.registerComponent(EnterpriseSecurityContext.class, ctx -> asEnterprise(ctx.get(SECURITY_CONTEXT)), true);
if (config.get(SecuritySettings.native_authentication_enabled) || config.get(SecuritySettings.native_authorization_enabled)) {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> authManager.getUserManager(asEnterprise(ctx.get(SECURITY_CONTEXT))), true);
if (config.get(SecuritySettings.auth_providers).size() > 1) {
procedures.registerProcedure(UserManagementProcedures.class, true, Optional.of("%s only applies to native users."));
} else {
procedures.registerProcedure(UserManagementProcedures.class, true);
}
} else {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> EnterpriseUserManager.NOOP, true);
}
procedures.registerProcedure(SecurityProcedures.class, true);
}
Aggregations