use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class StoreUpgradeIntegrationTest method checkIndexCounts.
private static void checkIndexCounts(Store store, GraphDatabaseAPI db) throws KernelException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
Iterator<NewIndexDescriptor> indexes = getAllIndexes(db);
DoubleLongRegister register = Registers.newDoubleLongRegister();
for (int i = 0; indexes.hasNext(); i++) {
NewIndexDescriptor descriptor = indexes.next();
// wait index to be online since sometimes we need to rebuild the indexes on migration
awaitOnline(statement.readOperations(), descriptor);
assertDoubleLongEquals(store.indexCounts[i][0], store.indexCounts[i][1], statement.readOperations().indexUpdatesAndSize(descriptor, register));
assertDoubleLongEquals(store.indexCounts[i][2], store.indexCounts[i][3], statement.readOperations().indexSample(descriptor, register));
double selectivity = statement.readOperations().indexUniqueValuesSelectivity(descriptor);
assertEquals(store.indexSelectivity[i], selectivity, 0.0000001d);
}
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class Kernel method newTransaction.
@Override
public KernelTransaction newTransaction(KernelTransaction.Type type, SecurityContext securityContext, long timeout) throws TransactionFailureException {
health.assertHealthy(TransactionFailureException.class);
KernelTransaction transaction = transactions.newInstance(type, securityContext, timeout);
transactionMonitor.transactionStarted();
return transaction;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class RemoveOrphanConstraintIndexesOnStartup method perform.
public void perform() {
try (KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
Statement statement = transaction.acquireStatement()) {
for (NewIndexDescriptor index : loop(statement.readOperations().uniqueIndexesGetAll())) {
if (statement.readOperations().indexGetOwningUniquenessConstraintId(index) == null) {
log.info("Removing orphan constraint index: " + index);
statement.schemaWriteOperations().uniqueIndexDrop(index);
}
}
transaction.success();
} catch (KernelException e) {
log.error("Failed to execute orphan index checking transaction.", e);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ClassicCoreSPI method currentTransaction.
@Override
public KernelTransaction currentTransaction() {
availability.assertDatabaseAvailable();
KernelTransaction tx = dataSource.threadToTransactionBridge.getKernelTransactionBoundToThisThread(false);
if (tx == null) {
throw new NotInTransactionException();
}
return tx;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class GraphDatabaseFacade method init.
/**
* Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies
*/
public void init(SPI spi, Guard guard, ThreadToStatementContextBridge txBridge, Config config) {
this.spi = spi;
this.defaultTransactionTimeout = config.get(GraphDatabaseSettings.transaction_timeout);
Supplier<Statement> statementSupplier = spi::currentStatement;
Supplier<KernelTransaction> transactionSupplier = spi::currentTransaction;
ThrowingAction<RuntimeException> assertTransactionOpen = this::assertTransactionOpen;
this.schema = new SchemaImpl(statementSupplier);
this.relActions = new StandardRelationshipActions(statementSupplier, transactionSupplier, assertTransactionOpen, (id) -> new NodeProxy(nodeActions, id), this);
this.nodeActions = new StandardNodeActions(statementSupplier, transactionSupplier, assertTransactionOpen, relActions, this);
this.indexManager = Suppliers.lazySingleton(() -> {
IndexProviderImpl idxProvider = new IndexProviderImpl(this, statementSupplier);
AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>(() -> new ReadOnlyIndexFacade<>(idxProvider.getOrCreateNodeIndex(NODE_AUTO_INDEX, null)), spi.autoIndexing().nodes());
RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade(() -> new ReadOnlyRelationshipIndexFacade(idxProvider.getOrCreateRelationshipIndex(RELATIONSHIP_AUTO_INDEX, null)), spi.autoIndexing().relationships());
return new IndexManagerImpl(statementSupplier, idxProvider, nodeAutoIndexer, relAutoIndexer);
});
this.contextFactory = Neo4jTransactionalContextFactory.create(spi, guard, txBridge, locker);
}
Aggregations