Search in sources :

Example 6 with Stopwatch

use of org.neo4j.time.Stopwatch in project neo4j by neo4j.

the class CrashGenerationCleaner method clean.

// === Methods about the execution and threading ===
public void clean(CleanupJob.Executor executor) {
    monitor.cleanupStarted();
    assert unstableGeneration > stableGeneration : unexpectedGenerations();
    assert unstableGeneration - stableGeneration > 1 : unexpectedGenerations();
    Stopwatch startTime = Stopwatch.start();
    long pagesToClean = highTreeNodeId - lowTreeNodeId;
    int threads = NUMBER_OF_WORKERS;
    long batchSize = batchSize(pagesToClean, threads);
    AtomicLong nextId = new AtomicLong(lowTreeNodeId);
    AtomicBoolean stopFlag = new AtomicBoolean();
    LongAdder cleanedPointers = new LongAdder();
    LongAdder numberOfTreeNodes = new LongAdder();
    List<CleanupJob.JobResult<?>> jobResults = new ArrayList<>();
    for (int i = 0; i < threads; i++) {
        Callable<?> cleanerTask = cleaner(nextId, batchSize, numberOfTreeNodes, cleanedPointers, stopFlag, pageCacheTracer);
        CleanupJob.JobResult<?> jobHandle = executor.submit("Recovery clean up of '" + treeName + "'", cleanerTask);
        jobResults.add(jobHandle);
    }
    awaitAll(jobResults);
    monitor.cleanupFinished(pagesToClean, numberOfTreeNodes.sum(), cleanedPointers.sum(), startTime.elapsed(MILLISECONDS));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) LongAdder(java.util.concurrent.atomic.LongAdder) Stopwatch(org.neo4j.time.Stopwatch) ArrayList(java.util.ArrayList)

Example 7 with Stopwatch

use of org.neo4j.time.Stopwatch in project neo4j by neo4j.

the class Bootloader method stop.

int stop() {
    BootloaderOsAbstraction os = ctx.os();
    Long pid = os.getPidIfRunning();
    if (pid == null) {
        ctx.out.println("Neo4j is not running.");
        return EXIT_CODE_OK;
    }
    ctx.out.print("Stopping Neo4j.");
    int timeout = ctx.getEnv(ENV_NEO4J_SHUTDOWN_TIMEOUT, DEFAULT_NEO4J_SHUTDOWN_TIMEOUT, INT);
    Stopwatch stopwatch = Stopwatch.start();
    os.stop(pid);
    int printCount = 0;
    do {
        if (os.getPidIfRunning() == null) {
            ctx.out.println(" stopped.");
            return EXIT_CODE_OK;
        }
        if (stopwatch.hasTimedOut(printCount, SECONDS)) {
            printCount++;
            ctx.out.print(".");
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            break;
        }
    } while (!stopwatch.hasTimedOut(timeout, SECONDS));
    ctx.out.println(" failed to stop.");
    ctx.out.printf("Neo4j%s took more than %d seconds to stop.%n", pidIfKnown(pid), stopwatch.elapsed(SECONDS));
    ctx.out.printf("Please see %s for details.%n", ctx.config().get(GraphDatabaseSettings.store_user_log_path));
    return EXIT_CODE_RUNNING;
}
Also used : Stopwatch(org.neo4j.time.Stopwatch)

Example 8 with Stopwatch

use of org.neo4j.time.Stopwatch in project neo4j by neo4j.

the class WindowsBootloaderOs method uninstallService.

