You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sunkai-cai (via GitHub)" <gi...@apache.org> on 2023/03/09 10:59:17 UTC

[GitHub] [shardingsphere] sunkai-cai opened a new pull request, #24524: Support unix domain socket

sunkai-cai opened a new pull request, #24524:
URL: https://github.com/apache/shardingsphere/pull/24524

   Fixes #24095.
   
    ShardingSphere-Proxy supported UDS。
   
   Changes proposed in this pull request:
     -  In  ShardingSphere-Proxy,add supported UDS by the `socket path` paramet.
     -  In  start.sh,add `-s` of paramet  to setting  `socket path`.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1135637605


##########
proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java:
##########
@@ -147,6 +150,10 @@ private boolean authorizeDatabase(final AuthorityRule rule, final Grantee grante
     }
     
     private String getHostAddress(final ChannelHandlerContext context) {
+        if (context.channel() instanceof EpollDomainSocketChannel) {
+            return context.channel().parent().localAddress().toString();
+        }
+        

Review Comment:
   ok



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131900661


##########
proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java:
##########
@@ -97,4 +118,13 @@ private String paddingWithSlash(final String pathArg) {
         }
         return result.toString();
     }
+    
+    private boolean isValidPath(final String path) {
+        try {
+            Paths.get(path);
+        } catch (InvalidPathException | NullPointerException ex) {
+            return false;

Review Comment:
   yes, it was designed that way.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131891244


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/UnixDomainSocketServer.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.proxy.frontend;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.unix.DomainSocketAddress;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.netty.ServerHandlerInitializer;
+import org.apache.shardingsphere.proxy.frontend.protocol.FrontDatabaseProtocolTypeFactory;
+
+/**
+ * UnixDomainSocketServer.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class UnixDomainSocketServer extends Thread {
+    
+    private final String socketPath;
+    
+    private EventLoopGroup bossGroup;
+    
+    private EventLoopGroup workerGroup;
+    
+    @Override
+    public void run() {
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.channel().closeFuture().sync();
+        } catch (final InterruptedException ignored) {
+        } finally {
+            close();
+        }
+    }
+    
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {
+        log.info("DomainSocket Starting {}", socketPath);
+        createEventLoopGroup();

Review Comment:
   Could we reuse the EventLoopGroup?



##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/UnixDomainSocketServer.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.proxy.frontend;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.unix.DomainSocketAddress;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.netty.ServerHandlerInitializer;
+import org.apache.shardingsphere.proxy.frontend.protocol.FrontDatabaseProtocolTypeFactory;
+
+/**
+ * UnixDomainSocketServer.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class UnixDomainSocketServer extends Thread {
+    
+    private final String socketPath;
+    
+    private EventLoopGroup bossGroup;
+    
+    private EventLoopGroup workerGroup;
+    
+    @Override
+    public void run() {
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.channel().closeFuture().sync();
+        } catch (final InterruptedException ignored) {
+        } finally {
+            close();
+        }
+    }
+    
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {
+        log.info("DomainSocket Starting {}", socketPath);
+        createEventLoopGroup();
+        ServerBootstrap bootstrap = new ServerBootstrap();
+        initServerBootstrap(bootstrap, new DomainSocketAddress(socketPath));
+        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
+        return bootstrap.bind().sync();
+    }
+    
+    private void createEventLoopGroup() {
+        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);

Review Comment:
   If the Epoll was not available, how EpollServerDomainSocketChannel work?



##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/UnixDomainSocketServer.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.proxy.frontend;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.unix.DomainSocketAddress;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.netty.ServerHandlerInitializer;
+import org.apache.shardingsphere.proxy.frontend.protocol.FrontDatabaseProtocolTypeFactory;
+
+/**
+ * UnixDomainSocketServer.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class UnixDomainSocketServer extends Thread {

Review Comment:
   Could we move the ServerBootstrap to class `ShardingSphereProxy`? UDS is just a way to connect Proxy.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1136837710


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -111,4 +146,22 @@ private void initServerBootstrap(final ServerBootstrap bootstrap) {
                 .handler(new LoggingHandler(LogLevel.INFO))
                 .childHandler(new ServerHandlerInitializer(FrontDatabaseProtocolTypeFactory.getDatabaseType()));
     }
+    
+    private void initServerBootstrap(final ServerBootstrap bootstrap, final DomainSocketAddress localDomainSocketAddress) {
+        bootstrap.group(bossGroup, workerGroup)
+                .channel(EpollServerDomainSocketChannel.class)
+                .localAddress(localDomainSocketAddress)
+                .handler(new LoggingHandler(LogLevel.INFO))
+                .childHandler(new ServerHandlerInitializer(FrontDatabaseProtocolTypeFactory.getDatabaseType()));
+    }
+    
+    private void close() {
+        if (null != bossGroup) {

Review Comment:
   Is this null check necessary?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#issuecomment-1471380280

   > Thank you @sunkai-cai The codes are more clear now.
   
   thanks for your review for make it better.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1135639258


##########
proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java:
##########
@@ -56,6 +58,7 @@
 /**
  * Authentication engine for MySQL.
  */
+@Slf4j

Review Comment:
   ok



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131892886


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -100,6 +98,7 @@ private EventLoopGroup getWorkerGroup() {
     
     private void initServerBootstrap(final ServerBootstrap bootstrap) {
         Integer backLog = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG);
+        

Review Comment:
   The blank line could be removed.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1136842810


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -63,24 +71,51 @@ public void start(final int port, final List<String> addresses) {
             List<ChannelFuture> futures = startInternal(port, addresses);
             accept(futures);
         } finally {
-            workerGroup.shutdownGracefully();
-            bossGroup.shutdownGracefully();
-            BackendExecutorContext.getInstance().getExecutorEngine().close();
+            close();
+        }
+    }
+    
+    /**
+     * Start ShardingSphere-Proxy with DomainSocket.
+     *
+     * @param socketPath socket path
+     */
+    public void start(final String socketPath) {
+        if (!Epoll.isAvailable()) {
+            log.error("Epoll is unavailable, DomainSocket can't start.");
+            return;
+        }
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.addListener((ChannelFutureListener) futureParams -> {
+                if (futureParams.isSuccess()) {
+                    log.info("The listening address for DomainSocket is {}", socketPath);
+                } else {
+                    log.error("DomainSocket failed to start.");
+                    futureParams.cause().printStackTrace();
+                }
+            });
+        } catch (final InterruptedException ignored) {
+            close();
         }
     }
     
     private List<ChannelFuture> startInternal(final int port, final List<String> addresses) throws InterruptedException {
-        createEventLoopGroup();
         ServerBootstrap bootstrap = new ServerBootstrap();
         initServerBootstrap(bootstrap);
-        
         List<ChannelFuture> futures = new ArrayList<>();
         for (String address : addresses) {
             futures.add(bootstrap.bind(address, port).sync());
         }
         return futures;
     }
     
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {

Review Comment:
   Does `InterruptedException` necessary?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1135638275


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -89,8 +123,12 @@ private void accept(final List<ChannelFuture> futures) throws InterruptedExcepti
     }
     
     private void createEventLoopGroup() {
-        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);
-        workerGroup = getWorkerGroup();
+        if (null == bossGroup) {

Review Comment:
   ok



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN merged pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN merged PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131982154


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/UnixDomainSocketServer.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.proxy.frontend;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.unix.DomainSocketAddress;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.netty.ServerHandlerInitializer;
+import org.apache.shardingsphere.proxy.frontend.protocol.FrontDatabaseProtocolTypeFactory;
+
+/**
+ * UnixDomainSocketServer.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class UnixDomainSocketServer extends Thread {
+    
+    private final String socketPath;
+    
+    private EventLoopGroup bossGroup;
+    
+    private EventLoopGroup workerGroup;
+    
+    @Override
+    public void run() {
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.channel().closeFuture().sync();
+        } catch (final InterruptedException ignored) {
+        } finally {
+            close();
+        }
+    }
+    
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {
+        log.info("DomainSocket Starting {}", socketPath);
+        createEventLoopGroup();
+        ServerBootstrap bootstrap = new ServerBootstrap();
+        initServerBootstrap(bootstrap, new DomainSocketAddress(socketPath));
+        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
+        return bootstrap.bind().sync();
+    }
+    
+    private void createEventLoopGroup() {
+        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);
+        workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
+    }
+    
+    private void initServerBootstrap(final ServerBootstrap bootstrap, final DomainSocketAddress localDomainSocketAddress) {
+        Integer backLog = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG);
+        bootstrap.group(bossGroup, workerGroup)
+                .channel(EpollServerDomainSocketChannel.class)
+                .localAddress(localDomainSocketAddress)
+                .option(ChannelOption.SO_BACKLOG, backLog)

Review Comment:
   ok



##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -100,6 +98,7 @@ private EventLoopGroup getWorkerGroup() {
     
     private void initServerBootstrap(final ServerBootstrap bootstrap) {
         Integer backLog = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG);
+        

Review Comment:
   ok



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131904638


##########
proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java:
##########
@@ -97,4 +118,13 @@ private String paddingWithSlash(final String pathArg) {
         }
         return result.toString();
     }
+    
+    private boolean isValidPath(final String path) {
+        try {
+            Paths.get(path);
+        } catch (InvalidPathException | NullPointerException ex) {
+            return false;

Review Comment:
   of course, we can throw a error in this.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1135621186


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -89,8 +123,12 @@ private void accept(final List<ChannelFuture> futures) throws InterruptedExcepti
     }
     
     private void createEventLoopGroup() {
-        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);
-        workerGroup = getWorkerGroup();
+        if (null == bossGroup) {

Review Comment:
   EventLoopGroup could be created once and used in both ServerBootstrap. Please avoid null check here.



##########
proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java:
##########
@@ -56,6 +58,7 @@
 /**
  * Authentication engine for MySQL.
  */
+@Slf4j

Review Comment:
   Please remove unused annotation.



##########
proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java:
##########
@@ -147,6 +150,10 @@ private boolean authorizeDatabase(final AuthorityRule rule, final Grantee grante
     }
     
     private String getHostAddress(final ChannelHandlerContext context) {
+        if (context.channel() instanceof EpollDomainSocketChannel) {
+            return context.channel().parent().localAddress().toString();
+        }
+        

Review Comment:
   Please remove the blank line.



##########
proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java:
##########
@@ -97,4 +118,13 @@ private String paddingWithSlash(final String pathArg) {
         }
         return result.toString();
     }
+    
+    private boolean isValidPath(final String path) {
+        try {
+            Paths.get(path);
+        } catch (InvalidPathException | NullPointerException ex) {
+            return false;

Review Comment:
   I prefer throwing an exception if path was invalid.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#issuecomment-1469638764

   > Please add tests to cover your changes.
   
   ok


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] codecov-commenter commented on pull request #24524: Support unix domain socket

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#issuecomment-1461875767

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#24524](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4dbca31) into [master](https://codecov.io/gh/apache/shardingsphere/commit/5fec520bb9884e6c81da67f9943e3f7828a76a97?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5fec520) will **increase** coverage by `0.25%`.
   > The diff coverage is `74.48%`.
   
   > :exclamation: Current head 4dbca31 differs from pull request most recent head ed50fd5. Consider uploading reports for the commit ed50fd5 to get more accurate results
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #24524      +/-   ##
   ============================================
   + Coverage     50.05%   50.30%   +0.25%     
   - Complexity     1584     1599      +15     
   ============================================
     Files          3237     3289      +52     
     Lines         53392    53884     +492     
     Branches       9847     9927      +80     
   ============================================
   + Hits          26724    27105     +381     
   - Misses        24290    24359      +69     
   - Partials       2378     2420      +42     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...shardingsphere/agent/core/ShardingSphereAgent.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvYWdlbnQvY29yZS9TaGFyZGluZ1NwaGVyZUFnZW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ore/advisor/config/AdvisorConfigurationLoader.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvYWdlbnQvY29yZS9hZHZpc29yL2NvbmZpZy9BZHZpc29yQ29uZmlndXJhdGlvbkxvYWRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...gin/tracing/core/advice/TracingRootSpanAdvice.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvcGx1Z2lucy90cmFjaW5nL2NvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2FnZW50L3BsdWdpbi90cmFjaW5nL2NvcmUvYWR2aWNlL1RyYWNpbmdSb290U3BhbkFkdmljZS5qYXZh) | `0.00% <ø> (ø)` | |
   | [...ingsphere/agent/plugin/tracing/AgentExtension.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvcGx1Z2lucy90cmFjaW5nL3Rlc3Qvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2FnZW50L3BsdWdpbi90cmFjaW5nL0FnZW50RXh0ZW5zaW9uLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ser/core/kernel/KernelDistSQLStatementVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGlzdHNxbC9wYXJzZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2Rpc3RzcWwvcGFyc2VyL2NvcmUva2VybmVsL0tlcm5lbERpc3RTUUxTdGF0ZW1lbnRWaXNpdG9yLmphdmE=) | `5.15% <0.00%> (-0.34%)` | :arrow_down: |
   | [...atement/ral/queryable/ExportMetaDataStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGlzdHNxbC9zdGF0ZW1lbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2Rpc3RzcWwvcGFyc2VyL3N0YXRlbWVudC9yYWwvcXVlcnlhYmxlL0V4cG9ydE1ldGFEYXRhU3RhdGVtZW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ent/ral/queryable/ExportStorageNodesStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGlzdHNxbC9zdGF0ZW1lbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2Rpc3RzcWwvcGFyc2VyL3N0YXRlbWVudC9yYWwvcXVlcnlhYmxlL0V4cG9ydFN0b3JhZ2VOb2Rlc1N0YXRlbWVudC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...atement/ral/updatable/ImportMetaDataStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGlzdHNxbC9zdGF0ZW1lbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2Rpc3RzcWwvcGFyc2VyL3N0YXRlbWVudC9yYWwvdXBkYXRhYmxlL0ltcG9ydE1ldGFEYXRhU3RhdGVtZW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...s/prometheus/PrometheusPluginLifecycleService.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvcGx1Z2lucy9tZXRyaWNzL3R5cGUvcHJvbWV0aGV1cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvYWdlbnQvcGx1Z2luL21ldHJpY3MvcHJvbWV0aGV1cy9Qcm9tZXRoZXVzUGx1Z2luTGlmZWN5Y2xlU2VydmljZS5qYXZh) | `64.51% <50.00%> (-7.49%)` | :arrow_down: |
   | [...ics/core/exporter/impl/jdbc/JDBCStateExporter.java](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YWdlbnQvcGx1Z2lucy9tZXRyaWNzL2NvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2FnZW50L3BsdWdpbi9tZXRyaWNzL2NvcmUvZXhwb3J0ZXIvaW1wbC9qZGJjL0pEQkNTdGF0ZUV4cG9ydGVyLmphdmE=) | `59.09% <59.09%> (ø)` | |
   | ... and [182 more](https://codecov.io/gh/apache/shardingsphere/pull/24524?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#issuecomment-1469614541

   Please add tests to cover your changes.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1136841262


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -63,24 +71,51 @@ public void start(final int port, final List<String> addresses) {
             List<ChannelFuture> futures = startInternal(port, addresses);
             accept(futures);
         } finally {
-            workerGroup.shutdownGracefully();
-            bossGroup.shutdownGracefully();
-            BackendExecutorContext.getInstance().getExecutorEngine().close();
+            close();
+        }
+    }
+    
+    /**
+     * Start ShardingSphere-Proxy with DomainSocket.
+     *
+     * @param socketPath socket path
+     */
+    public void start(final String socketPath) {
+        if (!Epoll.isAvailable()) {
+            log.error("Epoll is unavailable, DomainSocket can't start.");
+            return;
+        }
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.addListener((ChannelFutureListener) futureParams -> {
+                if (futureParams.isSuccess()) {
+                    log.info("The listening address for DomainSocket is {}", socketPath);
+                } else {
+                    log.error("DomainSocket failed to start.");

Review Comment:
   Please pass the cause to log.error.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1137354393


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -63,24 +71,51 @@ public void start(final int port, final List<String> addresses) {
             List<ChannelFuture> futures = startInternal(port, addresses);
             accept(futures);
         } finally {
-            workerGroup.shutdownGracefully();
-            bossGroup.shutdownGracefully();
-            BackendExecutorContext.getInstance().getExecutorEngine().close();
+            close();
+        }
+    }
+    
+    /**
+     * Start ShardingSphere-Proxy with DomainSocket.
+     *
+     * @param socketPath socket path
+     */
+    public void start(final String socketPath) {
+        if (!Epoll.isAvailable()) {
+            log.error("Epoll is unavailable, DomainSocket can't start.");
+            return;
+        }
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.addListener((ChannelFutureListener) futureParams -> {
+                if (futureParams.isSuccess()) {
+                    log.info("The listening address for DomainSocket is {}", socketPath);
+                } else {
+                    log.error("DomainSocket failed to start.");
+                    futureParams.cause().printStackTrace();
+                }
+            });
+        } catch (final InterruptedException ignored) {
+            close();
         }
     }
     
     private List<ChannelFuture> startInternal(final int port, final List<String> addresses) throws InterruptedException {
-        createEventLoopGroup();
         ServerBootstrap bootstrap = new ServerBootstrap();
         initServerBootstrap(bootstrap);
-        
         List<ChannelFuture> futures = new ArrayList<>();
         for (String address : addresses) {
             futures.add(bootstrap.bind(address, port).sync());
         }
         return futures;
     }
     
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {

Review Comment:
   oh,it‘s not need。



##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -63,24 +71,51 @@ public void start(final int port, final List<String> addresses) {
             List<ChannelFuture> futures = startInternal(port, addresses);
             accept(futures);
         } finally {
-            workerGroup.shutdownGracefully();
-            bossGroup.shutdownGracefully();
-            BackendExecutorContext.getInstance().getExecutorEngine().close();
+            close();
+        }
+    }
+    
+    /**
+     * Start ShardingSphere-Proxy with DomainSocket.
+     *
+     * @param socketPath socket path
+     */
+    public void start(final String socketPath) {
+        if (!Epoll.isAvailable()) {
+            log.error("Epoll is unavailable, DomainSocket can't start.");
+            return;
+        }
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.addListener((ChannelFutureListener) futureParams -> {
+                if (futureParams.isSuccess()) {
+                    log.info("The listening address for DomainSocket is {}", socketPath);
+                } else {
+                    log.error("DomainSocket failed to start.");

Review Comment:
   ok



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131889544


##########
proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/arguments/BootstrapArguments.java:
##########
@@ -97,4 +118,13 @@ private String paddingWithSlash(final String pathArg) {
         }
         return result.toString();
     }
+    
+    private boolean isValidPath(final String path) {
+        try {
+            Paths.get(path);
+        } catch (InvalidPathException | NullPointerException ex) {
+            return false;

Review Comment:
   My understanding is that if user specified an invalid path, the socket will not be present and no error will occur. Am I right?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] sunkai-cai commented on a diff in pull request #24524: Support unix domain socket

Posted by "sunkai-cai (via GitHub)" <gi...@apache.org>.
sunkai-cai commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1137354944


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java:
##########
@@ -111,4 +146,22 @@ private void initServerBootstrap(final ServerBootstrap bootstrap) {
                 .handler(new LoggingHandler(LogLevel.INFO))
                 .childHandler(new ServerHandlerInitializer(FrontDatabaseProtocolTypeFactory.getDatabaseType()));
     }
+    
+    private void initServerBootstrap(final ServerBootstrap bootstrap, final DomainSocketAddress localDomainSocketAddress) {
+        bootstrap.group(bossGroup, workerGroup)
+                .channel(EpollServerDomainSocketChannel.class)
+                .localAddress(localDomainSocketAddress)
+                .handler(new LoggingHandler(LogLevel.INFO))
+                .childHandler(new ServerHandlerInitializer(FrontDatabaseProtocolTypeFactory.getDatabaseType()));
+    }
+    
+    private void close() {
+        if (null != bossGroup) {

Review Comment:
   we can remove it now。



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24524: Support unix domain socket

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24524:
URL: https://github.com/apache/shardingsphere/pull/24524#discussion_r1131900395


##########
proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/UnixDomainSocketServer.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.proxy.frontend;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerDomainSocketChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.unix.DomainSocketAddress;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.netty.ServerHandlerInitializer;
+import org.apache.shardingsphere.proxy.frontend.protocol.FrontDatabaseProtocolTypeFactory;
+
+/**
+ * UnixDomainSocketServer.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class UnixDomainSocketServer extends Thread {
+    
+    private final String socketPath;
+    
+    private EventLoopGroup bossGroup;
+    
+    private EventLoopGroup workerGroup;
+    
+    @Override
+    public void run() {
+        try {
+            ChannelFuture future = startDomainSocket(socketPath);
+            future.channel().closeFuture().sync();
+        } catch (final InterruptedException ignored) {
+        } finally {
+            close();
+        }
+    }
+    
+    private ChannelFuture startDomainSocket(final String socketPath) throws InterruptedException {
+        log.info("DomainSocket Starting {}", socketPath);
+        createEventLoopGroup();
+        ServerBootstrap bootstrap = new ServerBootstrap();
+        initServerBootstrap(bootstrap, new DomainSocketAddress(socketPath));
+        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
+        return bootstrap.bind().sync();
+    }
+    
+    private void createEventLoopGroup() {
+        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1);
+        workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
+    }
+    
+    private void initServerBootstrap(final ServerBootstrap bootstrap, final DomainSocketAddress localDomainSocketAddress) {
+        Integer backLog = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG);
+        bootstrap.group(bossGroup, workerGroup)
+                .channel(EpollServerDomainSocketChannel.class)
+                .localAddress(localDomainSocketAddress)
+                .option(ChannelOption.SO_BACKLOG, backLog)

Review Comment:
   This option is not for UDS, it could be removed.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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