Search in sources :

Example 46 with Log

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

the class LoggingResourcePoolMonitorTest method testUpdatedTargetSizeOnlyOnChange.

@Test
public void testUpdatedTargetSizeOnlyOnChange() throws Exception {
    Log log = mock(Log.class);
    LoggingResourcePoolMonitor monitor = new LoggingResourcePoolMonitor(log);
    monitor.updatedTargetSize(10);
    verify(log, times(1)).debug(anyString());
    monitor.updatedTargetSize(10);
    verify(log, times(1)).debug(anyString());
    monitor.updatedTargetSize(11);
    verify(log, times(2)).debug(anyString());
}
Also used : Log(org.neo4j.logging.Log) Test(org.junit.Test)

Example 47 with Log

use of org.neo4j.logging.Log in project neo4j-documentation by neo4j.

the class CommunityServerBuilder method build.

public CommunityNeoServer build() throws IOException {
    if (dataDir == null && persistent) {
        throw new IllegalStateException("Must specify path");
    }
    final File configFile = buildBefore();
    Log log = logProvider.getLog(getClass());
    Config config = Config.fromFile(configFile).build();
    config.setLogger(log);
    return build(Optional.of(configFile), config, GraphDatabaseDependencies.newDependencies().userLogProvider(logProvider).monitors(new Monitors()));
}
Also used : Log(org.neo4j.logging.Log) Config(org.neo4j.kernel.configuration.Config) LegacySslPolicyConfig(org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig) Monitors(org.neo4j.kernel.monitoring.Monitors) File(java.io.File)

Example 48 with Log

use of org.neo4j.logging.Log in project neo4j-apoc-procedures by neo4j-contrib.

the class Periodic method iterateAndExecuteBatchedInSeparateThread.

private Stream<BatchAndTotalResult> iterateAndExecuteBatchedInSeparateThread(int batchsize, boolean parallel, boolean iterateList, long retries, Iterator<Map<String, Object>> iterator, Consumer<Map<String, Object>> consumer) {
    ExecutorService pool = parallel ? Pools.DEFAULT : Pools.SINGLE;
    List<Future<Long>> futures = new ArrayList<>(1000);
    long batches = 0;
    long start = System.nanoTime();
    AtomicLong count = new AtomicLong();
    AtomicInteger failedOps = new AtomicInteger();
    AtomicLong retried = new AtomicLong();
    Map<String, Long> operationErrors = new ConcurrentHashMap<>();
    AtomicInteger failedBatches = new AtomicInteger();
    Map<String, Long> batchErrors = new HashMap<>();
    long successes = 0;
    do {
        if (Util.transactionIsTerminated(terminationGuard))
            break;
        if (log.isDebugEnabled())
            log.debug("execute in batch no " + batches + " batch size " + batchsize);
        List<Map<String, Object>> batch = Util.take(iterator, batchsize);
        long currentBatchSize = batch.size();
        Callable<Long> task;
        if (iterateList) {
            task = () -> {
                long c = count.addAndGet(currentBatchSize);
                if (Util.transactionIsTerminated(terminationGuard))
                    return 0L;
                List<Map<String, Object>> batchLocal = batch;
                try {
                    Map<String, Object> params = Util.map("_count", c, "_batch", batchLocal);
                    retried.addAndGet(retry(consumer, params, 0, retries));
                } catch (Exception e) {
                    failedOps.addAndGet(batchsize);
                    recordError(operationErrors, e);
                }
                return currentBatchSize;
            };
        } else {
            task = () -> {
                if (Util.transactionIsTerminated(terminationGuard))
                    return 0L;
                return batch.stream().map(p -> {
                    long c = count.incrementAndGet();
                    if (c % 1000 == 0 && Util.transactionIsTerminated(terminationGuard))
                        return 0;
                    List<Map<String, Object>> batchLocal = batch;
                    try {
                        Map<String, Object> params = merge(p, Util.map("_count", c, "_batch", batchLocal));
                        retried.addAndGet(retry(consumer, params, 0, retries));
                    } catch (Exception e) {
                        failedOps.incrementAndGet();
                        recordError(operationErrors, e);
                    }
                    return 1;
                }).mapToLong(l -> l).sum();
            };
        }
        futures.add(Util.inTxFuture(pool, db, task));
        batches++;
        if (futures.size() > 50) {
            while (futures.stream().filter(Future::isDone).count() == 0) {
                // none done yet, block for a bit
                LockSupport.parkNanos(1000);
            }
            Iterator<Future<Long>> it = futures.iterator();
            while (it.hasNext()) {
                Future<Long> future = it.next();
                if (future.isDone()) {
                    successes += Util.getFuture(future, batchErrors, failedBatches, 0L);
                    it.remove();
                }
            }
        }
    } while (iterator.hasNext());
    boolean wasTerminated = Util.transactionIsTerminated(terminationGuard);
    if (wasTerminated) {
        successes += futures.stream().mapToLong(f -> Util.getFutureOrCancel(f, batchErrors, failedBatches, 0L)).sum();
    } else {
        successes += futures.stream().mapToLong(f -> Util.getFuture(f, batchErrors, failedBatches, 0L)).sum();
    }
    Util.logErrors("Error during iterate.commit:", batchErrors, log);
    Util.logErrors("Error during iterate.execute:", operationErrors, log);
    long timeTaken = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start);
    BatchAndTotalResult result = new BatchAndTotalResult(batches, count.get(), timeTaken, successes, failedOps.get(), failedBatches.get(), retried.get(), operationErrors, batchErrors, wasTerminated);
    return Stream.of(result);
}
Also used : java.util(java.util) Log(org.neo4j.logging.Log) Result(org.neo4j.graphdb.Result) Pools(apoc.Pools) org.neo4j.procedure(org.neo4j.procedure) java.util.concurrent(java.util.concurrent) Iterators(org.neo4j.helpers.collection.Iterators) Util.merge(apoc.util.Util.merge) System.nanoTime(java.lang.System.nanoTime) LockSupport(java.util.concurrent.locks.LockSupport) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Collections.singletonMap(java.util.Collections.singletonMap) Pattern(java.util.regex.Pattern) Util(apoc.util.Util) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collections.singletonMap(java.util.Collections.singletonMap)

