Search in sources :

Example 61 with RecordInfo

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

the class MessageJournalTest method testStoreCore.

@Test
public void testStoreCore() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    CoreMessage message = new CoreMessage().initBuffer(10 * 1024).setDurable(true);
    message.setMessageID(333);
    CoreProtocolManagerFactory factory = (CoreProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("CORE");
    Assert.assertNotNull(factory);
    message.getBodyBuffer().writeByte((byte) 'Z');
    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) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 62 with RecordInfo

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

the class NIOJournalCompactTest method testCompactFirstFileReclaimed.

@Test
public void testCompactFirstFileReclaimed() throws Exception {
    setup(2, 60 * 1024, false);
    final byte recordType = (byte) 0;
    journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO);
    journal.start();
    journal.loadInternalOnly();
    journal.appendAddRecord(1, recordType, "test".getBytes(), true);
    journal.forceMoveNextFile();
    journal.appendUpdateRecord(1, recordType, "update".getBytes(), true);
    journal.appendDeleteRecord(1, true);
    journal.appendAddRecord(2, recordType, "finalRecord".getBytes(), true);
    for (int i = 10; i < 100; i++) {
        journal.appendAddRecord(i, recordType, ("tst" + i).getBytes(), true);
        journal.forceMoveNextFile();
        journal.appendUpdateRecord(i, recordType, ("uptst" + i).getBytes(), true);
        journal.appendDeleteRecord(i, true);
    }
    journal.testCompact();
    journal.stop();
    List<RecordInfo> records1 = new ArrayList<>();
    List<PreparedTransactionInfo> preparedRecords = new ArrayList<>();
    journal.start();
    journal.load(records1, preparedRecords, null);
    assertEquals(1, records1.size());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 63 with RecordInfo

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

the class ActiveMQTestBase method loadMessageJournal.

/**
 * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
 * independent of being deleted or not
 *
 * @param config
 * @return
 * @throws Exception
 */
protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception {
    JournalImpl messagesJournal = null;
    try {
        SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1);
        messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
        final List<RecordInfo> committedRecords = new LinkedList<>();
        final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
        messagesJournal.start();
        messagesJournal.load(committedRecords, preparedTransactions, null, false);
        return new Pair<>(committedRecords, preparedTransactions);
    } finally {
        try {
            if (messagesJournal != null) {
                messagesJournal.stop();
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) File(java.io.File) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 64 with RecordInfo

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

the class HornetqJournalStore method remove_committed.

/**
 * Remove the object's committed state.
 *
 * @param uid  The object to work on.
 * @param typeName The type of the object to work on.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 * @throws ObjectStoreException if things go wrong.
 */
public boolean remove_committed(Uid uid, String typeName) throws ObjectStoreException {
    try {
        RecordInfo record = getContentForType(typeName).remove(uid);
        long id = (record != null ? record.id : getId(uid, typeName));
        journal.appendDeleteRecord(id, syncDeletes);
        return true;
    } catch (IllegalStateException e) {
        tsLogger.i18NLogger.warn_hornetqobjectstore_remove_state_exception(e);
        return false;
    } catch (Exception e) {
        throw new ObjectStoreException(e);
    }
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 65 with RecordInfo

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

the class HornetqJournalStore method read_committed.

/**
 * Read the object's committed state.
 *
 * @param uid  The object to work on.
 * @param typeName The type of the object to work on.
 * @return the state of the object.
 * @throws ObjectStoreException if things go wrong.
 */
public InputObjectState read_committed(Uid uid, String typeName) throws ObjectStoreException {
    RecordInfo record = getContentForType(typeName).get(uid);
    if (record == null) {
        return null;
    }
    // not too much of an issue as log reads are done for recovery only.
    try {
        InputBuffer inputBuffer = new InputBuffer(record.data);
        UidHelper.unpackFrom(inputBuffer);
        inputBuffer.unpackString();
        return new InputObjectState(uid, typeName, inputBuffer.unpackBytes());
    } catch (Exception e) {
        throw new ObjectStoreException(e);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) InputBuffer(com.arjuna.ats.arjuna.state.InputBuffer) 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