wy96f commented on a change in pull request #2666: ARTEMIS-2336 Use zero copy 
to replicate journal/page/large message file
URL: https://github.com/apache/activemq-artemis/pull/2666#discussion_r285101658
 
 

 ##########
 File path: 
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImpl.java
 ##########
 @@ -274,67 +276,103 @@ private void waitForFailOver(String timeoutMsg) {
       }
    }
 
-   // This must never called by more than one thread concurrently
-   private boolean send(final Packet packet, final int reconnectID, final 
boolean flush, final boolean batch) {
-      if (invokeInterceptors(packet, interceptors, connection) != null) {
-         return false;
+   private ActiveMQBuffer beforeSend(final Packet packet, final int 
reconnectID) {
+      packet.setChannelID(id);
+
+      if (responseAsyncCache != null && packet.isRequiresResponse() && 
packet.isResponseAsync()) {
+         packet.setCorrelationID(responseAsyncCache.nextCorrelationID());
       }
 
-      synchronized (sendLock) {
-         packet.setChannelID(id);
+      if (logger.isTraceEnabled()) {
+         logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : 
connection.getID()) + " Sending packet nonblocking " + packet + " on 
channelID=" + id);
+      }
 
-         if (responseAsyncCache != null && packet.isRequiresResponse() && 
packet.isResponseAsync()) {
-            packet.setCorrelationID(responseAsyncCache.nextCorrelationID());
+      ActiveMQBuffer buffer = packet.encode(connection);
+
+      lock.lock();
+
+      try {
+         if (failingOver) {
+            waitForFailOver("RemotingConnectionID=" + (connection == null ? 
"NULL" : connection.getID()) + " timed-out waiting for fail-over condition on 
non-blocking send");
          }
 
-         if (logger.isTraceEnabled()) {
-            logger.trace("RemotingConnectionID=" + (connection == null ? 
"NULL" : connection.getID()) + " Sending packet nonblocking " + packet + " on 
channelID=" + id);
+         // Sanity check
+         if (transferring) {
+            throw 
ActiveMQClientMessageBundle.BUNDLE.cannotSendPacketDuringFailover();
          }
 
-         ActiveMQBuffer buffer = packet.encode(connection);
+         if (resendCache != null && packet.isRequiresConfirmations()) {
+            addResendPacket(packet);
+         }
 
-         lock.lock();
+      } finally {
+         lock.unlock();
+      }
 
-         try {
-            if (failingOver) {
-               waitForFailOver("RemotingConnectionID=" + (connection == null ? 
"NULL" : connection.getID()) + " timed-out waiting for fail-over condition on 
non-blocking send");
-            }
+      if (logger.isTraceEnabled()) {
+         logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : 
connection.getID()) + " Writing buffer for channelID=" + id);
+      }
 
-            // Sanity check
-            if (transferring) {
-               throw 
ActiveMQClientMessageBundle.BUNDLE.cannotSendPacketDuringFailover();
-            }
+      checkReconnectID(reconnectID);
 
-            if (resendCache != null && packet.isRequiresConfirmations()) {
-               addResendPacket(packet);
+      //We do this outside the lock as ResponseCache is threadsafe and allows 
responses to come in,
+      //As the send could block if the response cache cannot add, preventing 
responses to be handled.
+      if (responseAsyncCache != null && packet.isRequiresResponse() && 
packet.isResponseAsync()) {
+         while (!responseAsyncCache.add(packet)) {
+            try {
+               Thread.sleep(1);
+            } catch (Exception e) {
+               // Ignore
 
 Review comment:
    It seems responseAsyncCache::add always returns true, so the sleep code 
doesn't make sense?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to