Search in sources :

Example 21 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class Database method registerUpgradeListener.

private void registerUpgradeListener() {
    DatabaseUpgradeTransactionHandler handler = new DatabaseUpgradeTransactionHandler(storageEngine, globalDependencies.resolveDependency(DbmsRuntimeRepository.class), storageEngine.metadataProvider(), databaseTransactionEventListeners, UpgradeLocker.DEFAULT, internalLogProvider);
    handler.registerUpgradeListener(commands -> {
        PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(commands);
        long time = clock.millis();
        transactionRepresentation.setHeader(EMPTY_BYTE_ARRAY, time, storageEngine.metadataProvider().getLastClosedTransactionId(), time, leaseService.newClient().leaseId(), AuthSubject.AUTH_DISABLED);
        TransactionToApply toApply = new TransactionToApply(transactionRepresentation, CursorContext.NULL);
        TransactionCommitProcess commitProcess = databaseDependencies.resolveDependency(TransactionCommitProcess.class);
        commitProcess.commit(toApply, CommitEvent.NULL, TransactionApplicationMode.INTERNAL);
    });
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 22 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class CommitProcessTracingIT method tracePageCacheAccessOnEmptyTransactionApply.

@Test
void tracePageCacheAccessOnEmptyTransactionApply() throws TransactionFailureException {
    var transaction = new PhysicalTransactionRepresentation(emptyList(), EMPTY_BYTE_ARRAY, 0, 0, 0, 0, ANONYMOUS);
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnEmptyTransactionApply"))) {
        assertZeroCursor(cursorContext);
        commitProcess.commit(new TransactionToApply(transaction, cursorContext), NULL, EXTERNAL);
        assertCursor(cursorContext, 2);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 23 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class GraphStoreFixture method apply.

public void apply(Transaction transaction) throws KernelException {
    TransactionRepresentation representation = transaction.representation(idGenerator(), transactionIdStore.getLastCommittedTransactionId(), neoStores, indexingService);
    commitProcess.commit(new TransactionToApply(representation, NULL), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation)

Example 24 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class ReplicatedTokenStateMachine method applyToStore.

private int applyToStore(Collection<StorageCommand> commands, long logIndex) throws NoSuchEntryException {
    int tokenId = extractTokenId(commands);
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(commands);
    representation.setHeader(encodeLogIndexAsTxHeader(logIndex), 0, 0, 0, 0L, 0L, 0);
    try (LockGroup ignored = new LockGroup()) {
        commitProcess.commit(new TransactionToApply(representation), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    }
    return tokenId;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) LockGroup(org.neo4j.kernel.impl.locking.LockGroup) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 25 with TransactionToApply

use of org.neo4j.kernel.impl.api.TransactionToApply in project neo4j by neo4j.

the class SlaveTransactionCommitProcessTest method mustTranslateComExceptionsToTransientTransactionFailures.

@Test(expected = TransientTransactionFailureException.class)
public void mustTranslateComExceptionsToTransientTransactionFailures() throws Exception {
    when(master.commit(requestContext, tx)).thenThrow(new ComException());
    // When
    commitProcess.commit(new TransactionToApply(tx), CommitEvent.NULL, TransactionApplicationMode.INTERNAL);
// Then we assert that the right exception is thrown
}
Also used : ComException(org.neo4j.com.ComException) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) Test(org.junit.Test)

Aggregations

TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)46 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)14 Test (org.junit.jupiter.api.Test)11 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)11 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)6 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)4 TransactionId (org.neo4j.storageengine.api.TransactionId)4 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)3 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)3 ArrayList (java.util.ArrayList)2 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)2 TransactionApplier (org.neo4j.kernel.impl.api.TransactionApplier)2 LockGroup (org.neo4j.kernel.impl.locking.LockGroup)2 FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)2 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2