Search in sources :

Example 6 with PageCountRecordInc

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc 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 7 with PageCountRecordInc

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc in project activemq-artemis by apache.

the class AbstractJournalStorageManager method storePageCounterInc.

@Override
public long storePageCounterInc(long txID, long queueID, int value, long persistentSize) throws Exception {
    readLock();
    try {
        long recordID = idGenerator.generateID();
        messageJournal.appendAddRecordTransactional(txID, recordID, JournalRecordIds.PAGE_CURSOR_COUNTER_INC, new PageCountRecordInc(queueID, value, persistentSize));
        return recordID;
    } finally {
        readUnLock();
    }
}
Also used : PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)

Example 8 with PageCountRecordInc

use of org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc 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)

Aggregations

PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)8 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)6 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)5 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)5 HashMap (java.util.HashMap)4 PageCountRecord (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord)4 LinkedList (java.util.LinkedList)3 Message (org.apache.activemq.artemis.api.core.Message)3 PageTransactionInfoImpl (org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl)3 CursorAckRecordEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding)3 DuplicateIDEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.DuplicateIDEncoding)3 RefEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.RefEncoding)3 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PageTransactionInfo (org.apache.activemq.artemis.core.paging.PageTransactionInfo)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2 PageSubscriptionCounterImpl (org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl)2