Search in sources :

Example 6 with JournalImpl

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

the class JournalCleanupCompactStressTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = Executors.newFixedThreadPool(20, tFactory);
    executorFactory = new OrderedExecutorFactory(threadPool);
    testExecutor = executorFactory.getExecutor();
    maxRecords = new Semaphore(MAX_WRITES);
    errors.set(0);
    File dir = new File(getTemporaryDir());
    dir.mkdirs();
    SequentialFileFactory factory;
    int maxAIO;
    if (LibaioContext.isLoaded()) {
        factory = new AIOSequentialFileFactory(dir, 10);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio();
    } else {
        factory = new NIOSequentialFileFactory(dir, true, 1);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoNio();
    }
    journal = new JournalImpl(50 * 1024, 20, 20, 50, ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage(), factory, "activemq-data", "amq", maxAIO) {

        @Override
        protected void onCompactLockingTheJournal() throws Exception {
        }

        @Override
        protected void onCompactStart() throws Exception {
            testExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        // System.out.println("OnCompactStart enter");
                        if (running) {
                            long id = idGen.generateID();
                            journal.appendAddRecord(id, (byte) 0, new byte[] { 1, 2, 3 }, false);
                            journal.forceMoveNextFile();
                            journal.appendDeleteRecord(id, id == 20);
                        }
                    // System.out.println("OnCompactStart leave");
                    } catch (Exception e) {
                        e.printStackTrace();
                        errors.incrementAndGet();
                    }
                }
            });
        }
    };
    journal.start();
    journal.loadInternalOnly();
}
Also used : OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) Semaphore(java.util.concurrent.Semaphore) File(java.io.File) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Before(org.junit.Before)

Example 7 with JournalImpl

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

the class NIOMultiThreadCompactorStressTest method testMultiThreadCompact.

@Test
public void testMultiThreadCompact() throws Throwable {
    setupServer(getJournalType());
    for (int i = 0; i < getNumberOfIterations(); i++) {
        System.out.println("######################################");
        System.out.println("test # " + i);
        internalTestProduceAndConsume();
        stopServer();
        NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 1);
        JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
        List<RecordInfo> committedRecords = new ArrayList<>();
        List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
        journal.start();
        journal.load(committedRecords, preparedTransactions, null);
        Assert.assertEquals(0, committedRecords.size());
        Assert.assertEquals(0, preparedTransactions.size());
        System.out.println("DataFiles = " + journal.getDataFilesCount());
        if (i % 2 == 0 && i > 0) {
            System.out.println("DataFiles = " + journal.getDataFilesCount());
            journal.forceMoveNextFile();
            journal.debugWait();
            journal.checkReclaimStatus();
            if (journal.getDataFilesCount() != 0) {
                System.out.println("DebugJournal:" + journal.debug());
            }
            Assert.assertEquals(0, journal.getDataFilesCount());
        }
        journal.stop();
        journal = null;
        setupServer(getJournalType());
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 8 with JournalImpl

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

the class JournalAsyncTest method setupJournal.

// Private -------------------------------------------------------
private void setupJournal(final int journalSize, final int alignment, final int numberOfMinimalFiles) throws Exception {
    if (factory == null) {
        factory = new FakeSequentialFileFactory(alignment, true);
    }
    if (journalImpl != null) {
        journalImpl.stop();
    }
    journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, numberOfMinimalFiles, 0, 0, factory, "tt", "tt", 1000);
    journalImpl.start();
    records.clear();
    transactions.clear();
    journalImpl.load(records, transactions, null);
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 9 with JournalImpl

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

the class AlignedJournalImplTest method testAlignmentOverReload.

@Test
public void testAlignmentOverReload() throws Exception {
    factory = new FakeSequentialFileFactory(512, false);
    journalImpl = new JournalImpl(512 + 512 * 3, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    journalImpl.start();
    journalImpl.load(AlignedJournalImplTest.dummyLoader);
    journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(100, (byte) 'a'), false);
    journalImpl.appendAddRecord(2L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.appendAddRecord(3L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.appendAddRecord(4L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.stop();
    journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    addActiveMQComponent(journalImpl);
    journalImpl.start();
    journalImpl.load(AlignedJournalImplTest.dummyLoader);
    // It looks silly, but this forceMoveNextFile is in place to replicate one
    // specific bug caught during development
    journalImpl.forceMoveNextFile();
    journalImpl.appendDeleteRecord(1L, false);
    journalImpl.appendDeleteRecord(2L, false);
    journalImpl.appendDeleteRecord(3L, false);
    journalImpl.appendDeleteRecord(4L, false);
    journalImpl.stop();
    journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    addActiveMQComponent(journalImpl);
    journalImpl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    journalImpl.load(info, trans, null);
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 10 with JournalImpl

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

the class BatchIDGeneratorUnitTest method testSequence.

@Test
public void testSequence() throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), 1);
    Journal journal = new JournalImpl(10 * 1024, 2, 2, 0, 0, factory, "activemq-bindings", "bindings", 1);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), new ArrayList<PreparedTransactionInfo>(), null);
    BatchingIDGenerator batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    long id1 = batch.generateID();
    long id2 = batch.generateID();
    Assert.assertTrue(id2 > id1);
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    long id3 = batch.generateID();
    Assert.assertEquals(1001, id3);
    long id4 = batch.generateID();
    Assert.assertTrue(id4 > id3 && id4 < 2000);
    batch.persistCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    long id5 = batch.generateID();
    Assert.assertTrue(id5 > id4 && id5 < 2000);
    long lastId = id5;
    boolean close = true;
    for (int i = 0; i < 100000; i++) {
        if (i % 1000 == 0) {
            // interchanging closes and simulated crashes
            if (close) {
                batch.persistCurrentID();
            }
            close = !close;
            journal.stop();
            batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
            loadIDs(journal, batch);
        }
        long id = batch.generateID();
        Assert.assertTrue(id > lastId);
        lastId = id;
    }
    batch.persistCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    lastId = batch.getCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    Assert.assertEquals("No Ids were generated, so the currentID was supposed to stay the same", lastId, batch.getCurrentID());
    journal.stop();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) Journal(org.apache.activemq.artemis.core.journal.Journal) BatchingIDGenerator(org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

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