Search in sources :

Example 1 with CountsRecordState

use of org.neo4j.kernel.impl.api.CountsRecordState 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)

Example 2 with CountsRecordState

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

the class RecordStorageEngine method createCommands.

@SuppressWarnings("resource")
@Override
public void createCommands(Collection<StorageCommand> commands, ReadableTransactionState txState, StorageStatement storageStatement, ResourceLocker locks, long lastTransactionIdWhenStarted) throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException {
    if (txState != null) {
        RecordChangeSet recordChangeSet = new RecordChangeSet(loaders);
        TransactionRecordState recordState = new TransactionRecordState(neoStores, integrityValidator, recordChangeSet, lastTransactionIdWhenStarted, locks, relationshipCreator, relationshipDeleter, propertyCreator, propertyDeleter);
        // Visit transaction state and populate these record state objects
        TxStateVisitor txStateVisitor = new TransactionToRecordStateVisitor(recordState, schemaStateChangeCallback, schemaStorage, constraintSemantics, schemaIndexProviderMap);
        CountsRecordState countsRecordState = new CountsRecordState();
        txStateVisitor = constraintSemantics.decorateTxStateVisitor(storeLayer, txState, txStateVisitor);
        txStateVisitor = new TransactionCountingStateVisitor(txStateVisitor, storeLayer, storageStatement, txState, countsRecordState);
        try (TxStateVisitor visitor = txStateVisitor) {
            txState.accept(txStateVisitor);
        }
        // Convert record state into commands
        recordState.extractCommands(commands);
        countsRecordState.extractCommands(commands);
    }
}
Also used : RecordChangeSet(org.neo4j.kernel.impl.transaction.state.RecordChangeSet) TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) TransactionRecordState(org.neo4j.kernel.impl.transaction.state.TransactionRecordState) CountsRecordState(org.neo4j.kernel.impl.api.CountsRecordState) TransactionCountingStateVisitor(org.neo4j.kernel.api.txstate.TransactionCountingStateVisitor)

Aggregations

CountsRecordState (org.neo4j.kernel.impl.api.CountsRecordState)2 TransactionCountingStateVisitor (org.neo4j.kernel.api.txstate.TransactionCountingStateVisitor)1 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)1 CountsVisitor (org.neo4j.kernel.impl.api.CountsVisitor)1 RecordChangeSet (org.neo4j.kernel.impl.transaction.state.RecordChangeSet)1 TransactionRecordState (org.neo4j.kernel.impl.transaction.state.TransactionRecordState)1 Registers.newDoubleLongRegister (org.neo4j.register.Registers.newDoubleLongRegister)1 TxStateVisitor (org.neo4j.storageengine.api.txstate.TxStateVisitor)1