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 2020/07/06 05:35:51 UTC

[GitHub] [shardingsphere] tuohai666 commented on a change in pull request #6270: Fix 6239

tuohai666 commented on a change in pull request #6270:
URL: https://github.com/apache/shardingsphere/pull/6270#discussion_r449983168



##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";

Review comment:
       Should delete if only use for serverVersion once.

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.
+     * @param version version
      */
-    public static final int CHARSET = 0x21;
+    public static void setServerVersion(final String version) {
+        if (version != null) {

Review comment:
       null != version

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.

Review comment:
       follow an empty line.

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.
+     * @param version version

Review comment:
       server version

##########
File path: shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/bin/start.sh
##########
@@ -38,6 +38,17 @@ JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn1g -Xss256k -XX:+DisableExplicitGC -XX
 
 MAIN_CLASS=org.apache.shardingsphere.proxy.Bootstrap
 
+print_usage() {

Review comment:
       What's this for?  I suggest delete it from this pr. If you would like to add help, please create a new issue to do this.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ShardingConfigurationLoader.java
##########
@@ -52,9 +53,10 @@
      * @throws IOException IO exception
      */
     public ShardingConfiguration load(final String path) throws IOException {
+        //this is just check for schemaName duplication

Review comment:
       remove this change if it's not about the server version.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
##########
@@ -157,6 +162,26 @@ private static void initialize(final Authentication authentication, final Proper
         log(authentication, properties);
         initControlPanelFacade(metricsConfiguration);
         initCluster(cluster);
+        updateServerInfo();
+    }
+    
+    private static void updateServerInfo() {
+        List<String> schemaNames = ProxySchemaContexts.getInstance().getSchemaNames();
+        if (CollectionUtils.isEmpty(schemaNames)) {
+            return;
+        }
+        Map<String, DataSource> dataSources = ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0)).getSchema().getDataSources();
+        DataSource singleDataSource = dataSources.values().iterator().next();
+        try (Connection connection = singleDataSource.getConnection()) {
+            DatabaseMetaData meta = connection.getMetaData();
+            String name = meta.getDatabaseProductName();
+            String version = meta.getDatabaseProductVersion();
+            log.info("server name {} , server version {}", name, version);
+            MySQLServerInfo.setServerVersion(version);
+        } catch (SQLException e) {

Review comment:
       SQLException e -> final SQLException ex

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.

Review comment:
       set should be capitalized.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
##########
@@ -157,6 +162,26 @@ private static void initialize(final Authentication authentication, final Proper
         log(authentication, properties);
         initControlPanelFacade(metricsConfiguration);
         initCluster(cluster);
+        updateServerInfo();
+    }
+    
+    private static void updateServerInfo() {
+        List<String> schemaNames = ProxySchemaContexts.getInstance().getSchemaNames();
+        if (CollectionUtils.isEmpty(schemaNames)) {
+            return;
+        }
+        Map<String, DataSource> dataSources = ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0)).getSchema().getDataSources();
+        DataSource singleDataSource = dataSources.values().iterator().next();
+        try (Connection connection = singleDataSource.getConnection()) {
+            DatabaseMetaData meta = connection.getMetaData();

Review comment:
       meta -> databaseMetaData, note that we rarely use abbreviation.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
##########
@@ -157,6 +162,26 @@ private static void initialize(final Authentication authentication, final Proper
         log(authentication, properties);
         initControlPanelFacade(metricsConfiguration);
         initCluster(cluster);
+        updateServerInfo();
+    }
+    
+    private static void updateServerInfo() {
+        List<String> schemaNames = ProxySchemaContexts.getInstance().getSchemaNames();
+        if (CollectionUtils.isEmpty(schemaNames)) {
+            return;
+        }
+        Map<String, DataSource> dataSources = ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0)).getSchema().getDataSources();
+        DataSource singleDataSource = dataSources.values().iterator().next();
+        try (Connection connection = singleDataSource.getConnection()) {
+            DatabaseMetaData meta = connection.getMetaData();
+            String name = meta.getDatabaseProductName();
+            String version = meta.getDatabaseProductVersion();
+            log.info("server name {} , server version {}", name, version);
+            MySQLServerInfo.setServerVersion(version);
+        } catch (SQLException e) {
+            log.error(e.getMessage(), e);
+        }
+    

Review comment:
       remove meaningless empty line.

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.
+     * @param version version
      */
-    public static final int CHARSET = 0x21;
+    public static void setServerVersion(final String version) {
+        if (version != null) {
+            serverVersion = String.format("%s-ShardingSphere-Proxy 5.0.0-RC1", version);
+        }
+    }
+    
+    /**
+     * get current server version.

Review comment:
       get should be capitalized.

##########
File path: shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
##########
@@ -157,6 +162,26 @@ private static void initialize(final Authentication authentication, final Proper
         log(authentication, properties);
         initControlPanelFacade(metricsConfiguration);
         initCluster(cluster);
+        updateServerInfo();
+    }
+    
+    private static void updateServerInfo() {
+        List<String> schemaNames = ProxySchemaContexts.getInstance().getSchemaNames();
+        if (CollectionUtils.isEmpty(schemaNames)) {
+            return;
+        }
+        Map<String, DataSource> dataSources = ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0)).getSchema().getDataSources();
+        DataSource singleDataSource = dataSources.values().iterator().next();
+        try (Connection connection = singleDataSource.getConnection()) {
+            DatabaseMetaData meta = connection.getMetaData();
+            String name = meta.getDatabaseProductName();
+            String version = meta.getDatabaseProductVersion();
+            log.info("server name {} , server version {}", name, version);
+            MySQLServerInfo.setServerVersion(version);
+        } catch (SQLException e) {
+            log.error(e.getMessage(), e);

Review comment:
       throw a ShardingSphereException instead of print log.

##########
File path: shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
##########
@@ -31,13 +31,33 @@
      */
     public static final int PROTOCOL_VERSION = 0x0A;
     
+    /**
+     * Charset code 0x21 is utf8_general_ci.
+     */
+    public static final int CHARSET = 0x21;
+    
+    private static final String DEFAULT_SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    
     /**
      * Server version.
      */
-    public static final String SERVER_VERSION = "8.0.20-ShardingSphere-Proxy 5.0.0-RC1";
+    private static String serverVersion = DEFAULT_SERVER_VERSION;
     
     /**
-     * Charset code 0x21 is utf8_general_ci.
+     *  set server version.
+     * @param version version
      */
-    public static final int CHARSET = 0x21;
+    public static void setServerVersion(final String version) {
+        if (version != null) {
+            serverVersion = String.format("%s-ShardingSphere-Proxy 5.0.0-RC1", version);
+        }
+    }
+    
+    /**
+     * get current server version.

Review comment:
       follow an empty line.




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