You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/01/06 03:30:42 UTC

[GitHub] [incubator-doris] lingbin commented on a change in pull request #2603: Add nio support for mysql protocol implementation

lingbin commented on a change in pull request #2603: Add nio support for mysql protocol implementation
URL: https://github.com/apache/incubator-doris/pull/2603#discussion_r363147726
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java
 ##########
 @@ -0,0 +1,111 @@
+// 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.doris.mysql.nio;
+
+import org.apache.doris.mysql.MysqlChannel;
+import org.apache.doris.qe.ConnectProcessor;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.xnio.StreamConnection;
+import org.xnio.channels.Channels;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+
+/**
+ * mysql Channel based on nio.
+ */
+public class NMysqlChannel extends MysqlChannel {
+    protected final Logger LOG = LogManager.getLogger(this.getClass());
+    private StreamConnection conn;
+
+    public NMysqlChannel(StreamConnection connection) {
+        super();
+        this.conn = connection;
+        if (connection.getPeerAddress() instanceof InetSocketAddress) {
+            InetSocketAddress address = (InetSocketAddress) connection.getPeerAddress();
+            remoteHostPortString = address.getHostString() + ":" + address.getPort();
+            remoteIp = address.getAddress().getHostAddress();
+        } else {
+            // Reach here, what's it?
+            remoteHostPortString = connection.getPeerAddress().toString();
+            remoteIp = connection.getPeerAddress().toString();
+        }
+    }
+
+    /**
+     * read packet until all data is ready, unless block.
+     *
+     * @param dstBuf
+     * @return
+     * @throws IOException
+     */
+    @Override
+    protected int readAll(ByteBuffer dstBuf) throws IOException {
+        int ret = Channels.readBlocking(conn.getSourceChannel(), dstBuf);
+        // return -1 when remote peer close the channel
+        if (ret == -1) {
+            return 0;
+        }
+        return ret;
 
 Review comment:
   **The problem has been discussed again offline, and here is a summary.**
   
   According to the current implementation logic, when a MySQL message is relatively large, we must ensure that `readAll()` fills `desBuf`, and `readBlocking()` in `jboss.xnio` can not achieve this. So for the sake of simplicity, a loop logic will be added into `readAll()` to ensure that desBuf is filled (that is, the first method mentioned above)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org