Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
87edc98e
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
87edc98e
编写于
4月 26, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update sharding-jdbc/configuration/spring-namespace for cn
上级
bb0ac649
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
322 addition
and
414 deletion
+322
-414
document/cn/content/06-sharding-jdbc/configuration/config-java.md
.../cn/content/06-sharding-jdbc/configuration/config-java.md
+12
-12
document/cn/content/06-sharding-jdbc/configuration/config-spring-boot.md
...tent/06-sharding-jdbc/configuration/config-spring-boot.md
+3
-3
document/cn/content/06-sharding-jdbc/configuration/config-spring-namespace.md
...06-sharding-jdbc/configuration/config-spring-namespace.md
+305
-397
document/cn/content/06-sharding-jdbc/configuration/config-yaml.md
.../cn/content/06-sharding-jdbc/configuration/config-yaml.md
+2
-2
未找到文件。
document/cn/content/06-sharding-jdbc/configuration/config-java.md
浏览文件 @
87edc98e
...
@@ -169,8 +169,8 @@ weight = 1
...
@@ -169,8 +169,8 @@ weight = 1
| ------------------ | ------------------------ | -------------- |
| ------------------ | ------------------------ | -------------- |
| dataSourceMap | Map
\<
String, DataSource
\>
| 数据源配置 |
| dataSourceMap | Map
\<
String, DataSource
\>
| 数据源配置 |
| shardingRuleConfig | ShardingRuleConfiguration | 数据分片配置规则 |
| shardingRuleConfig | ShardingRuleConfiguration | 数据分片配置规则 |
|
configMap (?) | Map
\<
String, Object
\>
| 配置映射关系
|
|
props (?) | Properties | 属性配置
|
|
props (?) | Properties | 相关属性配置
|
|
configMap (?) | Map
\<
String, Object
\>
| 用户自定义配置
|
#### ShardingRuleConfiguration
#### ShardingRuleConfiguration
...
@@ -184,21 +184,21 @@ weight = 1
...
@@ -184,21 +184,21 @@ weight = 1
| defaultDatabaseShardingStrategyConfig (?) | ShardingStrategyConfiguration | 默认分库策略 |
| defaultDatabaseShardingStrategyConfig (?) | ShardingStrategyConfiguration | 默认分库策略 |
| defaultTableShardingStrategyConfig (?) | ShardingStrategyConfiguration | 默认分表策略 |
| defaultTableShardingStrategyConfig (?) | ShardingStrategyConfiguration | 默认分表策略 |
| defaultKeyGenerator (?) | KeyGenerator | 默认自增列值生成器,缺省使用io.shardingjdbc.core.keygen.DefaultKeyGenerator |
| defaultKeyGenerator (?) | KeyGenerator | 默认自增列值生成器,缺省使用io.shardingjdbc.core.keygen.DefaultKeyGenerator |
| masterSlaveRuleConfigs (?) | Collection
\<
MasterSlaveRuleConfiguration
\>
| 读写分离规则,
不填写表示不使用读写分离
|
| masterSlaveRuleConfigs (?) | Collection
\<
MasterSlaveRuleConfiguration
\>
| 读写分离规则,
缺省表示不使用读写分离
|
#### TableRuleConfiguration
#### TableRuleConfiguration
表分片规则配置对象。
表分片规则配置对象。
|
*名称*
|
*数据类型*
|
*说明*
|
|
*名称*
|
*数据类型*
|
*说明*
|
| ---------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------- |
| ---------------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
|
| logicTable | String | 逻辑表名称 |
| logicTable | String | 逻辑表名称
|
| actualDataNodes (?) | String | 由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况 |
| actualDataNodes (?) | String | 由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况 |
| databaseShardingStrategyConfig (?) | ShardingStrategyConfiguration | 分库策略,
不填写表示使用默认分库策略
|
| databaseShardingStrategyConfig (?) | ShardingStrategyConfiguration | 分库策略,
缺省表示使用默认分库策略
|
| tableShardingStrategyConfig (?) | ShardingStrategyConfiguration | 分表策略,
不填写表示使用默认分表策略
|
| tableShardingStrategyConfig (?) | ShardingStrategyConfiguration | 分表策略,
缺省表示使用默认分表策略
|
| logicIndex (?) | String | 逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表 |
| logicIndex (?) | String | 逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表
|
| keyGeneratorColumnName (?) | String | 自增列名称,
不填写表示不使用自增主键生成器
|
| keyGeneratorColumnName (?) | String | 自增列名称,
缺省表示不使用自增主键生成器
|
| keyGenerator (?) | KeyGenerator | 自增列值生成器,
如果填写了keyGeneratorColumnName,不填写keyGenerator,表示使用默认自增主键生成器
|
| keyGenerator (?) | KeyGenerator | 自增列值生成器,
缺省表示使用默认自增主键生成器
|
#### StandardShardingStrategyConfiguration
#### StandardShardingStrategyConfiguration
...
@@ -263,7 +263,7 @@ ShardingStrategyConfiguration的实现类,用于配置不分片的策略。
...
@@ -263,7 +263,7 @@ ShardingStrategyConfiguration的实现类,用于配置不分片的策略。
| --------------------- | ---------------------------- | ------------------ |
| --------------------- | ---------------------------- | ------------------ |
| dataSourceMap | Map
\<
String, DataSource
\>
| 数据源与其名称的映射 |
| dataSourceMap | Map
\<
String, DataSource
\>
| 数据源与其名称的映射 |
| masterSlaveRuleConfig | MasterSlaveRuleConfiguration | 读写分离规则 |
| masterSlaveRuleConfig | MasterSlaveRuleConfiguration | 读写分离规则 |
| configMap (?) | Map
\<
String, Object
\>
|
配置映射关系
|
| configMap (?) | Map
\<
String, Object
\>
|
用户自定义配置
|
#### MasterSlaveRuleConfiguration
#### MasterSlaveRuleConfiguration
...
...
document/cn/content/06-sharding-jdbc/configuration/config-spring-boot.md
浏览文件 @
87edc98e
...
@@ -221,7 +221,7 @@ sharding.jdbc.datasource.<data_source_name>.xxx= #数据库连接池的其它属
...
@@ -221,7 +221,7 @@ sharding.jdbc.datasource.<data_source_name>.xxx= #数据库连接池的其它属
sharding.jdbc.config.sharding.tables.<logic_table_name>
.actual-data-nodes
=
#由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况
sharding.jdbc.config.sharding.tables.<logic_table_name>
.actual-data-nodes
=
#由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况
#分库策略,
不填写
表示使用默认分库策略,以下的分片策略只能选其一
#分库策略,
缺省
表示使用默认分库策略,以下的分片策略只能选其一
#用于单分片键的标准分片场景
#用于单分片键的标准分片场景
sharding.jdbc.config.sharding.tables.<logic_table_name>
.database-strategy.standard.sharding-column
=
#分片列名称
sharding.jdbc.config.sharding.tables.<logic_table_name>
.database-strategy.standard.sharding-column
=
#分片列名称
...
@@ -242,8 +242,8 @@ sharding.jdbc.config.sharding.tables.<logic_table_name>.database-strategy.hint.a
...
@@ -242,8 +242,8 @@ sharding.jdbc.config.sharding.tables.<logic_table_name>.database-strategy.hint.a
#分表策略,同分库策略
#分表策略,同分库策略
sharding.jdbc.config.sharding.tables.<logic_table_name>
.table-strategy.xxx
=
#省略
sharding.jdbc.config.sharding.tables.<logic_table_name>
.table-strategy.xxx
=
#省略
sharding.jdbc.config.sharding.tables.<logic_table_name>
.key-generator-column-name
=
#自增列名称,
不填写
表示不使用自增主键生成器
sharding.jdbc.config.sharding.tables.<logic_table_name>
.key-generator-column-name
=
#自增列名称,
缺省
表示不使用自增主键生成器
sharding.jdbc.config.sharding.tables.<logic_table_name>.key-generator-class= #自增列值生成器类名称。该类需提供无参数的构造器
sharding.jdbc.config.sharding.tables.<logic_table_name>.key-generator-class= #自增列值生成器类名称
,缺省表示使用默认自增列值生成器
。该类需提供无参数的构造器
sharding.jdbc.config.sharding.tables.<logic_table_name>
.logic-index
=
#逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表
sharding.jdbc.config.sharding.tables.<logic_table_name>
.logic-index
=
#逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表
...
...
document/cn/content/06-sharding-jdbc/configuration/config-spring-namespace.md
浏览文件 @
87edc98e
...
@@ -4,21 +4,13 @@ title = "Spring命名空间配置"
...
@@ -4,21 +4,13 @@ title = "Spring命名空间配置"
weight = 4
weight = 4
+++
+++
##
Spring命名空间配置
##
注意事项
### 引入maven依赖
行表达式标识符可以使用
`$->{...}`
或
`$->{...}`
,但前者与Spring本身的属性文件占位符冲突,因此在Spring环境中使用行表达式标识符建议使用
`$->{...}`
。
```
xml
## 配置示例
<dependency>
<groupId>
io.shardingjdbc
</groupId>
<artifactId>
sharding-jdbc-core-spring-namespace
</artifactId>
<version>
${latest.release.version}
</version>
</dependency>
```
### 配置示例
###
#
数据分片
### 数据分片
```
xml
```
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
...
@@ -37,7 +29,7 @@ weight = 4
...
@@ -37,7 +29,7 @@ weight = 4
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<context:annotation-config
/>
<context:annotation-config
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
...
@@ -54,20 +46,20 @@ weight = 4
...
@@ -54,20 +46,20 @@ weight = 4
</property>
</property>
</bean>
</bean>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<tx:annotation-driven/>
<tx:annotation-driven
/>
<bean
id=
"d
emo_d
s_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_0"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_1"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"preciseModuloDatabaseShardingAlgorithm"
class=
"io.shardingjdbc.example.spring.namespace.jpa.algorithm.PreciseModuloDatabaseShardingAlgorithm"
/>
<bean
id=
"preciseModuloDatabaseShardingAlgorithm"
class=
"io.shardingjdbc.example.spring.namespace.jpa.algorithm.PreciseModuloDatabaseShardingAlgorithm"
/>
...
@@ -77,171 +69,17 @@ weight = 4
...
@@ -77,171 +69,17 @@ weight = 4
<sharding:standard-strategy
id=
"tableShardingStrategy"
sharding-column=
"order_id"
precise-algorithm-ref=
"preciseModuloTableShardingAlgorithm"
/>
<sharding:standard-strategy
id=
"tableShardingStrategy"
sharding-column=
"order_id"
precise-algorithm-ref=
"preciseModuloTableShardingAlgorithm"
/>
<sharding:data-source
id=
"shardingDataSource"
>
<sharding:data-source
id=
"shardingDataSource"
>
<sharding:sharding-rule
data-source-names=
"d
emo_ds_0, demo_
ds_1"
>
<sharding:sharding-rule
data-source-names=
"d
s_0,
ds_1"
>
<sharding:table-rules>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"d
emo_ds_${0..1}.t_order_$
{0..1}"
database-strategy-ref=
"databaseShardingStrategy"
table-strategy-ref=
"tableShardingStrategy"
generate-key-column-name=
"order_id"
/>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"d
s_$->{0..1}.t_order_$->
{0..1}"
database-strategy-ref=
"databaseShardingStrategy"
table-strategy-ref=
"tableShardingStrategy"
generate-key-column-name=
"order_id"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"d
emo_ds_${0..1}.t_order_item_$
{0..1}"
database-strategy-ref=
"databaseShardingStrategy"
table-strategy-ref=
"tableShardingStrategy"
generate-key-column-name=
"order_item_id"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"d
s_$->{0..1}.t_order_item_$->
{0..1}"
database-strategy-ref=
"databaseShardingStrategy"
table-strategy-ref=
"tableShardingStrategy"
generate-key-column-name=
"order_item_id"
/>
</sharding:table-rules>
</sharding:table-rules>
</sharding:sharding-rule>
</sharding:sharding-rule>
</sharding:data-source>
</sharding:data-source>
</beans>
</beans>
```
```
##### 标签说明
##### 分库分表
##### \<sharding:data-source/\>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | --------- | ------ | -------------- |
| id | 属性 | String | 是 | Spring Bean ID |
| sharding-rule | 标签 | - | 是 | 分片规则 |
| config-map? | 标签 | - | 否 | 配置映射关系|
| props? | 标签 | - | 否 | 相关属性配置 |
##### \<sharding:sharding-rule/>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | --------------------------------------------------------------------- |
| data-source-names | 属性 | String | 是 | 数据源Bean列表,需要配置所有需要被Sharding-JDBC管理的数据源BEAN ID(包括默认数据源),多个Bean以逗号分隔 |
| default-data-source-name? | 属性 | String | 否 | 默认数据源名称,未配置分片规则的表将通过默认数据源定位 |
| default-database-strategy-ref? | 属性 | String | 否 | 默认分库策略,对应
\<
sharding:xxx-strategy>中的策略id,不填则使用不分库的策略 |
| default-table-strategy-ref? | 属性 | String | 否 | 默认分表策略,对应
\<
sharding:xxx-strategy>中的策略id,不填则使用不分表的策略 |
| default-key-generator? | 属性 | String | 否 |默认自增列生成策略 |
| table-rules | 标签 | - | 是 | 分片规则列表 |
| binding-table-rules? | 标签 | - | 否| 绑定表规则|
##### \<sharding:table-rules/>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ----------- | ---------- | ------ | ------- |
| table-rule+ | 标签 | - | 是 | 分片规则 |
##### \<sharding:table-rule/>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| -------------------- | ------------ | ---------- | ------ | ------- |
| logic-table | 属性 | String | 是 | 逻辑表名 |
| actual-data-nodes? | 属性 | String | 否 | 真实数据节点,由数据源名(读写分离引用
<master-slave:data-source>
中的id属性) + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。不填写表示将为现有已知的数据源 + 逻辑表名称生成真实数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况。|
| database-strategy-ref? | 属性 | String | 否 | 分库策略,对应
\<
sharding:xxx-strategy>中的策略id,不填则使用
\<
sharding:sharding-rule/>配置的default-database-strategy-ref |
| table-strategy-ref? | 属性 | String | 否 | 分表策略,对应
\<
sharding:xxx-strategy>中的略id,不填则使用
\<
sharding:sharding-rule/>配置的default-table-strategy-ref |
| logic-index? | 属性 | String | 否 | 逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表 |
| generate-key-column-name? | 属性| String | 否 | 自增列名|
| key-generator? | 属性 | String | 否| 自增列生成策略|
##### \<sharding:binding-table-rules/>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ----------- | --------- | ------ | ------- |
| binding-table-rule+ | 标签 | - | 是 | 绑定规则 |
##### \<sharding:binding-table-rule/>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | ------------------------ |
| logic-tables | 属性 | String | 是 | 逻辑表名,多个表名以逗号分隔 |
##### \<sharding:standard-strategy/>
标准分片策略,用于单分片键的场景
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | --------------------------------- |
| id | 属性 | String | 是 | Spring Bean ID |
| sharding-column | 属性 | String | 是 | 分片列名 |
| precise-algorithm-ref | 属性 | String | 是 | 精确的分片算法Bean引用,用于=和IN。 |
| range-algorithm-ref? | 属性 | String | 否 | 范围的分片算法Bean引用,用于BETWEEN。 |
##### \<sharding:complex-strategy/>
复合分片策略,用于多分片键的场景
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | ---------------------- |
| id | 属性 | String | 是 | Spring Bean ID |
| sharding-columns | 属性 | String | 是 | 分片列名,多个列以逗号分隔 |
| algorithm-ref | 属性 | String | 是 | 分片算法Bean引用 |
##### \<sharding:inline-strategy/>
inline表达式分片策略
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | ------------ |
| id | 属性 | String | 是 | Spring Bean ID |
| sharding-column | 属性 | String | 是 | 分片列名 |
| algorithm-expression | 属性 | String | 是 | 分片算法表达式 |
##### \<sharding:hint-database-strategy/>
Hint方式分片策略
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | -------------- |
| id | 属性 | String | 是 | Spring Bean ID |
| algorithm-ref | 属性 | String | 是 | 分片算法Bean引用 |
##### \<sharding:none-strategy/>
不分片的策略
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | ---------- | ------ | --------------------------------------------------- |
| id | 属性 | String | 是 | Spring Bean ID |
##### \<sharding:props/\>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ------------------------------------ | ------------ | ---------- | ----- | ----------------------------------- |
| sql.show | 属性 | boolean | 是 | 是否开启SQL显示,默认为false不开启 |
| executor.size? | 属性 | int | 否 | 最大工作线程数量 |
##### \<sharding:config-map/\>
##### 读写分离
##### \<master-slave:data-source/\>
|
*名称*
|
*类型*
|
*数据类型*
|
*必填*
|
*说明*
|
| ----------------------------- | ------------ | --------- | ------ | ---------------------------------------- |
| id | 属性 | String | 是 | Spring Bean ID |
| master-data-source-name | 属性 | String | 是 | 主库数据源Bean ID |
| slave-data-source-names | 属性 | String | 是 | 从库数据源Bean列表,多个Bean以逗号分隔 |
| strategy-ref? | 属性 | String | 否 | 主从库复杂策略Bean ID,可以使用自定义复杂策略 |
| strategy-type? | 属性 | String | 否 | 主从库复杂策略类型
<br
/>
可选值:ROUND_ROBIN, RANDOM
<br
/>
默认值:ROUND_ROBIN |
| config-map? | 标签 | - | 否 | 配置映射关系|
##### \<sharding:config-map/\>
##### Spring格式特别说明
如需使用inline表达式,需配置ignore-unresolvable为true,否则placeholder会把inline表达式当成属性key值导致出错.
##### 分片算法表达式语法说明
##### inline表达式特别说明
${begin..end} 表示范围区间
${[unit1, unit2, unitX]} 表示枚举值
inline表达式中连续多个${...}表达式,整个inline最终的结果将会根据每个子表达式的结果进行笛卡尔组合,例如正式表inline表达式如下:
```
groovy
dbtbl_$
{[
'online'
,
'offline'
]}
_$
{
1
..
3
}
```
最终会解析为dbtbl_online_1,dbtbl_online_2,dbtbl_online_3,dbtbl_offline_1,dbtbl_offline_2和dbtbl_offline_3这6张表。
##### 字符串内嵌groovy代码
表达式本质上是一段字符串,字符串中使用${}来嵌入groovy代码。
```
groovy
data_source_$
{
id
%
2
+
1
}
```
上面的表达式中data_source_是字符串前缀,id % 2 + 1是groovy代码。
###
#
读写分离
### 读写分离
```
xml
```
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
...
@@ -260,7 +98,7 @@ data_source_${id % 2 + 1}
...
@@ -260,7 +98,7 @@ data_source_${id % 2 + 1}
http://shardingjdbc.io/schema/shardingjdbc/masterslave
http://shardingjdbc.io/schema/shardingjdbc/masterslave
http://shardingjdbc.io/schema/shardingjdbc/masterslave/master-slave.xsd"
>
http://shardingjdbc.io/schema/shardingjdbc/masterslave/master-slave.xsd"
>
<context:annotation-config
/>
<context:annotation-config
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property
name=
"dataSource"
ref=
"masterSlaveDataSource"
/>
<property
name=
"dataSource"
ref=
"masterSlaveDataSource"
/>
...
@@ -277,44 +115,36 @@ data_source_${id % 2 + 1}
...
@@ -277,44 +115,36 @@ data_source_${id % 2 + 1}
</property>
</property>
</bean>
</bean>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<tx:annotation-driven/>
<tx:annotation-driven
/>
<bean
id=
"d
emo_d
s_master"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_slave_0"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_slave_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_slave_1"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_slave_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"randomStrategy"
class=
"io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm"
/>
<bean
id=
"randomStrategy"
class=
"io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm"
/>
<master-slave:data-source
id=
"masterSlaveDataSource"
master-data-source-name=
"d
emo_ds_master"
slave-data-source-names=
"demo_ds_slave_0, demo_
ds_slave_1"
strategy-ref=
"randomStrategy"
/>
<master-slave:data-source
id=
"masterSlaveDataSource"
master-data-source-name=
"d
s_master"
slave-data-source-names=
"ds_slave_0,
ds_slave_1"
strategy-ref=
"randomStrategy"
/>
</beans>
</beans>
```
```
##### 使用Hint强制路由主库示例
### 数据分片 + 读写分离
```
java
HintManager
hintManager
=
HintManager
.
getInstance
();
hintManager
.
setMasterRouteOnly
();
// 继续JDBC操作
```
#### 分库分表 + 读写分离
```
xml
```
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
...
@@ -336,7 +166,7 @@ hintManager.setMasterRouteOnly();
...
@@ -336,7 +166,7 @@ hintManager.setMasterRouteOnly();
http://shardingjdbc.io/schema/shardingjdbc/masterslave
http://shardingjdbc.io/schema/shardingjdbc/masterslave
http://shardingjdbc.io/schema/shardingjdbc/masterslave/master-slave.xsd"
>
http://shardingjdbc.io/schema/shardingjdbc/masterslave/master-slave.xsd"
>
<context:annotation-config
/>
<context:annotation-config
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<context:component-scan
base-package=
"io.shardingjdbc.example.spring.namespace.jpa"
/>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<bean
id=
"entityManagerFactory"
class=
"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
<property
name=
"dataSource"
ref=
"shardingDataSource"
/>
...
@@ -353,243 +183,321 @@ hintManager.setMasterRouteOnly();
...
@@ -353,243 +183,321 @@ hintManager.setMasterRouteOnly();
</property>
</property>
</bean>
</bean>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<bean
id=
"transactionManager"
class=
"org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref=
"entityManagerFactory"
/>
<tx:annotation-driven/>
<tx:annotation-driven
/>
<bean
id=
"d
emo_d
s_master_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_0"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_master_0_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_0_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_0_slave_0"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_0_slave_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_master_0_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_0_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_0_slave_1"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_0_slave_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_master_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_1"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_master_1_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_1_slave_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_1_slave_0"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_1_slave_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"d
emo_d
s_master_1_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<bean
id=
"ds_master_1_slave_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
emo_ds_master_1_slave_1"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/d
s_master_1_slave_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
<property
name=
"password"
value=
""
/>
</bean>
</bean>
<bean
id=
"randomStrategy"
class=
"io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm"
/>
<bean
id=
"randomStrategy"
class=
"io.shardingjdbc.core.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm"
/>
<master-slave:data-source
id=
"d
emo_ds_ms_0"
master-data-source-name=
"demo_ds_master_0"
slave-data-source-names=
"demo_ds_master_0_slave_0, demo_
ds_master_0_slave_1"
strategy-ref=
"randomStrategy"
/>
<master-slave:data-source
id=
"d
s_ms_0"
master-data-source-name=
"ds_master_0"
slave-data-source-names=
"ds_master_0_slave_0,
ds_master_0_slave_1"
strategy-ref=
"randomStrategy"
/>
<master-slave:data-source
id=
"d
emo_ds_ms_1"
master-data-source-name=
"demo_ds_master_1"
slave-data-source-names=
"demo_ds_master_1_slave_0, demo_
ds_master_1_slave_1"
strategy-ref=
"randomStrategy"
/>
<master-slave:data-source
id=
"d
s_ms_1"
master-data-source-name=
"ds_master_1"
slave-data-source-names=
"ds_master_1_slave_0,
ds_master_1_slave_1"
strategy-ref=
"randomStrategy"
/>
<sharding:inline-strategy
id=
"databaseStrategy"
sharding-column=
"user_id"
algorithm-expression=
"d
emo_ds_ms_$
{user_id % 2}"
/>
<sharding:inline-strategy
id=
"databaseStrategy"
sharding-column=
"user_id"
algorithm-expression=
"d
s_ms_$->
{user_id % 2}"
/>
<sharding:inline-strategy
id=
"orderTableStrategy"
sharding-column=
"order_id"
algorithm-expression=
"t_order_${order_id % 2}"
/>
<sharding:inline-strategy
id=
"orderTableStrategy"
sharding-column=
"order_id"
algorithm-expression=
"t_order_$
->
{order_id % 2}"
/>
<sharding:inline-strategy
id=
"orderItemTableStrategy"
sharding-column=
"order_id"
algorithm-expression=
"t_order_item_${order_id % 2}"
/>
<sharding:inline-strategy
id=
"orderItemTableStrategy"
sharding-column=
"order_id"
algorithm-expression=
"t_order_item_$
->
{order_id % 2}"
/>
<sharding:data-source
id=
"shardingDataSource"
>
<sharding:data-source
id=
"shardingDataSource"
>
<sharding:sharding-rule
data-source-names=
"d
emo_ds_ms_0,demo_
ds_ms_1"
>
<sharding:sharding-rule
data-source-names=
"d
s_ms_0,
ds_ms_1"
>
<sharding:table-rules>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"d
emo_ds_ms_${0..1}.t_order_$
{0..1}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"orderTableStrategy"
generate-key-column-name=
"order_id"
/>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"d
s_ms_$->{0..1}.t_order_$->
{0..1}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"orderTableStrategy"
generate-key-column-name=
"order_id"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"d
emo_ds_ms_${0..1}.t_order_item_$
{0..1}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"orderItemTableStrategy"
generate-key-column-name=
"order_item_id"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"d
s_ms_$->{0..1}.t_order_item_$->
{0..1}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"orderItemTableStrategy"
generate-key-column-name=
"order_item_id"
/>
</sharding:table-rules>
</sharding:table-rules>
</sharding:sharding-rule>
</sharding:sharding-rule>
</sharding:data-source>
</sharding:data-source>
</beans>
</beans>
```
```
###
# 编排
治理
###
使用Zookeeper的数据
治理
##### Zookeeper配置示例
```
xml
```
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:sharding=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding"
xmlns:sharding=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding"
xmlns:master-slave=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave"
xmlns:reg=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg"
xmlns:reg=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg
http://www.springframework.org/schema/context/spring-context.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg
http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave/master-slave.xsd"
>
"
>
<context:property-placeholder
location=
"classpath:conf/rdb/conf.properties"
ignore-unresolvable=
"true"
/>
<bean
id=
"dbtbl_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/dbtbl_0"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
</bean>
<bean
id=
"dbtbl_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/dbtbl_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
</bean>
<bean
id=
"preciseModuloDatabaseShardingAlgorithm"
class=
"io.shardingjdbc.spring.algorithm.PreciseModuloDatabaseShardingAlgorithm"
/>
<bean
id=
"preciseModuloTableShardingAlgorithm"
class=
"io.shardingjdbc.spring.algorithm.PreciseModuloTableShardingAlgorithm"
/>
<sharding:standard-strategy
id=
"databaseStrategy"
sharding-column=
"user_id"
precise-algorithm-ref=
"preciseModuloDatabaseShardingAlgorithm"
/>
<sharding:standard-strategy
id=
"tableStrategy"
sharding-column=
"order_id"
precise-algorithm-ref=
"preciseModuloTableShardingAlgorithm"
/>
<sharding:data-source
id=
"shardingDataSource"
registry-center-ref=
"regCenter"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
default-data-source-name=
"dbtbl_0"
>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"dbtbl_${0..1}.t_order_${0..3}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"tableStrategy"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"dbtbl_${0..1}.t_order_item_${0..3}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"tableStrategy"
/>
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule
logic-tables=
"t_order, t_order_item"
/>
</sharding:binding-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop
key=
"sql.show"
>
true
</prop>
</sharding:props>
</sharding:data-source>
<reg:zookeeper
id=
"regCenter"
server-lists=
"localhost:2181"
namespace=
"orchestration-spring-namespace"
base-sleep-time-milliseconds=
"1000"
max-sleep-time-milliseconds=
"3000"
max-retries=
"3"
/>
<reg:zookeeper
id=
"regCenter"
server-lists=
"localhost:2181"
namespace=
"orchestration-spring-namespace-demo"
overwtite=
"false"
/>
<sharding:data-source
id=
"shardingMasterSlaveDataSource"
registry-center-ref=
"regCenter"
/>
<master-slave:data-source
id=
"masterSlaveDataSource"
registry-center-ref=
"regCenter"
/>
</beans>
</beans>
```
```
###
## Zookeeper标签说明
###
使用Etcd的数据治理
##### \<reg:zookeeper/>
| 属性名 | 类型 | 是否必填 | 缺省值 | 描述 |
| ------------------------------- |:-------|:-------|:------|:---------------------------------------------------------------------------------------------------|
| id | String | 是 | | 注册中心在Spring容器中的主键 |
| server-lists | String | 是 | | 连接Zookeeper服务器的列表
<br
/>
包括IP地址和端口号
<br
/>
多个地址用逗号分隔
<br
/>
如: host1:2181,host2:2181 |
| namespace | String | 是 | | Zookeeper的命名空间 |
| base-sleep-time-milliseconds | int | 否 | 1000 | 等待重试的间隔时间的初始值
<br
/>
单位:毫秒 |
| max-sleep-time-milliseconds | int | 否 | 3000 | 等待重试的间隔时间的最大值
<br
/>
单位:毫秒 |
| max-retries | int | 否 | 3 | 最大重试次数 |
| session-timeout-milliseconds | int | 否 | 60000 | 会话超时时间
<br
/>
单位:毫秒 |
| connection-timeout-milliseconds | int | 否 | 15000 | 连接超时时间
<br
/>
单位:毫秒 |
| digest | String | 否 | | 连接Zookeeper的权限令牌
<br
/>
缺省为不需要权限验证 |
##### Etcd配置示例
```
xml
```
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:sharding=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding"
xmlns:sharding=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding"
xmlns:master-slave=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave"
xmlns:reg=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg"
xmlns:reg=
"http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg
http://www.springframework.org/schema/context/spring-context.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg
http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave
http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave/master-slave.xsd"
>
"
>
<context:property-placeholder
location=
"classpath:conf/rdb/conf.properties"
ignore-unresolvable=
"true"
/>
<bean
id=
"dbtbl_0"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<reg:etcd
id=
"regCenter"
server-lists=
"http://localhost:2379"
/>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<sharding:data-source
id=
"shardingMasterSlaveDataSource"
registry-center-ref=
"regCenter"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/dbtbl_0"
/>
<master-slave:data-source
id=
"masterSlaveDataSource"
registry-center-ref=
"regCenter"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
</bean>
<bean
id=
"dbtbl_1"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://localhost:3306/dbtbl_1"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
""
/>
</bean>
<bean
id=
"preciseModuloDatabaseShardingAlgorithm"
class=
"io.shardingjdbc.spring.algorithm.PreciseModuloDatabaseShardingAlgorithm"
/>
<bean
id=
"preciseModuloTableShardingAlgorithm"
class=
"io.shardingjdbc.spring.algorithm.PreciseModuloTableShardingAlgorithm"
/>
<sharding:standard-strategy
id=
"databaseStrategy"
sharding-column=
"user_id"
precise-algorithm-ref=
"preciseModuloDatabaseShardingAlgorithm"
/>
<sharding:standard-strategy
id=
"tableStrategy"
sharding-column=
"order_id"
precise-algorithm-ref=
"preciseModuloTableShardingAlgorithm"
/>
<sharding:data-source
id=
"shardingDataSource"
registry-center-ref=
"regCenter"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
default-data-source-name=
"dbtbl_0"
>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
actual-data-nodes=
"dbtbl_${0..1}.t_order_${0..3}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"tableStrategy"
/>
<sharding:table-rule
logic-table=
"t_order_item"
actual-data-nodes=
"dbtbl_${0..1}.t_order_item_${0..3}"
database-strategy-ref=
"databaseStrategy"
table-strategy-ref=
"tableStrategy"
/>
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule
logic-tables=
"t_order, t_order_item"
/>
</sharding:binding-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop
key=
"sql.show"
>
true
</prop>
</sharding:props>
</sharding:data-source>
<reg:etcd
id=
"regCenter"
server-lists=
"http://localhost:2379"
time-to-live-seconds=
"60"
timeout-milliseconds=
"500"
max-retries=
"3"
retry-interval-milliseconds=
"200"
/>
</beans>
</beans>
```
```
##### Etcd标签说明
## 配置项说明
### 分库分表
##### \<reg:etcd/>
命名空间:http://shardingjdbc.io/schema/shardingjdbc/sharding/sharding.xsd
| 属性名 | 类型 | 是否必填 | 缺省值 | 描述 |
#### \<sharding:data-source />
| ------------------------------- |:-------|:-------|:------|:---------------------------------------------------------------------------------------------------|
| id | String | 是 | | 注册中心在Spring容器中的主键 |
| server-lists | String | 是 | | 连接Etcd服务器的列表
<br
/>
包括IP地址和端口号
<br
/>
多个地址用逗号分隔
<br
/>
如: http://host1:2379,http://host2:2379 |
| time-to-live-seconds | int | 否 | 60 | 临时节点存活时间
<br
/>
单位:秒 |
| timeout-milliseconds | int | 否 | 500 | 每次请求的超时时间
<br
/>
单位:毫秒 |
| max-retries | int | 否 | 3 | 每次请求的最大重试次数 |
| retry-interval-milliseconds | int | 否 | 200 | 重试间隔时间
<br
/>
单位:毫秒 |
|
*名称*
|
*类型*
|
*说明*
|
| -------------- | ----- | -------------- |
| id | 属性 | Spring Bean Id |
| sharding-rule | 标签 | 数据分片配置规则 |
| props (?) | 标签 | 属性配置 |
| config-map (?) | 标签 | 用户自定义配置 |
####
柔性事务
####
\<sharding:sharding-rule />
##### 事务管理器配置项
|
*名称*
|
*类型*
|
*说明*
|
| --------------------------------- | ----- | ------------------------------------------------------------------------- |
| data-source-names | 属性 | 数据源Bean列表,多个Bean以逗号分隔 |
| table-rules | 标签 | 表分片规则配置对象 |
| binding-table-rules (?) | 标签 | 绑定表规则列表 |
| default-data-source-name (?) | 属性 | 未配置分片规则的表将通过默认数据源定位 |
| default-database-strategy-ref (?) | 属性 | 默认数据库分片策略,对应
\<
sharding:xxx-strategy>中的策略Id,缺省表示不分库 |
| default-table-strategy-ref (?) | 属性 | 默认表分片策略,对应
\<
sharding:xxx-strategy>中的策略Id,缺省表示不分表 |
| default-key-generator (?) | 属性 | 默认自增列值生成器,缺省使用
`io.shardingjdbc.core.keygen.DefaultKeyGenerator`
|
#### \<sharding:table-rules />
|
*名称*
|
*类型*
|
*说明*
|
| -------------- | ----- | --------------- |
| table-rule (+) | 标签 | 表分片规则配置对象 |
#### \<sharding:table-rule />
|
*名称*
|
*类型*
|
*说明*
|
| ---------------------------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| logic-table | 属性 | 逻辑表名称 |
| actual-data-nodes (?) | 属性 | 由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况 |
| database-strategy-ref (?) | 属性 | 数据库分片策略,对应
\<
sharding:xxx-strategy>中的策略Id,缺省表示使用
\<
sharding:sharding-rule />配置的默认数据库分片策略 |
| table-strategy-ref (?) | 属性 | 表分片策略,对应
\<
sharding:xxx-strategy>中的策略Id,缺省表示使用
\<
sharding:sharding-rule />配置的默认表分片策略 |
| generate-key-column-name (?) | 属性 | 自增列名称,缺省表示不使用自增主键生成器 |
| key-generator (?) | 属性 | 自增列值生成器,缺省表示使用默认自增列值生成器 |
| logic-index (?) | 属性 | 逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表 |
#### \<sharding:binding-table-rules />
|
*名称*
|
*类型*
|
*说明*
|
| ---------------------- | ----- | -------- |
| binding-table-rule (+) | 标签 | 绑定表规则 |
#### \<sharding:binding-table-rule />
|
*名称*
|
*类型*
|
*说明*
|
| ------------ | ----- | ----------------------------- |
| logic-tables | 属性 | 绑定规则的逻辑表名,多表以逗号分隔 |
#### \<sharding:standard-strategy />
|
*名称*
|
*类型*
|
*说明*
|
| ----------------------- | ------ | -------------------------- |
| id | 属性 | Spring Bean Id |
| sharding-column | 属性 | 分片列名称 |
| precise-algorithm-ref | 属性 | 精确分片算法引用,用于=和IN |
| range-algorithm-ref (?) | 属性 | 范围分片算法引用,用于BETWEEN |
#### \<sharding:complex-strategy />
|
*名称*
|
*类型*
|
*说明*
|
| --------------- | ------ | ------------------------ |
| id | 属性 | Spring Bean Id |
| sharding-columns | 属性 | 分片列名称,多个列以逗号分隔 |
| algorithm-ref | 属性 | 复合分片算法引用 |
#### \<sharding:inline-strategy />
|
*名称*
|
*类型*
|
*说明*
|
| -------------------- | ----- | ------------------------------ |
| id | 属性 | Spring Bean Id |
| sharding-column | 属性 | 分片列名称 |
| algorithm-expression | 属性 | 分片算法行表达式,需符合groovy语法 |
#### \<sharding:hint-database-strategy />
|
*名称*
|
*类型*
|
*说明*
|
| ------------- | ----- | ------------- |
| id | 属性 | Spring Bean Id |
| algorithm-ref | 属性 | Hint分片算法 |
#### \<sharding:none-strategy />
|
*名称*
|
*类型*
|
*说明*
|
| ----- | ------ | -------------- |
| id | 属性 | Spring Bean Id |
#### \<sharding:props />
|
*名称*
|
*类型*
|
*说明*
|
| ----------------- | ----- | --------------------------- |
| sql.show (?) | 属性 | 是否开启SQL显示,默认值: false |
| executor.size (?) | 属性 | 工作线程数量,默认值: CPU核数 |
#### \<sharding:config-map />
### 读写分离
命名空间:http://shardingjdbc.io/schema/shardingjdbc/masterslave/master-slave.xsd
#### \<master-slave:data-source />
|
*名称*
|
*类型*
|
*说明*
|
| ----------------------- | ----- | -------------------------------------------- |
| id | 属性 | Spring Bean Id |
| master-data-source-name | 属性 | 主库数据源Bean Id |
| slave-data-source-names | 属性 | 从库数据源Bean Id列表,多个Bean以逗号分隔 |
| strategy-ref (?) | 属性 | 从库负载均衡算法引用 |
| strategy-type (?) | 属性 | 从库负载均衡算法类型,可选值:ROUND_ROBIN,RANDOM |
| config-map (?) | 标签 | 用户自定义配置 |
#### \<sharding:config-map />
### 数据分片 + 数据治理
命名空间:http://shardingjdbc.io/schema/shardingjdbc/orchestration/sharding/sharding.xsd
#### \<sharding:data-source />
|
*名称*
|
*类型*
|
*说明*
|
| ------------------- | ----- | ---------------------------------------------------------------------- |
| id | 属性 | 配置同数据分片 |
| sharding-rule | 标签 | 配置同数据分片 |
| props (?) | 标签 | 配置同数据分片 |
| config-map (?) | 标签 | 配置同数据分片 |
| registry-center-ref | 属性 | 数据治理注册中心Bean引用 |
| overwrite | 属性 | 本地配置是否覆盖注册中心配置。如果可覆盖,每次启动都以本地配置为准。缺省为不覆盖 |
### 读写分离 + 数据治理
命名空间:http://shardingjdbc.io/schema/shardingjdbc/orchestration/masterslave/master-slave.xsd
#### \<master-slave:data-source />
|
*名称*
|
*类型*
|
*说明*
|
| ----------------------- | ----- | ---------------------- |
| id | 属性 | 配置同读写分离 |
| master-data-source-name | 属性 | 配置同数据分片 |
| slave-data-source-names | 属性 | 配置同数据分片 |
| strategy-ref (?) | 属性 | 配置同数据分片 |
| strategy-type (?) | 属性 | 配置同数据分片 |
| config-map (?) | 标签 | 配置同数据分片 |
| registry-center-ref | 属性 | 配置同数据分片 + 数据治理 |
| overwrite | 属性 | 配置同数据分片 + 数据治理 |
### 数据治理注册中心
命名空间:http://shardingjdbc.io/schema/shardingjdbc/orchestration/reg/reg.xsd
#### \<reg:zookeeper />
|
*名称*
|
*类型*
|
*说明*
|
| ----------------------------------- | ----- | ------------------------------------------------------------------------------------ |
| id | 属性 | 注册中心的Spring Bean Id |
| server-lists | 属性 | 连接Zookeeper服务器的列表。包括IP地址和端口号。多个地址用逗号分隔。如: host1:2181,host2:2181 |
| namespace | 属性 | Zookeeper的命名空间 |
| base-sleep-time-milliseconds (?) | 属性 | 等待重试的间隔时间的初始毫秒数,默认1000毫秒 |
| max-sleep-time-milliseconds (?) | 属性 | 等待重试的间隔时间的最大毫秒数,默认3000毫秒 |
| max-retries (?) | 属性 | 连接失败后的最大重试次数,默认3次 |
| session-timeout-milliseconds (?) | 属性 | 会话超时毫秒数,默认60000毫秒 |
| connection-timeout-milliseconds (?) | 属性 | 连接超时毫秒数,默认15000毫秒 |
| digest (?) | 属性 | 连接Zookeeper的权限令牌。缺省为不需要权限验证 |
#### \<reg:etcd />
|
*名称*
|
*类型*
|
*说明*
|
| ------------------------------- | ----- | --------------------------------------------------------------------------------------------- |
| id | 属性 | 注册中心的Spring Bean Id |
| server-lists | 属性 | 连接Etcd服务器的列表。包括IP地址和端口号。多个地址用逗号分隔。如: http://host1:2379,http://host2:2379 |
| time-to-live-seconds (?) | 属性 | 临时节点存活秒数,默认60秒 |
| timeout-milliseconds (?) | 属性 | 请求超时毫秒数,默认500毫秒 |
| max-retries (?) | 属性 | 重试间隔毫秒数,默认200毫秒 |
| retry-interval-milliseconds (?) | 属性 | 请求失败后的最大重试次数,默认3次 |
### 柔性事务
#### SoftTransactionConfiguration配置
##### SoftTransactionConfiguration配置
用于配置事务管理器。
用于配置事务管理器。
|
*名称*
|
*类型*
|
*必填*
|
*默认值*
|
*说明*
|
| ---------------------------------- | ------------------------------------------ | ------ | ------- | ----------------------------------------------------------------------------------------- |
| shardingDataSource | ShardingDataSource | 是 | | 事务管理器管理的数据源 |
| syncMaxDeliveryTryTimes | int | 否 | 3 | 同步的事务送达的最大尝试次数 |
| storageType | enum | 否 | RDB | 事务日志存储类型。可选值: RDB,MEMORY。使用RDB类型将自动建表 |
| transactionLogDataSource | DataSource | 否 | null | 存储事务日志的数据源,如果storageType为RDB则必填 |
| bestEffortsDeliveryJobConfiguration| NestedBestEffortsDeliveryJobConfiguration | 否 | null | 最大努力送达型内嵌异步作业配置对象。如需使用,请参考NestedBestEffortsDeliveryJobConfiguration配置 |
|
*名称*
|
*类型*
|
*必填*
|
*默认值*
|
*说明*
|
#### NestedBestEffortsDeliveryJobConfiguration配置 (仅开发环境)
| ---------------------------------- | ------------------------------------------ | ------ | --------- | ------------------------------------------------------------------------------------------- |
| shardingDataSource | ShardingDataSource | 是 | | 事务管理器管理的数据源 |
| syncMaxDeliveryTryTimes | int | 否 | 3 | 同步的事务送达的最大尝试次数 |
| storageType | enum | 否 | RDB | 事务日志存储类型。可选值: RDB,MEMORY。使用RDB类型将自动建表 |
| transactionLogDataSource | DataSource | 否 | null | 存储事务日志的数据源,如果storageType为RDB则必填 |
| bestEffortsDeliveryJobConfiguration| NestedBestEffortsDeliveryJobConfiguration | 否 | null | 最大努力送达型内嵌异步作业配置对象。如需使用,请参考NestedBestEffortsDeliveryJobConfiguration配置 |
##### NestedBestEffortsDeliveryJobConfiguration配置 (仅开发环境)
用于配置内嵌的异步作业,仅用于开发环境。生产环境应使用独立部署的作业版本。
用于配置内嵌的异步作业,仅用于开发环境。生产环境应使用独立部署的作业版本。
|
*名称*
|
*类型*
|
*必填*
|
*默认值*
|
*说明*
|
|
*名称*
|
*类型*
|
*必填*
|
*默认值*
|
*说明*
|
| ---------------------------------- | --------------------------- | ------ | ------------------------ | --------------------------------------------------------------- |
| ---------------------------------- | --------------------------- | ------ | ------------------------- | --------------------------------------------------------------- |
| zookeeperPort | int | 否 | 4181 | 内嵌的注册中心端口号 |
| zookeeperPort | int | 否 | 4181 | 内嵌的注册中心端口号 |
| zookeeperDataDir | String | 否 | target/test_zk_data/nano/| 内嵌的注册中心的数据存放目录 |
| zookeeperDataDir | String | 否 | target/test_zk_data/nano/ | 内嵌的注册中心的数据存放目录 |
| asyncMaxDeliveryTryTimes | int | 否 | 3 | 异步的事务送达的最大尝试次数 |
| asyncMaxDeliveryTryTimes | int | 否 | 3 | 异步的事务送达的最大尝试次数 |
| asyncMaxDeliveryTryDelayMillis | long | 否 | 60000 | 执行异步送达事务的延迟毫秒数,早于此间隔时间的入库事务才会被异步作业执行 |
| asyncMaxDeliveryTryDelayMillis | long | 否 | 60000 | 执行异步送达事务的延迟毫秒数,早于此间隔时间的入库事务才会被异步作业执行 |
document/cn/content/06-sharding-jdbc/configuration/config-yaml.md
浏览文件 @
87edc98e
...
@@ -124,7 +124,7 @@ shardingRule:
...
@@ -124,7 +124,7 @@ shardingRule:
<logic_table_name>
:
#逻辑表名称
<logic_table_name>
:
#逻辑表名称
actualDataNodes
:
#由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况
actualDataNodes
:
#由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持inline表达式。缺省表示使用已知数据源与逻辑表名称生成数据节点。用于广播表(即每个库中都需要一个同样的表用于关联查询,多为字典表)或只分库不分表且所有库的表结构完全一致的情况
databaseStrategy
:
#分库策略,
不填写
表示使用默认分库策略,以下的分片策略只能选其一
databaseStrategy
:
#分库策略,
缺省
表示使用默认分库策略,以下的分片策略只能选其一
standard
:
#用于单分片键的标准分片场景
standard
:
#用于单分片键的标准分片场景
shardingColumn
:
#分片列名称
shardingColumn
:
#分片列名称
preciseAlgorithmClassName
:
#精确分片算法类名称,用于=和IN。该类需提供无参数构造器
preciseAlgorithmClassName
:
#精确分片算法类名称,用于=和IN。该类需提供无参数构造器
...
@@ -140,7 +140,7 @@ shardingRule:
...
@@ -140,7 +140,7 @@ shardingRule:
none
:
#不分片
none
:
#不分片
tableStrategy
:
#分表策略,同分库策略
tableStrategy
:
#分表策略,同分库策略
keyGeneratorColumnName
:
#自增列名称,
不填写
表示不使用自增主键生成器
keyGeneratorColumnName
:
#自增列名称,
缺省
表示不使用自增主键生成器
keyGeneratorClass
:
#自增列值生成器类名称。该类需提供无参数的构造器
keyGeneratorClass
:
#自增列值生成器类名称。该类需提供无参数的构造器
logicIndex
:
#逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表
logicIndex
:
#逻辑索引名称,对于分表的Oracle/PostgreSQL数据库中DROP INDEX XXX语句,需要通过配置逻辑索引名称定位所执行SQL的真实分表
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录