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();
}
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();
}
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;
}
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.
}
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));
});
}
Aggregations