use of org.neo4j.storageengine.api.CommandCreationContext in project neo4j by neo4j.
the class BatchingNeoStoresTest method someDataInTheDatabase.
private void someDataInTheDatabase(Config config) throws Exception {
NullLog nullLog = NullLog.getInstance();
try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
Lifespan life = new Lifespan()) {
// TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.propertyKeyDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.labelDoCreateForName(name, internal, id);
}
};
DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {
@Override
void create(String name, boolean internal, int id) {
txState.relationshipTypeDoCreateForName(name, internal, id);
}
};
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
IndexConfigCompleter indexConfigCompleter = index -> index;
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
// Create the relationship type token
TxState txState = new TxState();
NeoStores neoStores = storageEngine.testAccessNeoStores();
CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
commandCreationContext.initialize(NULL);
propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
apply(txState, commandCreationContext, storageEngine);
// Finally, we're initialized and ready to create two nodes and a relationship
txState = new TxState();
long node1 = commandCreationContext.reserveNode();
long node2 = commandCreationContext.reserveNode();
txState.nodeDoCreate(node1);
txState.nodeDoCreate(node2);
txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
apply(txState, commandCreationContext, storageEngine);
neoStores.flush(NULL);
}
}
use of org.neo4j.storageengine.api.CommandCreationContext in project neo4j by neo4j.
the class CommitProcessTracingIT method tracePageCacheAccessOnCommandCreation.
@Test
void tracePageCacheAccessOnCommandCreation() throws KernelException {
long sourceId;
try (Transaction transaction = database.beginTx()) {
sourceId = transaction.createNode(Label.label("a")).getId();
transaction.commit();
}
var pageCacheTracer = new DefaultPageCacheTracer();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnCommandCreation"));
var reader = storageEngine.newReader()) {
assertZeroCursor(cursorContext);
try (CommandCreationContext context = storageEngine.newCommandCreationContext(INSTANCE)) {
context.initialize(cursorContext);
List<StorageCommand> commands = new ArrayList<>();
var txState = new TxState();
txState.nodeDoAddLabel(1, sourceId);
storageEngine.createCommands(commands, txState, reader, context, IGNORE, LockTracer.NONE, 0, NO_DECORATION, cursorContext, INSTANCE);
}
assertCursor(cursorContext, 2);
}
}
use of org.neo4j.storageengine.api.CommandCreationContext in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingRelationshipId.
@Test
void shouldAcquireTxStateBeforeAllocatingRelationshipId() throws EntityNotFoundException {
// given
KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
when(ktx.txState()).thenReturn(mock(TransactionState.class));
Locks.Client lockClient = mock(Locks.Client.class);
when(ktx.lockClient()).thenReturn(lockClient);
when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
when(ktx.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(CommunitySecurityLog.NULL_LOG));
CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
AllStoreHolder allStoreHolder = mock(AllStoreHolder.class);
when(allStoreHolder.nodeExists(anyLong())).thenReturn(true);
Operations operations = new Operations(allStoreHolder, 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.relationshipCreate(0, 1, 2);
// then
InOrder inOrder = inOrder(ktx, commandCreationContext);
inOrder.verify(ktx).txState();
inOrder.verify(commandCreationContext).reserveRelationship();
inOrder.verifyNoMoreInteractions();
}
use of org.neo4j.storageengine.api.CommandCreationContext 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.storageengine.api.CommandCreationContext 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();
}
Aggregations