Search in sources :

Example 11 with JournalInternalRecord

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

the class JournalCompactor method onReadCommitRecord.

@Override
public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("onReadCommitRecord " + transactionID);
    }
    if (pendingTransactions.get(transactionID) != null) {
        // Sanity check, this should never happen
        ActiveMQJournalLogger.LOGGER.inconsistencyDuringCompacting(transactionID);
    } else {
        JournalTransaction newTransaction = newTransactions.remove(transactionID);
        if (newTransaction != null) {
            JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, transactionID, null);
            checkSize(commitRecord.getEncodeSize());
            writeEncoder(commitRecord, newTransaction.getCounter(currentFile));
            newTransaction.commit(currentFile);
        }
    }
}
Also used : JournalCompleteRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 12 with JournalInternalRecord

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

the class JournalCompactor method onReadAddRecordTX.

@Override
public void onReadAddRecordTX(final long transactionID, final RecordInfo info) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Read Add Recprd TX " + transactionID + " info " + info);
    }
    if (pendingTransactions.get(transactionID) != null || lookupRecord(info.id)) {
        JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
        JournalInternalRecord record = new JournalAddRecordTX(true, transactionID, info.id, info.getUserRecordType(), EncoderPersister.getInstance(), new ByteArrayEncoding(info.data));
        record.setCompactCount((short) (info.compactCount + 1));
        checkSize(record.getEncodeSize(), info.compactCount);
        newTransaction.addPositive(currentFile, info.id, record.getEncodeSize());
        writeEncoder(record);
    }
}
Also used : ByteArrayEncoding(org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding) JournalAddRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 13 with JournalInternalRecord

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

the class JournalImpl method appendRollbackRecord.

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

        @Override
        public void run() {
            journalLock.readLock().lock();
            final JournalTransaction tx = transactions.remove(txID);
            try {
                if (logger.isTraceEnabled()) {
                    logger.trace("appendRollbackRecord::txID=" + txID);
                }
                if (tx == null) {
                    throw new IllegalStateException("Cannot find tx with id " + txID);
                }
                JournalInternalRecord rollbackRecord = new JournalRollbackRecordTX(txID);
                JournalFile usedFile = appendRecord(rollbackRecord, false, sync, tx, callback);
                tx.rollback(usedFile);
            } catch (Throwable e) {
                result.fail(e);
                logger.error("appendRollbackRecord:" + e, e);
                setErrorCondition(callback, tx, e);
            } finally {
                journalLock.readLock().unlock();
                result.set(tx);
            }
        }
    });
    JournalTransaction tx = result.get();
    if (tx != null) {
        tx.checkErrorCondition();
    }
}
Also used : JournalRollbackRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalRollbackRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 14 with JournalInternalRecord

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

the class AbstractJournalUpdateTask method writeControlFile.

// Public --------------------------------------------------------
public static SequentialFile writeControlFile(final SequentialFileFactory fileFactory, final List<JournalFile> files, final List<JournalFile> newFiles, final List<Pair<String, String>> renames) throws Exception {
    SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
    try {
        controlFile.open(1, false);
        JournalImpl.initFileHeader(fileFactory, controlFile, 0, 0);
        ActiveMQBuffer filesToRename = ActiveMQBuffers.dynamicBuffer(1);
        if (files == null) {
            filesToRename.writeInt(0);
        } else {
            filesToRename.writeInt(files.size());
            for (JournalFile file : files) {
                filesToRename.writeUTF(file.getFile().getFileName());
            }
        }
        if (newFiles == null) {
            filesToRename.writeInt(0);
        } else {
            filesToRename.writeInt(newFiles.size());
            for (JournalFile file : newFiles) {
                filesToRename.writeUTF(file.getFile().getFileName());
            }
        }
        // Renames from clean up third
        if (renames == null) {
            filesToRename.writeInt(0);
        } else {
            filesToRename.writeInt(renames.size());
            for (Pair<String, String> rename : renames) {
                filesToRename.writeUTF(rename.getA());
                filesToRename.writeUTF(rename.getB());
            }
        }
        JournalInternalRecord controlRecord = new JournalAddRecord(true, 1, (byte) 0, EncoderPersister.getInstance(), new ByteArrayEncoding(filesToRename.toByteBuffer().array()));
        ActiveMQBuffer renameBuffer = ActiveMQBuffers.dynamicBuffer(filesToRename.writerIndex());
        controlRecord.setFileID(0);
        controlRecord.encode(renameBuffer);
        ByteBuffer writeBuffer = fileFactory.newBuffer(renameBuffer.writerIndex());
        writeBuffer.put(renameBuffer.toByteBuffer().array(), 0, renameBuffer.writerIndex());
        writeBuffer.rewind();
        controlFile.writeDirect(writeBuffer, true);
        return controlFile;
    } finally {
        controlFile.close();
    }
}
Also used : JournalAddRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ByteArrayEncoding(org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding) ByteBuffer(java.nio.ByteBuffer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 15 with JournalInternalRecord

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

the class JournalImpl method appendAddRecord.

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

        @Override
        public void run() {
            journalLock.readLock().lock();
            try {
                JournalInternalRecord addRecord = new JournalAddRecord(true, id, recordType, persister, record);
                JournalFile usedFile = appendRecord(addRecord, false, sync, null, callback);
                records.put(id, new JournalRecord(usedFile, addRecord.getEncodeSize()));
                if (logger.isTraceEnabled()) {
                    logger.trace("appendAddRecord::id=" + id + ", userRecordType=" + recordType + ", record = " + record + ", usedFile = " + usedFile);
                }
                result.set(true);
            } catch (Throwable e) {
                result.fail(e);
                setErrorCondition(callback, null, e);
                logger.error("appendAddRecord::" + e, e);
            } finally {
                pendingRecords.remove(id);
                journalLock.readLock().unlock();
            }
        }
    });
    result.get();
}
Also used : JournalAddRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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