Search in sources :

Example 11 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class AbstractInProcessNeo4jBuilder method build.

@Override
public InProcessNeo4j build() {
    Path userLogFile = serverFolder.resolve("neo4j.log");
    Path internalLogFile = serverFolder.resolve("debug.log");
    config.set(ServerSettings.third_party_packages, unmanagedExtentions.toList());
    config.set(GraphDatabaseSettings.store_internal_log_path, internalLogFile.toAbsolutePath());
    var certificates = serverFolder.resolve("certificates");
    if (disabledServer) {
        config.set(HttpConnector.enabled, false);
        config.set(HttpsConnector.enabled, false);
    }
    Config dbConfig = config.build();
    if (dbConfig.get(HttpsConnector.enabled) || dbConfig.get(BoltConnector.enabled) && dbConfig.get(BoltConnector.encryption_level) != BoltConnector.EncryptionLevel.DISABLED) {
        SelfSignedCertificateFactory.create(certificates);
        List<SslPolicyConfig> policies = List.of(SslPolicyConfig.forScope(HTTPS), SslPolicyConfig.forScope(BOLT));
        for (SslPolicyConfig policy : policies) {
            config.set(policy.enabled, Boolean.TRUE);
            config.set(policy.base_directory, certificates);
            config.set(policy.trust_all, true);
            config.set(policy.client_auth, ClientAuth.NONE);
        }
        dbConfig = config.build();
    }
    Neo4jLoggerContext loggerContext = LogConfig.createBuilder(new DefaultFileSystemAbstraction(), userLogFile, Level.INFO).withTimezone(dbConfig.get(db_timezone)).build();
    var userLogProvider = new Log4jLogProvider(loggerContext);
    GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies().userLogProvider(userLogProvider);
    dependencies = dependencies.extensions(buildExtensionList(dependencies));
    var managementService = createNeo(dbConfig, dependencies);
    InProcessNeo4j controls = new InProcessNeo4j(serverFolder, userLogFile, internalLogFile, managementService, dbConfig, userLogProvider);
    controls.start();
    try {
        fixtures.applyTo(controls);
    } catch (Exception e) {
        controls.close();
        throw e;
    }
    return controls;
}
Also used : Path(java.nio.file.Path) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) Neo4jLoggerContext(org.neo4j.logging.log4j.Neo4jLoggerContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) Config(org.neo4j.configuration.Config) LogConfig(org.neo4j.logging.log4j.LogConfig) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) GraphDatabaseDependencies(org.neo4j.graphdb.facade.GraphDatabaseDependencies) IOException(java.io.IOException)

Example 12 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class ConsistencyCheckService method runFullConsistencyCheck.

public Result runFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, final LogProvider logProvider, final FileSystemAbstraction fileSystem, final PageCache pageCache, DebugContext debugContext, Path reportDir, ConsistencyFlags consistencyFlags, PageCacheTracer pageCacheTracer, MemoryTracker memoryTracker) throws ConsistencyCheckIncompleteException {
    assertRecovered(databaseLayout, config, fileSystem, memoryTracker);
    Log outLog = logProvider.getLog(getClass());
    config.set(GraphDatabaseSettings.pagecache_warmup_enabled, false);
    LifeSupport life = new LifeSupport();
    final DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    DatabaseReadOnlyChecker readOnlyChecker = readOnly();
    StoreFactory factory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fileSystem, logProvider, pageCacheTracer, readOnlyChecker);
    // Don't start the counts stores here as part of life, instead only shut down. This is because it's better to let FullCheck
    // start it and add its missing/broken detection where it can report to user.
    ConsistencySummaryStatistics summary;
    final Path reportFile = chooseReportPath(reportDir);
    Log4jLogProvider reportLogProvider = new Log4jLogProvider(LogConfig.createBuilder(fileSystem, reportFile, Level.INFO).createOnDemand().withCategory(false).build());
    Log reportLog = reportLogProvider.getLog(getClass());
    Log log = new DuplicatingLog(outLog, reportLog);
    // Bootstrap kernel extensions
    Monitors monitors = new Monitors();
    JobScheduler jobScheduler = life.add(JobSchedulerFactory.createInitialisedScheduler());
    TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_RELATIONSHIP_TYPE));
    final RecoveryCleanupWorkCollector workCollector = RecoveryCleanupWorkCollector.ignore();
    DatabaseExtensions extensions = life.add(instantiateExtensions(databaseLayout, fileSystem, config, new SimpleLogService(logProvider), pageCache, jobScheduler, workCollector, // We use TOOL context because it's true, and also because it uses the 'single' operational mode, which is important.
    TOOL, monitors, tokenHolders, pageCacheTracer, readOnlyChecker));
    DefaultIndexProviderMap indexes = life.add(new DefaultIndexProviderMap(extensions, config));
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        long lastCommittedTransactionId = neoStores.getMetaDataStore().getLastCommittedTransactionId();
        CountsStoreManager countsStoreManager = life.add(new CountsStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
        RelationshipGroupDegreesStoreManager groupDegreesStoreManager = life.add(new RelationshipGroupDegreesStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
        // Load tokens before starting extensions, etc.
        try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_READER_TAG))) {
            tokenHolders.setInitialTokens(StoreTokens.allReadableTokens(neoStores), cursorContext);
        }
        life.start();
        IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(pageCache, databaseLayout, workCollector, readOnlyChecker, pageCacheTracer);
        life.add(indexStatisticsStore);
        int numberOfThreads = defaultConsistencyCheckThreadsNumber();
        DirectStoreAccess stores = new DirectStoreAccess(neoStores, indexes, tokenHolders, indexStatisticsStore, idGeneratorFactory);
        double memoryLimitLeewayFactor = config.get(GraphDatabaseInternalSettings.consistency_check_memory_limit_factor);
        FullCheck check = new FullCheck(progressFactory, numberOfThreads, consistencyFlags, config, debugContext, NodeBasedMemoryLimiter.defaultWithLeeway(memoryLimitLeewayFactor));
        summary = check.execute(pageCache, stores, countsStoreManager, groupDegreesStoreManager, null, pageCacheTracer, memoryTracker, log);
    } finally {
        life.shutdown();
        reportLogProvider.close();
    }
    if (!summary.isConsistent()) {
        log.warn("See '%s' for a detailed consistency report.", reportFile);
        return Result.failure(reportFile, summary);
    }
    return Result.success(reportFile, summary);
}
Also used : SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DuplicatingLog(org.neo4j.logging.DuplicatingLog) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Path(java.nio.file.Path) JobScheduler(org.neo4j.scheduler.JobScheduler) Log(org.neo4j.logging.Log) DuplicatingLog(org.neo4j.logging.DuplicatingLog) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) DatabaseExtensions(org.neo4j.kernel.extension.DatabaseExtensions) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) FullCheck(org.neo4j.consistency.checking.full.FullCheck) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Monitors(org.neo4j.monitoring.Monitors) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator)

