use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.
the class ReplicatedTokenHolder method createCommands.
private byte[] createCommands(String tokenName) {
StorageEngine storageEngine = dependencies.resolveDependency(StorageEngine.class);
Collection<StorageCommand> commands = new ArrayList<>();
TransactionState txState = new TxState();
int tokenId = Math.toIntExact(idGeneratorFactory.get(tokenIdType).nextId());
createToken(txState, tokenName, tokenId);
try (StorageStatement statement = storageEngine.storeReadLayer().newStatement()) {
storageEngine.createCommands(commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE);
} catch (CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e) {
throw new RuntimeException("Unable to create token '" + tokenName + "'", e);
}
return ReplicatedTokenRequestSerializer.commandBytes(commands);
}
use of org.neo4j.kernel.impl.api.state.TxState 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.kernel.impl.api.state.TxState in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createUniqueIndex.
private IndexDescriptor createUniqueIndex(Label label, String propertyKey) throws Exception {
TxState txState = new TxState();
int labelId = getOrCreateLabelId(label);
int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
long id = commitContext.reserveSchema();
IndexDescriptor index = IndexPrototype.uniqueForSchema(forLabel(labelId, propertyKeyId)).withName("constraint_" + id).materialise(id);
txState.indexDoAdd(index);
apply(txState);
return index;
}
use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.
the class RecordStorageReaderTestBase method deleteRelationship.
protected void deleteRelationship(long relationshipId) throws Exception {
TxState txState = new TxState();
try (RecordRelationshipScanCursor cursor = commitReader.allocateRelationshipScanCursor(NULL)) {
cursor.single(relationshipId);
assertTrue(cursor.next());
txState.relationshipDoDelete(relationshipId, cursor.type(), cursor.getFirstNode(), cursor.getSecondNode());
}
apply(txState);
}
use of org.neo4j.kernel.impl.api.state.TxState in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createIndex.
protected IndexDescriptor createIndex(Label label, String propertyKey) throws Exception {
TxState txState = new TxState();
int labelId = getOrCreateLabelId(label);
int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
long id = commitContext.reserveSchema();
IndexPrototype prototype = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + id);
IndexDescriptor index = prototype.materialise(id);
txState.indexDoAdd(index);
apply(txState);
return index;
}
Aggregations