Search in sources :

Example 1 with PageSubscriptionCounterImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl in project activemq-artemis by apache.

the class DescribeJournal method lookupCounter.

protected static PageSubscriptionCounterImpl lookupCounter(Map<Long, PageSubscriptionCounterImpl> counters, long queueIDForCounter) {
    PageSubscriptionCounterImpl subsCounter;
    subsCounter = counters.get(queueIDForCounter);
    if (subsCounter == null) {
        subsCounter = new PageSubscriptionCounterImpl(null, null, null, false, -1);
        counters.put(queueIDForCounter, subsCounter);
    }
    return subsCounter;
}
Also used : PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl)

Example 2 with PageSubscriptionCounterImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl in project activemq-artemis by apache.

the class DescribeJournal method printSurvivingRecords.

public static DescribeJournal printSurvivingRecords(Journal journal, PrintStream out, boolean safe) throws Exception {
    final Map<Long, PageSubscriptionCounterImpl> counters = new HashMap<>();
    out.println("### Surviving Records Summary ###");
    List<RecordInfo> records = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    journal.start();
    final StringBuffer bufferFailingTransactions = new StringBuffer();
    int messageCount = 0;
    Map<Long, Integer> messageRefCounts = new HashMap<>();
    int preparedMessageCount = 0;
    Map<Long, Integer> preparedMessageRefCount = new HashMap<>();
    journal.load(records, preparedTransactions, new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records1, List<RecordInfo> recordsToDelete) {
            bufferFailingTransactions.append("Transaction " + transactionID + " failed with these records:\n");
            for (RecordInfo info : records1) {
                bufferFailingTransactions.append("- " + describeRecord(info, safe) + "\n");
            }
            for (RecordInfo info : recordsToDelete) {
                bufferFailingTransactions.append("- " + describeRecord(info, safe) + " <marked to delete>\n");
            }
        }
    }, false);
    for (RecordInfo info : records) {
        PageSubscriptionCounterImpl subsCounter = null;
        long queueIDForCounter = 0;
        Object o = newObjectEncoding(info);
        if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE) {
            messageCount++;
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            ReferenceDescribe ref = (ReferenceDescribe) o;
            Integer count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                count = 1;
                messageRefCounts.put(ref.refEncoding.queueID, count);
            } else {
                messageRefCounts.put(ref.refEncoding.queueID, count + 1);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
            AckDescribe ref = (AckDescribe) o;
            Integer count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                messageRefCounts.put(ref.refEncoding.queueID, 0);
            } else {
                messageRefCounts.put(ref.refEncoding.queueID, count - 1);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE) {
            PageCountRecord encoding = (PageCountRecord) o;
            queueIDForCounter = encoding.getQueueID();
            subsCounter = lookupCounter(counters, queueIDForCounter);
            subsCounter.loadValue(info.id, encoding.getValue(), encoding.getPersistentSize());
            subsCounter.processReload();
        } else if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_INC) {
            PageCountRecordInc encoding = (PageCountRecordInc) o;
            queueIDForCounter = encoding.getQueueID();
            subsCounter = lookupCounter(counters, queueIDForCounter);
            subsCounter.loadInc(info.id, encoding.getValue(), encoding.getPersistentSize());
            subsCounter.processReload();
        }
        out.println(describeRecord(info, o, safe));
        if (subsCounter != null) {
            out.println("##SubsCounter for queue=" + queueIDForCounter + ", value=" + subsCounter.getValue());
            out.println();
        }
    }
    if (counters.size() > 0) {
        out.println("### Page Counters");
        printCounters(out, counters);
    }
    out.println();
    out.println("### Prepared TX ###");
    for (PreparedTransactionInfo tx : preparedTransactions) {
        out.println(tx.getId());
        for (RecordInfo info : tx.getRecords()) {
            Object o = newObjectEncoding(info);
            out.println("- " + describeRecord(info, o, safe));
            if (info.getUserRecordType() == 31) {
                preparedMessageCount++;
            } else if (info.getUserRecordType() == 32) {
                ReferenceDescribe ref = (ReferenceDescribe) o;
                Integer count = preparedMessageRefCount.get(ref.refEncoding.queueID);
                if (count == null) {
                    count = 1;
                    preparedMessageRefCount.put(ref.refEncoding.queueID, count);
                } else {
                    preparedMessageRefCount.put(ref.refEncoding.queueID, count + 1);
                }
            }
        }
        for (RecordInfo info : tx.getRecordsToDelete()) {
            out.println("- " + describeRecord(info, safe) + " <marked to delete>");
        }
    }
    String missingTX = bufferFailingTransactions.toString();
    if (missingTX.length() > 0) {
        out.println();
        out.println("### Failed Transactions (Missing commit/prepare/rollback record) ###");
    }
    out.println(bufferFailingTransactions.toString());
    out.println("### Message Counts ###");
    out.println("message count=" + messageCount);
    out.println("message reference count");
    for (Map.Entry<Long, Integer> longIntegerEntry : messageRefCounts.entrySet()) {
        out.println("queue id " + longIntegerEntry.getKey() + ",count=" + longIntegerEntry.getValue());
    }
    out.println("prepared message count=" + preparedMessageCount);
    for (Map.Entry<Long, Integer> longIntegerEntry : preparedMessageRefCount.entrySet()) {
        out.println("queue id " + longIntegerEntry.getKey() + ",count=" + longIntegerEntry.getValue());
    }
    journal.stop();
    return new DescribeJournal(records, preparedTransactions);
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PageSubscriptionCounterImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl in project activemq-artemis by apache.

