use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class KernelTransactions method newInstance.
public KernelTransaction newInstance(KernelTransaction.Type type, LoginContext loginContext, ClientConnectionInfo clientInfo, long timeout) {
assertCurrentThreadIsNotBlockingNewTransactions();
SecurityContext securityContext = loginContext.authorize(tokenHoldersIdLookup, namedDatabaseId.name(), securityLog);
try {
while (!newTransactionsLock.readLock().tryLock(1, TimeUnit.SECONDS)) {
assertRunning();
}
try {
assertRunning();
TransactionId lastCommittedTransaction = transactionIdStore.getLastCommittedTransaction();
KernelTransactionImplementation tx = localTxPool.acquire();
Locks.Client lockClient = locks.newClient();
tx.initialize(lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), lockClient, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet(), clientInfo);
return tx;
} finally {
newTransactionsLock.readLock().unlock();
}
} catch (InterruptedException ie) {
Thread.interrupted();
throw new TransactionFailureException("Fail to start new transaction.", ie);
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class TransactionLogInitializer method appendEmptyTransactionAndCheckPoint.
private void appendEmptyTransactionAndCheckPoint(LogFiles logFiles, String reason) throws IOException {
TransactionId committedTx = store.getLastCommittedTransaction();
long timestamp = committedTx.commitTimestamp();
long transactionId = committedTx.transactionId();
LogFile logFile = logFiles.getLogFile();
TransactionLogWriter transactionLogWriter = logFile.getTransactionLogWriter();
PhysicalTransactionRepresentation emptyTx = emptyTransaction(timestamp);
int checksum = transactionLogWriter.append(emptyTx, BASE_TX_ID, BASE_TX_CHECKSUM);
logFile.forceAfterAppend(LogAppendEvent.NULL);
LogPosition position = transactionLogWriter.getCurrentPosition();
appendCheckpoint(logFiles, reason, position);
try (CursorContext cursorContext = new CursorContext(tracer.createPageCursorTracer(LOGS_UPGRADER_TRACER_TAG))) {
store.setLastCommittedAndClosedTransactionId(transactionId, checksum, timestamp, position.getByteOffset(), position.getLogVersion(), cursorContext);
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class MetaDataStoreTest method transactionCommittedMustBeAtomic.
@Test
void transactionCommittedMustBeAtomic() throws Throwable {
try (MetaDataStore store = newMetaDataStore()) {
PagedFile pf = store.pagedFile;
store.transactionCommitted(2, 2, 2, NULL);
AtomicLong writeCount = new AtomicLong();
AtomicLong fileReadCount = new AtomicLong();
AtomicLong apiReadCount = new AtomicLong();
int upperLimit = 10_000;
int lowerLimit = 100;
long endTime = currentTimeMillis() + SECONDS.toMillis(10);
Race race = new Race();
race.withEndCondition(() -> writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
race.withEndCondition(() -> writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
race.addContestants(3, () -> {
long count = writeCount.incrementAndGet();
store.transactionCommitted(count, (int) count, count, NULL);
});
race.addContestants(3, throwing(() -> {
try (PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_READ_LOCK, NULL)) {
assertTrue(cursor.next());
long id;
long checksum;
do {
id = store.getRecordValue(cursor, MetaDataStore.Position.LAST_TRANSACTION_ID);
checksum = store.getRecordValue(cursor, MetaDataStore.Position.LAST_TRANSACTION_CHECKSUM);
} while (cursor.shouldRetry());
assertIdEqualsChecksum(id, checksum, "file");
fileReadCount.incrementAndGet();
}
}));
race.addContestants(3, () -> {
TransactionId transaction = store.getLastCommittedTransaction();
assertIdEqualsChecksum(transaction.transactionId(), transaction.checksum(), "API");
apiReadCount.incrementAndGet();
});
race.go();
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class HighestTransactionIdTest method assertRejected.
private static void assertRejected(HighestTransactionId highest, long txId) {
TransactionId current = highest.get();
assertFalse(highest.offer(txId, -1, -1));
assertEquals(current, highest.get());
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class HighestTransactionIdTest method assertAccepted.
private static void assertAccepted(HighestTransactionId highest, long txId) {
TransactionId current = highest.get();
assertTrue(highest.offer(txId, -1, -1));
assertTrue(txId > current.transactionId());
}
Aggregations