Search in sources :

Example 1 with TransactionFailureCallback

use of org.apache.activemq.artemis.core.journal.TransactionFailureCallback in project narayana by jbosstm.

the class HornetqJournalStore method start.

public void start() throws Exception {
    journal.start();
    List<RecordInfo> committedRecords = new LinkedList<RecordInfo>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<PreparedTransactionInfo>();
    TransactionFailureCallback failureCallback = new TransactionFailureCallback() {

        public void failedTransaction(long l, List<RecordInfo> recordInfos, List<RecordInfo> recordInfos1) {
            tsLogger.i18NLogger.warn_journal_load_error();
        }
    };
    JournalLoadInformation journalLoadInformation = journal.load(committedRecords, preparedTransactions, failureCallback);
    maxID.set(journalLoadInformation.getMaxID());
    if (!preparedTransactions.isEmpty()) {
        tsLogger.i18NLogger.warn_journal_load_error();
    }
    for (RecordInfo record : committedRecords) {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        Uid uid = UidHelper.unpackFrom(inputBuffer);
        String typeName = inputBuffer.unpackString();
        getContentForType(typeName).put(uid, record);
    // don't unpack the rest yet, we may never need it. read_committed does it on demand.
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) Uid(com.arjuna.ats.arjuna.common.Uid) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) LinkedList(java.util.LinkedList) List(java.util.List) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList)

Example 2 with TransactionFailureCallback

use of org.apache.activemq.artemis.core.journal.TransactionFailureCallback in project activemq-artemis by apache.

the class JDBCJournalLoaderCallbackTest method testAddDeleteRecord.

@Test
public void testAddDeleteRecord() throws Exception {
    ArrayList<RecordInfo> committedRecords = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
    TransactionFailureCallback failureCallback = null;
    boolean fixBadTX = false;
    JDBCJournalLoaderCallback cb = new JDBCJournalLoaderCallback(committedRecords, preparedTransactions, failureCallback, fixBadTX);
    RecordInfo record = new RecordInfo(42, (byte) 0, null, false, (short) 0);
    cb.addRecord(record);
    assertEquals(1, committedRecords.size());
    assertTrue(committedRecords.contains(record));
    cb.deleteRecord(record.id);
    assertTrue(committedRecords.isEmpty());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) Test(org.junit.Test)

Example 3 with TransactionFailureCallback

use of org.apache.activemq.artemis.core.journal.TransactionFailureCallback in project activemq-artemis by apache.

the class CrashOnCompactTest method checkJournalSize.

private void checkJournalSize() throws Exception {
    JournalImpl journal = createJournal(getTestDirfile(), false);
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> txInfo = new ArrayList<>();
    journal.load(info, txInfo, new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    });
    Assert.assertEquals(900, info.size());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 4 with TransactionFailureCallback

use of org.apache.activemq.artemis.core.journal.TransactionFailureCallback in project activemq-artemis by apache.

the class DescribeJournal method printSurvivingRecords.

