提交 32b350d6 编写于 作者: G gaohongtao

Update doc

上级 436cc581
本文档使用[hugo](http://gohugo.io/overview/introduction/)生成文档。
同时使用主题[hugo theme learn](https://github.com/matcornic/hugo-theme-learn)来作为文档风格。
\ No newline at end of file
baseurl = "http://dangdangdotcom.github.io/sharding-jdbc/"
languageCode = "en-us"
title = "Sharding-JDBC"
[params]
description = "A JDBC driver for shard databases and tables"
author_url = "https://github.com/dangdangdotcom"
project_url = "https://github.com/dangdangdotcom/sharding-jdbc"
project_documentation = "http://dangdangdotcom.github.io/sharding-jdbc"
github_project_name = "Sharding-JDBC"
github_user_name = "dangdangdotcom"
first_color="#f8f8f8"
first_border_color="#e7e7e7"
first_text_color="#333"
second_color="white"
second_text_color="#333"
header_color="#f8f8f8"
header_text_color="rgb(51, 51, 51)"
header_link_color="#777"
header_link_hover_color="rgb(51, 51, 51)"
canonifyurls = true
theme = "hugo-theme-learn"
+++
date = "2016-11-23T20:30:55+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "FAQ"
weight = 0
+++
weight = 2
prev = "/01-start/quick-start"
next = "/01-start/features"
## 阅读源码时为什么会出现编译错误?
+++
代码使用[Lombok](https://projectlombok.org/download.html)实现极简代码。关于更多使用和安装细节,请参考官网。
## 使用问题
## 使用Spring命名空间时在网上相应地址找不到xsd?
### 使用Spring命名空间时在网上相应地址找不到xsd?
Spring命名空间使用规范并未强制要求将xsd文件部署至公网地址,只需在jar包的`META-INF\spring.schemas`配置,并在jar包中相关位置存在即可。
我们并未将`http://www.dangdang.com/schema/ddframe/rdb/rdb.xsd`部署至公网,但并不影响使用。相关问题请参考Spring命名空间规范。
## 异常:Cloud not resolve placeholder ... in string value ...?
### 异常:Cloud not resolve placeholder ... in string value ...?
由于inline表达式内使用Groovy语法,Groovy语法的变量占位符为`${}`,与Spring的Property占位符冲突。
故需要在Spring的配置文件中增加
`<context:property-placeholder location="classpath:conf/rdb/conf.properties" ignore-unresolvable="true"/>`
## inline表达式返回结果出现浮点数?
### inline表达式返回结果出现浮点数?
Java的整数相除结果是整数,但是对于inline表达式中的Groovy语法则不同,整数相除结果是浮点数。
想获得除法整数结果需要将`A/B`改为`A.intdiv(B)`
\ No newline at end of file
想获得除法整数结果需要将`A/B`改为`A.intdiv(B)`
## 编译源代码问题
### 阅读源码时为什么会出现编译错误?
代码使用[Lombok](https://projectlombok.org/download.html)实现极简代码。关于更多使用和安装细节,请参考官网。
\ No newline at end of file
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "详细功能列表"
weight = 3
prev = "/01-start/faq"
next = "/01-start/limitations"
+++
# 详细功能列表
## 功能性需求
......
+++
icon = "<b>1. </b>"
date = "2016-12-02T16:06:17+08:00"
title = "起航"
weight = 0
next = "/01-start/faq"
chapter = true
+++
# 本章导航
- 如果想快速体验`Sharding-JDBC`的强大功能,请阅读[快速上手](/01-start/quick-start)
- 如果在使用中遇到什么问题,请首先在[FAQ](/01-start/faq)中寻找解决问题的答案。
- 想要在自己的项目中集成`Sharding-JDBC`,您一定很关心它[能做什么](/01-start/features)[不能做什么](/01-start/limitations)
- 数据库中间件一般都不会支持完全的SQL语法,在这里你能了解到[支持的SQL语法](/01-start/sql-supported)
- 最后,你会关心中间件的性能情况。这里将为你我们的[性能测试结果](/01-start/stress-test)
# 简介
* `Sharding-JDBC`直接封装`JDBC API`,可以理解为增强版的`JDBC`驱动,旧代码迁移成本几乎为零
* 可适用于任何基于`java``ORM`框架,如:`JPA`, `Hibernate`, `Mybatis`, `Spring JDBC Template`或直接使用`JDBC`
* 可基于任何第三方的数据库连接池,如:`DBCP`, `C3P0`, `BoneCP`, `Druid`等。
* 理论上可支持任意实现`JDBC`规范的数据库。虽然目前仅支持`MySQL`,但已有支持`Oracle``SQLServer``DB2`等数据库的计划。
* `Sharding-JDBC`功能灵活且全面
* 分片策略灵活,可支持`=``BETWEEN``IN`等多维度分片,也可支持多分片键共用。
* `SQL`解析功能完善,支持聚合,分组,排序,`Limit``OR`等查询,并且支持`Binding Table`以及笛卡尔积的表查询。
* 支持柔性事务(目前仅最大努力送达型)。
* 支持读写分离。
* 支持生成唯一有顺序主键
* `Sharding-JDBC`配置多样
* 可支持YAML和Spring命名空间配置
* 灵活多样的`inline`方式
# 整体架构图
![整体架构图1](/img/architecture.png)
\ No newline at end of file
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "使用限制"
weight = 8
+++
weight = 4
prev = "/01-start/features"
next = "/01-start/sql-supported"
# 使用限制
+++
## `JDBC`未支持列表
......
# 主要贡献者
+++
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "快速入门"
weight = 1
prev = "/start"
next = "/01-start/faq"
* 张亮 &nbsp;&nbsp;&nbsp;[当当](http://www.dangdang.com/) zhangliang@dangdang.com
* 高洪涛 [当当](http://www.dangdang.com/) gaohongtao@dangdang.com
* 曹昊 &nbsp;&nbsp;&nbsp;[当当](http://www.dangdang.com/) caohao@dangdang.com
* 岳令 &nbsp;&nbsp;&nbsp;[当当](http://www.dangdang.com/) yueling@dangdang.com
+++
# 交流与参与
## 使用API配置
- **讨论QQ群:** 532576663(不限于Sharding-JDBC,包括分布式,数据库相关以及其他互联网技术交流。由于QQ群已接近饱和,我们希望您在申请加群之前仔细阅读文档,并在加群申请中正确回答问题,以及在申请时写上您的姓名和公司名称。并且在入群后及时修改群名片。否则我们将有权拒绝您的入群申请。谢谢合作。)
- **邮件组 sharding_jdbc@groups.163.com** ,如果在使用上需要帮助,或者疑似的bug,请发邮件到该邮件组中。发邮件之前请先阅读[FAQ](http://dangdangdotcom.github.io/sharding-jdbc/post/faq/)
- 报告bug,提交增强功能建议和提交补丁等,请阅读[如何进行贡献](https://github.com/dangdangdotcom/sharding-jdbc/blob/master/CONTRIBUTING.md)
### Maven安装
# 简介
`Sharding-JDBC`直接封装`JDBC API`,可以理解为增强版的`JDBC`驱动,旧代码迁移成本几乎为零:
* 可适用于任何基于`java``ORM`框架,如:`JPA`, `Hibernate`, `Mybatis`, `Spring JDBC Template`或直接使用`JDBC`
* 可基于任何第三方的数据库连接池,如:`DBCP`, `C3P0`, `BoneCP`, `Druid`等。
* 理论上可支持任意实现`JDBC`规范的数据库。虽然目前仅支持`MySQL`,但已有支持`Oracle``SQLServer``DB2`等数据库的计划。
`Sharding-JDBC`定位为轻量级`java`框架,使用客户端直连数据库,以`jar`包形式提供服务,未使用中间层,无需额外部署,无其他依赖,`DBA`也无需改变原有的运维方式。`SQL`解析使用`Druid`解析器,是目前性能最高的`SQL`解析器。
`Sharding-JDBC`功能灵活且全面:
* 分片策略灵活,可支持`=``BETWEEN``IN`等多维度分片,也可支持多分片键共用。
* `SQL`解析功能完善,支持聚合,分组,排序,`Limit``OR`等查询,并且支持`Binding Table`以及笛卡尔积的表查询。
* 支持柔性事务(目前仅最大努力送达型)。
* 支持读写分离。
`Sharding-JDBC`配置多样:
* 可支持YAML和Spring命名空间配置
* 灵活多样的`inline`方式
***
以下是常见的分库分表产品和`Sharding-JDBC`的对比:
| 功能 | Cobar | Cobar-client | TDDL | Sharding-JDBC |
| ------------- |:-------------:| --------------:| -----------:|----------------:|
| 分库 | 有 | 有 | 未开源 | 有 |
| 分表 | 无 | 无 | 未开源 | 有 |
| 中间层 | 是 | 否 | 否 | 否 |
| ORM支持 | 任意 | 仅MyBatis | 任意 | 任意 |
| 数据库支持 | 仅MySQL | 任意 | 任意 | 任意 |
| 异构语言 | 可 | 仅Java | 仅Java | 仅Java |
| 外部依赖 | 无 | 无 | Diamond | 无 |
***
# 整体架构图
![整体架构图1](img/architecture.png)
# Quick Start
## 引入maven依赖
```xml
<!-- 引入sharding-jdbc核心模块 -->
<dependency>
<groupId>com.dangdang</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>1.0.0</version>
<version>${sharding-jdbc.version}</version>
</dependency>
```
## 规则配置
`Sharding-JDBC`的分库分表通过规则配置描述,请简单浏览配置全貌:
```java
......@@ -78,9 +36,10 @@ ShardingRule shardingRule = ShardingRule.builder()
规则配置包括数据源配置、表规则配置、分库策略和分表策略组成。这只是最简单的配置方式,实际使用可更加灵活,如:多分片键,分片策略直接和`tableRule`绑定等。
>详细的规则配置请参考[用户指南](post/user_guide)
>详细的规则配置请参考[分库分表](guide/sharding)
## 使用基于ShardingDataSource的JDBC接口
通过`ShardingDataSourceFactory`工厂和规则配置对象获取`ShardingDataSource``ShardingDataSource`实现自`JDBC`的标准接口`DataSource`。然后可通过`DataSource`选择使用原生`JDBC`开发,或者使用`JPA`, `MyBatis``ORM`工具。
`JDBC`原生实现为例:
......@@ -101,7 +60,19 @@ try (
}
```
## 使用Spring命名空间配置
## 使用Spring
### Maven安装
```xml
<!-- 引入sharding-jdbc核心模块 -->
<dependency>
<groupId>com.dangdang</groupId>
<artifactId>sharding-jdbc-config-spring</artifactId>
<version>${sharding-jdbc.version}</version>
</dependency>
```
### Spring命名空间
```xml
<?xml version="1.0" encoding="UTF-8"?>
......@@ -144,3 +115,4 @@ try (
</rdb:data-source>
</beans>
```
>详细的规则配置请参考[Spring配置](guide/spring)
\ No newline at end of file
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "SQL支持详细列表"
weight = 9
+++
weight = 5
prev = "/01-start/limitations"
next = "/01-start/stress-test"
# SQL支持详细列表
+++
由于`SQL`语法灵活复杂,分布式数据库和单机数据库的查询场景又不完全相同,难免有和单机数据库不兼容的`SQL`出现。
本文详细罗列出已明确可支持的`SQL`种类以及已明确不支持的`SQL`种类,尽量让使用者避免踩坑。
......@@ -36,6 +38,7 @@ SELECT select_expr [, select_expr ...] FROM table_reference [, table_reference .
```
#### select_expr
```sql
* |
COLUMN_NAME [AS] [alias] |
......@@ -44,6 +47,7 @@ COUNT(* | COLUMN_NAME | alias) [AS] [alias]
```
#### table_reference
```sql
tbl_name [AS] alias] [index_hint_list] |
table_reference ([INNER] | {LEFT|RIGHT} [OUTER]) JOIN table_factor [JOIN ON conditional_expr | USING (column_list)] |
......
+++
date = "2016-01-08T16:14:21+08:00"
title = "压力测试报告"
weight = 10
chart = true
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "性能测试报告"
weight = 6
prev = "/01-start/sql-supported"
next = "/02-guide"
+++
# 压力测试报告
## 测试目的
`Sharding-JDBC`进行性能测试,客观、公正评估系统的性能,目的有三:
......@@ -25,7 +28,7 @@ chart = true
| 数据表行数 | 1000万 | 1000万 |
## 网络拓扑
![网络拓扑图](../../img/stress_test_arch.png)
![网络拓扑图](/img/stress_test_arch.png)
## 单库情况下Sharding-JDBC与JDBC性能对比
测试结论:
......@@ -87,3 +90,18 @@ chart = true
经过8个小时的疲劳测试,jvm的堆大约占用不到600MB的内存,且使用量比较稳定。没有发生Full GC。
<canvas id="fatigueTest" width="400" height="150"></canvas>
<script src="//cdn.bootcss.com/moment.js/2.11.1/moment.min.js"></script>
<script src="//cdn.bootcss.com/Chart.js/2.0.0-beta2/Chart.min.js"></script>
<script src="/data/chart.js"></script>
<script>
$("canvas").each(function(){
var data = chartData[$(this).attr("id")];
$(data.datasets).each(function(index, obj){
$.extend(obj, charStyle[index])
});
new Chart(this.getContext("2d"),{
type: 'line',
data: data
});
})
</script>
\ No newline at end of file
+++
date = "2016-03-03T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "核心概念"
weight = 4
weight = 1
prev = "/02-guide"
next = "/02-guide/sharding"
+++
本文介绍`Sharding-JDBC`包含的一些核心概念。
......
+++
date = "2016-03-25T16:14:21+08:00"
title = "Spring命名空间和Yaml配置"
weight = 2
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "配置文件"
weight = 4
prev = "/02-guide/hint-sharding-value"
next = "/02-guide/id-generator"
+++
# Yaml配置
## Yaml配置
## 引入maven依赖
......@@ -16,13 +20,13 @@ weight = 2
</dependency>
```
## Java示例
### Java示例
```java
DataSource dataSource = new YamlShardingDataSource(yamlFile);
```
## 配置示例
### 配置示例
```yaml
dataSource:
......@@ -64,9 +68,10 @@ defaultDatabaseStrategy:
props:
metrics.enable: false
```
## 配置项说明
### 配置项说明
```yaml
dataSource: 数据源配置
......@@ -114,7 +119,7 @@ props: 属性配置(可选)
executor.max.idle.timeout.millisecond: 工作线程空闲时超时时间,单位: 毫秒,默认值: 60000毫秒
```
### Yaml格式特别说明
#### Yaml格式特别说明
`!!` 表示实现类
`&` 表示变量定义
......@@ -123,9 +128,9 @@ props: 属性配置(可选)
`-` 表示多个
# Spring命名空间配置
## Spring命名空间配置
## 引入maven依赖
### 引入maven依赖
```xml
<dependency>
......@@ -135,7 +140,7 @@ props: 属性配置(可选)
</dependency>
```
## 配置示例
### 配置示例
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
......@@ -185,9 +190,9 @@ props: 属性配置(可选)
</rdb:data-source>
</beans>
```
## 标签说明
### 标签说明
### \<rdb:data-source/\>
#### \<rdb:data-source/\>
定义sharding-jdbc数据源
......@@ -200,7 +205,7 @@ props: 属性配置(可选)
| default-table-strategy`?` | 标签 | - | 是 | 默认分表策略 |
| props`?` | 标签 | - | 是 | 相关属性配置 |
### \<rdb:sharding-rule/>
#### \<rdb:sharding-rule/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ------------ | ---------- | ------ | -------------------------------------------------------- |
......@@ -208,13 +213,13 @@ props: 属性配置(可选)
| default-data-source | 属性 | String | 否 | 默认数据源名称,未配置分片规则的表将通过默认数据源定位 |
| table-rules | 标签 | - | 是 | 分片规则列表 |
### \<rdb:table-rules/>
#### \<rdb:table-rules/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ----------- | ---------- | ------ | ------- |
| table-rule`+` | 标签 | - | 是 | 分片规则 |
### \<rdb:table-rule/>
#### \<rdb:table-rule/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| -------------------- | ------------ | ---------- | ------ | ------- |
......@@ -225,19 +230,19 @@ props: 属性配置(可选)
| database-strategy | 属性 | String | 否 | 分库策略,对应`<rdb:strategy>`中分库策略id, 如果不填需配置`<rdb:default-database-strategy/>` |
| table-strategy | 属性 | String | 否 | 分表策略,对应`<rdb:strategy>`中分表策略id, 如果不填需配置`<rdb:default-table-strategy/>` |
### \<rdb:binding-table-rules/>
#### \<rdb:binding-table-rules/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ----------- | --------- | ------ | ------- |
| binding-table-rule | 标签 | - | 是 | 绑定规则 |
### \<rdb:binding-table-rule/>
#### \<rdb:binding-table-rule/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ------------ | ---------- | ------ | ------------------------ |
| logic-tables | 属性 | String | 是 | 逻辑表名,多个表名以逗号分隔 |
### \<rdb:default-database-strategy/>
#### \<rdb:default-database-strategy/>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ------------ | ---------- | ------ | ------- |
......@@ -245,7 +250,7 @@ props: 属性配置(可选)
| algorithm-class | 属性 | Class | 否 | 默认分库算法全类名,该类需使用默认的构造器或者提供无参数的构造器,与`algorithm-expression`有且仅有一个出现 |
| algorithm-expression | 属性 | String | 否 | 默认分库算法表达式,与`algorithm-class`有且仅有一个出现 |
### \<rdb:default-table-strategy/\>
#### \<rdb:default-table-strategy/\>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ----------------------------- | ------------ | --------- | ------ | ------- |
......@@ -253,7 +258,7 @@ props: 属性配置(可选)
| algorithm-class | 属性 | Class | 否 | 默认分表算法全类名,该类需使用默认的构造器或者提供无参数的构造器,与`algorithm-expression`有且仅有一个出现 |
| algorithm-expression | 属性 | String | 否 | 默认分表算法表达式,与`algorithm-class`有且仅有一个出现 |
### \<rdb:strategy/\>`*`
#### \<rdb:strategy/\>`*`
定义数据分库或分表策略
......@@ -264,7 +269,7 @@ props: 属性配置(可选)
| algorithm-class | 属性 | Class | 否 | 分库或分表算法全类名,该类需使用默认的构造器或者提供无参数的构造器,与`algorithm-expression`有且仅有一个出现 |
| algorithm-expression | 属性 | String | 否 | 分库或分表算法表达式,与`algorithm-class`有且仅有一个出现 |
### \<rdb:props/\>
#### \<rdb:props/\>
| *名称* | *类型* | *数据类型* | *必填* | *说明* |
| ------------------------------------ | ------------ | ---------- | ----- | ----------------------------------- |
......@@ -275,13 +280,13 @@ props: 属性配置(可选)
| executor.max.size | 属性 | int | 否 | 最大工作线程数量 |
| executor.max.idle.timeout.millisecond| 属性 | int | 否 | 工作线程空闲时超时时间,默认以毫秒为单位 |
### Spring格式特别说明
#### Spring格式特别说明
如需使用inline表达式,需配置`ignore-unresolvable``true`,否则placeholder会把inline表达式当成属性key值导致出错.
# 分片算法表达式语法说明
## 分片算法表达式语法说明
## inline表达式特别说明
### inline表达式特别说明
`${begin..end}` 表示范围区间
`${[unit1, unit2, unitX]}` 表示枚举值
......@@ -292,7 +297,7 @@ 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`代码。
```groovy
......@@ -301,7 +306,7 @@ data_source_${id.longValue() % 2 + 1}
上面的表达式中`data_source_`是字符串前缀,`id.longValue() % 2 + 1``groovy`代码。
## 分区键值获取
### 分区键值获取
`groovy`代码中可以使用分区键的名字直接获取表达式的值对象。
该对象是`com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ShardingValueWrapper`类型的对象。
......
+++
date = "2016-02-05T17:03:18+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "基于暗示(Hint)的分片键值注册方法"
weight = 12
+++
weight = 3
prev = "/02-guide/sharding"
next = "/02-guide/configuration"
# 基于暗示(Hint)的分片键值注册方法
+++
> 提示:阅读本文前请详细预读 [使用指南](../user_guide)
> 提示:阅读本文前请详细预读 [分库分表](/02-guide/sharding)
## 背景
`Sharding-JDBC`有初步了解的朋友已经发现了:在编写分片算法的时候,传入的分片键值是来自`SQL`语句中`WHERE`条件的。
......
+++
date = "2016-11-16T15:07:10+08:00"
draft = false
title = "Id生成器"
weight = 13
+++
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "分布式Id生成器"
weight = 5
prev = "/02-guide/configuration"
next = "/02-guide/master-slave"
# 分布式Id生成器
+++
## 实现动机
......@@ -16,7 +17,7 @@ weight = 13
目前有许多第三方解决方案可以完美解决这个问题,比如UUID等依靠特定算法自生成不重复键,或者通过引入Id生成服务等。
但也正因为这种多样性导致了`Sharding-JDBC`如果强依赖于任何一种方案就会限制其自身的发展。
基于以上的原因,最终采用了以`JDBC`接口来实现对于生成Id的访问,而将底层具体的Id生成实现分离出来.
基于以上的原因,最终采用了以`JDBC`接口来实现对于生成Id的访问,而将底层具体的Id生成实现分离出来
## 使用方法
......
+++
icon = "<b>2. </b>"
date = "2016-12-12T16:06:17+08:00"
title = "使用指南"
weight = 0
prev = "/01-start/stress-test"
next = "/02-guide/concepts"
chapter = true
+++
# 本章导航
本章节最重要将详细介绍如何使用`Sharding-JDBC`
- 想一览基本的概念,请阅读[基本概念](/02-guide/concepts)
- 想通过一个完整的例子使用`Sharding-JDBC`进行分库分表,请阅读[如何分库分表](/02-guide/sharding)章节。
- 一般情况`Sharding-JDBC`是通过`SQL解析`来获取数据路由数据的,同时你可以使用[Hint](/02-guide/hint-sharding-value)方式来编程设置该数据。该模式非常适合存量系统扩容。
- [使用配置文件](/02-guide/configuration)介绍了如何利用配置文件来使用`Sharding-JDBC`,配置文件支持`YAML``Spring`两种方式。
- 分库分表后主键如何生成?[分布式Id生成器](/02-guide/id-generator)将给你答案。
- 分库分表后,要进一步提高性能,可以使用[读写分离](/02-guide/master-slave)功能。
- 分库后事务如何保证?[事务说明](/02-guide/transaction)章节将告诉你我们的回答。如果你认同我们的理念,[柔性事务](/02-guide/soft-transaction)将告诉你如何使用这种`Sharding-JDBC`特有的事务模式。`
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "读写分离"
weight = 6
prev = "/02-guide/id-generator"
next = "/02-guide/transaction"
+++
# 读写分离
## 概念
为了缓解数据库压力,将写入和读取操作分离为不同数据源,写库称为主库,读库称为从库,一主库可配置多从库。
......
+++
date = "2016-01-08T16:14:21+08:00"
title = "使用指南"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "分库分表"
weight = 2
prev = "/02-guide/concepts"
next = "/02-guide/hint-sharding-value"
+++
# 使用指南
阅读本指南前,请先阅读快速起步。本文档使用更复杂的场景进一步介绍`Sharding-JDBC`的分库分表能力。
## 数据库模式
本文档中提供了两个数据源`db0``db1`,每个数据源之中包含了两组表`t_order_0``t_order_1``t_order_item_0``t_order_item_1 `。这两组表的建表语句为:
......
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "柔性事务"
weight = 6
weight = 8
prev = "/02-guide/transaction"
next = "/03-community"
+++
# 最大努力送达型
## 概念
## 最大努力送达型
### 概念
在分布式数据库的场景下,相信对于该数据库的操作最终一定可以成功,所以通过最大努力反复尝试送达操作。
## 架构图
### 架构图
![最大努力送达型事务](../../img/architecture-soft-transaction-bed.png)
## 适用场景
### 适用场景
* 根据主键删除数据。
* 更新记录永久状态,如更新通知送达状态。
## 使用限制
### 使用限制
使用最大努力送达型柔性事务的`SQL`需要满足幂等性。
* INSERT语句要求必须包含主键,且不能是自增主键。
* UPDATE语句要求幂等,不能是`UPDATE xxx SET x=x+1`
* DELETE语句无要求。
## 开发指南
### 开发指南
* `Sharding-JDBC-transaction`完全基于`java`开发,直接提供`jar`包,可直接使用maven导入坐标即可使用。
* 为了保证事务不丢失,`Sharding-JDBC-transaction`需要提供数据库存储事务日志,配置方法可参见事务管理器配置项。
* 由于柔性事务采用异步尝试,需要部署独立的作业和`Zookeeper``Sharding-JDBC-transaction`采用`elastic-job`实现的`Sharding-JDBC-transaction-async-job`,通过简单配置即可启动高可用作业异步送达柔性事务,启动脚本为`start.sh`
* 为了便于开发,`Sharding-JDBC-transaction`提供了基于内存的事务日志存储器和内嵌异步作业。
## 开发示例
### 开发示例
```java
// 1. 配置SoftTransactionConfiguration
......@@ -55,7 +60,7 @@ weight = 6
transaction.end();
```
## 事务管理器配置项
### 事务管理器配置项
### `SoftTransactionConfiguration`配置
用于配置事务管理器。
......@@ -79,13 +84,13 @@ weight = 6
| asyncMaxDeliveryTryTimes | int | 否 | 3 | 异步的事务送达的最大尝试次数 |
| asyncMaxDeliveryTryDelayMillis | long | 否 | 60000 | 执行异步送达事务的延迟毫秒数,早于此间隔时间的入库事务才会被异步作业执行 |
## 独立部署作业指南
### 独立部署作业指南
* 部署用于存储事务日志的数据库。
* 部署用于异步作业使用的`Zookeeper`
* 配置`yaml`文件,参照示例。
* 下载并解压文件`sharding-jdbc-transaction-async-job-$VERSION.tar`,通过`start.sh`脚本启动异步作业。
## 异步作业yaml文件配置
### 异步作业yaml文件配置
```yaml
#目标数据库的数据源.
targetDataSource:
......@@ -143,5 +148,5 @@ jobConfig:
maxDeliveryTryDelayMillis: 60000
```
# TCC型
## TCC型
开发中...
+++
date = "2016-01-29T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "事务支持说明"
weight = 12
weight = 7
prev = "/02-guide/master-slave"
next = "/02-guide/soft-transaction"
+++
# 事务支持说明
`Sharding-JDBC`由于性能方面的考量,决定不支持`强一致性`分布式事务。我们已明确规划线路图,未来会支持最终一致性的柔性事务。
......
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "架构图"
weight = 5
weight = 1
prev = "/03-community"
next = "/03-community/release-notes"
+++
# 架构图
![整体架构图1](../../img/architecture.png)
......
+++
date = "2016-01-28T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "目录结构说明"
weight = 7
+++
weight = 3
prev = "/03-community/release-notes"
next = "/03-community/roadmap"
# 目录结构说明
+++
```
sharding-jdbc
......
+++
icon = "<b>3. </b>"
date = "2016-12-12T16:06:17+08:00"
title = "社区"
weight = 0
prev = "/02-guide/soft-transaction"
next = "/03-community/architecture"
chapter = true
+++
# 本章导航
欢迎加入社区。
- 想一览基本的概念,请阅读[基本概念](/02-guide/concepts)
- 想通过一个完整的例子使用`Sharding-JDBC`进行分库分表,请阅读[如何分库分表](/02-guide/sharding)章节。
- 一般情况`Sharding-JDBC`是通过`SQL解析`来获取数据路由数据的,同时你可以使用[Hint](/02-guide/hint-sharding-value)方式来编程设置该数据。该模式非常适合存量系统扩容。
- [使用配置文件](/02-guide/configuration)介绍了如何利用配置文件来使用`Sharding-JDBC`,配置文件支持`YAML``Spring`两种方式。
- 分库分表后主键如何生成?[分布式Id生成器](/02-guide/id-generator)将给你答案。
- 分库分表后,要进一步提高性能,可以使用[读写分离](/02-guide/master-slave)功能。
- 分库后事务如何保证?[事务说明](/02-guide/transaction)章节将告诉你我们的回答。如果你认同我们的理念,[柔性事务](/02-guide/soft-transaction)将告诉你如何使用这种`Sharding-JDBC`特有的事务模式。`
+++
date = "2016-02-05T17:03:18+08:00"
title = "Release Notes"
weight = 1
+++
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "Release Note"
weight = 2
prev = "/03-community/architecture"
next = "/03-community/directory-structure"
# Release Notes
+++
## 1.4.1
......
+++
date = "2016-01-08T16:14:21+08:00"
toc = true
date = "2016-12-06T22:38:50+08:00"
title = "未来线路规划"
weight = 11
weight = 4
prev = "/03-community/directory-structure"
+++
# 未来线路规划
## 已完成
......
{{ partial "head.html" . }}
{{ partial "header.html" . }}
{{ partial "services.html" . }}
{{ partial "footer.html" . }}
{{ partial "head.html" . }}
<style>
.container {
width: 95%;
}
</style>
{{ partial "nav.html" . }}
<section id="services">
<div class="content-section-a">
<div class="container">
<div class="clearfix"></div>
<div class="row">
<div class="col-sm-8">
{{ .Content }}
</div>
<div class="col-sm-3 col-sm-offset-1 doc-sidebar">
{{ .TableOfContents }}
</div><!-- /.doc-sidebar -->
</div>
</div>
</div>
</div>
</section>
{{ partial "footer.html" . }}
{{ partial "head.html" . }}
{{ partial "nav.html" . }}
{{ partial "header.html" . }}
{{ partial "services.html" . }}
{{ partial "footer.html" . }}
<!DOCTYPE html>
<!--
~ Copyright 1999-2015 dangdang.com.
~ <p>
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ </p>
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=http://dangdangdotcom.github.io/sharding-jdbc/01-start">
<title>Index</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-md-8">
<p class="copyright text-muted small">Copyright &copy; {{ .Title }} All Rights Reserved</p>
</div>
<div class="col-md-4">
</div>
</div>
</div>
</footer>
{{ partial "js.html" . }}
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>{{ .Title }}</title>
<!-- Bootstrap Core CSS -->
<link href="//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="{{ .Site.BaseURL }}css/landing-page.css" rel="stylesheet">
<!-- Custom Fonts -->
<!--<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600&subset=latin,latin-ext' rel='stylesheet'>-->
<style>
{{ printf "%v" (partial "template.css" . ) | safeCSS }}
</style>
<link href="//cdn.bootcss.com/prism/1.4.1/themes/prism.min.css" rel="stylesheet">
<link href="{{ .Site.BaseURL }}css/table.css" rel="stylesheet">
</head>
<body>
<section id="intro">
<!-- Header -->
<div class="intro-header">
<div class="container header-container">
<div class="row">
<div class="intro-image col-md-4"></div>
<div class="intro-message col-md-6">
<h1>{{ .Site.Title }}</h1>
<h3>{{ .Site.Params.description }}</h3>
{{ if (isset .Site.Params "github_project_name") }}
{{ $user := .Site.Params.github_user_name }}
{{ $repo := .Site.Params.github_project_name }}
<iframe class="github-btn" src="https://ghbtns.com/github-btn.html?user={{ $user }}&repo={{ $repo }}&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
{{ end }}
<hr class="intro-divider">
</div>
</div>
</div>
<!-- /.container -->
</div>
<!-- /.intro-header -->
</section>
<!-- jQuery Version 1.11.0 -->
<script src="//cdn.bootcss.com/jquery/1.12.0/jquery.min.js"></script>
<!-- Plugin JavaScript -->
<script src="//cdn.bootcss.com/jquery-easing/1.3/jquery.easing.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="//cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="//cdn.bootcss.com/prism/1.4.1/prism.min.js"></script>
<script src="//cdn.bootcss.com/prism/1.4.1//components/prism-java.min.js"></script>
<script src="//cdn.bootcss.com/prism/1.4.1//components/prism-sql.min.js"></script>
<script src="//cdn.bootcss.com/prism/1.4.1//components/prism-groovy.min.js"></script>
<script src="//cdn.bootcss.com/prism/1.4.1//components/prism-yaml.min.js"></script>
{{ if isset .Params "chart" }}
<script src="//cdn.bootcss.com/moment.js/2.11.1/moment.min.js"></script>
<script src="//cdn.bootcss.com/Chart.js/2.0.0-beta2/Chart.min.js"></script>
<script src="{{ .Site.BaseURL }}data/chart.js"></script>
<script>
$("canvas").each(function(){
var data = chartData[$(this).attr("id")];
$(data.datasets).each(function(index, obj){
$.extend(obj, charStyle[index])
});
new Chart(this.getContext("2d"),{
type: 'line',
data: data
});
})
</script>
{{ end }}
<svg width="100%" height="100%" viewBox="0 0 960 279" version="1.1" xmlns="http://www.w3.org/2000/svg">
<!-- Generator: Sketch 39.1 (31720) - http://www.bohemiancoding.com/sketch -->
<title>logo</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Oval" transform="translate(1.000000, 1.000000)" stroke="#979797" fill="#FFFFFF">
<path d="M137,274 C212.663011,274 274,212.663011 274,137 C274,61.3369893 212.663011,0 137,0 C61.3369893,0 0,61.3369893 0,137 C0,212.663011 61.3369893,274 137,274 Z M113.574219,66.9726562 L196.191406,134.648438 C204.003945,140.898469 209.602848,147.050751 212.988281,153.105469 C216.438819,159.290396 218.164062,166.191368 218.164062,173.808594 C218.164062,183.183641 215.559922,191.647098 210.351562,199.199219 C205.208308,206.75134 198.144576,212.350242 189.160156,215.996094 C186.686186,217.037766 184.570321,217.753904 182.8125,218.144531 C180.338529,218.730472 177.864596,219.153645 175.390625,219.414062 C172.591132,219.67448 169.205749,219.869791 165.234375,220 C154.687447,212.643192 147.200543,207.402359 142.773438,204.277344 C138.346332,201.152328 133.105499,197.376324 127.050781,192.949219 C117.220003,185.72262 107.71489,178.203164 98.5351562,170.390625 C89.5507363,162.968713 82.4219014,156.360706 77.1484375,150.566406 C71.9400781,145.032524 68.2291777,140.182312 66.015625,136.015625 C64.2578037,132.565087 62.8906299,128.789083 61.9140625,124.6875 C60.8723906,120.585917 60.3515625,116.74481 60.3515625,113.164062 C60.3515625,103.26818 62.8905996,94.6745156 67.96875,87.3828125 C73.0469004,80.0260049 80.1757354,74.4922061 89.3554688,70.78125 C92.9362158,69.4140557 96.4843574,68.4375029 100,67.8515625 C103.450538,67.3307266 107.975232,67.0377607 113.574219,66.9726562 Z M61.2304688,220 L61.2304688,155.644531 L143.359375,220 L61.2304688,220 Z M209.179688,128.398438 L133.203125,65.9960938 L209.179688,65.9960938 L209.179688,128.398438 Z" id="Combined-Shape"></path>
</g>
<path d="M366.100586,124.876953 L366.100586,170.165039 L288,170.165039 L288,124.876953 L366.100586,124.876953 Z M489.660156,17.7236328 L553.576172,17.7236328 L553.576172,159.740234 C553.576172,185.83086 546.740303,207.07902 533.068359,223.485352 C525.206992,232.941779 515.209533,240.461235 503.075684,246.043945 C490.941834,251.626656 478.494855,254.417969 465.734375,254.417969 C440.327347,254.417969 418.90829,245.873132 401.476562,228.783203 C384.044835,211.693274 375.329102,190.729942 375.329102,165.892578 C375.329102,141.852744 383.987869,121.060309 401.305664,103.514648 C418.623459,85.9689878 439.131066,77.1962891 462.829102,77.1962891 C466.588886,77.1962891 472.285444,77.5380825 479.918945,78.2216797 L479.918945,148.631836 C474.678034,144.530253 469.437201,142.479492 464.196289,142.479492 C457.588183,142.479492 451.920108,144.900529 447.191895,149.742676 C442.463681,154.584822 440.099609,160.423794 440.099609,167.259766 C440.099609,173.867872 442.549129,179.535946 447.448242,184.26416 C452.347355,188.992374 458.21481,191.356445 465.050781,191.356445 C481.457113,191.356445 489.660156,180.020296 489.660156,157.347656 L489.660156,17.7236328 Z M668.078125,77.0253906 C692.231892,77.0253906 712.938879,85.712641 730.199707,103.087402 C747.460536,120.462164 756.09082,141.283082 756.09082,165.550781 C756.09082,190.160279 747.346604,211.123611 729.85791,228.441406 C712.369216,245.759201 691.26347,254.417969 666.540039,254.417969 C641.816608,254.417969 620.682379,245.730718 603.136719,228.355957 C585.591058,210.981196 576.818359,190.046346 576.818359,165.550781 C576.818359,140.599485 585.591058,119.60767 603.136719,102.574707 C620.682379,85.5417443 642.329298,77.0253906 668.078125,77.0253906 L668.078125,77.0253906 Z M666.369141,140.086914 C659.533169,140.086914 653.72268,142.564917 648.9375,147.520996 C644.15232,152.477076 641.759766,158.543909 641.759766,165.72168 C641.759766,172.785517 644.180803,178.823868 649.022949,183.836914 C653.865096,188.84996 659.647102,191.356445 666.369141,191.356445 C673.205112,191.356445 679.044084,188.84996 683.88623,183.836914 C688.728377,178.823868 691.149414,172.785517 691.149414,165.72168 C691.149414,158.543909 688.75686,152.477076 683.97168,147.520996 C679.1865,142.564917 673.319045,140.086914 666.369141,140.086914 L666.369141,140.086914 Z M887.34082,172.557617 L950.744141,170.165039 C948.921215,194.774537 939.749757,214.997317 923.229492,230.833984 C906.709227,246.670652 886.600379,254.588867 862.902344,254.588867 C837.837114,254.588867 816.674403,245.873134 799.413574,228.441406 C782.152746,211.009678 773.522461,189.647587 773.522461,164.354492 C773.522461,140.314658 782.238194,119.750085 799.669922,102.660156 C817.10165,85.5702271 838.008016,77.0253906 862.389648,77.0253906 C883.695094,77.0253906 902.493734,83.7473286 918.786133,97.1914062 C935.078532,110.635484 945.218405,127.782122 949.206055,148.631836 L884.435547,151.024414 C878.852837,143.732711 871.789105,140.086914 863.244141,140.086914 C855.952437,140.086914 849.971052,142.479468 845.299805,147.264648 C840.628557,152.049829 838.292969,158.08818 838.292969,165.379883 C838.292969,172.785519 840.770971,178.994767 845.727051,184.007812 C850.68313,189.020858 856.863895,191.527344 864.269531,191.527344 C875.093153,191.527344 882.783506,185.204165 887.34082,172.557617 L887.34082,172.557617 Z" id="-doc" fill="#FFFFFF"></path>
</g>
</svg>
\ No newline at end of file
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="page-scroll navbar-brand" href="#intro">{{ .Site.Title }}</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href={{ .Site.Params.project_url }}>Github</a>
</li>
<li>
<a class="page-scroll" href={{ .Site.Params.project_documentation }}>Docs</a>
</li>
<li>
<a class="page-scroll" href={{ .Site.Params.author_url }}>DangDang</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<script src="//cdn.bootcss.com/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<section id="services">
<!-- Page Content -->
{{ range $index, $element := where .Data.Pages "Section" "in" "index" }}
<div class="container">
<div class="row">
<div>
<div class="clearfix"></div>
{{ .Content }}
</div>
</div>
</div>
<!-- /.container -->
{{ end }}
<div class="container">
<div class="row">
<div>
<div class="clearfix"></div>
<h2>相关文档</h2>
<ul>
{{ range $index, $element := where .Data.Pages "Section" "in" "post" }}
<li> <a href="{{.Permalink}}" target="_blank">{{.Title}}</a></li>
{{ end }}
</ul>
</div>
</div>
</div>
<!-- /.container -->
</section>
<link rel="stylesheet" href="//cdn.bootcss.com/highlight.js/9.8.0/styles/monokai-sublime.min.css">
\ No newline at end of file
.navbar {
border-color: {{ .Site.Params.first_border_color }};
}
.content-section-a,
footer,
.navbar {
background-color: {{ .Site.Params.first_color }};
color: {{ .Site.Params.first_text_color }};
}
.navbar a:link,
.navbar-default .navbar-nav>li>a {
color: {{ .Site.Params.header_link_color }};
}
.navbar a:hover,
.navbar-default .navbar-nav>li>a:hover {
color: {{ .Site.Params.header_link_hover_color }};
}
.content-section-b {
background-color: {{ .Site.Params.second_color }};
color: {{ .Site.Params.second_text_color }};
}
body {
color: {{ .Site.Params.header_text_color }};
}
.header-container h1,
.header-container h2,
.header-container h3,
.header-container h4 {
color: {{ .Site.Params.header_text_color }};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册