Search in sources :

Example 11 with PreparedTransactionInfo

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

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

the class ActiveMQTestBase method internalCountJournalLivingRecords.

/**
 * This method will load a journal and count the living records
 *
 * @param config
 * @param messageJournal if true -> MessageJournal, false -> BindingsJournal
 * @return
 * @throws Exception
 */
protected HashMap<Integer, AtomicInteger> internalCountJournalLivingRecords(Configuration config, boolean messageJournal) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory ff;
    JournalImpl journal;
    if (messageJournal) {
        ff = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
        journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, ff, "activemq-data", "amq", 1);
    } else {
        ff = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
        journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), ff, "activemq-bindings", "bindings", 1);
    }
    journal.start();
    final List<RecordInfo> committedRecords = new LinkedList<>();
    final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    journal.load(committedRecords, preparedTransactions, null, false);
    for (RecordInfo info : committedRecords) {
        Integer ikey = new Integer(info.getUserRecordType());
        AtomicInteger value = recordsType.get(ikey);
        if (value == null) {
            value = new AtomicInteger();
            recordsType.put(ikey, value);
        }
        value.incrementAndGet();
    }
    journal.stop();
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) 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) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 13 with PreparedTransactionInfo

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

the class PagingTest method testMissingTXEverythingAcked.

@Test
public void testMissingTXEverythingAcked() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 5000;
    final int numberOfTX = 10;
    final int messagesPerTX = numberOfMessages / numberOfTX;
    try {
        locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        sf = createSessionFactory(locator);
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS.toString(), "q1", true);
        session.createQueue(ADDRESS.toString(), "q2", true);
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        byte[] body = new byte[MESSAGE_SIZE];
        ByteBuffer bb = ByteBuffer.wrap(body);
        for (int j = 1; j <= MESSAGE_SIZE; j++) {
            bb.put(getSamplebyte(j));
        }
        for (int i = 0; i < numberOfMessages; i++) {
            message = session.createMessage(true);
            ActiveMQBuffer bodyLocal = message.getBodyBuffer();
            bodyLocal.writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);
            producer.send(message);
            if (i % messagesPerTX == 0) {
                session.commit();
            }
        }
        session.commit();
        session.close();
        ArrayList<RecordInfo> records = new ArrayList<>();
        List<PreparedTransactionInfo> list = new ArrayList<>();
        server.getStorageManager().getMessageJournal().stop();
        Journal jrn = server.getStorageManager().getMessageJournal();
        jrn.start();
        jrn.load(records, list, null);
        // Delete everything from the journal
        for (RecordInfo info : records) {
            if (!info.isUpdate && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_INC && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COMPLETE) {
                jrn.appendDeleteRecord(info.id, false);
            }
        }
        jrn.stop();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession sess = csf.createSession();
    sess.start();
    ClientConsumer cons = sess.createConsumer("q1");
    assertNull(cons.receiveImmediate());
    ClientConsumer cons2 = sess.createConsumer("q2");
    assertNull(cons2.receiveImmediate());
    Queue q1 = server.locateQueue(new SimpleString("q1"));
    Queue q2 = server.locateQueue(new SimpleString("q2"));
    q1.getPageSubscription().cleanupEntries(false);
    q2.getPageSubscription().cleanupEntries(false);
    PageCursorProvider provider = q1.getPageSubscription().getPagingStore().getCursorProvider();
    provider.cleanup();
    waitForNotPaging(q1);
    sess.close();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 14 with PreparedTransactionInfo

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

the class JournalPageCountSizeTest method testPageCountRecordSize.

@Test
public void testPageCountRecordSize() throws Exception {
    long tx = server.getStorageManager().generateID();
    server.getStorageManager().storePageCounter(tx, 1, 1, 100);
    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);
        PageCountRecord encoding = new PageCountRecord();
        encoding.decode(buff);
        Assert.assertEquals(100, encoding.getPersistentSize());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) 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 15 with PreparedTransactionInfo

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

the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.

@Test
public void testPageCursorCounterRecordSize() throws Exception {
    server.getStorageManager().storePageCounterInc(1, 1, 1000);
    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)

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