Search in sources :

Example 21 with PreparedTransactionInfo

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

the class JournalImplTestBase method loadAndCheck.

protected void loadAndCheck(final boolean printDebugJournal) throws Exception {
    List<RecordInfo> committedRecords = new ArrayList<>();
    List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
    journal.load(committedRecords, preparedTransactions, null);
    checkRecordsEquivalent(records, committedRecords);
    if (printDebugJournal) {
        printJournalLists(records, committedRecords);
    }
    // check prepared transactions
    List<PreparedTransactionInfo> prepared = new ArrayList<>();
    for (Map.Entry<Long, TransactionHolder> entry : transactions.entrySet()) {
        if (entry.getValue().prepared) {
            PreparedTransactionInfo info = new PreparedTransactionInfo(entry.getKey(), null);
            info.getRecords().addAll(entry.getValue().records);
            info.getRecordsToDelete().addAll(entry.getValue().deletes);
            prepared.add(info);
        }
    }
    checkTransactionsEquivalent(prepared, preparedTransactions);
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with PreparedTransactionInfo

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

the class BatchIDGeneratorUnitTest method loadIDs.

protected void loadIDs(final Journal journal, final BatchingIDGenerator batch) throws Exception {
    ArrayList<RecordInfo> records = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> tx = new ArrayList<>();
    journal.start();
    journal.load(records, tx, null);
    Assert.assertEquals(0, tx.size());
    Assert.assertTrue("Contains " + records.size(), records.size() > 0);
    for (RecordInfo record : records) {
        if (record.userRecordType == JournalRecordIds.ID_COUNTER_RECORD) {
            ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
            batch.loadState(record.id, buffer);
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 23 with PreparedTransactionInfo

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

the class JournalPageCountSizeTest method testPageCursorCounterRecordSizeTX.

@Test
public void testPageCursorCounterRecordSizeTX() throws Exception {
    long tx = server.getStorageManager().generateID();
    server.getStorageManager().storePageCounterInc(tx, 1, 1, 1000);
    server.getStorageManager().commit(tx);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
        PageCountRecordInc encoding = new PageCountRecordInc();
        encoding.decode(buff);
        Assert.assertEquals(1000, encoding.getPersistentSize());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 24 with PreparedTransactionInfo

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

the class JournalImpl method load.

/**
 * @see JournalImpl#load(LoaderCallback)
 */
@Override
public synchronized JournalLoadInformation load(final List<RecordInfo> committedRecords, final List<PreparedTransactionInfo> preparedTransactions, final TransactionFailureCallback failureCallback, final boolean fixBadTX) throws Exception {
    final Set<Long> recordsToDelete = new HashSet<>();
    // ArrayList was taking too long to delete elements on checkDeleteSize
    final List<RecordInfo> records = new LinkedList<>();
    final int DELETE_FLUSH = 20000;
    JournalLoadInformation info = load(new LoaderCallback() {

        Runtime runtime = Runtime.getRuntime();

        private void checkDeleteSize() {
            // HORNETQ-482 - Flush deletes only if memory is critical
            if (recordsToDelete.size() > DELETE_FLUSH && runtime.freeMemory() < runtime.maxMemory() * 0.2) {
                ActiveMQJournalLogger.LOGGER.debug("Flushing deletes during loading, deleteCount = " + recordsToDelete.size());
                // Clean up when the list is too large, or it won't be possible to load large sets of files
                // Done as part of JBMESSAGING-1678
                Iterator<RecordInfo> iter = records.iterator();
                while (iter.hasNext()) {
                    RecordInfo record = iter.next();
                    if (recordsToDelete.contains(record.id)) {
                        iter.remove();
                    }
                }
                recordsToDelete.clear();
                ActiveMQJournalLogger.LOGGER.debug("flush delete done");
            }
        }

        @Override
        public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) {
            preparedTransactions.add(preparedTransaction);
            checkDeleteSize();
        }

        @Override
        public void addRecord(final RecordInfo info) {
            records.add(info);
            checkDeleteSize();
        }

        @Override
        public void updateRecord(final RecordInfo info) {
            records.add(info);
            checkDeleteSize();
        }

        @Override
        public void deleteRecord(final long id) {
            recordsToDelete.add(id);
            checkDeleteSize();
        }

        @Override
        public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
            if (failureCallback != null) {
                failureCallback.failedTransaction(transactionID, records, recordsToDelete);
            }
        }
    }, fixBadTX, null);
    for (RecordInfo record : records) {
        if (!recordsToDelete.contains(record.id)) {
            committedRecords.add(record);
        }
    }
    return info;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LinkedList(java.util.LinkedList) LoaderCallback(org.apache.activemq.artemis.core.journal.LoaderCallback) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) AtomicLong(java.util.concurrent.atomic.AtomicLong) Iterator(java.util.Iterator) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) HashSet(java.util.HashSet) ConcurrentLongHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentLongHashSet)

Example 25 with PreparedTransactionInfo

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

the class BridgeTest method loadQueues.

/**
 * It will inspect the journal directly and determine if there are queues on this journal,
 *
 * @param serverToInvestigate
 * @return a Map containing the reference counts per queue
 * @throws Exception
 */
protected Map<Long, AtomicInteger> loadQueues(ActiveMQServer serverToInvestigate) throws Exception {
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(serverToInvestigate.getConfiguration().getJournalLocation(), 1);
    JournalImpl messagesJournal = new JournalImpl(serverToInvestigate.getConfiguration().getJournalFileSize(), serverToInvestigate.getConfiguration().getJournalMinFiles(), serverToInvestigate.getConfiguration().getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
    List<RecordInfo> records = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    messagesJournal.start();
    messagesJournal.load(records, preparedTransactions, null);
    // These are more immutable integers
    Map<Long, AtomicInteger> messageRefCounts = new HashMap<>();
    for (RecordInfo info : records) {
        Object o = DescribeJournal.newObjectEncoding(info);
        if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            DescribeJournal.ReferenceDescribe ref = (DescribeJournal.ReferenceDescribe) o;
            AtomicInteger count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                count = new AtomicInteger(1);
                messageRefCounts.put(ref.refEncoding.queueID, count);
            } else {
                count.incrementAndGet();
            }
        }
    }
    messagesJournal.stop();
    return messageRefCounts;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) HashMap(java.util.HashMap) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Aggregations

PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)34 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)33 ArrayList (java.util.ArrayList)17 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)13 Test (org.junit.Test)13 LinkedList (java.util.LinkedList)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)10 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)8 HashMap (java.util.HashMap)7 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)7 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)5 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)5 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)5 File (java.io.File)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3