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 2022/02/24 03:20:58 UTC

[GitHub] [shardingsphere] soulasuna opened a new pull request #15603: Set charset simple query supported in proxy

soulasuna opened a new pull request #15603:
URL: https://github.com/apache/shardingsphere/pull/15603


   ## Set charset simple query supported in proxy
   
   Related to #13317.
   
   Changes proposed in this pull request:
   - Set charset simple query supported for PostgreSQL by `SET CLIENT_ENCODING TO 'charsetName';`.
   - Set charset simple query supported for MySQL by `SET NAMES 'charsetName';`.
   


-- 
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] soulasuna commented on a change in pull request #15603: Set charset simple query supported in proxy

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/encoding/SetClientEncodingBackendHandler.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.backend.text.encoding;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import org.apache.shardingsphere.proxy.backend.response.header.update.ClientEncodingResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+/**
+ * Set client encoding backend handler.
+ */
+@RequiredArgsConstructor
+public class SetClientEncodingBackendHandler implements TextProtocolBackendHandler {

Review comment:
       OK. Only the Simple Query Protocol is currently supported.
   Will be refactored to support the JDBC extension protocol.




-- 
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 change in pull request #15603: Set charset simple query supported in proxy

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
##########
@@ -71,10 +80,19 @@ public MySQLComQueryPacketExecutor(final MySQLComQueryPacket packet, final Conne
     }
     
     private Collection<DatabasePacket<?>> processUpdate(final UpdateResponseHeader updateResponseHeader) {
-        responseType = ResponseType.UPDATE;
         return ResponsePacketBuilder.buildUpdateResponsePackets(updateResponseHeader);
     }
     
+    private Collection<DatabasePacket<?>> processClientEncoding(final ClientEncodingResponseHeader clientEncodingResponseHeader) {
+        String value = clientEncodingResponseHeader.getValue();
+        Optional<Charset> charset = MySQLCharacterSet.findByValue(value);
+        if (charset.isPresent()) {
+            clientEncodingResponseHeader.getConnectionSession().getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(charset.get());

Review comment:
       There is another value `MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY` which represented MySQL charset and collation is stored in channel attributes map. What if the charset changed to `GBK` while the collation are still `utf8mb4`? The wrong collation id may be returned to client.




-- 
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] soulasuna commented on a change in pull request #15603: Set charset simple query supported in proxy

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
##########
@@ -71,10 +80,19 @@ public MySQLComQueryPacketExecutor(final MySQLComQueryPacket packet, final Conne
     }
     
     private Collection<DatabasePacket<?>> processUpdate(final UpdateResponseHeader updateResponseHeader) {
-        responseType = ResponseType.UPDATE;
         return ResponsePacketBuilder.buildUpdateResponsePackets(updateResponseHeader);
     }
     
+    private Collection<DatabasePacket<?>> processClientEncoding(final ClientEncodingResponseHeader clientEncodingResponseHeader) {
+        String value = clientEncodingResponseHeader.getValue();
+        Optional<Charset> charset = MySQLCharacterSet.findByValue(value);
+        if (charset.isPresent()) {
+            clientEncodingResponseHeader.getConnectionSession().getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(charset.get());

Review comment:
       When using MySQL set character encoding not just for interacting with the client-side protocol. 
   The storage of data will also changed.
   I did test. The performance of proxy is consistent with MySQL.




-- 
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 #15603: Set charset simple query supported in proxy

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


   


-- 
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 #15603: Set charset simple query supported in proxy

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


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15603?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 [#15603](https://codecov.io/gh/apache/shardingsphere/pull/15603?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6da0197) into [master](https://codecov.io/gh/apache/shardingsphere/commit/9c4258dc73858683803ab8eb65db6c2ce2d0d14c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9c4258d) will **decrease** coverage by `0.05%`.
   > The diff coverage is `83.86%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15603/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/15603?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   #15603      +/-   ##
   ============================================
   - Coverage     60.48%   60.42%   -0.06%     
   + Complexity     1992     1763     -229     
   ============================================
     Files          3240     3242       +2     
     Lines         48753    48823      +70     
     Branches       8329     8345      +16     
   ============================================
   + Hits          29486    29502      +16     
   - Misses        16849    16897      +48     
   - Partials       2418     2424       +6     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15603?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...ol/postgresql/constant/PostgreSQLCharacterSet.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGIvcHJvdG9jb2wvcG9zdGdyZXNxbC9jb25zdGFudC9Qb3N0Z3JlU1FMQ2hhcmFjdGVyU2V0LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ackend/text/TextProtocolBackendHandlerFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L1RleHRQcm90b2NvbEJhY2tlbmRIYW5kbGVyRmFjdG9yeS5qYXZh) | `61.11% <0.00%> (-2.36%)` | :arrow_down: |
   | [...l/command/query/builder/ResponsePacketBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3Byb3h5L2Zyb250ZW5kL215c3FsL2NvbW1hbmQvcXVlcnkvYnVpbGRlci9SZXNwb25zZVBhY2tldEJ1aWxkZXIuamF2YQ==) | `90.90% <0.00%> (-4.33%)` | :arrow_down: |
   | [...roxy/frontend/mysql/err/MySQLErrPacketFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3Byb3h5L2Zyb250ZW5kL215c3FsL2Vyci9NeVNRTEVyclBhY2tldEZhY3RvcnkuamF2YQ==) | `61.11% <0.00%> (-2.36%)` | :arrow_down: |
   | [...mmand/query/simple/PostgreSQLComQueryExecutor.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9jb21tYW5kL3F1ZXJ5L3NpbXBsZS9Qb3N0Z3JlU1FMQ29tUXVlcnlFeGVjdXRvci5qYXZh) | `58.97% <0.00%> (-23.79%)` | :arrow_down: |
   | [...end/postgresql/err/PostgreSQLErrPacketFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvZnJvbnRlbmQvcG9zdGdyZXNxbC9lcnIvUG9zdGdyZVNRTEVyclBhY2tldEZhY3RvcnkuamF2YQ==) | `48.00% <0.00%> (-4.18%)` | :arrow_down: |
   | [...text/encoding/SetClientEncodingBackendHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2VuY29kaW5nL1NldENsaWVudEVuY29kaW5nQmFja2VuZEhhbmRsZXIuamF2YQ==) | `16.66% <16.66%> (ø)` | |
   | [.../query/text/query/MySQLComQueryPacketExecutor.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQvc2hhcmRpbmdzcGhlcmUtcHJveHktZnJvbnRlbmQtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3Byb3h5L2Zyb250ZW5kL215c3FsL2NvbW1hbmQvcXVlcnkvdGV4dC9xdWVyeS9NeVNRTENvbVF1ZXJ5UGFja2V0RXhlY3V0b3IuamF2YQ==) | `52.00% <30.00%> (-18.59%)` | :arrow_down: |
   | [.../db/protocol/mysql/constant/MySQLCharacterSet.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2RiL3Byb3RvY29sL215c3FsL2NvbnN0YW50L015U1FMQ2hhcmFjdGVyU2V0LmphdmE=) | `99.00% <98.95%> (-0.30%)` | :arrow_down: |
   | [.../protocol/mysql/constant/MySQLServerErrorCode.java](https://codecov.io/gh/apache/shardingsphere/pull/15603/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-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2RiL3Byb3RvY29sL215c3FsL2NvbnN0YW50L015U1FMU2VydmVyRXJyb3JDb2RlLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | ... and [2 more](https://codecov.io/gh/apache/shardingsphere/pull/15603/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15603?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/15603?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 [9c4258d...6da0197](https://codecov.io/gh/apache/shardingsphere/pull/15603?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.

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 change in pull request #15603: Set charset simple query supported in proxy

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



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/encoding/SetClientEncodingBackendHandler.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.backend.text.encoding;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import org.apache.shardingsphere.proxy.backend.response.header.update.ClientEncodingResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+/**
+ * Set client encoding backend handler.
+ */
+@RequiredArgsConstructor
+public class SetClientEncodingBackendHandler implements TextProtocolBackendHandler {

Review comment:
       Consider refactoring this by `DatabaseAdminExecutor` in future.




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