Search in sources :

Example 16 with LifeSupport

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);
}
Also used : LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport)

Example 17 with LifeSupport

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();
}
Also used : ClusterManager.clusterOfSize(org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize) Map(java.util.Map) FileUtils(org.neo4j.io.fs.FileUtils) IOException(java.io.IOException) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) File(java.io.File) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) File(java.io.File) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager)

Example 18 with LifeSupport

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());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Node(org.neo4j.graphdb.Node) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 19 with LifeSupport

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();
    }
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 20 with LifeSupport

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);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Procedures(org.neo4j.kernel.impl.proc.Procedures) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Aggregations

LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)51 Test (org.junit.Test)22 IOException (java.io.IOException)14 File (java.io.File)12 Monitors (org.neo4j.kernel.monitoring.Monitors)12 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)6 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)6 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)5 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)5 Monitor (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor)5 Dependencies (org.neo4j.kernel.impl.util.Dependencies)5 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 URI (java.net.URI)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Config (org.neo4j.kernel.configuration.Config)4 UnableToCopyStoreFromOldMasterException (org.neo4j.kernel.ha.store.UnableToCopyStoreFromOldMasterException)4 KernelContext (org.neo4j.kernel.impl.spi.KernelContext)4