Search in sources :

Example 26 with RecordInfo

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

the class PagingTest method testMissingTXEverythingAcked.

@Test
public void testMissingTXEverythingAcked() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 5000;
    final int numberOfTX = 10;
    final int messagesPerTX = numberOfMessages / numberOfTX;
    try {
        locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
        sf = createSessionFactory(locator);
        ClientSession session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS.toString(), "q1", true);
        session.createQueue(ADDRESS.toString(), "q2", true);
        ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
        ClientMessage message = null;
        byte[] body = new byte[MESSAGE_SIZE];
        ByteBuffer bb = ByteBuffer.wrap(body);
        for (int j = 1; j <= MESSAGE_SIZE; j++) {
            bb.put(getSamplebyte(j));
        }
        for (int i = 0; i < numberOfMessages; i++) {
            message = session.createMessage(true);
            ActiveMQBuffer bodyLocal = message.getBodyBuffer();
            bodyLocal.writeBytes(body);
            message.putIntProperty(new SimpleString("id"), i);
            producer.send(message);
            if (i % messagesPerTX == 0) {
                session.commit();
            }
        }
        session.commit();
        session.close();
        ArrayList<RecordInfo> records = new ArrayList<>();
        List<PreparedTransactionInfo> list = new ArrayList<>();
        server.getStorageManager().getMessageJournal().stop();
        Journal jrn = server.getStorageManager().getMessageJournal();
        jrn.start();
        jrn.load(records, list, null);
        // Delete everything from the journal
        for (RecordInfo info : records) {
            if (!info.isUpdate && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_INC && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COMPLETE) {
                jrn.appendDeleteRecord(info.id, false);
            }
        }
        jrn.stop();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession sess = csf.createSession();
    sess.start();
    ClientConsumer cons = sess.createConsumer("q1");
    assertNull(cons.receiveImmediate());
    ClientConsumer cons2 = sess.createConsumer("q2");
    assertNull(cons2.receiveImmediate());
    Queue q1 = server.locateQueue(new SimpleString("q1"));
    Queue q2 = server.locateQueue(new SimpleString("q2"));
    q1.getPageSubscription().cleanupEntries(false);
    q2.getPageSubscription().cleanupEntries(false);
    PageCursorProvider provider = q1.getPageSubscription().getPagingStore().getCursorProvider();
    provider.cleanup();
    waitForNotPaging(q1);
    sess.close();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 27 with RecordInfo

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

the class JournalPageCountSizeTest method testPageCountRecordSize.

@Test
public void testPageCountRecordSize() throws Exception {
    long tx = server.getStorageManager().generateID();
    server.getStorageManager().storePageCounter(tx, 1, 1, 100);
    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);
        PageCountRecord encoding = new PageCountRecord();
        encoding.decode(buff);
        Assert.assertEquals(100, encoding.getPersistentSize());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) 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)

Example 28 with RecordInfo

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

the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.

@Test
public void testPageCursorCounterRecordSize() throws Exception {
    server.getStorageManager().storePageCounterInc(1, 1, 1000);
    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)

Example 29 with RecordInfo

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

the class HornetqJournalStore method start.

public void start() throws Exception {
    journal.start();
    List<RecordInfo> committedRecords = new LinkedList<RecordInfo>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<PreparedTransactionInfo>();
    TransactionFailureCallback failureCallback = new TransactionFailureCallback() {

        public void failedTransaction(long l, List<RecordInfo> recordInfos, List<RecordInfo> recordInfos1) {
            tsLogger.i18NLogger.warn_journal_load_error();
        }
    };
    JournalLoadInformation journalLoadInformation = journal.load(committedRecords, preparedTransactions, failureCallback);
    maxID.set(journalLoadInformation.getMaxID());
    if (!preparedTransactions.isEmpty()) {
        tsLogger.i18NLogger.warn_journal_load_error();
    }
    for (RecordInfo record : committedRecords) {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        Uid uid = UidHelper.unpackFrom(inputBuffer);
        String typeName = inputBuffer.unpackString();
        getContentForType(typeName).put(uid, record);
    // don't unpack the rest yet, we may never need it. read_committed does it on demand.
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) Uid(com.arjuna.ats.arjuna.common.Uid) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) LinkedList(java.util.LinkedList) List(java.util.List) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList)

Example 30 with RecordInfo

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

the class HornetqJournalStore method write_committed.

/**
 * Write a new copy of the object's committed state.
 *
 * @param uid    The object to work on.
 * @param typeName   The type of the object to work on.
 * @param txData The state to write.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 * @throws ObjectStoreException if things go wrong.
 */
public boolean write_committed(Uid uid, String typeName, OutputObjectState txData) throws ObjectStoreException {
    RecordInfo previousRecord = null;
    try {
        OutputBuffer outputBuffer = new OutputBuffer();
        UidHelper.packInto(uid, outputBuffer);
        outputBuffer.packString(typeName);
        outputBuffer.packBytes(txData.buffer());
        byte[] data = outputBuffer.buffer();
        RecordInfo record = new RecordInfo(getId(uid, typeName), RECORD_TYPE, data, false, (short) 0);
        previousRecord = getContentForType(typeName).putIfAbsent(uid, record);
        if (previousRecord != null) {
            // the packed data may have changed so updated the map with the latest data
            getContentForType(typeName).replace(uid, record);
            journal.appendUpdateRecord(previousRecord.id, RECORD_TYPE, data, syncWrites);
        } else {
            journal.appendAddRecord(record.id, RECORD_TYPE, data, syncWrites);
        }
    } catch (Exception e) {
        if (previousRecord == null) {
            // if appendAddRecord() fails, remove record from map. Leave it there if appendUpdateRecord() fails.
            getContentForType(typeName).remove(uid);
        }
        throw new ObjectStoreException(e);
    }
    return true;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) OutputBuffer(com.arjuna.ats.arjuna.state.OutputBuffer) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

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