Search in sources :

Example 36 with RecordInfo

use of org.apache.activemq.artemis.core.journal.RecordInfo 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)

Example 37 with RecordInfo

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

the class JournalCrashTest method printJournal.

/**
 * @throws Exception
 */
private void printJournal() throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 100);
    JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
    ArrayList<RecordInfo> records = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> transactions = new ArrayList<>();
    journal.start();
    journal.load(records, transactions, null);
    // System.out.println("===============================================");
    // System.out.println("Journal records at the end:");
    // 
    // for (RecordInfo record : records)
    // {
    // System.out.println(record.id + ", update = " + record.isUpdate);
    // }
    journal.stop();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 38 with RecordInfo

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

the class HangConsumerTest method testDuplicateDestinationsOnTopic.

/**
 * This will simulate what would happen with topic creationg where a single record is supposed to be created on the journal
 *
 * @throws Exception
 */
@Test
public void testDuplicateDestinationsOnTopic() throws Exception {
    try {
        for (int i = 0; i < 5; i++) {
            if (server.locateQueue(SimpleString.toSimpleString("tt")) == null) {
                server.createQueue(SimpleString.toSimpleString("tt"), RoutingType.ANYCAST, SimpleString.toSimpleString("tt"), SimpleString.toSimpleString(Filter.GENERIC_IGNORED_FILTER), true, false);
            }
            server.stop();
            SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null, 1);
            JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 2, 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
            messagesJournal.start();
            LinkedList<RecordInfo> infos = new LinkedList<>();
            messagesJournal.load(infos, null, null);
            int bindings = 0;
            for (RecordInfo info : infos) {
                System.out.println("info: " + info);
                if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
                    bindings++;
                }
            }
            assertEquals(1, bindings);
            System.out.println("Bindings: " + bindings);
            messagesJournal.stop();
            if (i < 4)
                server.start();
        }
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 39 with RecordInfo

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

the class AlignedJournalImplTest method setupAndLoadJournal.

private void setupAndLoadJournal(final int journalSize, final int alignment, final int numberOfMinimalFiles) throws Exception {
    if (factory == null) {
        factory = new FakeSequentialFileFactory(alignment, true);
    }
    if (journalImpl != null) {
        journalImpl.stop();
    }
    journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, numberOfMinimalFiles, 0, 0, factory, "tt", "tt", 1000);
    addActiveMQComponent(journalImpl);
    journalImpl.start();
    records.clear();
    transactions.clear();
    incompleteTransactions.clear();
    journalImpl.load(records, transactions, new TransactionFailureCallback() {

        @Override
        public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
            System.out.println("records.length = " + records.size());
            incompleteTransactions.add(transactionID);
        }
    });
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 40 with RecordInfo

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

the class JournalImplTestBase method checkTransactionsEquivalent.

protected void checkTransactionsEquivalent(final List<PreparedTransactionInfo> expected, final List<PreparedTransactionInfo> actual) {
    Assert.assertEquals("Lists not same length", expected.size(), actual.size());
    Iterator<PreparedTransactionInfo> iterExpected = expected.iterator();
    Iterator<PreparedTransactionInfo> iterActual = actual.iterator();
    while (iterExpected.hasNext()) {
        PreparedTransactionInfo rexpected = iterExpected.next();
        PreparedTransactionInfo ractual = iterActual.next();
        Assert.assertEquals("ids not same", rexpected.getId(), ractual.getId());
        checkRecordsEquivalent(rexpected.getRecords(), ractual.getRecords());
        Assert.assertEquals("deletes size not same", rexpected.getRecordsToDelete().size(), ractual.getRecordsToDelete().size());
        Iterator<RecordInfo> iterDeletesExpected = rexpected.getRecordsToDelete().iterator();
        Iterator<RecordInfo> iterDeletesActual = ractual.getRecordsToDelete().iterator();
        while (iterDeletesExpected.hasNext()) {
            long lexpected = iterDeletesExpected.next().id;
            long lactual = iterDeletesActual.next().id;
            Assert.assertEquals("Delete ids not same", lexpected, lactual);
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo)

Aggregations

RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)65 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)33 ArrayList (java.util.ArrayList)22 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)20 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)15 HashMap (java.util.HashMap)10 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)10 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)9 File (java.io.File)7 Journal (org.apache.activemq.artemis.core.journal.Journal)7 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)7 List (java.util.List)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)6 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5