forked from mercyblitz/java-training-camp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7c4122
commit 2f42a18
Showing
3 changed files
with
171 additions
and
9 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
stage-2/docs/26. 第二十六节:基于 ShardingSphere 实现数据分片和读写分离.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
> <a name="ZMjg7"></a> | ||
#### 主要内容 | ||
> - 数据分片:使用 ShardingSphere 实现分库、分表、分库+分表以及强制路由 | ||
> - 读写分离:使用 ShardingSphere 实现数据读写分离 | ||
> - 底层原理(加餐):讨论 ShardingSphere 底层实现原理 | ||
|
||
<a name="qn9UY"></a> | ||
# MySQL JDBC Driver | ||
<a name="GXdza"></a> | ||
## MySQL JDBC Listener | ||
<a name="jRNlZ"></a> | ||
### MySQL JDBC Connection 拦截器 - ConnectionLifecycleInterceptor | ||
<a name="FXMmc"></a> | ||
### MySQL JDBC 异常拦截器 - ExceptionInterceptor | ||
<a name="mjxyf"></a> | ||
### MySQL JDBC 命令拦截器 - QueryInterceptor | ||
|
||
<a name="uyBDz"></a> | ||
### MySQL JDBC URL 属性 | ||
<a name="Fba98"></a> | ||
### MySQL JDBC 属性集合 - JdbcPropertySet | ||
|
||
|
||
|
||
<a name="zlwtB"></a> | ||
# ShardingSphere | ||
<a name="ZFY0V"></a> | ||
## ShardingSphere 介绍 | ||
Apache ShardingSphere 是一款分布式的数据库生态系统, 可以将任意数据库转换为分布式数据库,并通过数据分片、弹性伸缩、加密等能力对原有数据库进行增强。<br />Apache ShardingSphere 设计哲学为 Database Plus,旨在构建异构数据库上层的标准和生态。 它关注如何充分合理地利用数据库的计算和存储能力,而并非实现一个全新的数据库。 它站在数据库的上层视角,关注它们之间的协作多于数据库自身。 | ||
|
||
<a name="GiVan"></a> | ||
### 类似产品 | ||
<a name="UZoeE"></a> | ||
#### Alibaba TDDL | ||
|
||
<a name="vvceD"></a> | ||
### ShardingSphere-JDBC | ||
ShardingSphere-JDBC 定位为轻量级 Java 框架,在 Java 的 JDBC 层提供的额外服务。 | ||
|
||
<a name="cwxfr"></a> | ||
### ShardingSphere-Proxy | ||
ShardingSphere-Proxy 定位为透明化的数据库代理端,通过实现数据库二进制协议,对异构语言提供支持。 | ||
|
||
<a name="e3XX5"></a> | ||
### 产品功能 | ||
| **特性** | **定义** | | ||
| --- | --- | | ||
| 数据分片 | 数据分片,是应对海量数据存储与计算的有效手段。ShardingSphere 基于底层数据库提供分布式数据库解决方案,可以水平扩展计算和存储。 | | ||
| 分布式事务 | 事务能力,是保障数据库完整、安全的关键技术,也是数据库的核心技术。基于 XA 和 BASE 的混合事务引擎,ShardingSphere 提供在独立数据库上的分布式事务功能,保证跨数据源的数据安全。 | | ||
| 读写分离 | 读写分离,是应对高压力业务访问的手段。基于对 SQL 语义理解及对底层数据库拓扑感知能力,ShardingSphere 提供灵活的读写流量拆分和读流量负载均衡。 | | ||
| 数据迁移 | 数据迁移,是打通数据生态的关键能力。ShardingSphere 提供跨数据源的数据迁移能力,并可支持重分片扩展。 | | ||
| 联邦查询 | 联邦查询,是面对复杂数据环境下利用数据的有效手段。ShardingSphere 提供跨数据源的复杂查询分析能力,实现跨源的数据关联与聚合。 | | ||
| 数据加密 | 数据加密,是保证数据安全的基本手段。ShardingSphere 提供完整、透明、安全、低成本的数据加密解决方案。 | | ||
| 影子库 | 在全链路压测场景下,ShardingSphere 支持不同工作负载下的数据隔离,避免测试数据污染生产环境。 | | ||
|
||
<a name="yG1kJ"></a> | ||
### 产品优势 | ||
|
||
- 极致性能 | ||
|
||
驱动程序端历经长年打磨,效率接近原生 JDBC,性能极致。 | ||
|
||
- 生态兼容 | ||
|
||
代理端支持任何通过 MySQL/PostgreSQL 协议的应用访问,驱动程序端可对接任意实现 JDBC 规范的数据库。 | ||
|
||
- 业务零侵入 | ||
|
||
面对数据库替换场景,ShardingSphere 可满足业务无需改造,实现平滑业务迁移。 | ||
|
||
- 运维低成本 | ||
|
||
在保留原技术栈不变前提下,对 DBA 学习、管理成本低,交互友好。 | ||
|
||
- 安全稳定 | ||
|
||
基于成熟数据库底座之上提供增量能力,兼顾安全性及稳定性。 | ||
|
||
- 弹性扩展 | ||
|
||
具备计算、存储平滑在线扩展能力,可满足业务多变的需求。 | ||
|
||
- 开放生态 | ||
|
||
通过多层次(内核、功能、生态)插件化能力,为用户提供可定制满足自身特殊需求的独有系统。 | ||
|
||
<a name="Li9vM"></a> | ||
## [用户手册](https://shardingsphere.apache.org/document/current/cn/user-manual/) | ||
|
||
<a name="JKinN"></a> | ||
## 架构设计 | ||
<a name="UJtXm"></a> | ||
### API 设计 | ||
<a name="gmyfS"></a> | ||
#### 配置(Configurations) | ||
<a name="ufjZm"></a> | ||
##### 类型 | ||
|
||
- YAML | ||
- Properties | ||
<a name="RcMXa"></a> | ||
##### YAML 配置 - YamlConfiguration | ||
<a name="Pl74Y"></a> | ||
##### 规则配置 - RuleConfiguration | ||
|
||
<a name="hOVds"></a> | ||
#### YAML 规则配置交换器 - YamlRuleConfigurationSwapper | ||
YamlRuleConfiguration <-> RuleConfiguration | ||
<a name="YBr4w"></a> | ||
#### 规则(Rules) | ||
<a name="eXSwH"></a> | ||
##### 规则 API - ShardingSphereRule | ||
关联规则配置 - getRuleConfiguration()<br />规则类型 - getType() | ||
```java | ||
public interface ShardingSphereRule { | ||
|
||
/** | ||
* Get rule configuration. | ||
* | ||
* @return rule configuration | ||
*/ | ||
RuleConfiguration getConfiguration(); | ||
|
||
/** | ||
* Get type. | ||
* | ||
* @return rule type | ||
*/ | ||
String getType(); | ||
} | ||
``` | ||
<a name="enPXv"></a> | ||
#### 模式(Mode) | ||
元数据存储模式(方式) | ||
<a name="zY6xC"></a> | ||
#### 存储仓库 - PersistRepository | ||
<a name="VFebI"></a> | ||
##### 独立存储仓库 - StandalonePersistRepository | ||
mode : Standalone | ||
<a name="SHqxY"></a> | ||
##### 集群存储仓储 - ClusterPersistRepository | ||
mode : Cluster | ||
<a name="FbPzi"></a> | ||
#### 数据源(DataSources) | ||
<a name="BdSYl"></a> | ||
##### 数据源属性 - DataSourceProperties | ||
YAML 配置和当前 POJO 映射 | ||
|
||
<a name="UFTAL"></a> | ||
##### 数据源连接池创建器 - DataSourcePoolCreator | ||
|
||
|
||
<a name="P4h7h"></a> | ||
#### 路由器(Router) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters