[logseq-plugin-git:commit] 2025-06-18T08:57:35.296Z
This commit is contained in:
BIN
assets/image_1750234065362_0.png
Normal file
BIN
assets/image_1750234065362_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 626 KiB |
BIN
assets/image_1750234447742_0.png
Normal file
BIN
assets/image_1750234447742_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 631 KiB |
BIN
assets/image_1750234466701_0.png
Normal file
BIN
assets/image_1750234466701_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 404 KiB |
BIN
assets/image_1750234767614_0.png
Normal file
BIN
assets/image_1750234767614_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
BIN
assets/image_1750234843093_0.png
Normal file
BIN
assets/image_1750234843093_0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
@@ -1,2 +1,2 @@
|
||||
- [[长时间阅读就是大脑的马拉松]]
|
||||
-
|
||||
- [[ShardingSphere]]
|
||||
37
pages/ShardingSphere.md
Normal file
37
pages/ShardingSphere.md
Normal file
@@ -0,0 +1,37 @@
|
||||
- [[读写分离]]
|
||||
- [[数据库分片]]
|
||||
- 实现方式
|
||||
- 程序代码封装
|
||||
- 在数据访问层DAO层添加对应的处理逻辑
|
||||
- 中间件封装
|
||||
- MyCat
|
||||
- 对业务来说,访问中间件和数据库没有区别
|
||||
- Apache ShardingSphere
|
||||
- ShardingSphere-JDBC
|
||||
- 在JDBC层提供的额外服务
|
||||
- 
|
||||
- ShardingSphere-Proxy
|
||||
- 透明的数据库代理端
|
||||
- 
|
||||
- Sidecar(规划中)
|
||||
- 广播表
|
||||
- 所有分片数据源都存在的表,结构且数据在每个数据库当中完全一致,适用于数据量不大但是需要与海量数据表关联查询的场景(字典表)
|
||||
- ```properties
|
||||
#数据节点可不配置,默认情况下,向所有数据源广播
|
||||
spring.shardingsphere.rules.sharding.tables.t_dict.actual-data-nodes=server-user.t_dict,server-order$->{0..1}.t_dict
|
||||
|
||||
# 广播表
|
||||
spring.shardingsphere.rules.sharding.broadcast-tables[0]=t_dict
|
||||
|
||||
```
|
||||
- 启动方式
|
||||
- 二进制
|
||||
- Docker
|
||||
- 启动镜像
|
||||
- 上传MySQL驱动
|
||||
- 修改server.yaml
|
||||
- 修改config-readwrite-splitting.yaml
|
||||
- 需要配置垂直分片,水平分片
|
||||
- 需要配置各个表及其对应的服务器
|
||||
- Helm
|
||||
-
|
||||
93
pages/数据库分片.md
Normal file
93
pages/数据库分片.md
Normal file
@@ -0,0 +1,93 @@
|
||||
- 垂直拆分
|
||||
- 垂直分库
|
||||
- 按照业务对数据库进行拆分
|
||||
- 
|
||||
- ```properties
|
||||
# 读写分离类型,如: Static,Dynamic
|
||||
spring.shardingsphere.rules.readwrite-splitting.data-sources.myds.type=Static
|
||||
# 写数据源名称
|
||||
spring.shardingsphere.rules.readwrite-splitting.data-sources.myds.props.write-data-source-name=master
|
||||
# 读数据源名称,多个从数据源用逗号分隔
|
||||
spring.shardingsphere.rules.readwrite-splitting.data-sources.myds.props.read-data-source-names=slave1,slave2
|
||||
|
||||
# 负载均衡算法名称
|
||||
spring.shardingsphere.rules.readwrite-splitting.data-sources.myds.load-balancer-name=alg_round
|
||||
```
|
||||
- 垂直分表
|
||||
- 拆分表中某些不常用的列,或者是占用了大量空间的列
|
||||
- {:height 401, :width 749}
|
||||
- ```properties
|
||||
# 标准分片表配置(数据节点)
|
||||
# spring.shardingsphere.rules.sharding.tables.<table-name>.actual-data-nodes=值
|
||||
# 值由数据源名 + 表名组成,以小数点分隔。
|
||||
# <table-name>:逻辑表名
|
||||
spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=server-user.t_user
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=server-order.t_order
|
||||
```
|
||||
- 水平拆分
|
||||
- 水平分片
|
||||
- 通过id区分
|
||||
- 水平分片的id需要在业务层实现,不能依赖数据库的主键自增
|
||||
- 单表超过500万行或者超过2G才进行拆分
|
||||
- ```properties
|
||||
#========================标准分片表配置(数据节点配置)
|
||||
# spring.shardingsphere.rules.sharding.tables.<table-name>.actual-data-nodes=值
|
||||
# 值由数据源名 + 表名组成,以小数点分隔。多个表以逗号分隔,支持 inline 表达式。
|
||||
# <table-name>:逻辑表名
|
||||
spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=server-user.t_user
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=server-order0.t_order0,server-order0.t_order1,server-order1.t_order0,server-order1.t_order1
|
||||
|
||||
# ##取模算法配置
|
||||
#------------------------分库策略
|
||||
# 分片列名称
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-column=user_id
|
||||
# 分片算法名称
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-algorithm-name=alg_inline_userid
|
||||
|
||||
#------------------------分片算法配置
|
||||
# 行表达式分片算法
|
||||
# 分片算法类型
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_inline_userid.type=INLINE
|
||||
# 分片算法属性配置
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_inline_userid.props.algorithm-expression=server-order$->{user_id % 2}
|
||||
|
||||
# 取模分片算法
|
||||
# 分片算法类型
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_mod.type=MOD
|
||||
# 分片算法属性配置
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_mod.props.sharding-count=2
|
||||
|
||||
# ##哈希取模分片
|
||||
#------------------------分表策略
|
||||
# 分片列名称
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_no
|
||||
# 分片算法名称
|
||||
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=alg_hash_mod
|
||||
|
||||
|
||||
#------------------------分片算法配置
|
||||
# 哈希取模分片算法
|
||||
# 分片算法类型
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_hash_mod.type=HASH_MOD
|
||||
# 分片算法属性配置
|
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.alg_hash_mod.props.sharding-count=2
|
||||
|
||||
# 算法雪花
|
||||
```
|
||||
- ```java
|
||||
//@TableId(type = IdType.AUTO)//依赖数据库的主键自增策略
|
||||
@TableId(type = IdType.ASSIGN_ID)//分布式id
|
||||
```
|
||||
- 分片策略
|
||||
- 行表达式
|
||||
- 取模
|
||||
- 哈希取模
|
||||
- 雪花算法
|
||||
- 配置选项
|
||||
- 分库策略
|
||||
- 分片列
|
||||
- 分片算法
|
||||
- 分表策略
|
||||
- 分布式序列策略
|
||||
- 绑定表配置
|
||||
- 配置以后关联查询不会出现笛卡尔积
|
||||
24
pages/读写分离.md
Normal file
24
pages/读写分离.md
Normal file
@@ -0,0 +1,24 @@
|
||||
- 
|
||||
- 主库负责修改,从库负责查询
|
||||
- 通过对SQL语义进行分析,将操作路由到不同的库上
|
||||
- CAP理论
|
||||
- Consistency
|
||||
- Availability
|
||||
- Partition Tolerance
|
||||
- C在实践中是不可能完美实现的,做不到强一致性,但是可以做到最终一致性
|
||||
- BASE
|
||||
- Basic Available 基本可用
|
||||
- Soft State 软状态/中间状态
|
||||
- Eventual Consistency 最终一致
|
||||
- 主从同步
|
||||
- salve从master读取binlog来同步数据
|
||||
- binlog格式
|
||||
- STATEMENT
|
||||
- ROW
|
||||
- MIXED
|
||||
- 事务
|
||||
- 保证主从库之间数据一致性, [[ShardingSphere]]中事务的读写均使用主库
|
||||
- 不添加@Transactional:insert对主库操作,select对从库操作
|
||||
- 添加@Transactional:则insert和select均对主库操作
|
||||
- JUnit环境下的@Transactional注解,默认情况下就会对事务进行回滚(即使在没加注解@Rollback,也会对事务回滚)
|
||||
-
|
||||
Reference in New Issue
Block a user