Search in sources :

Example 1 with SerializeTransactionEvent

use of org.neo4j.kernel.impl.transaction.tracing.SerializeTransactionEvent in project neo4j by neo4j.

the class BatchingTransactionAppender method append.

@Override
public long append(TransactionToApply batch, LogAppendEvent logAppendEvent) throws IOException {
    // Assigned base tx id just to make compiler happy
    long lastTransactionId = TransactionIdStore.BASE_TX_ID;
    // Synchronized with logFile to get absolute control over concurrent rotations happening
    synchronized (logFile) {
        // Assert that kernel is healthy before making any changes
        databaseHealth.assertHealthy(IOException.class);
        try (SerializeTransactionEvent serialiseEvent = logAppendEvent.beginSerializeTransaction()) {
            // Append all transactions in this batch to the log under the same logFile monitor
            TransactionToApply tx = batch;
            while (tx != null) {
                long transactionId = transactionIdStore.nextCommittingTransactionId();
                // If we're in a scenario where we're merely replicating transactions, i.e. transaction
                // id have already been generated by another entity we simply check that our id
                // that we generated match that id. If it doesn't we've run into a problem we can't ยด
                // really recover from and would point to a bug somewhere.
                matchAgainstExpectedTransactionIdIfAny(transactionId, tx);
                TransactionCommitment commitment = appendToLog(tx.transactionRepresentation(), transactionId, logAppendEvent, previousChecksum);
                previousChecksum = commitment.getTransactionChecksum();
                tx.commitment(commitment, transactionId);
                tx.logPosition(commitment.logPosition());
                tx = tx.next();
                lastTransactionId = transactionId;
            }
        }
    }
    // in this batch exist durably on disk.
    if (logFile.forceAfterAppend(logAppendEvent)) {
        // We got lucky and were the one forcing the log. It's enough if ones of all doing concurrent committers
        // checks the need for log rotation.
        boolean logRotated = logRotation.rotateLogIfNeeded(logAppendEvent);
        logAppendEvent.setLogRotated(logRotated);
    }
    // Mark all transactions as committed
    publishAsCommitted(batch);
    return lastTransactionId;
}
Also used : SerializeTransactionEvent(org.neo4j.kernel.impl.transaction.tracing.SerializeTransactionEvent) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply)

Aggregations

TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 SerializeTransactionEvent (org.neo4j.kernel.impl.transaction.tracing.SerializeTransactionEvent)1