Search in sources :

Example 1 with PageCursorProvider

use of org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider in project activemq-artemis by apache.

the class PageCursorStressTest method testReadNextPage.

@Test
public void testReadNextPage() throws Exception {
    final int NUM_MESSAGES = 1;
    int numberOfPages = addMessages(NUM_MESSAGES, 1024);
    System.out.println("NumberOfPages = " + numberOfPages);
    PageCursorProvider cursorProvider = lookupCursorProvider();
    PageCache cache = cursorProvider.getPageCache(2);
    assertNull(cache);
}
Also used : PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) PageCache(org.apache.activemq.artemis.core.paging.cursor.PageCache) Test(org.junit.Test)

Example 2 with PageCursorProvider

use of org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider in project activemq-artemis by apache.

the class PageCursorStressTest method testLazyCommit.

@Test
public void testLazyCommit() throws Exception {
    PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    final int NUM_MESSAGES = 100;
    final int messageSize = 100 * 1024;
    PageCursorProvider cursorProvider = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider();
    System.out.println("cursorProvider = " + cursorProvider);
    PageSubscription cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    System.out.println("Cursor: " + cursor);
    StorageManager storage = this.server.getStorageManager();
    long pgtxLazy = storage.generateID();
    Transaction txLazy = pgMessages(storage, pageStore, pgtxLazy, 0, NUM_MESSAGES, messageSize);
    addMessages(100, NUM_MESSAGES, messageSize);
    System.out.println("Number of pages - " + pageStore.getNumberOfPages());
    // First consume what's already there without any tx as nothing was committed
    for (int i = 100; i < 200; i++) {
        PagedReference pos = iterator.next();
        assertNotNull("Null at position " + i, pos);
        assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
        cursor.ack(pos);
    }
    assertNull(iterator.next());
    txLazy.commit();
    storage.waitOnOperations();
    for (int i = 0; i < 100; i++) {
        PagedReference pos = iterator.next();
        assertNotNull("Null at position " + i, pos);
        assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
        cursor.ack(pos);
    }
    assertNull(iterator.next());
    waitCleanup();
    server.stop();
    createServer();
    waitCleanup();
    assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) Test(org.junit.Test)

Example 3 with PageCursorProvider

use of org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider in project activemq-artemis by apache.

the class PageCursorStressTest method testConsumeLivePage.

@Test
public void testConsumeLivePage() throws Exception {
    PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    final int NUM_MESSAGES = 100;
    final int messageSize = 1024 * 1024;
    PageCursorProvider cursorProvider = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider();
    System.out.println("cursorProvider = " + cursorProvider);
    PageSubscription cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    System.out.println("Cursor: " + cursor);
    RoutingContextImpl ctx = generateCTX();
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES; i++) {
        // if (i % 100 == 0)
        System.out.println("read/written " + i);
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        Message msg = new CoreMessage(i, buffer.writerIndex());
        msg.putIntProperty("key", i);
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
        assertNull(iterator.next());
    }
    OperationContextImpl.clearContext();
    ctx = generateCTX();
    pageStore = lookupPageStore(ADDRESS);
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES * 2; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        if (i >= NUM_MESSAGES) {
            ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
            Message msg = new CoreMessage(i, buffer.writerIndex());
            msg.putIntProperty("key", i);
            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
            Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        }
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
    }
    OperationContextImpl.clearContext();
    pageStore = lookupPageStore(ADDRESS);
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES * 3; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        if (i >= NUM_MESSAGES * 2 - 1) {
            ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
            Message msg = new CoreMessage(i, buffer.writerIndex());
            msg.putIntProperty("key", i + 1);
            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
            Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        }
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        cursor.ack(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
    }
    PagedReference readMessage = iterator.next();
    assertEquals(NUM_MESSAGES * 3, readMessage.getMessage().getIntProperty("key").intValue());
    cursor.ack(readMessage);
    server.getStorageManager().waitOnOperations();
    pageStore.flushExecutors();
    assertFalse(pageStore.isPaging());
    server.stop();
    createServer();
    assertFalse(pageStore.isPaging());
    waitCleanup();
    assertFalse(lookupPageStore(ADDRESS).isPaging());
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 4 with PageCursorProvider

