Search in sources :

Example 1 with CountsDelta

use of org.neo4j.storageengine.api.CountsDelta in project neo4j by neo4j.

the class AllStoreHolder method countsForNodeInTxState.

private long countsForNodeInTxState(int labelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            CursorContext cursorContext = ktx.cursorContext();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.nodeCount(labelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 2 with CountsDelta

use of org.neo4j.storageengine.api.CountsDelta in project neo4j by neo4j.

the class AllStoreHolder method countsForRelationshipInTxState.

private long countsForRelationshipInTxState(int startLabelId, int typeId, int endLabelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CursorContext cursorContext = ktx.cursorContext();
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.relationshipCount(startLabelId, typeId, endLabelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 3 with CountsDelta

use of org.neo4j.storageengine.api.CountsDelta in project neo4j by neo4j.

the class TransactionCountingStateVisitorTraceIT method traceStateWithChanges.

private void traceStateWithChanges(Consumer<Transaction> transactionalOperation) throws KernelException {
    try (var transaction = database.beginTx()) {
        var internalTransaction = (InternalTransaction) transaction;
        KernelTransactionImplementation kernelTransaction = (KernelTransactionImplementation) internalTransaction.kernelTransaction();
        var cursorContext = kernelTransaction.cursorContext();
        transactionalOperation.accept(transaction);
        cursorContext.getCursorTracer().reportEvents();
        assertZeroCursor(cursorContext);
        var transactionState = kernelTransaction.txState();
        var counts = new CountsDelta();
        try (StorageReader storageReader = kernelTransaction.newStorageReader();
            var stateVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, transactionState, counts, cursorContext)) {
            transactionState.accept(stateVisitor);
        }
        assertTwoCursor(cursorContext);
    }
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) CountsDelta(org.neo4j.storageengine.api.CountsDelta) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Aggregations

CountsDelta (org.neo4j.storageengine.api.CountsDelta)3 TransactionCountingStateVisitor (org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)3 KernelException (org.neo4j.exceptions.KernelException)2 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1