You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/05/06 15:28:35 UTC

[GitHub] [shardingsphere] TeslaCN opened a new pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

TeslaCN opened a new pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260


   Fixes #10184.
   
   Changes proposed in this pull request:
   - Replace `ChannelId` with `ConnectionId`.
   - Refactor `ChannelThreadExecutorGroup` to `ConnectionThreadExecutorGroup`.


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



[GitHub] [shardingsphere] TeslaCN commented on pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260#issuecomment-833641725


   I'm going to test this PR with BenchmarkSQL and sysbench before merging.


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



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260#discussion_r627547543



##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroup.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.executor;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Connection thread executor group.
+ *
+ * <p>
+ * Manage the thread for each backend connection invoking.
+ * This ensure XA transaction framework processed by current thread id.
+ * </p>
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ConnectionThreadExecutorGroup {
+    
+    private static final ConnectionThreadExecutorGroup INSTANCE = new ConnectionThreadExecutorGroup();
+    
+    private final Map<Integer, ExecutorService> executorServices = new ConcurrentHashMap<>();
+    
+    /**
+     * Get connection thread executor group.
+     *
+     * @return channel thread executor group
+     */
+    public static ConnectionThreadExecutorGroup getInstance() {
+        return INSTANCE;
+    }
+    
+    /**
+     * Register connection.
+     *
+     * @param connectionId connection id
+     */
+    public void register(final int connectionId) {
+        executorServices.put(connectionId, Executors.newSingleThreadExecutor());
+    }
+    
+    /**
+     * Get executor service of connection.
+     *
+     * @param connectionId connection id
+     * @return executor service of current channel
+     */
+    public ExecutorService get(final int connectionId) {
+        return executorServices.get(connectionId);
+    }
+    
+    /**
+     * Unregister connection.
+     *
+     * @param connectionId connection id
+     */
+    public void unregisterAndAwaitTermination(final int connectionId) {
+        executorServices.computeIfPresent(connectionId, (unused, executorService) -> {
+            executorService.shutdown();
+            try {
+                executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+            } catch (final InterruptedException ignored) {
+                Thread.currentThread().interrupt();
+            }
+            return null;
+        });

Review comment:
       We need to remove connectionId is unused.




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



[GitHub] [shardingsphere] terrymanu merged pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260


   


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



[GitHub] [shardingsphere] TeslaCN commented on a change in pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260#discussion_r627555871



##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroup.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.executor;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Connection thread executor group.
+ *
+ * <p>
+ * Manage the thread for each backend connection invoking.
+ * This ensure XA transaction framework processed by current thread id.
+ * </p>
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ConnectionThreadExecutorGroup {
+    
+    private static final ConnectionThreadExecutorGroup INSTANCE = new ConnectionThreadExecutorGroup();
+    
+    private final Map<Integer, ExecutorService> executorServices = new ConcurrentHashMap<>();
+    
+    /**
+     * Get connection thread executor group.
+     *
+     * @return channel thread executor group
+     */
+    public static ConnectionThreadExecutorGroup getInstance() {
+        return INSTANCE;
+    }
+    
+    /**
+     * Register connection.
+     *
+     * @param connectionId connection id
+     */
+    public void register(final int connectionId) {
+        executorServices.put(connectionId, Executors.newSingleThreadExecutor());
+    }
+    
+    /**
+     * Get executor service of connection.
+     *
+     * @param connectionId connection id
+     * @return executor service of current channel
+     */
+    public ExecutorService get(final int connectionId) {
+        return executorServices.get(connectionId);
+    }
+    
+    /**
+     * Unregister connection.
+     *
+     * @param connectionId connection id
+     */
+    public void unregisterAndAwaitTermination(final int connectionId) {
+        executorServices.computeIfPresent(connectionId, (unused, executorService) -> {
+            executorService.shutdown();
+            try {
+                executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+            } catch (final InterruptedException ignored) {
+                Thread.currentThread().interrupt();
+            }
+            return null;
+        });

Review comment:
       Indeed.




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



[GitHub] [shardingsphere] TeslaCN commented on pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260#issuecomment-839774222


   I've tested it with sysbench and it works fine.
   https://paste.ubuntu.com/p/yB49wZ7dzZ/


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



[GitHub] [shardingsphere] codecov-commenter commented on pull request #10260: Refactor ChannelThreadExecutorGroup to ConnectionThreadExecutorGroup

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #10260:
URL: https://github.com/apache/shardingsphere/pull/10260#issuecomment-835290626


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10260?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 [#10260](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6c6496e) into [master](https://codecov.io/gh/apache/shardingsphere/commit/f08b09816901de8ea82f789b15328f5849db12c7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (f08b098) will **increase** coverage by `0.01%`.
   > The diff coverage is `50.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/10260/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #10260      +/-   ##
   ============================================
   + Coverage     67.94%   67.95%   +0.01%     
     Complexity      683      683              
   ============================================
     Files          1706     1706              
     Lines         29292    29284       -8     
     Branches       5270     5268       -2     
   ============================================
   - Hits          19901    19899       -2     
   + Misses         7848     7843       -5     
   + Partials       1543     1542       -1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...mmunication/jdbc/connection/BackendConnection.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9jb21tdW5pY2F0aW9uL2pkYmMvY29ubmVjdGlvbi9CYWNrZW5kQ29ubmVjdGlvbi5qYXZh) | `82.05% <ø> (-0.16%)` | `0.00 <0.00> (ø)` | |
   | [...re/proxy/frontend/command/CommandExecutorTask.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvY29tbWFuZC9Db21tYW5kRXhlY3V0b3JUYXNrLmphdmE=) | `78.00% <ø> (-0.44%)` | `0.00 <0.00> (ø)` | |
   | [.../frontend/netty/FrontendChannelInboundHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvbmV0dHkvRnJvbnRlbmRDaGFubmVsSW5ib3VuZEhhbmRsZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [...sphere/proxy/frontend/state/impl/OKProxyState.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvc3RhdGUvaW1wbC9PS1Byb3h5U3RhdGUuamF2YQ==) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [.../frontend/postgresql/PostgreSQLFrontendEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9Qb3N0Z3JlU1FMRnJvbnRlbmRFbmdpbmUuamF2YQ==) | `100.00% <ø> (+33.33%)` | `0.00 <0.00> (ø)` | |
   | [...oxy/frontend/executor/CommandExecutorSelector.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvZXhlY3V0b3IvQ29tbWFuZEV4ZWN1dG9yU2VsZWN0b3IuamF2YQ==) | `50.00% <50.00%> (-16.67%)` | `0.00 <0.00> (ø)` | |
   | [...ontend/executor/ConnectionThreadExecutorGroup.java](https://codecov.io/gh/apache/shardingsphere/pull/10260/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvZXhlY3V0b3IvQ29ubmVjdGlvblRocmVhZEV4ZWN1dG9yR3JvdXAuamF2YQ==) | `83.33% <83.33%> (ø)` | `0.00 <0.00> (?)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [f08b098...6c6496e](https://codecov.io/gh/apache/shardingsphere/pull/10260?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?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.

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