Search in sources :

Example 11 with Dependencies

use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.

the class NeoStoreDataSource method start.

@Override
public void start() throws IOException {
    dependencies = new Dependencies();
    life = new LifeSupport();
    schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
    labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
    dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
    IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
    dependencies.satisfyDependency(lockService);
    dependencies.satisfyDependency(indexConfigStore);
    life.add(indexConfigStore);
    // Monitor listeners
    LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
    monitors.addMonitorListener(loggingLogMonitor);
    life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
    // Upgrade the store before we begin
    RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
    upgradeStore(formats);
    // Build all modules and their services
    StorageEngine storageEngine = null;
    try {
        UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
        SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
        storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
        LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
        TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
        LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
        NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
        transactionLogModule.satisfyDependencies(dependencies);
        buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
        // At the time of writing this comes from the storage engine (IndexStoreView)
        PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
        final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
        kernelModule.satisfyDependencies(dependencies);
        // Do these assignments last so that we can ensure no cyclical dependencies exist
        this.storageEngine = storageEngine;
        this.transactionLogModule = transactionLogModule;
        this.kernelModule = kernelModule;
        dependencies.satisfyDependency(this);
        dependencies.satisfyDependency(updateableSchemaState);
        dependencies.satisfyDependency(storageEngine.storeReadLayer());
        dependencies.satisfyDependency(logEntryReader);
        dependencies.satisfyDependency(storageEngine);
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
        try {
            // Close the neostore, so that locks are released properly
            if (storageEngine != null) {
                storageEngine.forceClose();
            }
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    // NOTE: please make sure this is performed after having added everything to the life, in fact we would like
    // to perform the checkpointing as first step when the life is shutdown.
    life.add(lifecycleToTriggerCheckPointOnShutdown());
    try {
        life.start();
    } catch (Throwable e) {
        // Something unexpected happened during startup
        msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
        try {
            life.shutdown();
            // Close the neostore, so that locks are released properly
            storageEngine.forceClose();
        } catch (Exception closeException) {
            msgLog.error("Couldn't close neostore after startup failure", closeException);
        }
        throw Exceptions.launderedException(e);
    }
    /*
         * At this point recovery has completed and the datasource is ready for use. Whatever panic might have
         * happened before has been healed. So we can safely set the kernel health to ok.
         * This right now has any real effect only in the case of internal restarts (for example, after a store copy
         * in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
         * kernel panics.
         */
    databaseHealth.healed();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelSchemaStateStore(org.neo4j.kernel.impl.api.KernelSchemaStateStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Dependencies(org.neo4j.kernel.impl.util.Dependencies) DeleteStoresFromOtherLabelScanStoreProviders(org.neo4j.kernel.extension.dependency.DeleteStoresFromOtherLabelScanStoreProviders) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) UpdateableSchemaState(org.neo4j.kernel.impl.api.UpdateableSchemaState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)

Example 12 with Dependencies

use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.

the class BackupServiceIT method shouldContainTransactionsThatHappenDuringBackupProcess.

@Test
public void shouldContainTransactionsThatHappenDuringBackupProcess() throws Throwable {
    // given
    defaultBackupPortHostParams();
    Config defaultConfig = dbRule.getConfigCopy();
    dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
    Config withOnlineBackupDisabled = dbRule.getConfigCopy();
    final Barrier.Control barrier = new Barrier.Control();
    final GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    // create some data
    createAndIndexNode(db, 1);
    final DependencyResolver resolver = db.getDependencyResolver();
    long expectedLastTxId = resolver.resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
    // This monitor is added server-side...
    monitors.addMonitorListener(new StoreSnoopingMonitor(barrier));
    Dependencies dependencies = new Dependencies(resolver);
    dependencies.satisfyDependencies(defaultConfig, monitors, NullLogProvider.getInstance());
    OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
    backup.start();
    // when
    BackupService backupService = backupService();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(() -> {
        barrier.awaitUninterruptibly();
        createAndIndexNode(db, 1);
        resolver.resolveDependency(StorageEngine.class).flushAndForce(limiter);
        barrier.release();
    });
    BackupService.BackupOutcome backupOutcome = backupService.doFullBackup(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.FULL, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
    backup.stop();
    executor.shutdown();
    executor.awaitTermination(30, TimeUnit.SECONDS);
    // then
    checkPreviousCommittedTxIdFromLog(0, expectedLastTxId);
    File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    long txIdFromOrigin = MetaDataStore.getRecord(resolver.resolveDependency(PageCache.class), neoStore, Position.LAST_TRANSACTION_ID);
    checkLastCommittedTxIdInLogAndNeoStore(expectedLastTxId + 1, txIdFromOrigin);
    assertEquals(DbRepresentation.of(db), getBackupDbRepresentation());
    assertTrue(backupOutcome.isConsistent());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Config(org.neo4j.kernel.configuration.Config) Barrier(org.neo4j.test.Barrier) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) ExecutorService(java.util.concurrent.ExecutorService) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 13 with Dependencies

use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.

the class BackupServiceIT method backupsShouldBeMentionedInServerConsoleLog.

@Test
public void backupsShouldBeMentionedInServerConsoleLog() throws Throwable {
    // given
    defaultBackupPortHostParams();
    Config config = dbRule.getConfigCopy();
    dbRule.setConfig(OnlineBackupSettings.online_backup_enabled, "false");
    Config withOnlineBackupDisabled = dbRule.getConfigCopy();
    createAndIndexNode(dbRule, 1);
    final Log log = mock(Log.class);
    LogProvider logProvider = new LogProvider() {

        @Override
        public Log getLog(Class loggingClass) {
            return log;
        }

        @Override
        public Log getLog(String name) {
            return log;
        }
    };
    Logger logger = mock(Logger.class);
    when(log.infoLogger()).thenReturn(logger);
    LogService logService = mock(LogService.class);
    when(logService.getInternalLogProvider()).thenReturn(logProvider);
    Dependencies dependencies = new Dependencies(dbRule.getDependencyResolver());
    dependencies.satisfyDependencies(config, monitors, logService);
    OnlineBackupKernelExtension backup = (OnlineBackupKernelExtension) new OnlineBackupExtensionFactory().newInstance(new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, dependencies), DependenciesProxy.dependencies(dependencies, OnlineBackupExtensionFactory.Dependencies.class));
    backup.start();
    // when
    backupService().doFullBackup(BACKUP_HOST, backupPort, backupDir, ConsistencyCheck.NONE, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
    // then
    verify(logger).log("Full backup started...");
    verify(logger).log("Full backup finished.");
    // when
    createAndIndexNode(dbRule, 2);
    backupService().doIncrementalBackupOrFallbackToFull(BACKUP_HOST, backupPort, backupDir, ConsistencyCheck.NONE, withOnlineBackupDisabled, BackupClient.BIG_READ_TIMEOUT, false);
    backup.stop();
    // then
    verify(logger).log("Incremental backup started...");
    verify(logger).log("Incremental backup finished.");
}
Also used : NullLogProvider(org.neo4j.logging.NullLogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) LogProvider(org.neo4j.logging.LogProvider) Log(org.neo4j.logging.Log) Config(org.neo4j.kernel.configuration.Config) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Dependencies(org.neo4j.kernel.impl.util.Dependencies) Logger(org.neo4j.logging.Logger) LogService(org.neo4j.kernel.impl.logging.LogService) Test(org.junit.Test)

Example 14 with Dependencies

use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.

the class ArbiterBootstrapper method start.

@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
    Config config = getConfig(configFile, configOverrides);
    try {
        DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        life.add(new FileSystemLifecycleAdapter(fileSystem));
        life.add(new Neo4jJobScheduler());
        new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
    } catch (LifecycleException e) {
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
        if (cause instanceof ChannelException) {
            System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
        } else {
            System.err.println("ERROR: Unknown error");
            throw e;
        }
    }
    addShutdownHook();
    life.start();
    return 0;
}
Also used : FileSystemLifecycleAdapter(org.neo4j.io.fs.FileSystemLifecycleAdapter) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NotElectableElectionCredentialsProvider(org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider) Monitors(org.neo4j.kernel.monitoring.Monitors) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) ChannelException(org.jboss.netty.channel.ChannelException)

Example 15 with Dependencies

use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.

the class ArbiterBootstrapperIT method before.

@Before
public void before() throws Exception {
    directory = testDirectory.directory("temp");
    life = new LifeSupport();
    // So that the clients get started as they are added
    life.start();
    clients = new ClusterClient[2];
    for (int i = 1; i <= clients.length; i++) {
        Map<String, String> config = stringMap();
        config.put(cluster_server.name(), ":" + (5000 + i));
        config.put(server_id.name(), "" + i);
        config.put(initial_hosts.name(), ":5001");
        LifeSupport moduleLife = new LifeSupport();
        ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
        ClusterClient client = clusterClientModule.clusterClient;
        CountDownLatch latch = new CountDownLatch(1);
        client.addClusterListener(new ClusterListener.Adapter() {

            @Override
            public void enteredCluster(ClusterConfiguration configuration) {
                latch.countDown();
                client.removeClusterListener(this);
            }
        });
        life.add(moduleLife);
        clients[i - 1] = client;
        assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
    }
}
Also used : ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Adapter(org.neo4j.cluster.protocol.cluster.ClusterListener.Adapter) ClusterClient(org.neo4j.cluster.client.ClusterClient) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Before(org.junit.Before)

Aggregations

Dependencies (org.neo4j.kernel.impl.util.Dependencies)18 Test (org.junit.Test)9 Config (org.neo4j.kernel.configuration.Config)8 SimpleKernelContext (org.neo4j.kernel.impl.spi.SimpleKernelContext)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 File (java.io.File)5 IOException (java.io.IOException)5 PageCache (org.neo4j.io.pagecache.PageCache)5 Monitors (org.neo4j.kernel.monitoring.Monitors)5 KernelContext (org.neo4j.kernel.impl.spi.KernelContext)4 NullLogProvider (org.neo4j.logging.NullLogProvider)4 SimpleLogService (org.neo4j.kernel.impl.logging.SimpleLogService)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 InetSocketAddress (java.net.InetSocketAddress)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 TimeUnit (java.util.concurrent.TimeUnit)2 Stream (java.util.stream.Stream)2 Assert.assertNull (org.junit.Assert.assertNull)2 Assert.fail (org.junit.Assert.fail)2