Search in sources :

Example 1 with JournalReaderCallback

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

Aggregations

HashMap (java.util.HashMap)1 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 JournalReaderCallback (org.apache.activemq.artemis.core.journal.impl.JournalReaderCallback)1 PageSubscriptionCounterImpl (org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl)1 PageCountRecord (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord)1 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)1