Search in sources :

Example 31 with JournalImpl

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

the class BridgeTest method loadQueues.

/**
 * It will inspect the journal directly and determine if there are queues on this journal,
 *
 * @param serverToInvestigate
 * @return a Map containing the reference counts per queue
 * @throws Exception
 */
protected Map<Long, AtomicInteger> loadQueues(ActiveMQServer serverToInvestigate) throws Exception {
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(serverToInvestigate.getConfiguration().getJournalLocation(), 1);
    JournalImpl messagesJournal = new JournalImpl(serverToInvestigate.getConfiguration().getJournalFileSize(), serverToInvestigate.getConfiguration().getJournalMinFiles(), serverToInvestigate.getConfiguration().getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
    List<RecordInfo> records = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    messagesJournal.start();
    messagesJournal.load(records, preparedTransactions, null);
    // These are more immutable integers
    Map<Long, AtomicInteger> messageRefCounts = new HashMap<>();
    for (RecordInfo info : records) {
        Object o = DescribeJournal.newObjectEncoding(info);
        if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            DescribeJournal.ReferenceDescribe ref = (DescribeJournal.ReferenceDescribe) o;
            AtomicInteger count = messageRefCounts.get(ref.refEncoding.queueID);
            if (count == null) {
                count = new AtomicInteger(1);
                messageRefCounts.put(ref.refEncoding.queueID, count);
            } else {
                count.incrementAndGet();
            }
        }
    }
    messagesJournal.stop();
    return messageRefCounts;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) HashMap(java.util.HashMap) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 32 with JournalImpl

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

the class MixupCompactorTestBase method createJournal.

@Override
public void createJournal() throws Exception {
    journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO) {

        @Override
        public void onCompactDone() {
            startedCompactingLatch.countDown();
            try {
                releaseCompactingLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    journal.setAutoReclaim(false);
}
Also used : JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 33 with JournalImpl

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

the class AddAndRemoveStressTest method testInsertAndLoad.

// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testInsertAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 0, new SimpleEncoding(1024, (byte) 'f'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    impl.forceMoveNextFile();
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 34 with JournalImpl

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

the class AddAndRemoveStressTest method testInsertUpdateAndLoad.

@Test
public void testInsertUpdateAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 21, new SimpleEncoding(40, (byte) 'f'), false);
        impl.appendUpdateRecord(i, (byte) 22, new SimpleEncoding(40, (byte) 'g'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.forceMoveNextFile();
    impl.checkReclaimStatus();
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
    System.out.println("Size = " + impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 35 with JournalImpl

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

the class ValidateTransactionHealthTest method internalTest.

// Package protected ---------------------------------------------
private void internalTest(final String type, final String journalDir, final long numberOfRecords, final int transactionSize, final boolean append, final boolean externalProcess, final int numberOfThreads) throws Exception {
    try {
        if (type.equals("aio") && !LibaioContext.isLoaded()) {
            // Using System.out as this output will go towards junit report
            System.out.println("AIO not found, test being ignored on this platform");
            return;
        }
        // This property could be set to false for debug purposes.
        if (append) {
            if (externalProcess) {
                Process process = SpawnedVMSupport.spawnVM(ValidateTransactionHealthTest.class.getCanonicalName(), type, journalDir, Long.toString(numberOfRecords), Integer.toString(transactionSize), Integer.toString(numberOfThreads));
                process.waitFor();
                Assert.assertEquals(ValidateTransactionHealthTest.OK, process.exitValue());
            } else {
                JournalImpl journal = ValidateTransactionHealthTest.appendData(type, journalDir, numberOfRecords, transactionSize, numberOfThreads);
                journal.stop();
            }
        }
        reload(type, journalDir, numberOfRecords, numberOfThreads);
    } finally {
        File file = new File(journalDir);
        deleteDirectory(file);
    }
}
Also used : File(java.io.File) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Aggregations

JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)41 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)20 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)19 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)13 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)13 Test (org.junit.Test)12 File (java.io.File)10 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)6 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)6 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)5 Pair (org.apache.activemq.artemis.api.core.Pair)4 Journal (org.apache.activemq.artemis.core.journal.Journal)4 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Configuration (org.apache.activemq.artemis.core.config.Configuration)3 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)3