Search in sources :

Example 1 with LongRange

use of org.neo4j.internal.helpers.collection.LongRange in project neo4j by neo4j.

the class RecordStorageConsistencyChecker method check.

public void check() throws ConsistencyCheckIncompleteException {
    assert !context.isCancelled();
    try {
        context.initialize();
        // Starting by loading all tokens from store into the TokenHolders, loaded in a safe way of course
        safeLoadTokens(neoStores);
        // Check schema - constraints and indexes, that sort of thing
        // This is done before instantiating the other checker instances because the schema checker will also
        // populate maps regarding mandatory properties which the node/relationship checkers uses
        SchemaChecker schemaChecker = new SchemaChecker(context);
        MutableIntObjectMap<MutableIntSet> mandatoryNodeProperties = new IntObjectHashMap<>();
        MutableIntObjectMap<MutableIntSet> mandatoryRelationshipProperties = new IntObjectHashMap<>();
        try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer(SCHEMA_CONSISTENCY_CHECKER_TAG))) {
            schemaChecker.check(mandatoryNodeProperties, mandatoryRelationshipProperties, cursorContext);
        }
        // Some pieces of check logic are extracted from this main class to reduce the size of this class. Instantiate those here first
        NodeChecker nodeChecker = new NodeChecker(context, mandatoryNodeProperties);
        IndexChecker indexChecker = new IndexChecker(context, EntityType.NODE);
        RelationshipChecker relationshipChecker = new RelationshipChecker(context, mandatoryRelationshipProperties);
        RelationshipGroupChecker relationshipGroupChecker = new RelationshipGroupChecker(context);
        RelationshipChainChecker relationshipChainChecker = new RelationshipChainChecker(context);
        ProgressMonitorFactory.Completer progressCompleter = progress.build();
        int numberOfRanges = limiter.numberOfRanges();
        for (int i = 1; limiter.hasNext(); i++) {
            if (isCancelled()) {
                break;
            }
            LongRange range = limiter.next();
            if (numberOfRanges > 1) {
                context.debug("=== Checking range %d/%d (%s) ===", i, numberOfRanges, range);
            }
            context.initializeRange();
            // Tell the cache that the pivot node id is the low end of this range. This will make all interactions with the cache
            // take that into consideration when working with offset arrays where the index is based on node ids.
            cacheAccess.setPivotId(range.from());
            // Go into a node-centric mode where the nodes themselves are checked and somewhat cached off-heap.
            // Then while we have the nodes loaded in cache do all other checking that has anything to do with nodes
            // so that the "other" store can be checked sequentially and the random node lookups will be cheap
            context.runIfAllowed(indexChecker, range);
            cacheAccess.setCacheSlotSizesAndClear(DEFAULT_SLOT_SIZES);
            context.runIfAllowed(nodeChecker, range);
            context.runIfAllowed(relationshipGroupChecker, range);
            context.runIfAllowed(relationshipChecker, range);
            context.runIfAllowed(relationshipChainChecker, range);
        }
        if (!isCancelled() && context.consistencyFlags.isCheckGraph()) {
            // All counts we've observed while doing other checking along the way we compare against the counts store here
            checkCounts();
        }
        progressCompleter.close();
    } catch (Exception e) {
        cancel("ConsistencyChecker failed unexpectedly");
        throw new ConsistencyCheckIncompleteException(e);
    }
}
Also used : ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) IntObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) LongRange(org.neo4j.internal.helpers.collection.LongRange)

Example 2 with LongRange

use of org.neo4j.internal.helpers.collection.LongRange in project neo4j by neo4j.

the class NodeBasedMemoryLimiter method fetchNextOrNull.

@Override
protected LongRange fetchNextOrNull() {
    if (currentRangeStart >= highNodeId) {
        return null;
    }
    LongRange range = LongRange.range(currentRangeStart, currentRangeEnd);
    currentRangeStart = currentRangeEnd;
    currentRangeEnd = min(highNodeId, currentRangeEnd + nodesPerRange);
    return range;
}
Also used : LongRange(org.neo4j.internal.helpers.collection.LongRange)

Example 3 with LongRange

use of org.neo4j.internal.helpers.collection.LongRange in project neo4j by neo4j.

the class NodeBasedMemoryLimiterTest method shouldReturnTheWholeRangeIfItFits.

@Test
void shouldReturnTheWholeRangeIfItFits() {
    // given
    NodeBasedMemoryLimiter limiter = new NodeBasedMemoryLimiter(100, 100, 250, 1, 40, 1);
    assertEquals(1, limiter.numberOfRanges());
    // when
    LongRange range = limiter.next();
    // then
    assertRange(range, 0, 40);
    assertFalse(limiter.hasNext());
}
Also used : LongRange(org.neo4j.internal.helpers.collection.LongRange) Test(org.junit.jupiter.api.Test)

Aggregations

LongRange (org.neo4j.internal.helpers.collection.LongRange)3 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)1 IntObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap)1 Test (org.junit.jupiter.api.Test)1 ConsistencyCheckIncompleteException (org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException)1 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1