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/12/27 10:33:29 UTC

[GitHub] [shardingsphere] goudai opened a new issue #14350: How do I configure the dataSourceProperties of HikariDataSource

goudai opened a new issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350


   
   How do I configure the dataSourceProperties of HikariDataSource .
   I use the following configuration can not take effect:
   
   ```yaml
   
   ds_1:
     dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     driverClassName: com.mysql.cj.jdbc.Driver
     jdbcUrl: jdbc:mysql://10.195.7.55:3306/order_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true
     username: root
     password: ""
     connectionInitSql: "set names utf8mb4;"
     connectionTimeout: 3000
     dataSourceProperties:
       cachePrepStmts: true
       prepStmtCacheSize: 250
       prepStmtCacheSqlLimit: 2048
       useServerPrepStmts: true
   
   ```
   


-- 
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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001843941


   I have seen the code and it doesn’t seem to be processed, I can only do it by extending the SPI


-- 
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] zjcnb commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1002011370


   @goudai It 's cool. i 'm try to fix it. 


-- 
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] goudai edited a comment on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai edited a comment on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001508599


   I use shardingsphere-jdbc. the following maven deps 
   ```xml
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               <artifactId>shardingsphere-jdbc-core</artifactId>
               <version>5.0.0</version>
           </dependency>
   ```


-- 
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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001833149


   I don't use spring-boot-starter


-- 
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] RaigorJiang commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001507371


   Hi @goudai 
   Do you use ShardingSpehere-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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001508599


   I use jdbc


-- 
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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001844623


   
   # I used the following configuration and it worked
   
   ![image](https://user-images.githubusercontent.com/16605628/147523546-a08b74f1-ad59-4f62-a72f-9f13ad0d6cae.png)
   
   ```java
   public  class HikariJDBCParameterDecorator implements JDBCParameterDecorator<HikariDataSource> {
       
       @Override
       public HikariDataSource decorate(final HikariDataSource dataSource) {
           final ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(dataSource.getJdbcUrl());
   
           Map<String, String> urlProps = connectionUrlParser.getProperties();
           addJDBCProperty(dataSource, urlProps, "useServerPrepStmts", Boolean.TRUE.toString());
           addJDBCProperty(dataSource, urlProps, "cachePrepStmts", Boolean.TRUE.toString());
           addJDBCProperty(dataSource, urlProps, "prepStmtCacheSize", "200000");
           addJDBCProperty(dataSource, urlProps, "prepStmtCacheSqlLimit", "2048");
           HikariDataSource result = new HikariDataSource(dataSource);
           dataSource.close();
           return result;
       }
       
       private void addJDBCProperty(final HikariConfig config, final Map<String, String> urlProps, final String key, final String value) {
           if (urlProps.isEmpty() || !urlProps.containsKey(key)) {
               config.getDataSourceProperties().setProperty(key, value);
           }
       }
       
       @Override
       public Class<HikariDataSource> getType() {
           return HikariDataSource.class;
       }
   }
   ```


-- 
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] zjcnb commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001831243


   ![image](https://user-images.githubusercontent.com/33742097/147519675-0f19c4b2-6290-4522-9b04-683c9febc8c5.png)
   
   Can you show me your all properties? by the way, the createDataSource() method has problem. refer to : # 14357


-- 
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] zjcnb commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1002987328


   @goudai Hi, this problem are fixed in master branch. you can try it.


-- 
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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001833656


   ```java
           final DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(yamlFile);
   ```
   # da.yaml
   ```yaml
   dataSources:
     ds_0:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.cj.jdbc.Driver
       jdbcUrl: jdbc:mysql://10.195.7.55:3306/order_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true
       username: root
       password: ""
       connectionInitSql: "set names utf8mb4;"
       # ms
       connectionTimeout: 3000
   #    data-source-properties: {cachePrepStmts: true, prepStmtCacheSize: 250, prepStmtCacheSqlLimit: 2048, useServerPrepStmts: true}
       data-source-properties:
         cachePrepStmts: true
         prepStmtCacheSize: 1000
         prepStmtCacheSqlLimit: 2048
         useServerPrepStmts: true
   
     ds_1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.cj.jdbc.Driver
       jdbcUrl: jdbc:mysql://10.195.7.55:3306/order_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true
       username: root
       password: ""
       connectionInitSql: "set names utf8mb4;"
       # ms
       connectionTimeout: 3000
       data-source-properties:
         cachePrepStmts: true
         prepStmtCacheSize: 1000
         prepStmtCacheSqlLimit: 2048
         useServerPrepStmts: true
   
   ```
   


