shardingsphere 5.0.0
pom
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.0</version>
</dependency>
yml
# 数据源
# 参考
# https://blog.csdn.net/if_icanfly/article/details/120063523?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link
spring:
# datasource:
# type: com.zaxxer.hikari.HikariDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
# username: root
# password: root
# url: jdbc:mysql://172.19.1.251:3306/yoyo?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
shardingsphere:
datasource:
names: master,slave
master:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
jdbc-url: jdbc:mysql://172.19.1.251:3306/database?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
slave:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
jdbc-url: jdbc:mysql://172.19.1.251:3306/database?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
props:
sql-show: true
enabled: true
rules:
# 读写分离
readwrite_splitting:
data-sources:
# database name
database:
auto-aware-data-source-name: master,slave
write-data-source-name: master
read-data-source-names: slave
load-balancers-name: round-robin
load-balancers:
# 轮训有多种,具体查看 shardingsphere 官网
round-robin:
type: ROUND_ROBIN
props:
workId: 1
sharding:
tables:
# table name
table_name:
actual-data-nodes: master.table_name_$->{0..0}
table-strategy:
standard:
sharding-column: table_column
sharding-algorithm-name: account-inline
table_name:
actual-data-nodes: master.table_name_$->{0..0}
table-strategy:
standard:
sharding-column: table_column
# algorithm-name 为自定义,与 sharding-algorithms 下 对应
sharding-algorithm-name: account-inline
table_name:
# master_$->{}.table_name_$->{} 具体查看 shardingsphere 官网的 行表达式
actual-data-nodes: master.table_name_$->{0..0}
table-strategy:
standard:
sharding-column: table_column
sharding-algorithm-name: short-inline
# INTERVAL 时间范围分片算法 按照月份分片
table_name:
actual-data-nodes: master.table_name_$->{2021..2023}_$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
table-strategy:
standard:
sharding-column: create_time
sharding-algorithm-name: table-interval
sharding-algorithms:
account-inline:
type: MOD
props:
# mod 获取 properties 为 get() 后 toString 然后进行 parse int
sharding-count: 1
short-inline:
type: HASH_MOD
props:
# hash_mod 获取 properties 为 getPropertity() 后进行 parse int
sharding-count: '1'
# 时间范围分片
table-interval:
type: INTERVAL
props:
datetime-pattern: "yyyy-MM-dd HH:mm:ss"
datetime-lower: "2021-01-01 00:00:00"
datetime-upper: "2023-12-31 23:59:59"
sharding-suffix-pattern: "yyyy_MM"
datetime-interval-amount: "1"
datetime-interval-unit: "MONTHS"
** 注意 **
MOD 以及 HASH_MOD 理应为 auto_table 的分片方法,但是 在 table 中可以使用,sharding 官方认为这是一个bug ,后期可能会将其解决掉
shardingsphere 5.0.0的更多相关文章
- 重磅|Apache ShardingSphere 5.0.0 即将正式发布
Apache ShardingSphere 5.0.0 GA 版在经历 5.0.0-alpha 及 5.0.0-beta 接近两年时间的研发和打磨,终于将在 11 月份与大家正式见面! 11 月 10 ...
- Apache ShardingSphere 5.0.0 内核优化及升级指南
经过近两年时间的优化和打磨,Apache ShardingSphere 5.0.0 GA 版终于在本月正式发布,相比于 4.1.1 GA 版,5.0.0 GA 版在内核层面进行了大量的优化.首先,基于 ...
- ElasticJob 3.0.0:打造面向互联网生态和海量任务的分布式调度解决方案
ElasticJob 于 2020 年 5 月 28 日重启并成为 Apache ShardingSphere 子项目.新版本借鉴了 ShardingSphere 可拔插架构的设计理念,对内核进行了大 ...
- 官宣!ElasticJob 3.0.0 版本正式发布
ElasticJob 是面向互联网生态和海量任务的分布式调度解决方案,由两个相互独立的子项目 ElasticJob-Lite 和 ElasticJob-Cloud 组成.它通过弹性调度.资源管控.以及 ...
- sharding-jdbc5.0.0分表实践
本文基于shardingsphere-jdbc-core-spring-boot-starter 5.0.0,请注意不同版本的sharding-jdbc配置可能有不一样的地方,本文不一定适用于其它版本 ...
- ShardingSphere-proxy-5.0.0部署之分表实现(一)
一.说明 环境准备:JDK8+ mysql 5.x 官网:https://shardingsphere.apache.org/ 下载地址:https://archive.apache.org/ ...
- ShardingSphere-proxy-5.0.0分布式雪花ID生成(三)
一.目的 保证在分库分表中每条数据具有唯一性 二.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Founda ...
- ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)
一.说明 主要是对字符串的字段进行hash取模 二.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Found ...
- ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
一.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Foundation (ASF) under one or ...
- ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
一.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Foundation (ASF) under one or ...
随机推荐
- 我曾经用“UC震惊部”震碎了很多人的三观
Hi,欢迎大家在有空的时候做客[江涛学编程],这里是2023年的第9篇原创文章,今天写的这篇是当事人对昨天上热搜的统一回复. 我没有曾经跨过山河大海,我也没有曾经穿越人山人海,但我曾经用"U ...
- [LeetCode]二进制求和
题目 代码 class Solution { public: string addBinary(string a, string b) { int lenA = a.length(); int len ...
- Java学习笔记:2022年1月11日
Java学习笔记:2022年1月11日 摘要:这篇笔记主要讲解了一些数据在计算机中的存在方式相关的知识点,并由此延伸出了数据在计算机中的操作以及一些数据结构的知识. @ 目录 Java学习笔记:2 ...
- 如何实现在react现有项目中嵌入Blazor?
如何实现在react现有项目中嵌入Blazor? 目前官方只提供了angular和react俩种示例所以本教程只将react教程 思路讲解: 首先在现有react项目中我们可能某些组件是在Blazor ...
- jupyter的配置
step1.安装jupyter 使用pip或者conda等包管理工具安装jupyter(这部分倒是没有任何难度,一般也没有什么坑) conda install jupyter notebook或者pi ...
- 11月18日内容总结——同步、异步与阻塞、非阻塞的概念、创建进程的多种方式及multiprocessing模块、进程间的数据隔离和IPC机制(队列)、生产者消费者模型、守护进程、僵尸进程、孤儿进程和多进程错乱问题
目录 一.同步与异步 同步 异步 二.阻塞与非阻塞 阻塞 非阻塞 三.综合使用 1.同步阻塞: 2.同步非阻塞: 3.异步阻塞: 4.异步非阻塞: 四.创建进程的多种方式 进程的创建 multipro ...
- .NET遍历二维数组-先行/先列哪个更快?
上周在.NET性能优化群里面有一个很有意思的讨论,讨论的问题如下所示: 请教大佬:2D数组,用C#先遍历行再遍历列,或者先遍历列再遍历行,两种方式在性能上有区别吗? 据我所知,Julia或者pytho ...
- 线程基础知识17 Quene
1 ConcurrentLinkedQueue 1.1 简介 它是一个基于链接节点的无界线程安全队列.此队列按照 FIFO(先进先出)原则对元素进行排序. 新的元素插入到队列的尾部,队列获取操作从队列 ...
- IDEA插件:lombok
1 安装插件lombok File => Settings => Plugins => Marketplace.在 Marketplace 中搜索 lombok 并安装,安装成功后 ...
- 线程基础知识11-CAS+自旋锁
1.CAS是什么(CompareAndSet) CAS(Compare and swap)比较和替换是设计并发算法时用到的一种技术.简单来说,比较和替换是使用一个期望值和一个变量的当前值进行比较,如果 ...