@Override public long relationshipsGetCount( ) { ktx.assertOpen(); long base = storageReader.relationshipsGetCount(); return ktx.hasTxStateWithChanges() ? base + ktx.txState().addedAndRemovedRelationships().delta() : base; }
@Override public KernelTransactionImplementation newInstance() { KernelTransactionImplementation tx = new KernelTransactionImplementation( config, statementOperations, schemaWriteGuard, hooks, constraintIndexCreator, procedures, transactionHeaderInformationFactory, transactionCommitProcess, transactionMonitor, auxTxStateManager, localTxPool, clock, cpuClockRef, heapAllocationRef, tracers.transactionTracer, tracers.lockTracer, tracers.pageCursorTracerSupplier, storageEngine, accessCapability, autoIndexing, explicitIndexStore, versionContextSupplier, collectionsFactorySupplier, constraintSemantics, schemaState, indexProviders, tokenHolders, dataSourceDependencies ); this.transactions.add( tx ); return tx; } }
private RawIterator<Object[],ProcedureException> callProcedure( QualifiedName name, Object[] input, final AccessMode override ) throws ProcedureException { ktx.assertOpen(); final SecurityContext procedureSecurityContext = ktx.securityContext().withMode( override ); final RawIterator<Object[],ProcedureException> procedureCall; try ( KernelTransaction.Revertable ignore = ktx.overrideWith( procedureSecurityContext ); Statement statement = ktx.acquireStatement() ) { procedureCall = procedures .callProcedure( prepareContext( procedureSecurityContext ), name, input, statement ); } return createIterator( procedureSecurityContext, procedureCall ); }
private boolean hasChanges() { return hasTxStateWithChanges() || hasAuxTxStateChanges(); }
KernelTransactionImplementationHandle( KernelTransactionImplementation tx, SystemNanoClock clock ) { this.txReuseCount = tx.getReuseCount(); this.lastTransactionIdWhenStarted = tx.lastTransactionIdWhenStarted(); this.lastTransactionTimestampWhenStarted = tx.lastTransactionTimestampWhenStarted(); this.startTime = tx.startTime(); this.timeoutMillis = tx.timeout(); this.subject = tx.subjectOrAnonymous(); this.terminationReason = tx.getReasonIfTerminated(); this.executingQueries = tx.executingQueries(); this.metaData = tx.getMetaData(); this.userTransactionId = tx.userTransactionId(); this.tx = tx; this.clock = clock; }
private void acquireExclusiveRelationshipLock( long relationshipId ) { if ( !ktx.hasTxStateWithChanges() || !ktx.txState().relationshipIsAddedInThisTx( relationshipId ) ) { ktx.statementLocks().optimistic() .acquireExclusive( ktx.lockTracer(), ResourceTypes.RELATIONSHIP, relationshipId ); } }
when( transaction.statementLocks() ).thenReturn( locks ); when( transaction.tokenRead() ).thenReturn( tokenRead ); when( transaction.schemaRead() ).thenReturn( schemaRead ); when( transaction.schemaWrite() ).thenReturn( schemaWrite ); TransactionState transactionState = mock( TransactionState.class ); when( transaction.txState() ).thenReturn( transactionState ); when( transaction.indexUniqueCreate( any( SchemaDescriptor.class ), any( String.class ) ) ).thenAnswer( i -> IndexDescriptorFactory.uniqueForSchema( i.getArgument( 0 ) ) );
when( transaction.getReasonIfTerminated() ).thenReturn( Optional.empty() ); when( transaction.statementLocks() ).thenReturn( new SimpleStatementLocks( locks ) ); when( transaction.dataWrite() ).thenReturn( write ); when( transaction.isOpen() ).thenReturn( true ); when( transaction.lockTracer() ).thenReturn( LockTracer.NONE ); when( transaction.txState() ).thenReturn( txState ); when( transaction.securityContext() ).thenReturn( SecurityContext.AUTH_DISABLED );
private void dropCreatedConstraintIndexes() throws TransactionFailureException { if ( hasTxStateWithChanges() ) { for ( IndexDescriptor createdConstraintIndex : txState().constraintIndexesCreatedInTx() ) { // TODO logically, which statement should this operation be performed on? constraintIndexCreator.dropUniquenessConstraintIndex( createdConstraintIndex ); } } }
@Override public int labelCreateForName( String labelName ) throws IllegalTokenNameException, TooManyLabelsException { ktx.assertOpen(); int id = store.reserveLabelTokenId(); ktx.txState().labelDoCreateForName( labelName, id ); return id; }
SchemaRead schemaRead = transaction.schemaRead(); try index = getOrCreateUniquenessConstraintIndex( schemaRead, transaction.tokenRead(), descriptor, provider ); Client locks = transaction.statementLocks().pessimistic(); try locks.acquireExclusive( transaction.lockTracer(), descriptor.keyType(), descriptor.keyId() ); reacquiredLabelLock = true; locks.acquireExclusive( transaction.lockTracer(), descriptor.keyType(), descriptor.keyId() );
transaction.initialize( 5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED, 0L, 1L ); transaction.txState(); try ( KernelStatement statement = transaction.acquireStatement() ) transaction.success();
@Override public ScoreEntityIterator query( KernelTransaction ktx, String indexName, String queryString ) throws IndexNotFoundKernelException, ParseException { KernelTransactionImplementation kti = (KernelTransactionImplementation) ktx; AllStoreHolder allStoreHolder = (AllStoreHolder) kti.dataRead(); IndexReference indexReference = kti.schemaRead().indexGetForName( indexName ); FulltextIndexReader fulltextIndexReader; if ( kti.hasTxStateWithChanges() && !((FulltextSchemaDescriptor) indexReference.schema()).isEventuallyConsistent() ) { FulltextAuxiliaryTransactionState auxiliaryTxState = (FulltextAuxiliaryTransactionState) allStoreHolder.auxiliaryTxState( TX_STATE_PROVIDER_KEY ); fulltextIndexReader = auxiliaryTxState.indexReader( indexReference, kti ); } else { IndexReader indexReader = allStoreHolder.indexReader( indexReference, false ); fulltextIndexReader = (FulltextIndexReader) indexReader; } return fulltextIndexReader.query( queryString ); }
@Override public int nodeDetachDelete( final long nodeId ) throws KernelException { final MutableInt count = new MutableInt(); TwoPhaseNodeForRelationshipLocking locking = new TwoPhaseNodeForRelationshipLocking( relId -> { ktx.assertOpen(); if ( relationshipDelete( relId, false ) ) { count.increment(); } }, ktx.statementLocks().optimistic(), ktx.lockTracer() ); locking.lockAllNodesAndConsumeRelationships( nodeId, ktx, ktx.ambientNodeCursor() ); ktx.assertOpen(); //we are already holding the lock nodeDelete( nodeId, false ); return count.intValue(); }
@Override public TransactionState txState() { return ktx.txState(); }
private void updateReader( KernelTransactionImplementation kti ) throws Exception { modifiedEntityIdsInThisTransaction.clear(); // Clear this so we don't filter out entities who have had their changes reversed since last time. writer.resetWriterState(); AllStoreHolder read = (AllStoreHolder) kti.dataRead(); TransactionState transactionState = kti.txState(); try ( NodeCursor nodeCursor = visitingNodes ? kti.cursors().allocateNodeCursor() : null; RelationshipScanCursor relationshipCursor = visitingNodes ? null : kti.cursors().allocateRelationshipScanCursor(); PropertyCursor propertyCursor = kti.cursors().allocatePropertyCursor() ) { transactionState.accept( txStateVisitor.init( read, nodeCursor, relationshipCursor, propertyCursor ) ); } FulltextIndexReader baseReader = (FulltextIndexReader) read.indexReader( descriptor, false ); FulltextIndexReader nearRealTimeReader = writer.getNearRealTimeReader(); currentReader = new TransactionStateFulltextIndexReader( baseReader, nearRealTimeReader, modifiedEntityIdsInThisTransaction ); lastUpdateRevision = kti.getTransactionDataRevision(); }
@Test public void createFulltextIndex() throws Exception { IndexReference fulltextIndex = createIndex( new int[]{7, 8, 9}, new int[]{2, 3, 4} ); try ( KernelTransactionImplementation transaction = getKernelTransaction() ) { IndexReference descriptor = transaction.schemaRead().indexGetForName( NAME ); assertEquals( descriptor.schema(), fulltextIndex.schema() ); transaction.success(); } }
@Test public void markForTerminationWithIncorrectReuseCount() throws Exception { int reuseCount = 13; int nextReuseCount = reuseCount + 2; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = newNotInitializedTransaction( ); initializeAndClose( tx, reuseCount ); Locks.Client locksClient = mock( Locks.Client.class ); SimpleStatementLocks statementLocks = new SimpleStatementLocks( locksClient ); tx.initialize( 42, 42, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); assertFalse( tx.markForTermination( nextReuseCount, terminationReason ) ); assertFalse( tx.getReasonIfTerminated().isPresent() ); verify( locksClient, never() ).stop(); }
try ( KernelTransactionImplementation transaction = getKernelTransaction() ) SchemaWrite schemaWrite = transaction.schemaWrite(); nodes = schemaWrite.indexCreate( descriptor, FulltextIndexProviderFactory.DESCRIPTOR.name(), Optional.of( "nodes" ) ); transaction.success(); try ( KernelTransactionImplementation ktx = getKernelTransaction() ) SchemaRead schemaRead = ktx.schemaRead(); await( schemaRead.indexGetForName( "nodes" ) );
@Test public void markForTerminationTerminatedTransaction() { Locks.Client locksClient = mock( Locks.Client.class ); KernelTransactionImplementation tx = newTransaction( loginContext(), locksClient ); transactionInitializer.accept( tx ); tx.markForTermination( Status.Transaction.Terminated ); tx.markForTermination( Status.Transaction.Outdated ); tx.markForTermination( Status.Transaction.LockClientStopped ); assertEquals( Status.Transaction.Terminated, tx.getReasonIfTerminated().get() ); verify( locksClient ).stop(); verify( transactionMonitor ).transactionTerminated( isWriteTx ); }