Search in sources :

Example 1 with ByteArrayEncoding

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

the class JournalCompactor method onReadUpdateRecord.

@Override
public void onReadUpdateRecord(final RecordInfo info) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("onReadUpdateRecord " + info);
    }
    if (lookupRecord(info.id)) {
        JournalInternalRecord updateRecord = new JournalAddRecord(false, info.id, info.userRecordType, EncoderPersister.getInstance(), new ByteArrayEncoding(info.data));
        updateRecord.setCompactCount((short) (info.compactCount + 1));
        checkSize(updateRecord.getEncodeSize(), info.compactCount);
        JournalRecord newRecord = newRecords.get(info.id);
        if (newRecord == null) {
            ActiveMQJournalLogger.LOGGER.compactingWithNoAddRecord(info.id);
        } else {
            newRecord.addUpdateFile(currentFile, updateRecord.getEncodeSize());
        }
        writeEncoder(updateRecord);
    }
}
Also used : JournalAddRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord) ByteArrayEncoding(org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 2 with ByteArrayEncoding

use of org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding 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 3 with ByteArrayEncoding

use of org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding 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 4 with ByteArrayEncoding

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

the class JournalCompactor method onReadPrepareRecord.

@Override
public void onReadPrepareRecord(final long transactionID, final byte[] extraData, final int numberOfRecords) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("onReadPrepareRecord " + transactionID);
    }
    if (pendingTransactions.get(transactionID) != null) {
        JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
        JournalInternalRecord prepareRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, transactionID, new ByteArrayEncoding(extraData));
        checkSize(prepareRecord.getEncodeSize());
        writeEncoder(prepareRecord, newTransaction.getCounter(currentFile));
        newTransaction.prepare(currentFile);
    }
}
Also used : ByteArrayEncoding(org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding) JournalCompleteRecordTX(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Example 5 with ByteArrayEncoding

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

the class JournalCompactor method onReadAddRecord.

// JournalReaderCallback implementation -------------------------------------------
@Override
public void onReadAddRecord(final RecordInfo info) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Read Record " + info);
    }
    if (lookupRecord(info.id)) {
        JournalInternalRecord addRecord = new JournalAddRecord(true, info.id, info.getUserRecordType(), EncoderPersister.getInstance(), new ByteArrayEncoding(info.data));
        addRecord.setCompactCount((short) (info.compactCount + 1));
        checkSize(addRecord.getEncodeSize(), info.compactCount);
        writeEncoder(addRecord);
        newRecords.put(info.id, new JournalRecord(currentFile, addRecord.getEncodeSize()));
    }
}
Also used : JournalAddRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord) ByteArrayEncoding(org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding) JournalInternalRecord(org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)

Aggregations

ByteArrayEncoding (org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding)7 JournalInternalRecord (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalRecord)7 JournalAddRecord (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord)3 JournalAddRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX)2 ByteBuffer (java.nio.ByteBuffer)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)1 JournalCompleteRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalCompleteRecordTX)1 JournalDeleteRecordTX (org.apache.activemq.artemis.core.journal.impl.dataformat.JournalDeleteRecordTX)1