use of org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider in project activemq-artemis by apache.

the class PagingTest method testRestartWithComplete.

// The pages are complete, and this is simulating a scenario where the server crashed before deleting the pages.
@Test
public void testRestartWithComplete() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig();
    final AtomicBoolean mainCleanup = new AtomicBoolean(true);
    class InterruptedCursorProvider extends PageCursorProviderImpl {

        InterruptedCursorProvider(PagingStore pagingStore, StorageManager storageManager, ArtemisExecutor executor, int maxCacheSize) {
            super(pagingStore, storageManager, executor, maxCacheSize);
        }

        @Override
        public void cleanup() {
            if (mainCleanup.get()) {
                super.cleanup();
            } else {
                try {
                    pagingStore.unlock();
                } catch (Throwable ignored) {
                }
            }
        }
    }
    server = new ActiveMQServerImpl(config, ManagementFactory.getPlatformMBeanServer(), new ActiveMQSecurityManagerImpl()) {

        @Override
        protected PagingStoreFactoryNIO getPagingStoreFactory() {
            return new PagingStoreFactoryNIO(this.getStorageManager(), this.getConfiguration().getPagingLocation(), this.getConfiguration().getJournalBufferTimeout_NIO(), this.getScheduledPool(), this.getExecutorFactory(), this.getConfiguration().isJournalSyncNonTransactional(), null) {

                @Override
                public PageCursorProvider newCursorProvider(PagingStore store, StorageManager storageManager, AddressSettings addressSettings, ArtemisExecutor executor) {
                    return new InterruptedCursorProvider(store, storageManager, executor, addressSettings.getPageCacheMaxSize());
                }
            };
        }
    };
    addServer(server);
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(PagingTest.PAGE_SIZE).setMaxSizeBytes(PagingTest.PAGE_MAX).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(true, true, 0);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    Queue queue = server.locateQueue(ADDRESS);
    queue.getPageSubscription().getPagingStore().startPaging();
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message;
    for (int i = 0; i < 20; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[100 * 4]);
        message.putIntProperty(new SimpleString("idi"), i);
        producer.send(message);
        session.commit();
        if (i < 19) {
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    Assert.assertEquals(20, queue.getPageSubscription().getPagingStore().getCurrentWritingPage());
    // This will force a scenario where the pages are cleaned up. When restarting we need to check if the current page is complete
    // if it is complete we must move to another page avoiding races on cleanup
    // which could happen during a crash / restart
    long tx = server.getStorageManager().generateID();
    for (int i = 1; i <= 20; i++) {
        server.getStorageManager().storePageCompleteTransactional(tx, queue.getID(), new PagePositionImpl(i, 1));
    }
    server.getStorageManager().commit(tx);
    session.close();
    sf.close();
    server.stop();
    mainCleanup.set(false);
    logger.trace("Server restart");
    server.start();
    queue = server.locateQueue(ADDRESS);
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(null, null, false, false, true, false, 0);
    producer = session.createProducer(PagingTest.ADDRESS);
    for (int i = 0; i < 10; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[100 * 4]);
        message.putIntProperty(new SimpleString("newid"), i);
        producer.send(message);
        session.commit();
        if (i == 5) {
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    mainCleanup.set(true);
    queue = server.locateQueue(ADDRESS);
    queue.getPageSubscription().cleanupEntries(false);
    queue.getPageSubscription().getPagingStore().getCursorProvider().cleanup();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        message = consumer.receive(5000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty("newid").intValue());
        message.acknowledge();
    }
    server.stop();
// Thread.sleep(5000);
}
Also used : ActiveMQSecurityManagerImpl(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) PageCursorProviderImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageCursorProviderImpl) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) PagePositionImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PagePositionImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 5 with PageCursorProvider

use of org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider 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)

Aggregations

PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)9 Test (org.junit.Test)9 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 PagedReference (org.apache.activemq.artemis.core.paging.cursor.PagedReference)6 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)3 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)3 Message (org.apache.activemq.artemis.api.core.Message)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)2 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)2 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)2 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)2 Queue (org.apache.activemq.artemis.core.server.Queue)2