Search in sources :

Example 56 with RecordInfo

use of org.apache.activemq.artemis.core.journal.RecordInfo 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 57 with RecordInfo

use of org.apache.activemq.artemis.core.journal.RecordInfo 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 58 with RecordInfo

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

the class JMSJournalStorageManagerImpl method load.

@Override
public void load() throws Exception {
    mapFactories.clear();
    List<RecordInfo> data = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> list = new ArrayList<>();
    jmsJournal.load(data, list, null);
    for (RecordInfo record : data) {
        long id = record.id;
        ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
        byte rec = record.getUserRecordType();
        if (rec == CF_RECORD) {
            PersistedConnectionFactory cf = new PersistedConnectionFactory();
            cf.decode(buffer);
            cf.setId(id);
            mapFactories.put(cf.getName(), cf);
        } else if (rec == DESTINATION_RECORD) {
            PersistedDestination destination = new PersistedDestination();
            destination.decode(buffer);
            destination.setId(id);
            destinations.put(new Pair<>(destination.getType(), destination.getName()), destination);
        } else if (rec == BINDING_RECORD) {
            PersistedBindings bindings = new PersistedBindings();
            bindings.decode(buffer);
            bindings.setId(id);
            Pair<PersistedType, String> key = new Pair<>(bindings.getType(), bindings.getName());
            mapBindings.put(key, bindings);
        } else {
            throw new IllegalStateException("Invalid record type " + rec);
        }
    }
}
Also used : PersistedDestination(org.apache.activemq.artemis.jms.persistence.config.PersistedDestination) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) ArrayList(java.util.ArrayList) PersistedConnectionFactory(org.apache.activemq.artemis.jms.persistence.config.PersistedConnectionFactory) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 59 with RecordInfo

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

the class ValidateTransactionHealthTest method appendData.

public static JournalImpl appendData(final String journalType, final String journalDir, final long numberOfElements, final int transactionSize, final int numberOfThreads) throws Exception {
    final JournalImpl journal = ValidateTransactionHealthTest.createJournal(journalType, journalDir);
    journal.start();
    journal.load(new LoaderCallback() {

        @Override
        public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) {
        }

        @Override
        public void addRecord(final RecordInfo info) {
        }

        @Override
        public void deleteRecord(final long id) {
        }

        @Override
        public void updateRecord(final RecordInfo info) {
        }

        @Override
        public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
        }
    });
    LocalThread[] threads = new LocalThread[numberOfThreads];
    final AtomicLong sequenceTransaction = new AtomicLong();
    for (int i = 0; i < numberOfThreads; i++) {
        threads[i] = new LocalThread(journal, numberOfElements, transactionSize, sequenceTransaction);
        threads[i].start();
    }
    Exception e = null;
    for (LocalThread t : threads) {
        t.join();
        if (t.e != null) {
            e = t.e;
        }
    }
    if (e != null) {
        throw e;
    }
    journal.flush();
    return journal;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LoaderCallback(org.apache.activemq.artemis.core.journal.LoaderCallback) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 60 with RecordInfo

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

the class MessageJournalTest method testStoreAMQP.

@Test
public void testStoreAMQP() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    ProtonProtocolManagerFactory factory = (ProtonProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("AMQP");
    Message protonJMessage = Message.Factory.create();
    AMQPMessage message = new AMQPMessage(protonJMessage);
    message.setMessageID(333);
    Assert.assertNotNull(factory);
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Aggregations

RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)65 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)33 ArrayList (java.util.ArrayList)22 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)20 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)15 HashMap (java.util.HashMap)10 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)10 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)9 File (java.io.File)7 Journal (org.apache.activemq.artemis.core.journal.Journal)7 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)7 List (java.util.List)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)6 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5