Search in sources :

Example 16 with JournalInternalRecord

use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.

the class JournalImpl method appendDeleteRecord.

@Override
public void appendDeleteRecord(final long id, final boolean sync, final IOCompletion callback) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendDeleteRecord::id=" + id);
    }
    checkJournalIsLoaded();
    lineUpContext(callback);
    checkKnownRecordID(id);
    final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            try {
                JournalRecord record = null;
                if (compactor == null) {
                    record = records.remove(id);
                }
                JournalInternalRecord deleteRecord = new JournalDeleteRecord(id);
                JournalFile usedFile = appendRecord(deleteRecord, false, sync, null, callback);
                if (logger.isTraceEnabled()) {
                    logger.trace("appendDeleteRecord::id=" + id + ", usedFile = " + usedFile);
                }
                // computing the delete should be done after compacting is done
                if (record == null) {
                    compactor.addCommandDelete(id, usedFile);
                } else {
                    record.delete(usedFile);
                }
                result.set(true);
            } catch (Exception e) {
                result.fail(e);
                logger.error("appendDeleteRecord:" + e, e);
            } finally {
                journalLock.readLock().unlock();
            }
        }
    });
    result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JournalDeleteRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalDeleteRecord) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 17 with JournalInternalRecord

use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.

the class JournalImpl method appendPrepareRecord.

/**
 * <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction
 * back to a state it could be committed. </p>
 * <p> transactionData allows you to store any other supporting user-data related to the transaction</p>
 * <p> This method also uses the same logic applied on {@link JournalImpl#appendCommitRecord(long, boolean)}
 *
 * @param txID
 * @param transactionData extra user data for the prepare
 * @throws Exception
 */
@Override
public void appendPrepareRecord(final long txID, final EncodingSupport transactionData, final boolean sync, final IOCompletion callback) throws Exception {
    checkJournalIsLoaded();
    lineUpContext(callback);
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendPrepareRecord::txID=" + txID);
    }
    final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            final JournalTransaction tx = getTransactionInfo(txID);
            try {
                tx.checkErrorCondition();
                JournalInternalRecord prepareRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, txID, transactionData);
                JournalFile usedFile = appendRecord(prepareRecord, true, sync, tx, callback);
                if (logger.isTraceEnabled()) {
                    logger.trace("appendPrepareRecord::txID=" + txID + ", usedFile = " + usedFile);
                }
                tx.prepare(usedFile);
            } catch (Exception e) {
                result.fail(e);
                logger.error("appendPrepareRecord:" + e, e);
                setErrorCondition(callback, tx, e);
            } finally {
                journalLock.readLock().unlock();
                result.set(tx);
            }
        }
    });
    JournalTransaction tx = result.get();
    if (tx != null) {
        tx.checkErrorCondition();
    }
}
Also used : JournalCompleteRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 18 with JournalInternalRecord

use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.

the class JournalImpl method appendCommitRecord.

/**
 * Regarding the number of operations in a given file see {@link JournalCompleteRecordTX}.
 */
@Override
public void appendCommitRecord(final long txID, final boolean sync, final IOCompletion callback, final boolean lineUpContext) throws Exception {
    checkJournalIsLoaded();
    if (lineUpContext) {
        lineUpContext(callback);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendCommitRecord::txID=" + txID);
    }
    JournalTransaction txcheck = transactions.get(txID);
    if (txcheck != null) {
        txcheck.checkErrorCondition();
    }
    final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            // cannot remove otherwise compact may get lost
            final JournalTransaction tx = transactions.remove(txID);
            try {
                if (tx == null) {
                    throw new IllegalStateException("Cannot find tx with id " + txID);
                }
                JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, txID, null);
                JournalFile usedFile = appendRecord(commitRecord, true, sync, tx, callback);
                tx.commit(usedFile);
            } catch (Throwable e) {
                result.fail(e);
                logger.error("appendCommitRecord:" + e, e);
                setErrorCondition(callback, tx, e);
            } finally {
                journalLock.readLock().unlock();
                result.set(tx);
            }
        }
    });
    JournalTransaction tx = result.get();
    if (tx != null) {
        tx.checkErrorCondition();
    }
}
Also used : JournalCompleteRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 19 with JournalInternalRecord

use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.

the class FileWrapperJournal method appendUpdateRecordTransactional.

@Override
public void appendUpdateRecordTransactional(long txID, long id, byte recordType, Persister persister, Object record) throws Exception {
    JournalInternalRecord updateRecordTX = new JournalAddRecordTX(false, txID, id, recordType, persister, record);
    writeRecord(updateRecordTX, false, txID, false, null);
}
Also used : JournalAddRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 20 with JournalInternalRecord

use of org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord in project activemq-artemis by apache.

the class FileWrapperJournal method appendUpdateRecord.

@Override
public void appendUpdateRecord(long id, byte recordType, Persister persister, Object record, boolean sync, IOCompletion callback) throws Exception {
    JournalInternalRecord updateRecord = new JournalAddRecord(false, id, recordType, persister, record);
    writeRecord(updateRecord, false, -1, false, callback);
}
Also used : JournalAddRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Aggregations

JournalInternalRecord (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)27 ByteArrayEncoding (org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding)7 JournalAddRecord (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord)7 IOException (java.io.IOException)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 JournalAddRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX)6 JournalCompleteRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 JournalDeleteRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalDeleteRecordTX)3 JournalRollbackRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalRollbackRecordTX)3 JournalDeleteRecord (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalDeleteRecord)2 ByteBuffer (java.nio.ByteBuffer)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)1