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();
}
}
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;
}
}
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));
}
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);
}
}
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);
}
}
}
Aggregations