Search in sources :

Example 1 with LoaderCallback

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

the class RedeliveryConsumerTest method internaltestInfiniteDedeliveryMessageOnPersistent.

private void internaltestInfiniteDedeliveryMessageOnPersistent(final boolean strict) throws Exception {
    setUp(strict);
    ClientSession session = factory.createSession(false, false, false);
    RedeliveryConsumerTest.log.info("created");
    ClientProducer prod = session.createProducer(ADDRESS);
    prod.send(createTextMessage(session, "Hello"));
    session.commit();
    session.close();
    int expectedCount = 1;
    for (int i = 0; i < 700; i++) {
        session = factory.createSession(false, false, false);
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        assertEquals(expectedCount, msg.getDeliveryCount());
        if (i % 100 == 0) {
            expectedCount++;
            msg.acknowledge();
            session.rollback();
        }
        session.close();
    }
    factory.close();
    server.stop();
    setUp(false);
    for (int i = 0; i < 700; i++) {
        session = factory.createSession(false, false, false);
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        assertEquals(expectedCount, msg.getDeliveryCount());
        session.close();
    }
    server.stop();
    JournalImpl journal = new JournalImpl(server.getConfiguration().getJournalFileSize(), 2, 2, 0, 0, new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation(), 1), "activemq-data", "amq", 1);
    final AtomicInteger updates = new AtomicInteger();
    journal.start();
    journal.load(new LoaderCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }

        @Override
        public void updateRecord(RecordInfo info) {
            if (info.userRecordType == JournalRecordIds.UPDATE_DELIVERY_COUNT) {
                updates.incrementAndGet();
            }
        }

        @Override
        public void deleteRecord(long id) {
        }

        @Override
        public void addRecord(RecordInfo info) {
        }

        @Override
        public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction) {
        }
    });
    journal.stop();
    assertEquals(7, updates.get());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) LoaderCallback(org.apache.activemq.artemis.core.journal.LoaderCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 2 with LoaderCallback

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

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

the class ValidateTransactionHealthTest method appendData.

public static JournalImpl appendData(final String journalType, final String journalDir, final long numberOfElements, final int transactionSize, final int numberOfThreads) throws Exception {
    final JournalImpl journal = ValidateTransactionHealthTest.createJournal(journalType, journalDir);
    journal.start();
    journal.load(new LoaderCallback() {

        @Override
        public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) {
        }

        @Override
        public void addRecord(final RecordInfo info) {
        }

        @Override
        public void deleteRecord(final long id) {
        }

        @Override
        public void updateRecord(final RecordInfo info) {
        }

        @Override
        public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
        }
    });
    LocalThread[] threads = new LocalThread[numberOfThreads];
    final AtomicLong sequenceTransaction = new AtomicLong();
    for (int i = 0; i < numberOfThreads; i++) {
        threads[i] = new LocalThread(journal, numberOfElements, transactionSize, sequenceTransaction);
        threads[i].start();
    }
    Exception e = null;
    for (LocalThread t : threads) {
        t.join();
        if (t.e != null) {
            e = t.e;
        }
    }
    if (e != null) {
        throw e;
    }
    journal.flush();
    return journal;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LoaderCallback(org.apache.activemq.artemis.core.journal.LoaderCallback) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Aggregations

LoaderCallback (org.apache.activemq.artemis.core.journal.LoaderCallback)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)1 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)1 ConcurrentHashSet (org.apache.activemq.artemis.utils.collections.ConcurrentHashSet)1 ConcurrentLongHashSet (org.apache.activemq.artemis.utils.collections.ConcurrentLongHashSet)1