Search in sources :

Example 1 with JournalInternalRecord

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

the class JournalImpl method appendUpdateRecordTransactional.

@Override
public void appendUpdateRecordTransactional(final long txID, final long id, final byte recordType, final Persister persister, final Object record) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendUpdateRecordTransactional::txID=" + txID + ",id=" + id + ", userRecordType=" + recordType + ", record = " + record);
    }
    checkJournalIsLoaded();
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            final JournalTransaction tx = getTransactionInfo(txID);
            try {
                tx.checkErrorCondition();
                JournalInternalRecord updateRecordTX = new JournalAddRecordTX(false, txID, id, recordType, persister, record);
                JournalFile usedFile = appendRecord(updateRecordTX, false, false, tx, null);
                if (logger.isTraceEnabled()) {
                    logger.trace("appendUpdateRecordTransactional::txID=" + txID + ",id=" + id + ", userRecordType=" + recordType + ", record = " + record + ", usedFile = " + usedFile);
                }
                tx.addPositive(usedFile, id, updateRecordTX.getEncodeSize());
            } catch (Exception e) {
                logger.error("appendUpdateRecordTransactional:" + e.getMessage(), e);
                setErrorCondition(null, tx, e);
            } finally {
                journalLock.readLock().unlock();
            }
        }
    });
}
Also used : JournalAddRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 2 with JournalInternalRecord

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

the class JournalImpl method appendAddRecordTransactional.

@Override
public void appendAddRecordTransactional(final long txID, final long id, final byte recordType, final Persister persister, final Object record) throws Exception {
    checkJournalIsLoaded();
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendAddRecordTransactional:txID=" + txID + ",id=" + id + ", userRecordType=" + recordType + ", record = " + record);
    }
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            final JournalTransaction tx = getTransactionInfo(txID);
            try {
                if (tx != null) {
                    tx.checkErrorCondition();
                }
                JournalInternalRecord addRecord = new JournalAddRecordTX(true, txID, id, recordType, persister, record);
                JournalFile usedFile = appendRecord(addRecord, false, false, tx, null);
                if (logger.isTraceEnabled()) {
                    logger.trace("appendAddRecordTransactional:txID=" + txID + ",id=" + id + ", userRecordType=" + recordType + ", record = " + record + ", usedFile = " + usedFile);
                }
                tx.addPositive(usedFile, id, addRecord.getEncodeSize());
            } catch (Exception e) {
                logger.error("appendAddRecordTransactional:" + e, e);
                setErrorCondition(null, tx, e);
            } finally {
                journalLock.readLock().unlock();
            }
        }
    });
}
Also used : JournalAddRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 3 with JournalInternalRecord

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

the class JournalImpl method appendDeleteRecordTransactional.

@Override
public void appendDeleteRecordTransactional(final long txID, final long id, final EncodingSupport record) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("scheduling appendDeleteRecordTransactional::txID=" + txID + ", id=" + id);
    }
    checkJournalIsLoaded();
    appendExecutor.execute(new Runnable() {

        @Override
        public void run() {
            journalLock.readLock().lock();
            final JournalTransaction tx = getTransactionInfo(txID);
            try {
                if (tx != null) {
                    tx.checkErrorCondition();
                }
                JournalInternalRecord deleteRecordTX = new JournalDeleteRecordTX(txID, id, record);
                JournalFile usedFile = appendRecord(deleteRecordTX, false, false, tx, null);
                if (logger.isTraceEnabled()) {
                    logger.trace("appendDeleteRecordTransactional::txID=" + txID + ", id=" + id + ", usedFile = " + usedFile);
                }
                tx.addNegative(usedFile, id);
            } catch (Exception e) {
                logger.error("appendDeleteRecordTransactional:" + e, e);
                setErrorCondition(null, tx, e);
            } finally {
                journalLock.readLock().unlock();
            }
        }
    });
}
Also used : JournalDeleteRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalDeleteRecordTX) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 4 with JournalInternalRecord

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

the class JournalImpl method appendUpdateRecord.

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

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

Example 5 with JournalInternalRecord

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

the class FileWrapperJournal method appendAddRecord.

// ------------------------
// ------------------------
@Override
public void appendAddRecord(long id, byte recordType, Persister persister, Object record, boolean sync, IOCompletion callback) throws Exception {
    JournalInternalRecord addRecord = new JournalAddRecord(true, id, recordType, persister, record);
    writeRecord(addRecord, 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