Search in sources :

Example 51 with LogProvider

use of org.neo4j.logging.LogProvider in project neo4j by neo4j.

the class BackupService method incrementalWithContext.

/**
     * Performs an incremental backup based off the given context. This means
     * receiving and applying selectively (i.e. irrespective of the actual state
     * of the target db) a set of transactions starting at the desired txId and
     * spanning up to the latest of the master
     *
     * @param targetDb The database that contains a previous full copy
     * @param context The context, containing transaction id to start streaming transaction from
     * @return A backup context, ready to perform
     */
private BackupOutcome incrementalWithContext(String sourceHostNameOrIp, int sourcePort, GraphDatabaseAPI targetDb, long timeout, RequestContext context) throws IncrementalBackupNotPossibleException {
    DependencyResolver resolver = targetDb.getDependencyResolver();
    ProgressTxHandler handler = new ProgressTxHandler();
    TransactionCommittingResponseUnpacker unpacker = new TransactionCommittingResponseUnpacker(resolver, DEFAULT_BATCH_SIZE, 0);
    Monitors monitors = resolver.resolveDependency(Monitors.class);
    LogProvider logProvider = resolver.resolveDependency(LogService.class).getInternalLogProvider();
    BackupClient client = new BackupClient(sourceHostNameOrIp, sourcePort, null, logProvider, targetDb.storeId(), timeout, unpacker, monitors.newMonitor(ByteCounterMonitor.class, BackupClient.class), monitors.newMonitor(RequestMonitor.class, BackupClient.class), new VersionAwareLogEntryReader<>());
    try (Lifespan lifespan = new Lifespan(unpacker, client)) {
        try (Response<Void> response = client.incrementalBackup(context)) {
            unpacker.unpackResponse(response, handler);
        }
    } catch (MismatchingStoreIdException e) {
        throw new RuntimeException(DIFFERENT_STORE, e);
    } catch (RuntimeException | IOException e) {
        if (e.getCause() != null && e.getCause() instanceof MissingLogDataException) {
            throw new IncrementalBackupNotPossibleException(TOO_OLD_BACKUP, e.getCause());
        }
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        throw new RuntimeException("Failed to perform incremental backup.", e);
    } catch (Throwable throwable) {
        throw new RuntimeException("Unexpected error", throwable);
    }
    return new BackupOutcome(handler.getLastSeenTransactionId(), true);
}
Also used : MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) IOException(java.io.IOException) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) DependencyResolver(org.neo4j.graphdb.DependencyResolver) NullLogProvider(org.neo4j.logging.NullLogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) LogProvider(org.neo4j.logging.LogProvider) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Monitors(org.neo4j.kernel.monitoring.Monitors) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogService(org.neo4j.kernel.impl.logging.LogService) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) MissingLogDataException(org.neo4j.kernel.impl.transaction.log.MissingLogDataException) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) ConnectException(java.net.ConnectException)

Example 52 with LogProvider

use of org.neo4j.logging.LogProvider in project neo4j by neo4j.

the class HazelcastClientTest method shouldReturnEmptyTopologyIfUnableToConnectToHazelcast.

@Test
public void shouldReturnEmptyTopologyIfUnableToConnectToHazelcast() throws Throwable {
    // given
    HazelcastConnector connector = mock(HazelcastConnector.class);
    LogProvider logProvider = mock(LogProvider.class);
    Log log = mock(Log.class);
    when(logProvider.getLog(any(Class.class))).thenReturn(log);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(connector.connectToHazelcast()).thenThrow(new IllegalStateException());
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient client = new HazelcastClient(connector, jobScheduler, logProvider, config(), myself);
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    Set<Member> members = asSet(makeMember(1), makeMember(2));
    when(cluster.getMembers()).thenReturn(members);
    // when
    client.start();
    jobScheduler.runJob();
    CoreTopology topology = client.coreServers();
    assertEquals(0, topology.members().size());
}
Also used : Log(org.neo4j.logging.Log) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) NullLogProvider(org.neo4j.logging.NullLogProvider) LogProvider(org.neo4j.logging.LogProvider) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 53 with LogProvider

use of org.neo4j.logging.LogProvider in project neo4j by neo4j.

the class StoreMigratorFrom20IT method shouldMigrate.

