Search in sources :

Example 46 with KernelTransaction

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 47 with KernelTransaction

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;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction)

Example 48 with KernelTransaction

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 49 with KernelTransaction

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;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 50 with KernelTransaction

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);
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) StoreId(org.neo4j.kernel.impl.store.StoreId) RELATIONSHIP_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.RELATIONSHIP_AUTO_INDEX) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Suppliers(org.neo4j.function.Suppliers) ResourceClosingIterator(org.neo4j.helpers.collection.ResourceClosingIterator) URL(java.net.URL) ResourceIterable(org.neo4j.graphdb.ResourceIterable) Status(org.neo4j.kernel.api.exceptions.Status) TransactionEventHandler(org.neo4j.graphdb.event.TransactionEventHandler) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Statement(org.neo4j.kernel.api.Statement) Property(org.neo4j.kernel.api.properties.Property) RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NODE_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.NODE_AUTO_INDEX) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) Map(java.util.Map) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Transaction(org.neo4j.graphdb.Transaction) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) PrefetchingResourceIterator(org.neo4j.helpers.collection.PrefetchingResourceIterator) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) BidirectionalTraversalDescriptionImpl(org.neo4j.kernel.impl.traversal.BidirectionalTraversalDescriptionImpl) Result(org.neo4j.graphdb.Result) URLAccessValidationError(org.neo4j.graphdb.security.URLAccessValidationError) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) String.format(java.lang.String.format) Schema(org.neo4j.graphdb.schema.Schema) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) NO_SUCH_LABEL(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_LABEL) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) IndexManager(org.neo4j.graphdb.index.IndexManager) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) Optional(java.util.Optional) DependencyResolver(org.neo4j.graphdb.DependencyResolver) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Guard(org.neo4j.kernel.guard.Guard) Label(org.neo4j.graphdb.Label) PlaceboTransaction(org.neo4j.kernel.impl.coreapi.PlaceboTransaction) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) EntityType(org.neo4j.storageengine.api.EntityType) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) MonoDirectionalTraversalDescription(org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription) NotFoundException(org.neo4j.graphdb.NotFoundException) Supplier(java.util.function.Supplier) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) Node(org.neo4j.graphdb.Node) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) ThrowingAction(org.neo4j.function.ThrowingAction) NO_SUCH_PROPERTY_KEY(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_PROPERTY_KEY) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) AutoIndexing(org.neo4j.kernel.api.legacyindex.AutoIndexing) Config(org.neo4j.kernel.configuration.Config) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) Iterators.emptyIterator(org.neo4j.helpers.collection.Iterators.emptyIterator) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) File(java.io.File) PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) TimeUnit(java.util.concurrent.TimeUnit) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Relationship(org.neo4j.graphdb.Relationship) AUTH_DISABLED(org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) MultipleFoundException(org.neo4j.graphdb.MultipleFoundException) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Collections(java.util.Collections) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) Statement(org.neo4j.kernel.api.Statement) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)77 Test (org.junit.Test)37 Statement (org.neo4j.kernel.api.Statement)30 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)14 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)14 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)7 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)4 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)4 RemoteException (java.rmi.RemoteException)3 ExpectedException (org.junit.rules.ExpectedException)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)3 ShellException (org.neo4j.shell.ShellException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2