Search in sources :

Example 36 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class IndexPopulationJobTest method before.

@Before
public void before() throws Exception {
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    stateHolder = new KernelSchemaStateStore(NullLogProvider.getInstance());
    indexStoreView = indexStoreView();
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = tx.acquireStatement()) {
        labelId = statement.tokenWriteOperations().labelGetOrCreateForName(FIRST.name());
        statement.tokenWriteOperations().labelGetOrCreateForName(SECOND.name());
        tx.success();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelSchemaStateStore(org.neo4j.kernel.impl.api.KernelSchemaStateStore) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) KernelAPI(org.neo4j.kernel.api.KernelAPI) Before(org.junit.Before)

Example 37 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class IndexPopulationJobTest method indexDescriptor.

private NewIndexDescriptor indexDescriptor(Label label, String propertyKey, boolean constraint) throws TransactionFailureException {
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        int labelId = statement.readOperations().labelGetForName(label.name());
        int propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey);
        NewIndexDescriptor descriptor = constraint ? NewIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId) : NewIndexDescriptorFactory.forLabel(labelId, propertyKeyId);
        tx.success();
        return descriptor;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement)

Example 38 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class TransactionBatchCommitterTest method shouldTerminateOutdatedTransactions.

@Test
public void shouldTerminateOutdatedTransactions() throws Exception {
    // given
    long safeZone = 10;
    int txCount = 3;
    long firstCommitTimestamp = 10;
    long commitTimestampInterval = 2;
    TransactionBatchCommitter committer = newBatchCommitter(safeZone);
    TransactionChain chain = createTxChain(txCount, firstCommitTimestamp, commitTimestampInterval);
    long timestampOutsideSafeZone = chain.last.transactionRepresentation().getLatestCommittedTxWhenStarted() - safeZone - 1;
    KernelTransaction txToTerminate = newKernelTransaction(timestampOutsideSafeZone);
    KernelTransaction tx = newKernelTransaction(firstCommitTimestamp - 1);
    when(kernelTransactions.activeTransactions()).thenReturn(Iterators.asSet(newHandle(txToTerminate), newHandle(tx)));
    // when
    committer.apply(chain.first, chain.last);
    // then
    verify(txToTerminate).markForTermination(Status.Transaction.Outdated);
    verify(tx, never()).markForTermination(any());
    logProvider.assertContainsLogCallContaining("Marking transaction for termination");
    logProvider.assertContainsLogCallContaining("lastCommittedTxId:" + (BASE_TX_ID + txCount - 1));
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 39 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class GraphDatabaseShellServer method registerTopLevelTransactionInProgress.

public void registerTopLevelTransactionInProgress(Serializable clientId) throws ShellException {
    if (!clients.containsKey(clientId)) {
        ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
        KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(false);
        clients.put(clientId, tx);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 40 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class GraphDatabaseShellServer method bindTransaction.

public void bindTransaction(Serializable clientId) throws ShellException {
    KernelTransaction tx = clients.get(clientId);
    if (tx != null) {
        try {
            ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
            threadToStatementContextBridge.bindTransactionToCurrentThread(tx);
        } catch (Exception e) {
            throw wrapException(e);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

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