public static DescribeJournal printSurvivingRecords(Journal journal, PrintStream out, boolean safe) throws Exception {
    final Map<Long, PageSubscriptionCounterImpl> counters = new HashMap<>();
    out.println("### Surviving Records Summary ###");
    List<RecordInfo> records = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    journal.start();
    final StringBuffer bufferFailingTransactions = new StringBuffer();
    int messageCount = 0;
    Map<Long, Integer> messageRefCounts = new HashMap<>();
    int preparedMessageCount = 0;
    Map<Long, Integer> preparedMessageRefCount = new HashMap<>();
    journal.load(records, preparedTransactions, new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records1, List<RecordInfo> recordsToDelete) {
            bufferFailingTransactions.append("Transaction " + transactionID + " failed with these records:\n");
            for (RecordInfo info : records1) {
                bufferFailingTransactions.append("- " + describeRecord(info, safe) + "\n");
            }
            for (RecordInfo info : recordsToDelete) {
                bufferFailingTransactions.append("- " + describeRecord(info, safe) + " <marked to delete>\n");
            }
        }
    }, false);
    for (RecordInfo info : records) {
        PageSubscriptionCounterImpl subsCounter = null;
        long queueIDForCounter = 0;
        Object o = newObjectEncoding(info);
        if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE) {
            messageCount++;
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            ReferenceDescribe ref = (ReferenceDescribe) o;
            Integer count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                count = 1;
                messageRefCounts.put(ref.refEncoding.queueID, count);
            } else {
                messageRefCounts.put(ref.refEncoding.queueID, count + 1);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
            AckDescribe ref = (AckDescribe) o;
            Integer count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                messageRefCounts.put(ref.refEncoding.queueID, 0);
            } else {
                messageRefCounts.put(ref.refEncoding.queueID, count - 1);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE) {
            PageCountRecord encoding = (PageCountRecord) o;
            queueIDForCounter = encoding.getQueueID();
            subsCounter = lookupCounter(counters, queueIDForCounter);
            subsCounter.loadValue(info.id, encoding.getValue(), encoding.getPersistentSize());
            subsCounter.processReload();
        } else if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_INC) {
            PageCountRecordInc encoding = (PageCountRecordInc) o;
            queueIDForCounter = encoding.getQueueID();
            subsCounter = lookupCounter(counters, queueIDForCounter);
            subsCounter.loadInc(info.id, encoding.getValue(), encoding.getPersistentSize());
            subsCounter.processReload();
        }
        out.println(describeRecord(info, o, safe));
        if (subsCounter != null) {
            out.println("##SubsCounter for queue=" + queueIDForCounter + ", value=" + subsCounter.getValue());
            out.println();
        }
    }
    if (counters.size() > 0) {
        out.println("### Page Counters");
        printCounters(out, counters);
    }
    out.println();
    out.println("### Prepared TX ###");
    for (PreparedTransactionInfo tx : preparedTransactions) {
        out.println(tx.getId());
        for (RecordInfo info : tx.getRecords()) {
            Object o = newObjectEncoding(info);
            out.println("- " + describeRecord(info, o, safe));
            if (info.getUserRecordType() == 31) {
                preparedMessageCount++;
            } else if (info.getUserRecordType() == 32) {
                ReferenceDescribe ref = (ReferenceDescribe) o;
                Integer count = preparedMessageRefCount.get(ref.refEncoding.queueID);
                if (count == null) {
                    count = 1;
                    preparedMessageRefCount.put(ref.refEncoding.queueID, count);
                } else {
                    preparedMessageRefCount.put(ref.refEncoding.queueID, count + 1);
                }
            }
        }
        for (RecordInfo info : tx.getRecordsToDelete()) {
            out.println("- " + describeRecord(info, safe) + " <marked to delete>");
        }
    }
    String missingTX = bufferFailingTransactions.toString();
    if (missingTX.length() > 0) {
        out.println();
        out.println("### Failed Transactions (Missing commit/prepare/rollback record) ###");
    }
    out.println(bufferFailingTransactions.toString());
    out.println("### Message Counts ###");
    out.println("message count=" + messageCount);
    out.println("message reference count");
    for (Map.Entry<Long, Integer> longIntegerEntry : messageRefCounts.entrySet()) {
        out.println("queue id " + longIntegerEntry.getKey() + ",count=" + longIntegerEntry.getValue());
    }
    out.println("prepared message count=" + preparedMessageCount);
    for (Map.Entry<Long, Integer> longIntegerEntry : preparedMessageRefCount.entrySet()) {
        out.println("queue id " + longIntegerEntry.getKey() + ",count=" + longIntegerEntry.getValue());
    }
    journal.stop();
    return new DescribeJournal(records, preparedTransactions);
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with TransactionFailureCallback

use of org.apache.activemq.artemis.core.journal.TransactionFailureCallback in project activemq-artemis by apache.

the class XmlDataExporter method processMessageJournal.

