You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by so...@apache.org on 2022/07/27 08:02:46 UTC

[shardingsphere] branch master updated: update according to new module (#19599)

This is an automated email from the ASF dual-hosted git repository.

soulasuna pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7686bbe237c update according to new module (#19599)
7686bbe237c is described below

commit 7686bbe237c5f09acdb647982bf7552db4bbc05d
Author: Mike0601 <40...@users.noreply.github.com>
AuthorDate: Wed Jul 27 16:02:39 2022 +0800

    update according to new module (#19599)
    
    * Refactor document
    
    Remove concepts document
    
    * refactor
    
    * update feature sharding
    
    * update according new module
    
    * update according to new module
---
 .../java-api/rules/shadow.cn.md                    | 105 +++++++++++++++++--
 .../java-api/rules/shadow.en.md                    | 116 ++++++++++++++++++---
 2 files changed, 196 insertions(+), 25 deletions(-)

diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.cn.md
index 7c31ef7fad7..8a01535d2d4 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.cn.md
@@ -3,20 +3,25 @@ title = "影子库"
 weight = 6
 +++
 
-## 配置入口
+## 背景信息
+
+如果您只想使用 Java API 方式配置使用 ShardingSphere 影子库功能请参考以下配置。
+
+## 参数解释
+### 配置入口
 
 类名称:org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration
 
 可配置属性:
 
-| *名称*                      | *数据类型*                                           | *说明*               | *默认值* |
-| -------------------------- | --------------------------------------------------- | ------------------- | ------- |
-| dataSources                | Map\<String, ShadowDataSourceConfiguration\>        | 影子数据源映射名称和配置 |        |
-| tables                     | Map\<String, ShadowTableConfiguration\>             | 影子表名称和配置       |        |
-| defaultShadowAlgorithmName | String                                              | 默认影子算法名称       |        |
-| shadowAlgorithms           | Map\<String, ShardingSphereAlgorithmConfiguration\> | 影子算法名称和配置     | 无      |
+| *名称*   | *数据类型*  | *说明*  | *默认值* |
+| -------- | ----------- | ------- | ------- |
+| dataSources  | Map\<String, ShadowDataSourceConfiguration\> | 影子数据源映射名称和配置 | 无  |
+| tables | Map\<String, ShadowTableConfiguration\> | 影子表名称和配置 | 无 |
+| shadowAlgorithms | Map\<String, ShardingSphereAlgorithmConfiguration\> | 影子算法名称和配置 | 无   |
+| defaultShadowAlgorithmName | String | 默认影子算法名称  | 无 |
 
-## 影子数据源配置
+### 影子数据源配置
 
 类名称:org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration
 
@@ -27,7 +32,7 @@ weight = 6
 | sourceDataSourceName | String    | 生产数据源名称 |
 | shadowDataSourceName | String    | 影子数据源名称 |
 
-## 影子表配置
+### 影子表配置
 
 类名称:org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration
 
@@ -38,6 +43,86 @@ weight = 6
 | dataSourceNames      | Collection\<String\> | 影子表关联影子数据源映射名称列表 |
 | shadowAlgorithmNames | Collection\<String\> | 影子表关联影子算法名称列表   |
 
-## 影子算法配置
+### 影子算法配置
+
+类名称:org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration
+
+可配置属性:
+
+| *名称*  | *数据类型* | *说明* |
+| ------- | ---------- | ------- |
+| type | String | 影子算法类型 |
+| props | Properties | 影子算法配置 |
 
 算法类型的详情,请参见[内置影子算法列表](/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/shadow)。
+
+## 操作步骤
+
+1. 创建生产和影子数据源。
+1. 配置影子规则
+- 配置影子数据源
+- 配置影子表
+- 配置影子算法
+
+## 配置示例
+
+```java
+public final class ShadowConfiguration {
+
+    @Override
+    public DataSource getDataSource() throws SQLException {
+        Map<String, DataSource> dataSourceMap = createDataSourceMap();
+        return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, createRuleConfigurations(), createShardingSphereProps());
+    }
+    
+    private Map<String, DataSource> createDataSourceMap() {
+        Map<String, DataSource> result = new LinkedHashMap<>();
+        result.put("ds", DataSourceUtil.createDataSource("demo_ds"));
+        result.put("ds_shadow", DataSourceUtil.createDataSource("shadow_demo_ds"));
+        return result;
+    }
+    
+    private Collection<RuleConfiguration> createRuleConfigurations() {
+        Collection<RuleConfiguration> result = new LinkedList<>();
+        ShadowRuleConfiguration shadowRule = new ShadowRuleConfiguration();
+        shadowRule.setDataSources(createShadowDataSources());
+        shadowRule.setTables(createShadowTables());
+        shadowRule.setShadowAlgorithms(createShadowAlgorithmConfigurations());
+        result.add(shadowRule);
+        return result;
+    }
+    
+    private Map<String, ShadowDataSourceConfiguration> createShadowDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new LinkedHashMap<>();
+        result.put("shadow-data-source", new ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        return result;
+    }
+    
+    private Map<String, ShadowTableConfiguration> createShadowTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        result.put("t_user", new ShadowTableConfiguration(Collections.singletonList("shadow-data-source"), createShadowAlgorithmNames()));
+        return result;
+    }
+    
+    private Collection<String> createShadowAlgorithmNames() {
+        Collection<String> result = new LinkedList<>();
+        result.add("user-id-insert-match-algorithm");
+        result.add("simple-hint-algorithm");
+        return result;
+    }
+    
+    private Map<String, ShardingSphereAlgorithmConfiguration> createShadowAlgorithmConfigurations() {
+        Map<String, ShardingSphereAlgorithmConfiguration> result = new LinkedHashMap<>();
+        Properties userIdInsertProps = new Properties();
+        userIdInsertProps.setProperty("operation", "insert");
+        userIdInsertProps.setProperty("column", "user_type");
+        userIdInsertProps.setProperty("value", "1");
+        result.put("user-id-insert-match-algorithm", new ShardingSphereAlgorithmConfiguration("VALUE_MATCH", userIdInsertProps));
+        return result;
+    }
+}
+```
+
+## 相关参考
+
+[影子库的特性描述](/cn/features/shadow/)
diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.en.md
index c0604f9d222..d5f758319a1 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.en.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/shadow.en.md
@@ -3,20 +3,26 @@ title = "Shadow DB"
 weight = 6
 +++
 
-## Root Configuration
+## Background
+
+In the distributed application architecture based on microservices, businesses require multiple services to be completed through a series of services and middleware, so the stress test of a single service can no longer meet the needs of real scenarios. If we reconstruct a stress test environment similar to the production environment, it is too expensive and often fails to simulate the complexity and traffic of the online environment. For this reason, the industry often chooses the full l [...]
+
+## Parameters
+
+### Root Configuration
 
 Class name: org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration
 
 Attributes:
 
-| *Name*                     | *DataType*                                          | *Description*                                     | *Default Value* |
-| -------------------------- | --------------------------------------------------- | ------------------------------------------------- | --------------- |
-| dataSources                | Map\<String, ShadowDataSourceConfiguration\>        | Shadow data source mapping name and configuration |                 |
-| tables                     | Map\<String, ShadowTableConfiguration\>             | Shadow table name and configuration               |                 |
-| defaultShadowAlgorithmName | String                                              | Default shadow algorithm name                     |                 |
-| shadowAlgorithms           | Map\<String, ShardingSphereAlgorithmConfiguration\> | Shadow algorithm name and configuration           |                 |
+| *Name*   | *Data Type*  | *Description*  | *Default* |
+| -------- | ----------- | ------- | ------- |
+| dataSources  | Map\<String, ShadowDataSourceConfiguration\> | shadow data source mapping name and configuration | no  |
+| tables | Map\<String, ShadowTableConfiguration\> | shadow table name and configuration | no |
+| shadowAlgorithms | Map\<String, ShardingSphereAlgorithmConfiguration\> | shadow algorithm name and configuration | no  |
+| defaultShadowAlgorithmName | String | default shadow algorithm name  | no |
 
-## Shadow Data Source Configuration
+### Shadow Data Source Configuration
 
 Class name: org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration
 
@@ -27,17 +33,97 @@ Attributes:
 | sourceDataSourceName | String     | Production data source name |
 | shadowDataSourceName | String     | Shadow data source name     |
 
-## Shadow Table Configuration
+### Shadow Table Configuration
 
 Class name: org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration
 
 Attributes:
 
-| *Name*               | *DataType*           | *Description*                                  |
-| -------------------- | -------------------- | ---------------------------------------------- |
-| dataSourceNames      | Collection\<String\> | Shadow table location shadow data source mapping names |
-| shadowAlgorithmNames | Collection\<String\> | Shadow table location shadow algorithm names   |
+| *Name*  | *Data Type* | *Description* |
+| ------- | ---------- | ------- |
+| dataSourceNames | Collection\<String\> | shadow table associates shadow data source mapping name list |
+| shadowAlgorithmNames | Collection\<String\> | shadow table associates shadow algorithm name list |
+
+### Shadow Algorithm Configuration
+
+Class name:org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration
+
+Attributes:
+
+| *Name*  | *Data Type* | *Description* |
+| ------- | ---------- | ------- |
+| type | String | shadow algorithm type |
+| props | Properties | shadow algorithm configuration |
+
+Please refer to [Built-in Shadow Algorithm List](/en/user-manual/shardingsphere-jdbc/builtin-algorithm/shadow).
+
+## Procedure
+
+1. Create production and shadow data source.
+1. Configure shadow rule.
+- Configure shadow data source
+- Configure shadow table
+- Configure shadow algorithm
+
+## Sample
+
+```java
+public final class ShadowConfiguration {
+
+    @Override
+    public DataSource getDataSource() throws SQLException {
+        Map<String, DataSource> dataSourceMap = createDataSourceMap();
+        return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, createRuleConfigurations(), createShardingSphereProps());
+    }
+    
+    private Map<String, DataSource> createDataSourceMap() {
+        Map<String, DataSource> result = new LinkedHashMap<>();
+        result.put("ds", DataSourceUtil.createDataSource("demo_ds"));
+        result.put("ds_shadow", DataSourceUtil.createDataSource("shadow_demo_ds"));
+        return result;
+    }
+    
+    private Collection<RuleConfiguration> createRuleConfigurations() {
+        Collection<RuleConfiguration> result = new LinkedList<>();
+        ShadowRuleConfiguration shadowRule = new ShadowRuleConfiguration();
+        shadowRule.setDataSources(createShadowDataSources());
+        shadowRule.setTables(createShadowTables());
+        shadowRule.setShadowAlgorithms(createShadowAlgorithmConfigurations());
+        result.add(shadowRule);
+        return result;
+    }
+    
+    private Map<String, ShadowDataSourceConfiguration> createShadowDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new LinkedHashMap<>();
+        result.put("shadow-data-source", new ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        return result;
+    }
+    
+    private Map<String, ShadowTableConfiguration> createShadowTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        result.put("t_user", new ShadowTableConfiguration(Collections.singletonList("shadow-data-source"), createShadowAlgorithmNames()));
+        return result;
+    }
+    
+    private Collection<String> createShadowAlgorithmNames() {
+        Collection<String> result = new LinkedList<>();
+        result.add("user-id-insert-match-algorithm");
+        result.add("simple-hint-algorithm");
+        return result;
+    }
+    
+    private Map<String, ShardingSphereAlgorithmConfiguration> createShadowAlgorithmConfigurations() {
+        Map<String, ShardingSphereAlgorithmConfiguration> result = new LinkedHashMap<>();
+        Properties userIdInsertProps = new Properties();
+        userIdInsertProps.setProperty("operation", "insert");
+        userIdInsertProps.setProperty("column", "user_type");
+        userIdInsertProps.setProperty("value", "1");
+        result.put("user-id-insert-match-algorithm", new ShardingSphereAlgorithmConfiguration("VALUE_MATCH", userIdInsertProps));
+        return result;
+    }
+}
+```
 
-## Shadow Algorithm Configuration
+## Related References
 
-Please refer to [Built-in Shadow Algorithm List](/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/shadow).
+[Features Description of Shadow DB](/en/features/shadow/)