Search in sources :

Example 11 with KernelTransactionImplementation

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

the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingNodeIdInBareCreateMethod.

@Test
void shouldAcquireTxStateBeforeAllocatingNodeIdInBareCreateMethod() {
    // given
    KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
    when(ktx.txState()).thenReturn(mock(TransactionState.class));
    when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    when(ktx.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(CommunitySecurityLog.NULL_LOG));
    CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
    Operations operations = new Operations(mock(AllStoreHolder.class), mock(StorageReader.class), mock(IndexTxStateUpdater.class), commandCreationContext, ktx, mock(KernelToken.class), mock(DefaultPooledCursors.class), mock(ConstraintIndexCreator.class), mock(ConstraintSemantics.class), mock(IndexingProvidersService.class), Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    // when
    operations.nodeCreate();
    // then
    InOrder inOrder = inOrder(ktx, commandCreationContext);
    inOrder.verify(ktx).txState();
    inOrder.verify(commandCreationContext).reserveNode();
    inOrder.verifyNoMoreInteractions();
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) InOrder(org.mockito.InOrder) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.jupiter.api.Test)

Example 12 with KernelTransactionImplementation

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

the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingNodeIdInCreateWithLabelsMethod.

@Test
void shouldAcquireTxStateBeforeAllocatingNodeIdInCreateWithLabelsMethod() throws ConstraintValidationException {
    // given
    KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
    when(ktx.txState()).thenReturn(mock(TransactionState.class));
    when(ktx.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(CommunitySecurityLog.NULL_LOG));
    Locks.Client lockClient = mock(Locks.Client.class);
    when(ktx.lockClient()).thenReturn(lockClient);
    when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
    DefaultPooledCursors cursors = mock(DefaultPooledCursors.class);
    when(cursors.allocateFullAccessNodeCursor(NULL)).thenReturn(mock(FullAccessNodeCursor.class));
    when(cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE)).thenReturn(mock(FullAccessPropertyCursor.class));
    Operations operations = new Operations(mock(AllStoreHolder.class), mock(StorageReader.class), mock(IndexTxStateUpdater.class), commandCreationContext, ktx, mock(KernelToken.class), cursors, mock(ConstraintIndexCreator.class), mock(ConstraintSemantics.class), mock(IndexingProvidersService.class), Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    operations.initialize(NULL);
    // when
    operations.nodeCreateWithLabels(new int[] { 1 });
    // then
    InOrder inOrder = inOrder(ktx, commandCreationContext);
    inOrder.verify(ktx).txState();
    inOrder.verify(commandCreationContext).reserveNode();
    // for the constraints check for the label
    inOrder.verify(ktx).txState();
    inOrder.verifyNoMoreInteractions();
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) InOrder(org.mockito.InOrder) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) Locks(org.neo4j.kernel.impl.locking.Locks) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.jupiter.api.Test)

Example 13 with KernelTransactionImplementation

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

the class DefaultRelationshipTraversalCursorTest method txState.

private static Read txState(Rel... rels) {
    KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
    Read read = new TestRead(ktx);
    when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    if (rels.length > 0) {
        TxState txState = new TxState();
        for (Rel rel : rels) {
            txState.relationshipDoCreate(rel.relId, rel.type, rel.sourceId, rel.targetId);
        }
        when(read.hasTxStateWithChanges()).thenReturn(true);
        when(read.txState()).thenReturn(txState);
    }
    return read;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation)

Example 14 with KernelTransactionImplementation

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

the class FulltextProcedures method awaitOnline.

private void awaitOnline(IndexDescriptor index) {
    // We do the isAdded check on the transaction state first, because indexGetState will grab a schema read-lock, which can deadlock on the write-lock
    // held by the index populator. Also, if the index was created in this transaction, then we will never see it come online in this transaction anyway.
    // Indexes don't come online until the transaction that creates them has committed.
    KernelTransactionImplementation txImpl = (KernelTransactionImplementation) this.tx;
    if (!txImpl.hasTxStateWithChanges() || !txImpl.txState().indexDiffSetsBySchema(index.schema()).isAdded(index)) {
        // If the index was not created in this transaction, then wait for it to come online before querying.
        Schema schema = transaction.schema();
        schema.awaitIndexOnline(index.getName(), INDEX_ONLINE_QUERY_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    }
// If the index was created in this transaction, then we skip this check entirely.
// We will get an exception later, when we try to get an IndexReader, so this is fine.
}
Also used : KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Schema(org.neo4j.graphdb.schema.Schema)

Example 15 with KernelTransactionImplementation

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

the class DatabaseManagementServiceImpl method createDatabase.

@Override
public void createDatabase(String name, Configuration databaseSpecificSettings) {
    String storageEngineName = getStorageEngine(databaseSpecificSettings);
    systemDatabaseExecute("CREATE DATABASE `" + name + "`", (database, transaction) -> {
        // Inject the configured storage engine as a property on the node representing the created database
        // This is somewhat a temporary measure before CREATE DATABASE gets support for specifying the storage engine
        // directly into the command syntax.
        TransactionState txState = ((KernelTransactionImplementation) transaction.kernelTransaction()).txState();
        TokenHolders tokenHolders = database.getDependencyResolver().resolveDependency(TokenHolders.class);
        long nodeId = findNodeForCreatedDatabaseInTransactionState(txState, tokenHolders, name);
        int storageEngineNamePropertyKeyTokenId = tokenHolders.propertyKeyTokens().getOrCreateId(DATABASE_STORAGE_ENGINE_PROPERTY);
        txState.nodeDoAddProperty(nodeId, storageEngineNamePropertyKeyTokenId, Values.stringValue(storageEngineName));
    });
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TokenHolders(org.neo4j.token.TokenHolders)

Aggregations

KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)35 Test (org.junit.jupiter.api.Test)20 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)13 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)8 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)7 StorageReader (org.neo4j.storageengine.api.StorageReader)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)6 DbmsRuntimeRepository (org.neo4j.dbms.database.DbmsRuntimeRepository)5 Transaction (org.neo4j.graphdb.Transaction)5 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)5 CommandCreationContext (org.neo4j.storageengine.api.CommandCreationContext)5 InOrder (org.mockito.InOrder)4 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 Test (org.junit.Test)3 SecurityAuthorizationHandler (org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler)3 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)3 IndexingProvidersService (org.neo4j.kernel.impl.api.index.IndexingProvidersService)3