@Test
public void shouldMigrate() throws IOException, ConsistencyCheckIncompleteException {
    // WHEN
    StoreMigrator storeMigrator = new StoreMigrator(fs, pageCache, getConfig(), NullLogService.getInstance(), schemaIndexProvider);
    SchemaIndexMigrator indexMigrator = new SchemaIndexMigrator(fs, schemaIndexProvider, labelScanStoreProvider);
    upgrader(indexMigrator, storeMigrator).migrateIfNeeded(find20FormatStoreDirectory(storeDir.directory()));
    // THEN
    assertEquals(2, monitor.progresses().size());
    assertTrue(monitor.isStarted());
    assertTrue(monitor.isFinished());
    GraphDatabaseService database = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir.absolutePath()).newGraphDatabase();
    try {
        verifyDatabaseContents(database);
    } finally {
        // CLEANUP
        database.shutdown();
    }
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(storeDir.directory(), pageCache, fs, logProvider);
    try (NeoStores neoStores = storeFactory.openAllNeoStores(true)) {
        verifyNeoStore(neoStores);
    }
    assertConsistentStore(storeDir.directory());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NullLogProvider(org.neo4j.logging.NullLogProvider) LogProvider(org.neo4j.logging.LogProvider) EnterpriseGraphDatabaseFactory(org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreMigrator(org.neo4j.kernel.impl.storemigration.participant.StoreMigrator) SchemaIndexMigrator(org.neo4j.kernel.impl.storemigration.participant.SchemaIndexMigrator) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Test(org.junit.Test)

Example 54 with LogProvider

use of org.neo4j.logging.LogProvider in project neo4j by neo4j.

the class LuceneLabelScanStoreExtension method newInstance.

@Override
public LabelScanStoreProvider newInstance(KernelContext context, Dependencies dependencies) throws Throwable {
    Config config = dependencies.getConfig();
    boolean ephemeral = config.get(GraphDatabaseFacadeFactory.Configuration.ephemeral);
    FileSystemAbstraction fileSystem = dependencies.fileSystem();
    DirectoryFactory directoryFactory = directoryFactory(ephemeral, fileSystem);
    LuceneLabelScanIndexBuilder indexBuilder = getIndexBuilder(context, directoryFactory, fileSystem, config);
    LogProvider logger = dependencies.getLogService().getInternalLogProvider();
    Monitor loggingMonitor = new LoggingMonitor(logger.getLog(LuceneLabelScanStore.class), monitor);
    LuceneLabelScanStore scanStore = new LuceneLabelScanStore(indexBuilder, new FullLabelStream(dependencies.indexStoreView()), loggingMonitor);
    return new LabelScanStoreProvider(NAME, scanStore);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LoggingMonitor(org.neo4j.kernel.api.labelscan.LoggingMonitor) Monitor(org.neo4j.kernel.api.labelscan.LabelScanStore.Monitor) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) LoggingMonitor(org.neo4j.kernel.api.labelscan.LoggingMonitor) Config(org.neo4j.kernel.configuration.Config) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) FullLabelStream(org.neo4j.kernel.impl.api.scan.FullLabelStream)

Example 55 with LogProvider

use of org.neo4j.logging.LogProvider in project neo4j by neo4j.

the class ServerBootstrapper method start.

@Override
@SafeVarargs
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
    addShutdownHook();
    try {
        Config config = createConfig(homeDir, configFile, configOverrides);
        LogProvider userLogProvider = setupLogging(config);
        dependencies = dependencies.userLogProvider(userLogProvider);
        log = userLogProvider.getLog(getClass());
        config.setLogger(log);
        serverAddress = config.httpConnectors().stream().filter(c -> Encryption.NONE.equals(c.encryptionLevel())).findFirst().map((connector) -> config.get(connector.listen_address).toString()).orElse(serverAddress);
        checkCompatibility();
        server = createNeoServer(config, dependencies, userLogProvider);
        server.start();
        return OK;
    } catch (ServerStartupException e) {
        e.describeTo(log);
        return WEB_SERVER_STARTUP_ERROR_CODE;
    } catch (TransactionFailureException tfe) {
        String locationMsg = (server == null) ? "" : " Another process may be using database location " + server.getDatabase().getLocation();
        log.error(format("Failed to start Neo4j on %s.", serverAddress) + locationMsg, tfe);
        return GRAPH_DATABASE_STARTUP_ERROR_CODE;
    } catch (Exception e) {
        log.error(format("Failed to start Neo4j on %s.", serverAddress), e);
        return WEB_SERVER_STARTUP_ERROR_CODE;
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Config(org.neo4j.kernel.configuration.Config) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Aggregations

LogProvider (org.neo4j.logging.LogProvider)65 NullLogProvider (org.neo4j.logging.NullLogProvider)26 Config (org.neo4j.kernel.configuration.Config)16 File (java.io.File)15 Test (org.junit.Test)15 Log (org.neo4j.logging.Log)14 FormattedLogProvider (org.neo4j.logging.FormattedLogProvider)11 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)10 OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)9 Config (org.neo4j.configuration.Config)7 LogService (org.neo4j.kernel.impl.logging.LogService)7 DummyRaftableContentSerializer (org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)6 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)6 Monitors (org.neo4j.kernel.monitoring.Monitors)6 DependencyResolver (org.neo4j.graphdb.DependencyResolver)5 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)5 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4