the class DescribeJournal method describeJournal.

/**
 * @param fileFactory
 * @param journal
 * @throws Exception
 */
private static DescribeJournal describeJournal(SequentialFileFactory fileFactory, JournalImpl journal, final File path, PrintStream out, boolean safe) throws Exception {
    List<JournalFile> files = journal.orderFiles();
    final Map<Long, PageSubscriptionCounterImpl> counters = new HashMap<>();
    out.println("Journal path: " + path);
    for (JournalFile file : files) {
        out.println("#" + file + " (size=" + file.getFile().size() + ")");
        JournalImpl.readJournalFile(fileFactory, file, new JournalReaderCallback() {

            @Override
            public void onReadUpdateRecordTX(final long transactionID, final RecordInfo recordInfo) throws Exception {
                out.println("operation@UpdateTX;txID=" + transactionID + "," + describeRecord(recordInfo, safe));
                checkRecordCounter(recordInfo);
            }

            @Override
            public void onReadUpdateRecord(final RecordInfo recordInfo) throws Exception {
                out.println("operation@Update;" + describeRecord(recordInfo, safe));
                checkRecordCounter(recordInfo);
            }

            @Override
            public void onReadRollbackRecord(final long transactionID) throws Exception {
                out.println("operation@Rollback;txID=" + transactionID);
            }

            @Override
            public void onReadPrepareRecord(final long transactionID, final byte[] extraData, final int numberOfRecords) throws Exception {
                out.println("operation@Prepare,txID=" + transactionID + ",numberOfRecords=" + numberOfRecords + ",extraData=" + encode(extraData) + ", xid=" + toXid(extraData));
            }

            @Override
            public void onReadDeleteRecordTX(final long transactionID, final RecordInfo recordInfo) throws Exception {
                out.println("operation@DeleteRecordTX;txID=" + transactionID + "," + describeRecord(recordInfo, safe));
            }

            @Override
            public void onReadDeleteRecord(final long recordID) throws Exception {
                out.println("operation@DeleteRecord;recordID=" + recordID);
            }

            @Override
            public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception {
                out.println("operation@Commit;txID=" + transactionID + ",numberOfRecords=" + numberOfRecords);
            }

            @Override
            public void onReadAddRecordTX(final long transactionID, final RecordInfo recordInfo) throws Exception {
                out.println("operation@AddRecordTX;txID=" + transactionID + "," + describeRecord(recordInfo, safe));
            }

            @Override
            public void onReadAddRecord(final RecordInfo recordInfo) throws Exception {
                out.println("operation@AddRecord;" + describeRecord(recordInfo, safe));
            }

            @Override
            public void markAsDataFile(final JournalFile file1) {
            }

            public void checkRecordCounter(RecordInfo info) {
                if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE) {
                    PageCountRecord encoding = (PageCountRecord) newObjectEncoding(info);
                    long queueIDForCounter = encoding.getQueueID();
                    PageSubscriptionCounterImpl subsCounter = lookupCounter(counters, queueIDForCounter);
                    if (subsCounter.getValue() != 0 && subsCounter.getValue() != encoding.getValue()) {
                        out.println("####### Counter replace wrongly on queue " + queueIDForCounter + " oldValue=" + subsCounter.getValue() + " newValue=" + encoding.getValue());
                    }
                    subsCounter.loadValue(info.id, encoding.getValue(), encoding.getPersistentSize());
                    subsCounter.processReload();
                    out.print("#Counter queue " + queueIDForCounter + " value=" + subsCounter.getValue() + " persistentSize=" + subsCounter.getPersistentSize() + ", result=" + subsCounter.getValue());
                    if (subsCounter.getValue() < 0) {
                        out.println(" #NegativeCounter!!!!");
                    } else {
                        out.println();
                    }
                    out.println();
                } else if (info.getUserRecordType() == JournalRecordIds.PAGE_CURSOR_COUNTER_INC) {
                    PageCountRecordInc encoding = (PageCountRecordInc) newObjectEncoding(info);
                    long queueIDForCounter = encoding.getQueueID();
                    PageSubscriptionCounterImpl subsCounter = lookupCounter(counters, queueIDForCounter);
                    subsCounter.loadInc(info.id, encoding.getValue(), encoding.getPersistentSize());
                    subsCounter.processReload();
                    out.print("#Counter queue " + queueIDForCounter + " value=" + subsCounter.getValue() + " persistentSize=" + subsCounter.getPersistentSize() + " increased by " + encoding.getValue());
                    if (subsCounter.getValue() < 0) {
                        out.println(" #NegativeCounter!!!!");
                    } else {
                        out.println();
                    }
                    out.println();
                }
            }
        });
    }
    out.println();
    if (counters.size() != 0) {
        out.println("#Counters during initial load:");
        printCounters(out, counters);
    }
    return printSurvivingRecords(journal, out, safe);
}
Also used : HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) JournalReaderCallback(org.apache.activemq.artemis.core.journal.impl.JournalReaderCallback) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)

