use of org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor in project neo4j by neo4j.
the class RecordStorageEngine method createCommands.
/**
* @throws TransactionFailureException if command generation fails or some prerequisite of some command didn't validate,
* for example if trying to delete a node that still has relationships.
* @throws CreateConstraintFailureException if this transaction was set to create a constraint and that failed.
* @throws ConstraintValidationException if this transaction was set to create a constraint and some data violates that constraint.
*/
@SuppressWarnings("resource")
@Override
public void createCommands(Collection<StorageCommand> commands, ReadableTransactionState txState, StorageReader storageReader, CommandCreationContext commandCreationContext, ResourceLocker locks, LockTracer lockTracer, long lastTransactionIdWhenStarted, TxStateVisitor.Decorator additionalTxStateVisitor, CursorContext cursorContext, MemoryTracker transactionMemoryTracker) throws KernelException {
if (txState != null) {
KernelVersion version = neoStores.getMetaDataStore().kernelVersion();
Preconditions.checkState(version.isAtLeast(KernelVersion.V4_2), "Can not write older version than %s. Requested %s", KernelVersion.V4_2, version);
// We can make this cast here because we expected that the storageReader passed in here comes from
// this storage engine itself, anything else is considered a bug. And we do know the inner workings
// of the storage statements that we create.
RecordStorageCommandCreationContext creationContext = (RecordStorageCommandCreationContext) commandCreationContext;
LogCommandSerialization serialization = RecordStorageCommandReaderFactory.INSTANCE.get(version);
TransactionRecordState recordState = creationContext.createTransactionRecordState(integrityValidator, lastTransactionIdWhenStarted, locks, lockTracer, serialization, lockVerificationFactory.create(locks, txState, neoStores, schemaRuleAccess));
// Visit transaction state and populate these record state objects
TxStateVisitor txStateVisitor = new TransactionToRecordStateVisitor(recordState, schemaState, schemaRuleAccess, constraintSemantics, cursorContext);
CountsRecordState countsRecordState = new CountsRecordState(serialization);
txStateVisitor = additionalTxStateVisitor.apply(txStateVisitor);
txStateVisitor = new TransactionCountingStateVisitor(txStateVisitor, storageReader, txState, countsRecordState, cursorContext);
try (TxStateVisitor visitor = txStateVisitor) {
txState.accept(visitor);
}
// Convert record state into commands
recordState.extractCommands(commands, transactionMemoryTracker);
countsRecordState.extractCommands(commands, transactionMemoryTracker);
// Verify sufficient locks
CommandLockVerification commandLockVerification = commandLockVerificationFactory.create(locks, txState, neoStores, schemaRuleAccess);
commandLockVerification.verifySufficientlyLocked(commands);
}
}
use of org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor 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;
}
use of org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor 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;
}
use of org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor 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);
}
}
Aggregations