@Override
void uninstallService() throws BootFailureException {
    issueServiceCommand("DS", behaviour().blocking());
    Stopwatch stopwatch = Stopwatch.start();
    while (serviceInstalled() && !stopwatch.hasTimedOut(Bootloader.DEFAULT_NEO4J_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
        try {
            Thread.sleep(300);
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            break;
        }
    }
}
Also used : Stopwatch(org.neo4j.time.Stopwatch)

Example 9 with Stopwatch

use of org.neo4j.time.Stopwatch in project neo4j by neo4j.

the class SchemaImpl method awaitIndexesOnline.

private boolean awaitIndexesOnline(Iterable<IndexDescriptor> indexes, Function<IndexDescriptor, String> describe, long duration, TimeUnit unit, boolean bubbleNotFound) {
    Stopwatch startTime = Stopwatch.start();
    do {
        boolean allOnline = true;
        SchemaRead schemaRead = transaction.schemaRead();
        for (IndexDescriptor index : indexes) {
            if (index == IndexDescriptor.NO_INDEX) {
                allOnline = false;
                break;
            }
            try {
                InternalIndexState indexState = schemaRead.indexGetState(index);
                if (indexState == InternalIndexState.POPULATING) {
                    allOnline = false;
                    break;
                }
                if (indexState == InternalIndexState.FAILED) {
                    String cause = schemaRead.indexGetFailure(index);
                    String message = "Index " + describe.apply(index) + " entered a " + indexState + " state. Please see database logs.";
                    message = IndexPopulationFailure.appendCauseOfFailure(message, cause);
                    throw new IllegalStateException(message);
                }
            } catch (IndexNotFoundKernelException e) {
                if (bubbleNotFound) {
                    throw newIndexNotFoundException(descriptorToDefinition(transaction.tokenRead(), index), e);
                }
                // Weird that the index vanished, but we'll just wait and see if it comes back until we time out.
                allOnline = false;
                break;
            }
        }
        if (allOnline) {
            return false;
        }
        sleepIgnoreInterrupt();
    } while (!startTime.hasTimedOut(duration, unit));
    return true;
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stopwatch(org.neo4j.time.Stopwatch) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 10 with Stopwatch

use of org.neo4j.time.Stopwatch in project neo4j by neo4j.

the class RelationshipChainChecker method checkDirection.

private void checkDirection(LongRange nodeIdRange, ScanDirection direction) throws Exception {
    RelationshipStore relationshipStore = context.neoStores.getRelationshipStore();
    long highId = relationshipStore.getHighId();
    AtomicBoolean end = new AtomicBoolean();
    int numberOfThreads = numberOfChainCheckers + 1;
    ThrowingRunnable[] workers = new ThrowingRunnable[numberOfThreads];
    ProgressListener localProgress = progress.threadLocalReporter();
    ArrayBlockingQueue<BatchedRelationshipRecords>[] threadQueues = new ArrayBlockingQueue[numberOfChainCheckers];
    BatchedRelationshipRecords[] threadBatches = new BatchedRelationshipRecords[numberOfChainCheckers];
    for (int i = 0; i < numberOfChainCheckers; i++) {
        threadQueues[i] = new ArrayBlockingQueue<>(20);
        threadBatches[i] = new BatchedRelationshipRecords();
        workers[i] = relationshipVsRelationshipChecker(nodeIdRange, direction, relationshipStore, threadQueues[i], end, i);
    }
    // Record reader
    workers[workers.length - 1] = () -> {
        RelationshipRecord relationship = relationshipStore.newRecord();
        try (var cursorContext = new CursorContext(context.pageCacheTracer.createPageCursorTracer(RELATIONSHIP_CONSISTENCY_CHECKER_TAG));
            var cursor = relationshipStore.openPageCursorForReadingWithPrefetching(0, cursorContext)) {
            int recordsPerPage = relationshipStore.getRecordsPerPage();
            long id = direction.startingId(highId);
            while (id >= 0 && id < highId && !context.isCancelled()) {
                for (int i = 0; i < recordsPerPage && id >= 0 && id < highId; i++, id = direction.nextId(id)) {
                    relationshipStore.getRecordByCursor(id, relationship, FORCE, cursor);
                    localProgress.add(1);
                    if (relationship.inUse()) {
                        queueRelationshipCheck(threadQueues, threadBatches, relationship);
                    }
                }
            }
            processLastRelationshipChecks(threadQueues, threadBatches, end);
            localProgress.done();
        }
    };
    Stopwatch stopwatch = Stopwatch.start();
    cacheAccess.clearCache();
    context.execution.runAll(getClass().getSimpleName() + "-" + direction.name(), workers);
    detectSingleRelationshipChainInconsistencies(nodeIdRange);
    context.paddedDebug("%s %s took %s", this, direction, duration(stopwatch.elapsed(TimeUnit.MILLISECONDS)));
}
Also used : Stopwatch(org.neo4j.time.Stopwatch) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ThrowingRunnable(org.neo4j.consistency.checker.ParallelExecution.ThrowingRunnable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore)

Aggregations

Stopwatch (org.neo4j.time.Stopwatch)10 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 String.format (java.lang.String.format)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays.stream (java.util.Arrays.stream)1 List (java.util.List)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1