You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2018/09/04 17:28:00 UTC

[2/2] activemq-artemis git commit: ARTEMIS-2072 eliminate unnecessary binding queries

ARTEMIS-2072 eliminate unnecessary binding queries


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/d91da412
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/d91da412
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/d91da412

Branch: refs/heads/master
Commit: d91da412c36c590bd6f0e18f660b45c28e2ad346
Parents: d0272e6
Author: Justin Bertram <jb...@apache.org>
Authored: Tue Sep 4 10:34:03 2018 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Sep 4 13:27:28 2018 -0400

----------------------------------------------------------------------
 .../amqp/broker/AMQPSessionCallback.java        | 38 +++++++++-----------
 .../proton/ProtonServerReceiverContext.java     |  2 +-
 2 files changed, 18 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d91da412/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java
index b99a053..b32a4c7 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPSessionCallback.java
@@ -38,7 +38,6 @@ import org.apache.activemq.artemis.core.persistence.StorageManager;
 import org.apache.activemq.artemis.core.security.CheckType;
 import org.apache.activemq.artemis.core.security.SecurityAuth;
 import org.apache.activemq.artemis.core.server.AddressQueryResult;
-import org.apache.activemq.artemis.core.server.BindingQueryResult;
 import org.apache.activemq.artemis.core.server.MessageReference;
 import org.apache.activemq.artemis.core.server.QueueQueryResult;
 import org.apache.activemq.artemis.core.server.ServerConsumer;
@@ -109,8 +108,6 @@ public class AMQPSessionCallback implements SessionCallback {
 
    private final AddressQueryCache<AddressQueryResult> addressQueryCache = new AddressQueryCache<>();
 
-   private final AddressQueryCache<BindingQueryResult> bindingQueryCache = new AddressQueryCache<>();
-
    public AMQPSessionCallback(AMQPConnectionCallback protonSPI,
                               ProtonProtocolManager manager,
                               AMQPConnectionContext connection,
@@ -308,35 +305,34 @@ public class AMQPSessionCallback implements SessionCallback {
 
 
 
-   public boolean bindingQuery(SimpleString address, RoutingType routingType) throws Exception {
-      BindingQueryResult bindingQueryResult = bindingQueryCache.getResult(address);
+   public boolean checkAddressAndAutocreateIfPossible(SimpleString address, RoutingType routingType) throws Exception {
+      AddressInfo addressInfo = manager.getServer().getAddressInfo(address);
 
-      if (bindingQueryResult != null) {
-         return bindingQueryResult.isExists();
+      // if the address exists go ahead and return
+      if (addressInfo != null) {
+         return true;
       }
 
-      bindingQueryResult = serverSession.executeBindingQuery(address);
-      if (routingType == RoutingType.MULTICAST && !bindingQueryResult.isExists() && bindingQueryResult.isAutoCreateAddresses()) {
-         try {
-            serverSession.createAddress(address, routingType, true);
-         } catch (ActiveMQAddressExistsException e) {
-            // The address may have been created by another thread in the mean time.  Catch and do nothing.
+      // if the address and/or queue don't exist then create them if possible
+      if (routingType == RoutingType.MULTICAST && addressInfo == null) {
+         if (manager.getServer().getAddressSettingsRepository().getMatch(address.toString()).isAutoCreateAddresses()) {
+            try {
+               serverSession.createAddress(address, routingType, true);
+            } catch (ActiveMQAddressExistsException e) {
+               // The address may have been created by another thread in the mean time.  Catch and do nothing.
+            }
          }
-         bindingQueryResult = serverSession.executeBindingQuery(address);
-      } else if (routingType == RoutingType.ANYCAST && bindingQueryResult.isAutoCreateQueues()) {
-         QueueQueryResult queueBinding = serverSession.executeQueueQuery(address);
-         if (!queueBinding.isExists()) {
+      } else if (routingType == RoutingType.ANYCAST && manager.getServer().locateQueue(address) == null) {
+         if (manager.getServer().getAddressSettingsRepository().getMatch(address.toString()).isAutoCreateQueues()) {
             try {
                serverSession.createQueue(address, address, routingType, null, false, true, true);
             } catch (ActiveMQQueueExistsException e) {
                // The queue may have been created by another thread in the mean time.  Catch and do nothing.
             }
          }
-         bindingQueryResult = serverSession.executeBindingQuery(address);
       }
 
-      bindingQueryCache.setResult(address, bindingQueryResult);
-      return bindingQueryResult.isExists();
+      return manager.getServer().getAddressInfo(address) != null;
    }
 
 
@@ -475,7 +471,7 @@ public class AMQPSessionCallback implements SessionCallback {
 
       //here check queue-autocreation
       RoutingType routingType = context.getRoutingType(receiver, address);
-      if (!bindingQuery(address, routingType)) {
+      if (!checkAddressAndAutocreateIfPossible(address, routingType)) {
          throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
       }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d91da412/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java
index e54a1a5..30dd10a 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerReceiverContext.java
@@ -127,7 +127,7 @@ public class ProtonServerReceiverContext extends ProtonInitializable implements
             if (address != null && !address.isEmpty()) {
                defRoutingType = getRoutingType(target.getCapabilities(), address);
                try {
-                  if (!sessionSPI.bindingQuery(address, defRoutingType)) {
+                  if (!sessionSPI.checkAddressAndAutocreateIfPossible(address, defRoutingType)) {
                      throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
                   }
                } catch (ActiveMQAMQPNotFoundException e) {