/**
 * Read through the message journal and stuff all the events/data we care about into local data structures.  We'll
 * use this data later to print all the right information.
 *
 * @throws Exception will be thrown if anything goes wrong reading the journal
 */
private void processMessageJournal() throws Exception {
    ArrayList<RecordInfo> acks = new ArrayList<>();
    List<RecordInfo> records = new LinkedList<>();
    // We load these, but don't use them.
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    Journal messageJournal = storageManager.getMessageJournal();
    ActiveMQServerLogger.LOGGER.debug("Reading journal from " + config.getJournalDirectory());
    messageJournal.start();
    // Just logging these, no action necessary
    TransactionFailureCallback transactionFailureCallback = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records1, List<RecordInfo> recordsToDelete) {
            StringBuilder message = new StringBuilder();
            message.append("Encountered failed journal transaction: ").append(transactionID);
            for (int i = 0; i < records1.size(); i++) {
                if (i == 0) {
                    message.append("; Records: ");
                }
                message.append(records1.get(i));
                if (i != (records1.size() - 1)) {
                    message.append(", ");
                }
            }
            for (int i = 0; i < recordsToDelete.size(); i++) {
                if (i == 0) {
                    message.append("; RecordsToDelete: ");
                }
                message.append(recordsToDelete.get(i));
                if (i != (recordsToDelete.size() - 1)) {
                    message.append(", ");
                }
            }
            ActiveMQServerLogger.LOGGER.debug(message.toString());
        }
    };
    messageJournal.load(records, preparedTransactions, transactionFailureCallback, false);
    // Since we don't use these nullify the reference so that the garbage collector can clean them up
    preparedTransactions = null;
    for (RecordInfo info : records) {
        byte[] data = info.data;
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(data);
        Object o = DescribeJournal.newObjectEncoding(info, storageManager);
        if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE) {
            messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE_PROTOCOL) {
            messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_LARGE_MESSAGE) {
            messages.put(info.id, ((MessageDescribe) o).getMsg());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            ReferenceDescribe ref = (ReferenceDescribe) o;
            HashMap<Long, ReferenceDescribe> map = messageRefs.get(info.id);
            if (map == null) {
                HashMap<Long, ReferenceDescribe> newMap = new HashMap<>();
                newMap.put(ref.refEncoding.queueID, ref);
                messageRefs.put(info.id, newMap);
            } else {
                map.put(ref.refEncoding.queueID, ref);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
            acks.add(info);
        } else if (info.userRecordType == JournalRecordIds.ACKNOWLEDGE_CURSOR) {
            CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
            encoding.decode(buff);
            Set<PagePosition> set = cursorRecords.get(encoding.queueID);
            if (set == null) {
                set = new HashSet<>();
                cursorRecords.put(encoding.queueID, set);
            }
            set.add(encoding.position);
        } else if (info.userRecordType == JournalRecordIds.PAGE_TRANSACTION) {
            if (info.isUpdate) {
                PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
                pageUpdate.decode(buff);
                pgTXs.add(pageUpdate.pageTX);
            } else {
                PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
                pageTransactionInfo.decode(buff);
                pageTransactionInfo.setRecordID(info.id);
                pgTXs.add(pageTransactionInfo.getTransactionID());
            }
        }
    }
    messageJournal.stop();
    removeAcked(acks);
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) Set(java.util.Set) HashSet(java.util.HashSet) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) HashMap(java.util.HashMap) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) ArrayList(java.util.ArrayList) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList) PageUpdateTXEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageUpdateTXEncoding) MessageDescribe(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal.MessageDescribe) CursorAckRecordEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ReferenceDescribe(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal.ReferenceDescribe) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) HashSet(java.util.HashSet)

Aggregations

RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)9 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)9 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)8 LinkedList (java.util.LinkedList)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)2 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)2 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 InputBuffer (com.arjuna.ats.arjuna.state.InputBuffer)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 Journal (org.apache.activemq.artemis.core.journal.Journal)1 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)1