Search in sources :

Example 1 with EncodingSupport

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

the class DescribeJournal method newObjectEncoding.

public static Object newObjectEncoding(RecordInfo info, JournalStorageManager storageManager) {
    ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(info.data);
    long id = info.id;
    int rec = info.getUserRecordType();
    switch(rec) {
        case ADD_LARGE_MESSAGE_PENDING:
            {
                PendingLargeMessageEncoding lmEncoding = new PendingLargeMessageEncoding();
                lmEncoding.decode(buffer);
                return lmEncoding;
            }
        case ADD_LARGE_MESSAGE:
            {
                LargeServerMessage largeMessage = new LargeServerMessageImpl(storageManager);
                LargeMessagePersister.getInstance().decode(buffer, largeMessage);
                return new MessageDescribe(largeMessage);
            }
        case ADD_MESSAGE:
            {
                return "ADD-MESSAGE is not supported any longer, use export/import";
            }
        case ADD_MESSAGE_PROTOCOL:
            {
                Message message = MessagePersister.getInstance().decode(buffer, null);
                return new MessageDescribe(message);
            }
        case ADD_REF:
            {
                final RefEncoding encoding = new RefEncoding();
                encoding.decode(buffer);
                return new ReferenceDescribe(encoding);
            }
        case ACKNOWLEDGE_REF:
            {
                final RefEncoding encoding = new RefEncoding();
                encoding.decode(buffer);
                return new AckDescribe(encoding);
            }
        case UPDATE_DELIVERY_COUNT:
            {
                DeliveryCountUpdateEncoding updateDeliveryCount = new DeliveryCountUpdateEncoding();
                updateDeliveryCount.decode(buffer);
                return updateDeliveryCount;
            }
        case PAGE_TRANSACTION:
            {
                if (info.isUpdate) {
                    PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
                    pageUpdate.decode(buffer);
                    return pageUpdate;
                } else {
                    PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
                    pageTransactionInfo.decode(buffer);
                    pageTransactionInfo.setRecordID(info.id);
                    return pageTransactionInfo;
                }
            }
        case SET_SCHEDULED_DELIVERY_TIME:
            {
                ScheduledDeliveryEncoding encoding = new ScheduledDeliveryEncoding();
                encoding.decode(buffer);
                return encoding;
            }
        case DUPLICATE_ID:
            {
                DuplicateIDEncoding encoding = new DuplicateIDEncoding();
                encoding.decode(buffer);
                return encoding;
            }
        case HEURISTIC_COMPLETION:
            {
                HeuristicCompletionEncoding encoding = new HeuristicCompletionEncoding();
                encoding.decode(buffer);
                return encoding;
            }
        case ACKNOWLEDGE_CURSOR:
            {
                CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
                encoding.decode(buffer);
                return encoding;
            }
        case PAGE_CURSOR_COUNTER_VALUE:
            {
                PageCountRecord encoding = new PageCountRecord();
                encoding.decode(buffer);
                return encoding;
            }
        case PAGE_CURSOR_COMPLETE:
            {
                CursorAckRecordEncoding encoding = new PageCompleteCursorAckRecordEncoding();
                encoding.decode(buffer);
                return encoding;
            }
        case PAGE_CURSOR_COUNTER_INC:
            {
                PageCountRecordInc encoding = new PageCountRecordInc();
                encoding.decode(buffer);
                return encoding;
            }
        case PAGE_CURSOR_PENDING_COUNTER:
            {
                PageCountPendingImpl encoding = new PageCountPendingImpl();
                encoding.decode(buffer);
                encoding.setID(info.id);
                return encoding;
            }
        case QUEUE_STATUS_RECORD:
            return AbstractJournalStorageManager.newQueueStatusEncoding(id, buffer);
        case QUEUE_BINDING_RECORD:
            return AbstractJournalStorageManager.newQueueBindingEncoding(id, buffer);
        case ID_COUNTER_RECORD:
            EncodingSupport idReturn = new IDCounterEncoding();
            idReturn.decode(buffer);
            return idReturn;
        case JournalRecordIds.GROUP_RECORD:
            return AbstractJournalStorageManager.newGroupEncoding(id, buffer);
        case ADDRESS_SETTING_RECORD:
            return AbstractJournalStorageManager.newAddressEncoding(id, buffer);
        case SECURITY_RECORD:
            return AbstractJournalStorageManager.newSecurityRecord(id, buffer);
        case ADDRESS_BINDING_RECORD:
            return AbstractJournalStorageManager.newAddressBindingEncoding(id, buffer);
        default:
            return null;
    }
}
Also used : PendingLargeMessageEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PendingLargeMessageEncoding) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) Message(org.apache.activemq.artemis.api.core.Message) PageCountPendingImpl(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountPendingImpl) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) DeliveryCountUpdateEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.DeliveryCountUpdateEncoding) PageUpdateTXEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageUpdateTXEncoding) PageCountRecord(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecord) CursorAckRecordEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding) ScheduledDeliveryEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.ScheduledDeliveryEncoding) DuplicateIDEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.DuplicateIDEncoding) PageCountRecordInc(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) HeuristicCompletionEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.HeuristicCompletionEncoding) RefEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.RefEncoding) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) IDCounterEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator.IDCounterEncoding)

Example 2 with EncodingSupport

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

the class SequentialFileTptBenchmark method main.

