Search in sources :

Example 41 with PagingStore

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

the class PagingTest method testPageCompleteWasLive.

// Test a scenario where a page was complete and now needs to be cleared
@Test
public void testPageCompleteWasLive() throws Throwable {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    try {
        ServerLocator locator = createInVMNonHALocator();
        locator.setBlockOnDurableSend(false);
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession(true, true, 0);
        session.createQueue(ADDRESS.toString(), "Q1", "dest=1", true);
        session.createQueue(ADDRESS.toString(), "Q2", "dest=2", true);
        PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
        store.startPaging();
        ClientProducer prod = session.createProducer(ADDRESS);
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("dest", 1);
        prod.send(msg);
        msg = session.createMessage(true);
        msg.putIntProperty("dest", 2);
        prod.send(msg);
        session.start();
        ClientConsumer cons1 = session.createConsumer("Q1");
        ClientMessage msgReceivedCons1 = cons1.receive(1000);
        assertNotNull(msgReceivedCons1);
        ClientConsumer cons2 = session.createConsumer("Q2");
        ClientMessage msgReceivedCons2 = cons2.receive(1000);
        assertNotNull(msgReceivedCons2);
        store.forceAnotherPage();
        msg = session.createMessage(true);
        msg.putIntProperty("dest", 1);
        prod.send(msg);
        msgReceivedCons1.acknowledge();
        msgReceivedCons1 = cons1.receive(1000);
        assertNotNull(msgReceivedCons1);
        msgReceivedCons1.acknowledge();
        msgReceivedCons2.acknowledge();
        assertNull(cons1.receiveImmediate());
        assertNull(cons2.receiveImmediate());
        session.commit();
        session.close();
        waitForNotPaging(store);
    } finally {
        server.stop();
    }
}
Also used : 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) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 42 with PagingStore

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

the class ReplicationTest method testSendPackets.

