anmolnar commented on a change in pull request #4125:
URL: https://github.com/apache/hbase/pull/4125#discussion_r836607959



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
##########
@@ -321,31 +320,39 @@ public void run(boolean cancelled) throws IOException {
         } else {
           Channel channel = channelRef.get();
           if (channel == null) {
-            try {
-              Channel newChannel = connect();
-              if (!channelRef.compareAndSet(null, newChannel)) {
-                newChannel.close();
+            connect().addListener(new ChannelFutureListener() {
+              @Override public void operationComplete(ChannelFuture 
channelFuture) {
+                Channel ch = channelFuture.channel();
+                if (channelFuture.isSuccess()) {
+                  if (!channelRef.compareAndSet(null, ch)) {
+                    ch.close();
+                    ch = channelRef.get();
+                  }
+                  writeAndFlushToChannel(call, ch);

Review comment:
       Thanks @joshelser for chiming in, let me give a quick update. I'm 
talking to @meszibalu "offline" to speed things up a bit.
   1. I think what you're saying is a non issue. If compareAndSet() fails then 
must be something *different* set to the AtomicReference. I'm sure @meszibalu 
can confirm that.
   2. The issue we're talking is opening multiple channels concurrently. Balazs 
explained an example of 1000 concurrent Calls coming to the client and they're 
concurrently initiating `connect()`, because channelRef is null. The connection 
takes long and we'll end up having 1000 connections to the server and 1000 
Calls compete to set its channel to the Ref. One wins, the others will close 
their connection.
   
   Need to solve 2 things here:
   1. Make sure that no Call is falling through the cracks. All of them must be 
put on the winning connection.
   2. How can we avoid opening 999 connections that will be evantually closed.
   
   Balazs:
   ```
   AtomicBoolean connecting = new AtomicBoolean();
   if (!connecting.compareAndSet(false, true)) {
     // connect
   }
   ```
   
   Andor: ReentrantLock




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to