You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Jean-Baptiste Onofré (JIRA)" <ji...@apache.org> on 2015/11/27 14:27:11 UTC

[jira] [Commented] (AMQ-6025) Activemq ACTIVEMQ_ACKS table gets double updates

    [ https://issues.apache.org/jira/browse/AMQ-6025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15029865#comment-15029865 ] 

Jean-Baptiste Onofré commented on AMQ-6025:
-------------------------------------------

Here's the test that I implemented:

{code}
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.activemq.store.jdbc;

import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.Test;

import javax.jms.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JDBCSubAckTest extends TestCase {

    private EmbeddedDataSource dataSource;
    private BrokerService broker;
    private Connection connection;
    private Session session;
    private ActiveMQTopic topic;

    protected void setUp() throws Exception {
        broker = new BrokerService();
        broker.setBrokerName("subAckTest");
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc.setDataSource(dataSource);
        jdbc.setCleanupPeriod(300000);

        jdbc.deleteAllMessages();
        broker.setPersistenceAdapter(jdbc);

        PolicyEntry policy = new PolicyEntry();
        policy.setExpireMessagesPeriod(86400000);
        // policy.setPrioritizedMessages(true);
        PolicyMap policyMap = new PolicyMap();
        policyMap.put(new ActiveMQTopic("SUB_ACK_TEST_TOPIC"), policy);

        broker.setDestinationPolicy(policyMap);
        broker.start();
        broker.waitUntilStarted();

        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://subAckTest");
        connection = factory.createConnection();
        connection.setClientID("SUB_ACK_TEST_ID");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        topic = (ActiveMQTopic) session.createTopic("SUB_ACK_TEST_TOPIC");
    }

    protected void tearDown() throws Exception {
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
        if (broker != null) {
            broker.stop();
        }
    }

    @Test
    public void testAckUpdate() throws Exception {

        // start a durable subscriber
        TopicSubscriber subscriber = session.createDurableSubscriber(topic, "ACK_TEST_SUB");
        subscriber.close();

        ProducerThread producerThread = new ProducerThread(topic, 5, 4);
        producerThread.run();
        ProducerThread producerThread2 = new ProducerThread(topic, 5, 8);
        producerThread2.run();

        subscriber = session.createDurableSubscriber(topic, "ACK_TEST_SUB");
        subscriber.setMessageListener(new TestMessageListener());
        TopicSubscriber subscriber2 = session.createDurableSubscriber(topic, "ACK_TEST_SUB2");
        subscriber2.setMessageListener(new TestMessageListener());

        // check ACK count
        System.out.println("ACK count after consume: " + ackCount());

        // close subscriber
        subscriber.close();
        // check ACK count
        System.out.println("ACK count after subscriber: " + ackCount());
    }

    private int ackCount() throws Exception {
        java.sql.Connection connection = dataSource.getConnection();
        try {
            PreparedStatement statement = connection.prepareStatement("SELECT count(*) FROM ACTIVEMQ_ACKS");
            ResultSet resultSet = statement.executeQuery();
            if (resultSet.next()) {
                return resultSet.getInt(1);
            }
        } finally {
            connection.close();
        }
        return 0;
    }

    private class ProducerThread extends Thread {

        private ActiveMQDestination destination;
        private int count;
        private int priority;

        public ProducerThread(ActiveMQDestination destination, int count, int priority) {
            this.destination = destination;
            this.count = count;
            this.priority = priority;
        }

        public void run() {
            try {
                // send two messages in the topic
                MessageProducer producer = session.createProducer(topic);
                Message message = session.createTextMessage();
                producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                producer.setPriority(priority);
                for (int i = 0; i < count; i++) {
                    producer.send(session.createTextMessage("Message " + i));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    private class TestMessageListener implements MessageListener {

        public void onMessage(Message message) {
            try {
                System.out.println("Message (" + message.getJMSPriority() + "): " + ((TextMessage) message).getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
{code}

Here, we have two records in ACTIVEMQ_ACKS: one per durable subscriber.

Now, if I set:

{code}
policy.setPrioritizedMessages(true);
{code}

we have 20 records in ACTIVEMQ_ACKS: one per durable subscriber + one per message. This behavior is expected as the message has to be ordered depending of the priority.

Can you try to disable the prioritized messages on the policy:

{code}
<policyEntry topic="FOO" expireMessagesPeriod="0" prioritizedMessages="false">
{code}

> Activemq ACTIVEMQ_ACKS table gets double updates
> ------------------------------------------------
>
>                 Key: AMQ-6025
>                 URL: https://issues.apache.org/jira/browse/AMQ-6025
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: OSGi/Karaf
>    Affects Versions: 5.10.1
>            Reporter: Krishnan
>
> Customer feedback:
> Issue's on ActiveMQ 5.10
> We have 290 offline durable clients in Active MQ broker and which have 50 pending messages for each offline durable client. When the messages exceeds their TTL time for those messages, LAST_ACK_ID will be updated twice for each subscriber(e.g.: again 290 set of updates it is firing). why is the updates being duplicated and Is there any possibility to tune or remove second set of transactions.
> Following configuration made in activemq.xml file for this.
> cleanupPeriod:
> <persistenceAdapter>
> <jdbcPersistenceAdapter dataSource="#mysql-ds" cleanupPeriod="300000"/>
> </persistenceAdapter>
> expireMessagesPeriod
> <policyEntry topic="<<topic name>>" expireMessagesPeriod=" 86400000 ">
> And also attached the general Db log for the updates.
> Support Note: Checked Customer log 215MB . And there's lots of updates on the ACK table. Just a snippet of the logs..
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378703, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT149' AND SUB_NAME='300SUBS149'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378703, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT142' AND SUB_NAME='300SUBS142'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378703, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT141' AND SUB_NAME='300SUBS141'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT140' AND SUB_NAME='300SUBS140'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT14' AND SUB_NAME='300SUBS14'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT146' AND SUB_NAME='300SUBS146'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT147' AND SUB_NAME='300SUBS147'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT145' AND SUB_NAME='300SUBS145'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT148' AND SUB_NAME='300SUBS148'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT143' AND SUB_NAME='300SUBS143'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT144' AND SUB_NAME='300SUBS144'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT149' AND SUB_NAME='300SUBS149'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT142' AND SUB_NAME='300SUBS142'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378704, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT141' AND SUB_NAME='300SUBS141'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378705, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT140' AND SUB_NAME='300SUBS140'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378705, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT14' AND SUB_NAME='300SUBS14'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378705, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT146' AND SUB_NAME='300SUBS146'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378705, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT147' AND SUB_NAME='300SUBS147'
> 4171969 Query
> UPDATE ACTIVEMQ_ACKS SET LAST_ACKED_ID=378705, XID = NULL WHERE CONTAINER='topic://bmrsTopic' AND CLIENT_ID='300CLNT145' AND SUB_NAME='300SUBS145'
> There is also similar forum discussion on the same
> http://activemq.2283324.n4.nabble.com/Too-many-updates-in-MySQL-td4700512.html
> A related TalendESB Ticket is available at 
> https://jira.talendforge.org/browse/TESB-16693



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)