@Test
public void testSendPackets() throws Exception {
    setupServer(true);
    JournalStorageManager storage = getStorage();
    manager = liveServer.getReplicationManager();
    waitForComponent(manager);
    Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
    replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
    replicatedJournal.appendAddRecord(1, (byte) 1, new FakeData(), false);
    replicatedJournal.appendUpdateRecord(1, (byte) 2, new FakeData(), false);
    replicatedJournal.appendDeleteRecord(1, false);
    replicatedJournal.appendAddRecordTransactional(2, 2, (byte) 1, new FakeData());
    replicatedJournal.appendUpdateRecordTransactional(2, 2, (byte) 2, new FakeData());
    replicatedJournal.appendCommitRecord(2, false);
    replicatedJournal.appendDeleteRecordTransactional(3, 4, new FakeData());
    replicatedJournal.appendPrepareRecord(3, new FakeData(), false);
    replicatedJournal.appendRollbackRecord(3, false);
    blockOnReplication(storage, manager);
    Assert.assertTrue("Expecting no active tokens:" + manager.getActiveTokens(), manager.getActiveTokens().isEmpty());
    CoreMessage msg = new CoreMessage().initBuffer(1024).setMessageID(1);
    SimpleString dummy = new SimpleString("dummy");
    msg.setAddress(dummy);
    replicatedJournal.appendAddRecordTransactional(23, 24, (byte) 1, new FakeData());
    PagedMessage pgmsg = new PagedMessageImpl(msg, new long[0]);
    manager.pageWrite(pgmsg, 1);
    manager.pageWrite(pgmsg, 2);
    manager.pageWrite(pgmsg, 3);
    manager.pageWrite(pgmsg, 4);
    blockOnReplication(storage, manager);
    PagingManager pagingManager = createPageManager(backupServer.getStorageManager(), backupServer.getConfiguration(), backupServer.getExecutorFactory(), backupServer.getAddressSettingsRepository());
    PagingStore store = pagingManager.getPageStore(dummy);
    store.start();
    Assert.assertEquals(4, store.getNumberOfPages());
    store.stop();
    manager.pageDeleted(dummy, 1);
    manager.pageDeleted(dummy, 2);
    manager.pageDeleted(dummy, 3);
    manager.pageDeleted(dummy, 4);
    manager.pageDeleted(dummy, 5);
    manager.pageDeleted(dummy, 6);
    blockOnReplication(storage, manager);
    CoreMessage serverMsg = new CoreMessage();
    serverMsg.setMessageID(500);
    serverMsg.setAddress(new SimpleString("tttt"));
    ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(100);
    serverMsg.encodeHeadersAndProperties(buffer.byteBuf());
    manager.largeMessageBegin(500);
    manager.largeMessageWrite(500, new byte[1024]);
    manager.largeMessageDelete(Long.valueOf(500), storage);
    blockOnReplication(storage, manager);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) PagedMessageImpl(org.apache.activemq.artemis.core.paging.impl.PagedMessageImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 43 with PagingStore

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

the class ScaleDownHandler method scaleDownRegularMessages.

public long scaleDownRegularMessages(final SimpleString address, final Set<Queue> queues, final ClientSession clientSession, final ClientProducer producer) throws Exception {
    logger.debug("Scaling down messages on address " + address);
    long messageCount = 0;
    final HashMap<Queue, QueuesXRefInnerManager> controls = new HashMap<>();
    PagingStore pageStore = pagingManager.getPageStore(address);
    Transaction tx = new TransactionImpl(storageManager);
    pageStore.disableCleanup();
    try {
        for (Queue queue : queues) {
            controls.put(queue, new QueuesXRefInnerManager(clientSession, queue, pageStore));
        }
        // compile a list of all the relevant queues and queue iterators for this address
        for (Queue loopQueue : queues) {
            logger.debug("Scaling down messages on address " + address + " / performing loop on queue " + loopQueue);
            try (LinkedListIterator<MessageReference> messagesIterator = loopQueue.browserIterator()) {
                while (messagesIterator.hasNext()) {
                    MessageReference messageReference = messagesIterator.next();
                    Message message = messageReference.getMessage().copy();
                    logger.debug("Reading message " + message + " from queue " + loopQueue);
                    Set<QueuesXRefInnerManager> queuesFound = new HashSet<>();
                    for (Map.Entry<Queue, QueuesXRefInnerManager> controlEntry : controls.entrySet()) {
                        if (controlEntry.getKey() == loopQueue) {
                            // no need to lookup on itself, we just add it
                            queuesFound.add(controlEntry.getValue());
                        } else if (controlEntry.getValue().lookup(messageReference)) {
                            logger.debug("Message existed on queue " + controlEntry.getKey().getID() + " removeID=" + controlEntry.getValue().getQueueID());
                            queuesFound.add(controlEntry.getValue());
                        }
                    }
                    // get the ID for every queue that contains the message
                    ByteBuffer buffer = ByteBuffer.allocate(queuesFound.size() * 8);
                    for (QueuesXRefInnerManager control : queuesFound) {
                        long queueID = control.getQueueID();
                        buffer.putLong(queueID);
                    }
                    message.putBytesProperty(Message.HDR_ROUTE_TO_IDS.toString(), buffer.array());
                    if (logger.isDebugEnabled()) {
                        if (messageReference.isPaged()) {
                            logger.debug("*********************<<<<< Scaling down pdgmessage " + message);
                        } else {
                            logger.debug("*********************<<<<< Scaling down message " + message);
                        }
                    }
                    producer.send(address, message);
                    messageCount++;
                    messagesIterator.remove();
                    // We need to perform the ack / removal after sending, otherwise the message could been removed before the send is finished
                    for (QueuesXRefInnerManager queueFound : queuesFound) {
                        ackMessageOnQueue(tx, queueFound.getQueue(), messageReference);
                    }
                }
            } catch (NoSuchElementException ignored) {
            // this could happen through paging browsing
            }
        }
        tx.commit();
        for (QueuesXRefInnerManager controlRemoved : controls.values()) {
            controlRemoved.close();
        }
        return messageCount;
    } finally {
        pageStore.enableCleanup();
        pageStore.getCursorProvider().scheduleCleanup();
    }
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ByteBuffer(java.nio.ByteBuffer) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) HashMap(java.util.HashMap) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) HashSet(java.util.HashSet)

Example 44 with PagingStore

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

the class ServerSessionImpl method requestProducerCredits.

@Override
public void requestProducerCredits(SimpleString address, final int credits) throws Exception {
    final SimpleString addr = removePrefix(address);
    PagingStore store = server.getPagingManager().getPageStore(addr);
    if (!store.checkMemory(new Runnable() {

        @Override
        public void run() {
            callback.sendProducerCreditsMessage(credits, address);
        }
    })) {
        callback.sendProducerCreditsFailMessage(credits, address);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Example 45 with PagingStore

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

the class PagingOrderTest method testPagingOverCreatedDestinationTopics.

@Test
public void testPagingOverCreatedDestinationTopics() throws Exception {
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    jmsServer.createTopic(true, "tt", "/topic/TT");
    server.getActiveMQServerControl().addAddressSettings("TT", "DLQ", "DLQ", -1, false, 5, 1024 * 1024, 1024 * 10, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    Connection conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) context.lookup("/topic/TT");
    sess.createDurableSubscriber(topic, "t1");
    MessageProducer prod = sess.createProducer(topic);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    TextMessage txt = sess.createTextMessage("TST");
    prod.send(txt);
    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("TT"));
    assertEquals(1024 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    jmsServer.stop();
    server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    AddressSettings settings = server.getAddressSettingsRepository().getMatch("TT");
    assertEquals(1024 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());
    store = server.getPagingManager().getPageStore(new SimpleString("TT"));
    conn.close();
    server.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) TextMessage(javax.jms.TextMessage) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)48 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)24 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)17 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)17 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)17 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)16 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)15 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)15 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)11 HashMap (java.util.HashMap)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)9 Queue (org.apache.activemq.artemis.core.server.Queue)9 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)8 ArrayList (java.util.ArrayList)7 Page (org.apache.activemq.artemis.core.paging.impl.Page)6