public static void main(String[] args) throws Exception {
    final boolean dataSync = false;
    final boolean writeSync = true;
    final Type type = Type.Mapped;
    final int tests = 10;
    final int warmup = 20_000;
    final int measurements = 100_000;
    final int msgSize = 100;
    final byte[] msgContent = new byte[msgSize];
    Arrays.fill(msgContent, (byte) 1);
    final File tmpDirectory = new File("./");
    // using the default configuration when the broker starts!
    final SequentialFileFactory factory;
    switch(type) {
        case Mapped:
            final int fileSize = Math.max(msgSize * measurements, msgSize * warmup);
            factory = new MappedSequentialFileFactory(tmpDirectory, fileSize, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, null).setDatasync(dataSync);
            break;
        case Nio:
            factory = new NIOSequentialFileFactory(tmpDirectory, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_NIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_NIO, 1, false, null, null).setDatasync(dataSync);
            break;
        case Aio:
            factory = new AIOSequentialFileFactory(tmpDirectory, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, 500, false, null, null).setDatasync(dataSync);
            // disable it when using directly the same buffer: ((AIOSequentialFileFactory)factory).disableBufferReuse();
            if (!LibaioContext.isLoaded()) {
                throw new IllegalStateException("lib AIO not loaded!");
            }
            break;
        default:
            throw new AssertionError("unsupported case");
    }
    factory.start();
    try {
        final EncodingSupport encodingSupport = new EncodingSupport() {

            @Override
            public int getEncodeSize() {
                return msgSize;
            }

            @Override
            public void encode(ActiveMQBuffer buffer) {
                final int writerIndex = buffer.writerIndex();
                buffer.setBytes(writerIndex, msgContent);
                buffer.writerIndex(writerIndex + msgSize);
            }

            @Override
            public void decode(ActiveMQBuffer buffer) {
            }
        };
        final int alignedMessageSize = factory.calculateBlockSize(msgSize);
        final long totalFileSize = Math.max(alignedMessageSize * measurements, alignedMessageSize * warmup);
        if (totalFileSize > Integer.MAX_VALUE)
            throw new IllegalArgumentException("reduce measurements/warmup");
        final int fileSize = (int) totalFileSize;
        final SequentialFile sequentialFile = factory.createSequentialFile("seq.dat");
        sequentialFile.getJavaFile().delete();
        sequentialFile.getJavaFile().deleteOnExit();
        sequentialFile.open();
        final long startZeros = System.nanoTime();
        sequentialFile.fill(fileSize);
        final long elapsedZeros = System.nanoTime() - startZeros;
        System.out.println("Zeroed " + fileSize + " bytes in " + TimeUnit.NANOSECONDS.toMicros(elapsedZeros) + " us");
        try {
            {
                final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, warmup, writeSync);
                System.out.println("warmup:" + (measurements * 1000_000_000L) / elapsed + " ops/sec");
            }
            for (int t = 0; t < tests; t++) {
                final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, measurements, writeSync);
                System.out.println((measurements * 1000_000_000L) / elapsed + " ops/sec");
            }
        } finally {
            sequentialFile.close();
        }
    } finally {
        factory.stop();
    }
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ActiveMQExceptionType(org.apache.activemq.artemis.api.core.ActiveMQExceptionType) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 3 with EncodingSupport

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

the class JournalImpl method runDirectJournalBlast.

@Override
public void runDirectJournalBlast() throws Exception {
    final int numIts = 100000000;
    ActiveMQJournalLogger.LOGGER.runningJournalBlast(numIts);
    final CountDownLatch latch = new CountDownLatch(numIts * 2);
    class MyAIOCallback implements IOCompletion {

        @Override
        public void done() {
            latch.countDown();
        }

        @Override
        public void onError(final int errorCode, final String errorMessage) {
        }

        @Override
        public void storeLineUp() {
        }
    }
    final MyAIOCallback task = new MyAIOCallback();
    final int recordSize = 1024;
    final byte[] bytes = new byte[recordSize];
    class MyRecord implements EncodingSupport {

        @Override
        public void decode(final ActiveMQBuffer buffer) {
        }

        @Override
        public void encode(final ActiveMQBuffer buffer) {
            buffer.writeBytes(bytes);
        }

        @Override
        public int getEncodeSize() {
            return recordSize;
        }
    }
    MyRecord record = new MyRecord();
    for (int i = 0; i < numIts; i++) {
        appendAddRecord(i, (byte) 1, record, true, task);
        appendDeleteRecord(i, true, task);
    }
    latch.await();
}
Also used : IOCompletion(org.apache.activemq.artemis.core.journal.IOCompletion) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport)

Example 4 with EncodingSupport

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

the class JournalImplTestUnit method testXASimplePrepared.

@Test
public void testXASimplePrepared() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    updateTx(1, 1, 2, 3, 4, 7, 8);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 5 with EncodingSupport

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

the class JournalImplTestUnit method testXAChangesNotVisibleRollback.

@Test
public void testXAChangesNotVisibleRollback() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6);
    addTx(1, 7, 8, 9, 10);
    updateTx(1, 1, 2, 3, 7, 8, 9);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    rollback(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Aggregations

EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)19 Test (org.junit.Test)15 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)13 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 File (java.io.File)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)2 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 MpscArrayQueue (io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ActiveMQExceptionType (org.apache.activemq.artemis.api.core.ActiveMQExceptionType)1 Message (org.apache.activemq.artemis.api.core.Message)1 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)1 IOCompletion (org.apache.activemq.artemis.core.journal.IOCompletion)1