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/02/07 14:37:08 UTC

[GitHub] [shardingsphere] huanghao495430759 opened a new pull request #9379: Issue#9286

huanghao495430759 opened a new pull request #9379:
URL: https://github.com/apache/shardingsphere/pull/9379


   Issue#9286


----------------------------------------------------------------
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] tristaZero commented on a change in pull request #9379: Issue#9286

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



##########
File path: docs/document/content/user-manual/shardingsphere-jdbc/configuration/java-api/mix.en.md
##########
@@ -3,4 +3,98 @@ title = "Mixed Rules"
 weight = 6
 +++
 
-TODO
+The overlay between rule items in a mixed configuration is associated by the data source name and the table name.

Review comment:
       Same with  #9378 here.

##########
File path: docs/document/content/user-manual/shardingsphere-jdbc/configuration/java-api/mix.en.md
##########
@@ -3,4 +3,98 @@ title = "Mixed Rules"
 weight = 6
 +++
 
-TODO
+The overlay between rule items in a mixed configuration is associated by the data source name and the table name.
+
+If the previous rule is aggregation-oriented, the next rule needs to use the aggregated logical data source name configured by the previous rule when configuring the data source.
+Similarly, if the previous rule is table aggregation-oriented, the next rule needs to use the aggregated logical table name configured by the previous rule when configuring the table.
+
+## Configuration Item Explanation
+
+```java
+/* Data source configuration */
+HikariDataSource primaryDataSource0 = new HikariDataSource();
+primaryDataSource0.setDriverClassName("com.mysql.jdbc.Driver");
+primaryDataSource0.setJdbcUrl("jdbc:mysql://localhost:3306/db0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8");
+primaryDataSource0.setUsername("root");
+primaryDataSource0.setPassword("");
+
+HikariDataSource primaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica0OfPrimaryDataSource0 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica1OfPrimaryDataSource0 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica0OfPrimaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica1OfPrimaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+Map<String, DataSource> datasourceMaps = new HashMap<>(6);
+
+datasourceMaps.put("primary_ds0", primaryDataSource0);
+datasourceMaps.put("primary_ds0_replica0", replica0OfPrimaryDataSource0);
+datasourceMaps.put("primary_ds0_replica1", replica1OfPrimaryDataSource0);
+
+datasourceMaps.put("primary_ds1", primaryDataSource1);
+datasourceMaps.put("primary_ds1_replica0", replica0OfPrimaryDataSource1);
+datasourceMaps.put("primary_ds1_replica1", replica1OfPrimaryDataSource1);
+
+/* Sharding rule configuration */
+// The enumeration value of `ds_$->{0..1}` is the name of the logical data source configured with replica-query
+ShardingTableRuleConfiguration tOrderRuleConfiguration = new ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${[0, 1]}");
+tOrderRuleConfiguration.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_id", "snowflake"));
+
+ShardingTableRuleConfiguration tOrderItemRuleConfiguration = new ShardingTableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item_${[0, 1]}");
+tOrderItemRuleConfiguration.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_item_id", "snowflake"));
+        
+ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
+shardingRuleConfiguration.getTables().add(tOrderRuleConfiguration);
+shardingRuleConfiguration.getTables().add(tOrderItemRuleConfiguration);
+shardingRuleConfiguration.getBindingTableGroups().add("t_order, t_order_item");
+shardingRuleConfiguration.getBroadcastTables().add("t_bank");
+// Default database strategy configuration
+shardingRuleConfiguration.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("user_id", "default_db_strategy_inline"));
+Properties defaultDatabaseStrategyInlineProps = new Properties();
+defaultDatabaseStrategyInlineProps.setProperty("algorithm-expression", "ds_${user_id % 2}");
+shardingRuleConfiguration.getShardingAlgorithms().put("default_db_strategy_inline", new ShardingSphereAlgorithmConfiguration("INLINE", defaultDatabaseStrategyInlineProps));
+
+// Key generate algorithm configuration
+Properties snowflakeProperties = new Properties();
+snowflakeProperties.setProperty("worker-id", "123");
+shardingRuleConfiguration.getKeyGenerators().put("snowflake", new ShardingSphereAlgorithmConfiguration("SNOWFLAKE", snowflakeProperties));
+
+/* Data encrypt rule configuration */
+Properties encryptProperties = new Properties();
+encryptProperties.setProperty("aes-key-value", "123456");
+EncryptColumnRuleConfiguration columnConfigAes = new EncryptColumnRuleConfiguration("user_name", "user_name", "", "user_name_plain", "name_encryptor");
+EncryptColumnRuleConfiguration columnConfigTest = new EncryptColumnRuleConfiguration("pwd", "pwd", "assisted_query_pwd", "", "pwd_encryptor");
+EncryptTableRuleConfiguration encryptTableRuleConfig = new EncryptTableRuleConfiguration("t_user", Arrays.asList(columnConfigAes, columnConfigTest));
+// Data encrypt algorithm configuration
+Map<String, ShardingSphereAlgorithmConfiguration> encryptAlgorithmConfigs = new LinkedHashMap<>(2, 1);
+encryptAlgorithmConfigs.put("name_encryptor", new ShardingSphereAlgorithmConfiguration("AES", encryptProperties));
+encryptAlgorithmConfigs.put("pwd_encryptor", new ShardingSphereAlgorithmConfiguration("assistedTest", encryptProperties));
+EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig), encryptAlgorithmConfigs);
+
+/* Replica query rule configuration */
+ReplicaQueryDataSourceRuleConfiguration dataSourceConfiguration1 = new ReplicaQueryDataSourceRuleConfiguration("ds_0", "primary_ds0", Arrays.asList("primary_ds0_replica0", "primary_ds0_replica1"), null);
+ReplicaQueryDataSourceRuleConfiguration dataSourceConfiguration2 = new ReplicaQueryDataSourceRuleConfiguration("ds_1", "primary_ds0", Arrays.asList("primary_ds1_replica0", "primary_ds1_replica0"), null);

Review comment:
       The `loadBalancerName` is null?




----------------------------------------------------------------
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] tristaZero commented on pull request #9379: Issue#9286

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


   Hi @huanghao495430759 
   
   Kindly ping here. Could you look at these reviews?


----------------------------------------------------------------
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] tristaZero merged pull request #9379: Issue#9286

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


   


----------------------------------------------------------------
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] huanghao495430759 commented on a change in pull request #9379: Issue#9286

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



##########
File path: docs/document/content/user-manual/shardingsphere-jdbc/configuration/java-api/mix.en.md
##########
@@ -3,4 +3,98 @@ title = "Mixed Rules"
 weight = 6
 +++
 
-TODO
+The overlay between rule items in a mixed configuration is associated by the data source name and the table name.
+
+If the previous rule is aggregation-oriented, the next rule needs to use the aggregated logical data source name configured by the previous rule when configuring the data source.
+Similarly, if the previous rule is table aggregation-oriented, the next rule needs to use the aggregated logical table name configured by the previous rule when configuring the table.
+
+## Configuration Item Explanation
+
+```java
+/* Data source configuration */
+HikariDataSource primaryDataSource0 = new HikariDataSource();
+primaryDataSource0.setDriverClassName("com.mysql.jdbc.Driver");
+primaryDataSource0.setJdbcUrl("jdbc:mysql://localhost:3306/db0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8");
+primaryDataSource0.setUsername("root");
+primaryDataSource0.setPassword("");
+
+HikariDataSource primaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica0OfPrimaryDataSource0 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica1OfPrimaryDataSource0 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica0OfPrimaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+HikariDataSource replica1OfPrimaryDataSource1 = new HikariDataSource();
+// ...Omit specific configuration.
+
+Map<String, DataSource> datasourceMaps = new HashMap<>(6);
+
+datasourceMaps.put("primary_ds0", primaryDataSource0);
+datasourceMaps.put("primary_ds0_replica0", replica0OfPrimaryDataSource0);
+datasourceMaps.put("primary_ds0_replica1", replica1OfPrimaryDataSource0);
+
+datasourceMaps.put("primary_ds1", primaryDataSource1);
+datasourceMaps.put("primary_ds1_replica0", replica0OfPrimaryDataSource1);
+datasourceMaps.put("primary_ds1_replica1", replica1OfPrimaryDataSource1);
+
+/* Sharding rule configuration */
+// The enumeration value of `ds_$->{0..1}` is the name of the logical data source configured with replica-query
+ShardingTableRuleConfiguration tOrderRuleConfiguration = new ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${[0, 1]}");
+tOrderRuleConfiguration.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_id", "snowflake"));
+
+ShardingTableRuleConfiguration tOrderItemRuleConfiguration = new ShardingTableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item_${[0, 1]}");
+tOrderItemRuleConfiguration.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_item_id", "snowflake"));
+        
+ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
+shardingRuleConfiguration.getTables().add(tOrderRuleConfiguration);
+shardingRuleConfiguration.getTables().add(tOrderItemRuleConfiguration);
+shardingRuleConfiguration.getBindingTableGroups().add("t_order, t_order_item");
+shardingRuleConfiguration.getBroadcastTables().add("t_bank");
+// Default database strategy configuration
+shardingRuleConfiguration.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("user_id", "default_db_strategy_inline"));
+Properties defaultDatabaseStrategyInlineProps = new Properties();
+defaultDatabaseStrategyInlineProps.setProperty("algorithm-expression", "ds_${user_id % 2}");
+shardingRuleConfiguration.getShardingAlgorithms().put("default_db_strategy_inline", new ShardingSphereAlgorithmConfiguration("INLINE", defaultDatabaseStrategyInlineProps));
+
+// Key generate algorithm configuration
+Properties snowflakeProperties = new Properties();
+snowflakeProperties.setProperty("worker-id", "123");
+shardingRuleConfiguration.getKeyGenerators().put("snowflake", new ShardingSphereAlgorithmConfiguration("SNOWFLAKE", snowflakeProperties));
+
+/* Data encrypt rule configuration */
+Properties encryptProperties = new Properties();
+encryptProperties.setProperty("aes-key-value", "123456");
+EncryptColumnRuleConfiguration columnConfigAes = new EncryptColumnRuleConfiguration("user_name", "user_name", "", "user_name_plain", "name_encryptor");
+EncryptColumnRuleConfiguration columnConfigTest = new EncryptColumnRuleConfiguration("pwd", "pwd", "assisted_query_pwd", "", "pwd_encryptor");
+EncryptTableRuleConfiguration encryptTableRuleConfig = new EncryptTableRuleConfiguration("t_user", Arrays.asList(columnConfigAes, columnConfigTest));
+// Data encrypt algorithm configuration
+Map<String, ShardingSphereAlgorithmConfiguration> encryptAlgorithmConfigs = new LinkedHashMap<>(2, 1);
+encryptAlgorithmConfigs.put("name_encryptor", new ShardingSphereAlgorithmConfiguration("AES", encryptProperties));
+encryptAlgorithmConfigs.put("pwd_encryptor", new ShardingSphereAlgorithmConfiguration("assistedTest", encryptProperties));
+EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig), encryptAlgorithmConfigs);
+
+/* Replica query rule configuration */
+ReplicaQueryDataSourceRuleConfiguration dataSourceConfiguration1 = new ReplicaQueryDataSourceRuleConfiguration("ds_0", "primary_ds0", Arrays.asList("primary_ds0_replica0", "primary_ds0_replica1"), null);
+ReplicaQueryDataSourceRuleConfiguration dataSourceConfiguration2 = new ReplicaQueryDataSourceRuleConfiguration("ds_1", "primary_ds0", Arrays.asList("primary_ds1_replica0", "primary_ds1_replica0"), null);

Review comment:
       Oh ,it's my mistake,i've reviewed 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.

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