-- 
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] RaigorJiang edited a comment on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
RaigorJiang edited a comment on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001507371


   Hi @goudai 
   Do you use ShardingSphere-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] zjcnb commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001546663


   @goudai Hi, you can refer to this :
   
   ```
         ds-0:
           jdbc-url: jdbc:mysql://127.0.0.1:13306/demo_primary_ds?serverTimezone=UTC&useSSL=false
           username: root
           password: 123456
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           connectionTimeout: 5000
           data-source-properties:
             cachePrepStmts: true
             prepStmtCacheSize: 1000
             prepStmtCacheSqlLimit: 2048
   ```


-- 
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] zjcnb commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001836501


   I got it ! let 's me double check.


-- 
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] terrymanu closed issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350


   


-- 
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] terrymanu commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1046270603


   I just close this issue because no response for long time.


-- 
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] zjcnb edited a comment on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb edited a comment on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001836501


   I got it ! let me double check.


-- 
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] zjcnb edited a comment on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
zjcnb edited a comment on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001831243






-- 
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] goudai commented on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai commented on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001828947


   
   ```yaml
     ds_1:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.cj.jdbc.Driver
       jdbcUrl: jdbc:mysql://10.195.7.55:3306/order_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=true
       username: root
       password: ""
       connectionInitSql: "set names utf8mb4;"
       # ms
       connectionTimeout: 3000
       data-source-properties:
         cachePrepStmts: true
         prepStmtCacheSize: 1000
         prepStmtCacheSqlLimit: 2048
         useServerPrepStmts: true
   ```
   
   ![image](https://user-images.githubusercontent.com/16605628/147519242-66e71081-c178-4888-8df7-b567b12cbdfc.png)
   


-- 
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] goudai edited a comment on issue #14350: How do I configure the dataSourceProperties of HikariDataSource

Posted by GitBox <gi...@apache.org>.
goudai edited a comment on issue #14350:
URL: https://github.com/apache/shardingsphere/issues/14350#issuecomment-1001844623


   # I used the following configuration and it worked
   
   ![image](https://user-images.githubusercontent.com/16605628/147523546-a08b74f1-ad59-4f62-a72f-9f13ad0d6cae.png)
   
   ```java
   public  class HikariJDBCParameterDecorator implements JDBCParameterDecorator<HikariDataSource> {
       
       @Override
       public HikariDataSource decorate(final HikariDataSource dataSource) {
           final ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(dataSource.getJdbcUrl());
   
           Map<String, String> urlProps = connectionUrlParser.getProperties();
           addJDBCProperty(dataSource, urlProps, "useServerPrepStmts", Boolean.TRUE.toString());
           addJDBCProperty(dataSource, urlProps, "cachePrepStmts", Boolean.TRUE.toString());
           addJDBCProperty(dataSource, urlProps, "prepStmtCacheSize", "200");
           addJDBCProperty(dataSource, urlProps, "prepStmtCacheSqlLimit", "2048");
           HikariDataSource result = new HikariDataSource(dataSource);
           dataSource.close();
           return result;
       }
       
       private void addJDBCProperty(final HikariConfig config, final Map<String, String> urlProps, final String key, final String value) {
           if (urlProps.isEmpty() || !urlProps.containsKey(key)) {
               config.getDataSourceProperties().setProperty(key, value);
           }
       }
       
       @Override
       public Class<HikariDataSource> getType() {
           return HikariDataSource.class;
       }
   }
   ```


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