You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2011/06/03 00:52:32 UTC

svn commit: r1130865 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/state/ConnectionStateTracker.java test/java/org/apache/activemq/bugs/AMQ3352Test.java

Author: gtully
Date: Thu Jun  2 22:52:32 2011
New Revision: 1130865

URL: http://svn.apache.org/viewvc?rev=1130865&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3352 - failover ConnectionStateTracker can lead to OOM with TextMessages. have the cache retain the original message so that it can use the correct formatted size when it is evicted so the addition and substractions match

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java   (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/state/ConnectionStateTracker.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/state/ConnectionStateTracker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/state/ConnectionStateTracker.java?rev=1130865&r1=1130864&r2=1130865&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/state/ConnectionStateTracker.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/state/ConnectionStateTracker.java Thu Jun  2 22:52:32 2011
@@ -37,7 +37,6 @@ import org.apache.activemq.command.Desti
 import org.apache.activemq.command.ExceptionResponse;
 import org.apache.activemq.command.IntegerResponse;
 import org.apache.activemq.command.Message;
-import org.apache.activemq.command.MessageId;
 import org.apache.activemq.command.MessagePull;
 import org.apache.activemq.command.ProducerId;
 import org.apache.activemq.command.ProducerInfo;
@@ -60,7 +59,7 @@ public class ConnectionStateTracker exte
     private static final Logger LOG = LoggerFactory.getLogger(ConnectionStateTracker.class);
 
     private static final Tracked TRACKED_RESPONSE_MARKER = new Tracked(null);
-
+    private static final int MESSAGE_PULL_SIZE = 400;
     protected final ConcurrentHashMap<ConnectionId, ConnectionState> connectionStates = new ConcurrentHashMap<ConnectionId, ConnectionState>(); 
 
     private boolean trackTransactions;
@@ -79,7 +78,7 @@ public class ConnectionStateTracker exte
                 if (eldest.getValue() instanceof Message) {
                     currentCacheSize -= ((Message)eldest.getValue()).getSize();
                 } else if (eldest.getValue() instanceof MessagePull) {
-                    currentCacheSize -= 400;
+                    currentCacheSize -= MESSAGE_PULL_SIZE;
                 }
             }
             return result;
@@ -141,7 +140,7 @@ public class ConnectionStateTracker exte
                 }
             } else if (command instanceof MessagePull) {
                 // just needs to be a rough estimate of size, ~4 identifiers
-                currentCacheSize += 400;
+                currentCacheSize += MESSAGE_PULL_SIZE;
             }
         }
     }
@@ -469,7 +468,7 @@ public class ConnectionStateTracker exte
                 }
                 return TRACKED_RESPONSE_MARKER;
             }else if (trackMessages) {
-                messageCache.put(send.getMessageId(), send.copy());
+                messageCache.put(send.getMessageId(), send);
             }
         }
         return null;

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java?rev=1130865&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java Thu Jun  2 22:52:32 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.bugs;
+
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AMQ3352Test
+{
+    TransportConnector connector;
+     BrokerService brokerService;
+
+    @Before
+    public void startBroker() throws Exception {
+        brokerService = new BrokerService();
+        brokerService.setDeleteAllMessagesOnStartup(true);
+        connector = brokerService.addConnector("tcp://0.0.0.0:0");
+        brokerService.start();
+    }
+
+    @After
+    public void stopBroker() throws Exception {
+        brokerService.stop();
+    }
+
+   @Test
+   public void verifyEnqueueLargeNumWithStateTracker() throws Exception {
+        String url = "failover:(" + connector.getPublishableConnectString() + ")?jms.useAsyncSend=true&trackMessages=true&maxCacheSize=131072";
+
+        ActiveMQConnection conn = (ActiveMQConnection)new ActiveMQConnectionFactory(url).createConnection(null, null);
+
+        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+        MessageProducer producer = session.createProducer(session.createQueue("EVENTQ"));
+        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+        producer.setDisableMessageID(true);
+        producer.setDisableMessageTimestamp(true);
+
+        StringBuffer buffer = new StringBuffer();
+        for (int i=0;i<1024;i++)
+        {
+            buffer.append(String.valueOf(Math.random()));
+        }
+        String payload = buffer.toString();
+
+       for (int i=0; i<10000; i++) {
+            StringBuffer buff = new StringBuffer("x");
+            buff.append(payload);
+            producer.send(session.createTextMessage(buff.toString()));
+        }
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3352Test.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date