Search in sources :

Example 1 with CountsVisitor

use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.

the class CountsRotationTest method allRecords.

private Collection<Pair<? extends CountsKey, Long>> allRecords(CountsVisitor.Visitable store) {
    final Collection<Pair<? extends CountsKey, Long>> records = new ArrayList<>();
    store.accept(new CountsVisitor() {

        @Override
        public void visitNodeCount(int labelId, long count) {
            records.add(Pair.of(CountsKeyFactory.nodeKey(labelId), count));
        }

        @Override
        public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
            records.add(Pair.of(CountsKeyFactory.relationshipKey(startLabelId, typeId, endLabelId), count));
        }

        @Override
        public void visitIndexStatistics(long indexId, long updates, long size) {
            records.add(Pair.of(CountsKeyFactory.indexStatisticsKey(indexId), size));
        }

        @Override
        public void visitIndexSample(long indexId, long unique, long size) {
            records.add(Pair.of(CountsKeyFactory.indexSampleKey(indexId), size));
        }
    });
    return records;
}
Also used : CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) ArrayList(java.util.ArrayList) CountsKey(org.neo4j.kernel.impl.store.counts.keys.CountsKey) Pair(org.neo4j.helpers.collection.Pair)

Example 2 with CountsVisitor

use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.

the class CountsTrackerTest method shouldSupportTransactionsAppliedOutOfOrderOnRotation.

@Test
@Resources.Life(STARTED)
public void shouldSupportTransactionsAppliedOutOfOrderOnRotation() throws Exception {
    // given
    final CountsTracker tracker = resourceManager.managed(newTracker());
    try (CountsAccessor.Updater tx = tracker.apply(2).get()) {
        tx.incrementNodeCount(1, 1);
    }
    try (CountsAccessor.Updater tx = tracker.apply(4).get()) {
        tx.incrementNodeCount(1, 1);
    }
    // when
    Future<Long> rotated = threading.executeAndAwait(new Rotation(2), tracker, thread -> {
        switch(thread.getState()) {
            case BLOCKED:
            case WAITING:
            case TIMED_WAITING:
            case TERMINATED:
                return true;
            default:
                return false;
        }
    }, 10, SECONDS);
    try (CountsAccessor.Updater tx = tracker.apply(5).get()) {
        tx.incrementNodeCount(1, 1);
    }
    try (CountsAccessor.Updater tx = tracker.apply(3).get()) {
        tx.incrementNodeCount(1, 1);
    }
    // then
    assertEquals("rotated transaction", 4, rotated.get().longValue());
    assertEquals("stored transaction", 4, tracker.txId());
    // the value in memory
    assertEquals("count", 4, tracker.nodeCount(1, Registers.newDoubleLongRegister()).readSecond());
    // the value in the store
    CountsVisitor visitor = mock(CountsVisitor.class);
    tracker.visitFile(tracker.currentFile(), visitor);
    verify(visitor).visitNodeCount(1, 3);
    verifyNoMoreInteractions(visitor);
    assertEquals("final rotation", 5, tracker.rotate(5));
}
Also used : CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) Test(org.junit.Test)

Example 3 with CountsVisitor

use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.

the class CountsOracle method verify.

public <Tracker extends CountsVisitor.Visitable & CountsAccessor> void verify(final Tracker tracker) {
    CountsRecordState seenState = new CountsRecordState();
    final CountsAccessor.Initializer initializer = new CountsAccessor.Initializer(seenState, seenState);
    List<CountsRecordState.Difference> differences = state.verify(new CountsVisitor.Visitable() {

        @Override
        public void accept(final CountsVisitor verifier) {
            tracker.accept(CountsVisitor.Adapter.multiplex(initializer, verifier));
        }
    });
    seenState.accept(new CountsVisitor() {

        @Override
        public void visitNodeCount(int labelId, long count) {
            long expected = tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond();
            assertEquals("Should be able to read visited state.", expected, count);
        }

        @Override
        public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
            long expected = tracker.relationshipCount(startLabelId, typeId, endLabelId, newDoubleLongRegister()).readSecond();
            assertEquals("Should be able to read visited state.", expected, count);
        }

        @Override
        public void visitIndexStatistics(long indexId, long updates, long size) {
            Register.DoubleLongRegister output = tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister());
            assertEquals("Should be able to read visited state.", output.readFirst(), updates);
            assertEquals("Should be able to read visited state.", output.readSecond(), size);
        }

        @Override
        public void visitIndexSample(long indexId, long unique, long size) {
            Register.DoubleLongRegister output = tracker.indexSample(indexId, newDoubleLongRegister());
            assertEquals("Should be able to read visited state.", output.readFirst(), unique);
            assertEquals("Should be able to read visited state.", output.readSecond(), size);
        }
    });
    if (!differences.isEmpty()) {
        StringBuilder errors = new StringBuilder().append("Counts differ in ").append(differences.size()).append(" places...");
        for (CountsRecordState.Difference difference : differences) {
            errors.append("\n\t").append(difference);
        }
        throw new AssertionError(errors.toString());
    }
}
Also used : CountsRecordState(org.neo4j.kernel.impl.api.CountsRecordState) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) CountsVisitor(org.neo4j.kernel.impl.api.CountsVisitor) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister)

Aggregations

CountsVisitor (org.neo4j.kernel.impl.api.CountsVisitor)3 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Pair (org.neo4j.helpers.collection.Pair)1 CountsRecordState (org.neo4j.kernel.impl.api.CountsRecordState)1 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)1 Registers.newDoubleLongRegister (org.neo4j.register.Registers.newDoubleLongRegister)1