Search in sources :

Example 6 with Journal

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

the class JournalImplTestUnit method internaltestSpeedNonTransactional.

private void internaltestSpeedNonTransactional() throws Exception {
    final long numMessages = 10000;
    int numFiles = (int) ((numMessages * 1024 + 512) / (10 * 1024 * 1024) * 1.3);
    if (numFiles < 2) {
        numFiles = 2;
    }
    JournalImplTestUnit.log.debug("num Files=" + numFiles);
    Journal journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    JournalImplTestUnit.log.debug("Adding data");
    SimpleEncoding data = new SimpleEncoding(700, (byte) 'j');
    long start = System.currentTimeMillis();
    for (int i = 0; i < numMessages; i++) {
        journal.appendAddRecord(i, (byte) 0, data, true);
    }
    long end = System.currentTimeMillis();
    double rate = 1000 * (double) numMessages / (end - start);
    JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
    journal.stop();
    journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    journal.stop();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 7 with Journal

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

the class JournalImplTestUnit method testSpeedTransactional.

@Test
public void testSpeedTransactional() throws Exception {
    Journal journal = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    try {
        final int numMessages = 50050;
        SimpleEncoding data = new SimpleEncoding(1024, (byte) 'j');
        long start = System.currentTimeMillis();
        int count = 0;
        double[] rates = new double[50];
        for (int i = 0; i < 50; i++) {
            long startTrans = System.currentTimeMillis();
            for (int j = 0; j < 1000; j++) {
                journal.appendAddRecordTransactional(i, count++, (byte) 0, data);
            }
            journal.appendCommitRecord(i, true);
            long endTrans = System.currentTimeMillis();
            rates[i] = 1000 * (double) 1000 / (endTrans - startTrans);
        }
        long end = System.currentTimeMillis();
        for (double rate : rates) {
            JournalImplTestUnit.log.info("Transaction Rate = " + rate + " records/sec");
        }
        double rate = 1000 * (double) numMessages / (end - start);
        JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
    } finally {
        journal.stop();
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 8 with Journal

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

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

the class XmlDataExporter method getBindings.

/**
 * Open the bindings journal and extract all bindings data.
 *
 * @throws Exception will be thrown if anything goes wrong reading the bindings journal
 */
private void getBindings() throws Exception {
    List<RecordInfo> records = new LinkedList<>();
    Journal bindingsJournal = storageManager.getBindingsJournal();
    bindingsJournal.start();
    ActiveMQServerLogger.LOGGER.debug("Reading bindings journal from " + config.getBindingsDirectory());
    bindingsJournal.load(records, null, null);
    for (RecordInfo info : records) {
        if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
            PersistentQueueBindingEncoding bindingEncoding = (PersistentQueueBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
            queueBindings.put(bindingEncoding.getId(), bindingEncoding);
        } else if (info.getUserRecordType() == JournalRecordIds.ADDRESS_BINDING_RECORD) {
            PersistentAddressBindingEncoding bindingEncoding = (PersistentAddressBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
            addressBindings.put(bindingEncoding.getId(), bindingEncoding);
        }
    }
    bindingsJournal.stop();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PersistentAddressBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) LinkedList(java.util.LinkedList)

Example 10 with Journal

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

Journal (org.apache.activemq.artemis.core.journal.Journal)17 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)7 FileWrapperJournal (org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal)6 Test (org.junit.Test)6 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)5 ArrayList (java.util.ArrayList)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 ReplicatedJournal (org.apache.activemq.artemis.core.replication.ReplicatedJournal)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 JournalContent (org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent)3 DescribeJournal (org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)2