You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2021/10/22 05:02:35 UTC

[GitHub] [drill] paul-rogers commented on a change in pull request #2333: DRILL-8009: DrillConnectionImpl#isValid() doesn't correspond JDBC API

paul-rogers commented on a change in pull request #2333:
URL: https://github.com/apache/drill/pull/2333#discussion_r734233567



##########
File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
##########
@@ -121,7 +123,8 @@ protected void initChannel(SocketChannel ch) throws Exception {
               pipe.addLast(RpcConstants.IDLE_STATE_HANDLER, pingHandler);
             }
 
-            pipe.addLast(RpcConstants.MESSAGE_HANDLER, new InboundHandler(connection));
+            messageHandler = new InboundHandler(connection);
+            pipe.addLast(RpcConstants.MESSAGE_HANDLER, messageHandler);

Review comment:
       Left over debugging code?

##########
File path: exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
##########
@@ -520,8 +520,12 @@ public SQLXML createSQLXML() throws SQLException {
 
   @Override
   public boolean isValid(int timeout) throws SQLException {
-    checkOpen();
-    return super.isValid(timeout);
+    if (timeout < 0) {

Review comment:
       We can be nicer: if the timeout is <0, just set it to 0.

##########
File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
##########
@@ -324,6 +327,22 @@ public void setAutoRead(boolean enableAutoRead) {
     connection.setAutoRead(enableAutoRead);
   }
 
+  /**
+   * Send {@link RpcMode#PING PING} message and waits for {@link RpcMode#PONG PONG} answer to verify connection.
+   *
+   * @param timeout time in seconds to wait message receiving. Should be higher than 0
+   * @return true if {@link RpcMode#PONG PONG} received until timeout, false otherwise
+   * @throws DrillRuntimeException if the value supplied for timeout is less than 0
+   */
+  public boolean ping(int timeout) throws DrillRuntimeException {

Review comment:
       Always nice to put the units in the variable name: `timeoutSec` or `timeoutMs`.

##########
File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/PongListener.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.drill.exec.rpc;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.shaded.guava.com.google.common.base.Stopwatch;
+
+import java.util.EventListener;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * PongListener realizes the listener pattern. It is used to verify, whether {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler}
+ * received {@link InboundRpcMessage} with {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode.
+ */
+public class PongListener implements EventListener {

Review comment:
       Also, this change modifies the Drillbit RPC. Historically, the JDBC client tried to be backward and forward compatible. Suppose someone uses the new JDBC client with an older server that does not support this new handler. What happens?
   
   At some point we talked about having a protocol version number in the "hello" message. If that exists, you can check if the server is new enough to handle this message, else skip the active ping from the client (unless you can find a way to use the existing mechanism so the RPC protocol does not change.)

##########
File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/PongListener.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.drill.exec.rpc;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.shaded.guava.com.google.common.base.Stopwatch;
+
+import java.util.EventListener;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * PongListener realizes the listener pattern. It is used to verify, whether {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler}
+ * received {@link InboundRpcMessage} with {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode.
+ */
+public class PongListener implements EventListener {
+  private boolean hasReceivedPong = false;
+
+  /**
+   * Verify whether received {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode.
+   *
+   * @param timeout time in seconds to wait message receiving. Should be higher than 0
+   * @return true if message is received until timeout, false otherwise
+   * @throws DrillRuntimeException if the value supplied for timeout is less than 0
+   */
+  public boolean pongIsReceived(int timeout) throws DrillRuntimeException {
+    if (timeout < 0) {
+      throw new DrillRuntimeException(String.format("Invalid timeout (%d<0).", timeout));
+    }
+
+    Stopwatch stopwatch = Stopwatch.createStarted();
+    while (!hasReceivedPong) {

Review comment:
       This will spin the CPU at 100%. We need a sleep between checks.
   
   Also, looks like we're polling a boolean set in another thread. In this use case, it might be OK if we miss an update or two.
   
   But, a better solution is to use a semaphore so that this thread blocks, up to a timeout, waiting for the semaphore to be set. Check out the Java concurrency package to find a good candidate.

##########
File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/PongListener.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.drill.exec.rpc;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.shaded.guava.com.google.common.base.Stopwatch;
+
+import java.util.EventListener;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * PongListener realizes the listener pattern. It is used to verify, whether {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler}
+ * received {@link InboundRpcMessage} with {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode.
+ */
+public class PongListener implements EventListener {

Review comment:
       General question here: doesn't Drill's RPC already handle the ping/pong protocol? Can we reuse that: just trigger a ping on demand rather than waiting for the next scheduled event?




-- 
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: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org