Example 13 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class CheckConsistencyCommand method execute.

@Override
public void execute() {
    options.warnOnUsageOfDeprecatedOptions(spec, ctx);
    if (target.backup != null) {
        target.backup = target.backup.toAbsolutePath();
        if (!Files.isDirectory(target.backup)) {
            throw new CommandFailedException("Report directory path doesn't exist or not a directory: " + target.backup);
        }
    }
    Config config = loadNeo4jConfig(ctx.homeDir(), ctx.confDir(), additionalConfig);
    var memoryTracker = EmptyMemoryTracker.INSTANCE;
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        DatabaseLayout databaseLayout = Optional.ofNullable(target.backup).map(DatabaseLayout::ofFlat).orElseGet(() -> Neo4jLayout.of(config).databaseLayout(target.database.name()));
        checkDatabaseExistence(databaseLayout);
        try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
            checkDbState(databaseLayout, config, memoryTracker);
            // Only output progress indicator if a console receives the output
            ProgressMonitorFactory progressMonitorFactory = ProgressMonitorFactory.NONE;
            if (System.console() != null) {
                progressMonitorFactory = ProgressMonitorFactory.textual(System.out);
            }
            ConsistencyCheckService.Result consistencyCheckResult;
            try (Log4jLogProvider logProvider = Util.configuredLogProvider(config, System.out)) {
                consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, progressMonitorFactory, logProvider, fileSystem, verbose, options.getReportDir().normalize(), new ConsistencyFlags(options.isCheckGraph(), options.isCheckIndexes(), options.isCheckIndexStructure()));
            }
            if (!consistencyCheckResult.isSuccessful()) {
                throw new CommandFailedException(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
            }
        } catch (FileLockException e) {
            throw new CommandFailedException("The database is in use. Stop database '" + databaseLayout.getDatabaseName() + "' and try again.", e);
        } catch (CannotWriteException e) {
            throw new CommandFailedException("You do not have permission to check database consistency.", e);
        }
    } catch (ConsistencyCheckIncompleteException | IOException e) {
        throw new CommandFailedException("Consistency checking failed." + e.getMessage(), e);
    }
}
Also used : CannotWriteException(org.neo4j.commandline.dbms.CannotWriteException) FileLockException(org.neo4j.kernel.internal.locker.FileLockException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Closeable(java.io.Closeable) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout)

Example 14 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class NeoWebServerStartupLoggingIT method setupServer.

@BeforeClass
public static void setupServer() throws Exception {
    out = new ByteArrayOutputStream();
    webContainer = createNonPersistentContainer(new Log4jLogProvider(out));
}
Also used : Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BeforeClass(org.junit.BeforeClass)

Example 15 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class LockWorkFailureDump method dumpState.

public Path dumpState(Locks lm, LockWorker... workers) throws IOException {
    try (OutputStream out = Files.newOutputStream(file)) {
        LogProvider logProvider = new Log4jLogProvider(out);
        // * locks held by the lock manager
        lm.accept(new DumpLocksVisitor(logProvider.getLog(LockWorkFailureDump.class)));
        // * rag manager state;
        // * workers state
        Log log = logProvider.getLog(getClass());
        for (LockWorker worker : workers) {
            // - what each is doing and have up to now
            log.info("Worker %s", worker);
        }
        return file;
    }
}
Also used : LogProvider(org.neo4j.logging.LogProvider) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Log(org.neo4j.logging.Log) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) OutputStream(java.io.OutputStream)

Aggregations

Log4jLogProvider (org.neo4j.logging.log4j.Log4jLogProvider)15 Config (org.neo4j.configuration.Config)4 Neo4jLoggerContext (org.neo4j.logging.log4j.Neo4jLoggerContext)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)3 LogConfig (org.neo4j.logging.log4j.LogConfig)3 OutputStream (java.io.OutputStream)2 Test (org.junit.jupiter.api.Test)2 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)2 Node (org.neo4j.graphdb.Node)2 Log (org.neo4j.logging.Log)2 LogProvider (org.neo4j.logging.LogProvider)2 JobScheduler (org.neo4j.scheduler.JobScheduler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Closeable (java.io.Closeable)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1