Example 4 with PageSubscriptionCounterImpl

use of org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl in project activemq-artemis by apache.

the class PagingCounterTest method testCleanupCounterNonPersistent.

@Test
public void testCleanupCounterNonPersistent() throws Exception {
    ClientSessionFactory sf = createSessionFactory(sl);
    ClientSession session = sf.createSession();
    try {
        server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
        Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
        PageSubscriptionCounter counter = locateCounter(queue);
        ((PageSubscriptionCounterImpl) counter).setPersistent(false);
        StorageManager storage = server.getStorageManager();
        Transaction tx = new TransactionImpl(server.getStorageManager());
        for (int i = 0; i < 2100; i++) {
            counter.increment(tx, 1, 1000);
            if (i % 200 == 0) {
                tx.commit();
                storage.waitOnOperations();
                assertEquals(i + 1, counter.getValue());
                assertEquals((i + 1) * 1000, counter.getPersistentSize());
                tx = new TransactionImpl(server.getStorageManager());
            }
        }
        tx.commit();
        storage.waitOnOperations();
        assertEquals(2100, counter.getValue());
        assertEquals(2100 * 1000, counter.getPersistentSize());
        server.stop();
        server = newActiveMQServer();
        server.start();
        queue = server.locateQueue(new SimpleString("A1"));
        assertNotNull(queue);
        counter = locateCounter(queue);
        assertEquals(0, counter.getValue());
        assertEquals(0, counter.getPersistentSize());
    } finally {
        sf.close();
        session.close();
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) Test(org.junit.Test)

Aggregations

PageSubscriptionCounterImpl (org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl)4 HashMap (java.util.HashMap)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 PageCountRecord (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord)2 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)2 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)1 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 JournalReaderCallback (org.apache.activemq.artemis.core.journal.impl.JournalReaderCallback)1 PageSubscriptionCounter (org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter)1 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)1 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)1 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)1