Search in sources :

Example 6 with TransactionId

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);
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Locks(org.neo4j.kernel.impl.locking.Locks) TransactionId(org.neo4j.storageengine.api.TransactionId)

Example 7 with TransactionId

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);
    }
}
Also used : TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionId(org.neo4j.storageengine.api.TransactionId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 8 with TransactionId

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();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PagedFile(org.neo4j.io.pagecache.PagedFile) DelegatingPagedFile(org.neo4j.io.pagecache.DelegatingPagedFile) Race(org.neo4j.test.Race) PageCursor(org.neo4j.io.pagecache.PageCursor) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 9 with TransactionId

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

Example 10 with TransactionId

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

Aggregations

TransactionId (org.neo4j.storageengine.api.TransactionId)25 Test (org.junit.jupiter.api.Test)16 Path (java.nio.file.Path)4 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)4 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)4 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 IOException (java.io.IOException)3 Config (org.neo4j.configuration.Config)3 PageCursor (org.neo4j.io.pagecache.PageCursor)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 LogService (org.neo4j.logging.internal.LogService)3 NullLogService (org.neo4j.logging.internal.NullLogService)3 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)2 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2