Search in sources :

Example 11 with PopulationProgress

use of org.neo4j.internal.kernel.api.PopulationProgress in project neo4j by neo4j.

the class BlockBasedIndexPopulator method progress.

@Override
public PopulationProgress progress(PopulationProgress scanProgress) {
    // A general note on scanProgress.getTotal(). Before the scan is completed most progress parts will base their estimates on that value.
    // It is known that it may be slightly higher since it'll be based on store high-id, not the actual count.
    // This is fine, but it creates this small "jump" in the progress in the middle somewhere when it switches from scan to merge.
    // This also exists in the most basic population progress reports, but there it will be less visible since it will jump from
    // some close-to-100 percentage to 100% and ONLINE.
    // This progress report will consist of a couple of smaller parts, weighted differently based on empirically collected values.
    // The weights will not be absolutely correct in all environments, but they don't have to be either, it will just result in some
    // slices of the percentage progression range progressing at slightly different paces. However, progression of progress reporting
    // naturally fluctuates anyway due to data set and I/O etc. so this is not an actual problem.
    PopulationProgress.MultiBuilder builder = PopulationProgress.multiple();
    // Add scan progress (this one weights a bit heavier than the others)
    builder.add(scanProgress, 4);
    // Add merge progress
    if (!allScanUpdates.isEmpty()) {
        // The parts are merged in parallel so just take the first one and it will represent the whole merge progress.
        // It will be fairly accurate, but slightly off sometimes if other threads gets scheduling problems, i.e. if this part
        // finish far apart from others.
        long completed = 0;
        long total = 0;
        if (scanCompleted) {
            // We know the actual entry count to write during merge since we have been monitoring those values
            ThreadLocalBlockStorage part = first(allScanUpdates);
            completed = part.entriesMerged.get();
            total = part.totalEntriesToMerge;
        }
        builder.add(PopulationProgress.single(completed, total), 1);
    }
    // Add tree building incl. external updates
    PopulationProgress treeBuildProgress;
    if (allScanUpdates.stream().allMatch(part -> part.mergeStarted)) {
        long entryCount = allScanUpdates.stream().mapToLong(part -> part.count).sum() + externalUpdates.count();
        treeBuildProgress = PopulationProgress.single(numberOfAppliedScanUpdates.get() + numberOfAppliedExternalUpdates.get(), entryCount);
    } else {
        treeBuildProgress = PopulationProgress.NONE;
    }
    builder.add(treeBuildProgress, 2);
    return builder.build();
}
Also used : PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress)

Example 12 with PopulationProgress

use of org.neo4j.internal.kernel.api.PopulationProgress in project neo4j by neo4j.

the class BuiltInProcedures method getIndexStatus.

private static IndexStatus getIndexStatus(SchemaReadCore schemaRead, IndexDescriptor index) {
    IndexStatus status = new IndexStatus();
    try {
        InternalIndexState internalIndexState = schemaRead.indexGetState(index);
        status.state = internalIndexState.toString();
        PopulationProgress progress = schemaRead.indexGetPopulationProgress(index);
        status.populationProgress = progress.toIndexPopulationProgress().getCompletedPercentage();
        status.failureMessage = internalIndexState == InternalIndexState.FAILED ? schemaRead.indexGetFailure(index) : "";
    } catch (IndexNotFoundKernelException e) {
        status.state = "NOT FOUND";
        status.populationProgress = 0D;
        status.failureMessage = "Index not found. It might have been concurrently dropped.";
    }
    return status;
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)

Aggregations

PopulationProgress (org.neo4j.internal.kernel.api.PopulationProgress)12 Test (org.junit.jupiter.api.Test)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelException (org.neo4j.exceptions.KernelException)1 Transaction (org.neo4j.graphdb.Transaction)1 IndexPopulationProgress (org.neo4j.graphdb.schema.IndexPopulationProgress)1 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)1 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)1 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)1 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)1 Kernel (org.neo4j.kernel.api.Kernel)1 PropertyScanConsumer (org.neo4j.kernel.impl.api.index.PropertyScanConsumer)1 TokenScanConsumer (org.neo4j.kernel.impl.api.index.TokenScanConsumer)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1