Example 49 with Log

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

the class SpatialConfigExtractorTest method shouldLogFailureToExtractIndexConfigFromGenericBecauseOfIndexInFailedState.

@Test
void shouldLogFailureToExtractIndexConfigFromGenericBecauseOfIndexInFailedState() throws IOException {
    // given
    unzip(getClass(), ZIP_FAILED_SPATIAL_35_DIR, directory.homePath());
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log myLog = logProvider.getLog(getClass());
    // and
    Path spatialDirectory = directory.homePath().resolve(FAILED_SPATIAL_35_DIR);
    assertTrue(fs.fileExists(spatialDirectory));
    assertTrue(fs.isDirectory(spatialDirectory));
    // when
    List<SpatialFile> spatialFiles = IndexMigration.getSpatialFiles(fs, spatialDirectory);
    SpatialConfigExtractor.indexConfigFromSpatialFile(pageCache, spatialFiles, NULL, myLog, DEFAULT_DATABASE_NAME);
    // then
    String reason = "Index is in FAILED state.";
    assertContainsLogEntry(logProvider, spatialFiles.get(0).getIndexFile(), reason);
}
Also used : Path(java.nio.file.Path) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 50 with Log

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

the class ConfigTest method shouldLogIfConfigFileCouldNotBeRead.

@Test
@DisabledForRoot
void shouldLogIfConfigFileCouldNotBeRead() throws IOException {
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    Log log = logProvider.getLog(Config.class);
    Path confFile = testDirectory.file("test.conf");
    assertTrue(confFile.toFile().createNewFile());
    assumeTrue(confFile.toFile().setReadable(false));
    Config config = Config.emptyBuilder().fromFileNoThrow(confFile).build();
    config.setLogger(log);
    assertThat(logProvider).containsMessages("Unable to load config file [%s]");
}
Also used : Path(java.nio.file.Path) Log(org.neo4j.logging.Log) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Aggregations

Log (org.neo4j.logging.Log)164 Test (org.junit.Test)60 NullLog (org.neo4j.logging.NullLog)53 Test (org.junit.jupiter.api.Test)50 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)24 Path (java.nio.file.Path)20 LogProvider (org.neo4j.logging.LogProvider)15 File (java.io.File)13 IOException (java.io.IOException)12 Map (java.util.Map)12 Config (org.neo4j.kernel.configuration.Config)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 PageCache (org.neo4j.io.pagecache.PageCache)9 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)8 NullLogProvider (org.neo4j.logging.NullLogProvider)7 HashMap (java.util.HashMap)6 Config (org.neo4j.configuration.Config)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 BasicContext (org.neo4j.kernel.api.proc.BasicContext)6 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)6