MyCat 学习笔记 第八篇.数据分片 之 求摸运算分片
1 应用场景
Mycat 自带了多套数据分片的机制,其实根据数值取摸应该是最简单的一种。
优点:数据离散概率较为平均,可以有效的提高应用的数据吞吐。
缺点:比较明显,后期数据运维与迁移比较困难。好在Mycat有对应的解决方案,具体后期验证或可直接参考Mycat权威指南相应章节。
2 环境说明
参考 《MyCat 学习笔记》第六篇.数据分片 之 按月数据分片 http://www.cnblogs.com/kaye0110/p/5160826.html
3 参数配置
3.1 server.xml 配置
同上参考
3.2 schema.xml 配置
<!-- 配置 t_mod_long 数据表,分片规则为 mod-sharding-long ,数据结点有 4 个,注意在下面的 rule.xml 文件中其实只配置了3个, 因此dn7 不应该有数据才对 -->
<schema name="RANGEDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="t_range_date" dataNode="dn4,dn5,dn6,dn7,dn8,dn9,dn10,dn11" rule="sharding-by-date" />
<table name="t_range_long" dataNode="dn4,dn5,dn6" rule="sharding-long" />
<table name="t_mod_long" dataNode="dn4,dn5,dn6,dn7" rule="mod-sharding-long" />
</schema>
3.3 rule.xml 配置
<!-- 定义取摸运算规则 并设定 sharding_mod_id 为指定分片规则字段 -->
<tableRule name="mod-sharding-long">
<rule>
<columns>sharding_mod_id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<!-- 取摸运算的具体实现类,数字节点设为3个 dn4\dn5\dn6 -->
<function name="mod-long" class="org.opencloudb.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">3</property>
</function>
4 数据验证
4.1 Mycat 建表
mysql> CREATE TABLE `t_mod_long` (
-> `id` INT NOT NULL,
-> `sharding_mod_id` VARCHAR(45) NULL,
-> `context` VARCHAR(45) NULL,
-> PRIMARY KEY (`id`));
Query OK, 0 rows affected (0.02 sec)
4.2 数据插入与查询
insert into t_mod_long (id,sharding_mod_id,context) values (1,1,'test 1');
insert into t_mod_long (id,sharding_mod_id,context) values (2,2,'test 2');
insert into t_mod_long (id,sharding_mod_id,context) values (3,3,'test 3');
insert into t_mod_long (id,sharding_mod_id,context) values (4,4,'test 4');
insert into t_mod_long (id,sharding_mod_id,context) values (5,5,'test 5');
insert into t_mod_long (id,sharding_mod_id,context) values (6,6,'test 6');
insert into t_mod_long (id,sharding_mod_id,context) values (7,7,'test 7');
insert into t_mod_long (id,sharding_mod_id,context) values (8,8,'test 8');
insert into t_mod_long (id,sharding_mod_id,context) values (9,9,'test 9');
insert into t_mod_long (id,sharding_mod_id,context) values (10,10,'test 10');
insert into t_mod_long (id,sharding_mod_id,context) values (11,11,'test 11');
insert into t_mod_long (id,sharding_mod_id,context) values (12,12,'test 12');
insert into t_mod_long (id,sharding_mod_id,context) values (13,13,'test 13');
insert into t_mod_long (id,sharding_mod_id,context) values (14,14,'test 14');
Query OK, 1 row affected (0.01 sec)
...
mysql> select * from t_mod_long;
+----+-----------------+----------+
| id | sharding_mod_id | context |
+----+-----------------+----------+
| 3 | 3 | test 3 |
| 6 | 6 | test 6 |
| 9 | 9 | test 9 |
| 12 | 12 | test 12 |
| 1 | 1 | test 1 |
| 4 | 4 | test 4 |
| 7 | 7 | test 7 |
| 10 | 10 | test 10 |
| 13 | 13 | test 13 |
| 2 | 2 | test 2 |
| 5 | 5 | test 5 |
| 8 | 8 | test 8 |
| 11 | 11 | test 11 |
| 14 | 14 | test 14 |
+----+-----------------+----------+
14 rows in set (0.02 sec)
其实从数据反馈的角度已经可以很明确的发现,当前记录是进入了分片规则。
4.3 物理库查询
一共往数据库中新增记录 14 条,其实取摸后前 4 条记录进入 dn4 , dn5和dn6分别插入记录5条,dn7没有数据,验证通过。
mysql> select * from range_db_4.t_mod_long;
+----+-----------------+----------+
| id | sharding_mod_id | context |
+----+-----------------+----------+
| 3 | 3 | test 3 |
| 6 | 6 | test 6 |
| 9 | 9 | test 9 |
| 12 | 12 | test 12 |
+----+-----------------+----------+
4 rows in set (0.00 sec)
mysql> select * from range_db_5.t_mod_long;
+----+-----------------+----------+
| id | sharding_mod_id | context |
+----+-----------------+----------+
| 1 | 1 | test 1 |
| 4 | 4 | test 4 |
| 7 | 7 | test 7 |
| 10 | 10 | test 10 |
| 13 | 13 | test 13 |
+----+-----------------+----------+
5 rows in set (0.00 sec)
mysql> select * from range_db_6.t_mod_long;
+----+-----------------+----------+
| id | sharding_mod_id | context |
+----+-----------------+----------+
| 2 | 2 | test 2 |
| 5 | 5 | test 5 |
| 8 | 8 | test 8 |
| 11 | 11 | test 11 |
| 14 | 14 | test 14 |
+----+-----------------+----------+
5 rows in set (0.00 sec)
mysql> select * from range_db_7.t_mod_long;
Empty set (0.00 sec)
本篇完。
个人原创学习资料,若要转载,请加入原始地址 http://www.cnblogs.com/kaye0110/p/5162957.html
MyCat 学习笔记 第八篇.数据分片 之 求摸运算分片的更多相关文章
- MyCat 学习笔记 第十篇.数据分片 之 ER分片
1 应用场景 这篇来说下mycat中自带的er关系分片,所谓er关系分片即可以理解为有关联关系表之间数据分片.类似于订单主表与订单详情表间的分片存储规则. 本文所说的er分片分为两种: a. 依据主键 ...
- MyCat 学习笔记 第七篇.数据分片 之 按数据范围分片
1 应用场景 Mycat 其实自带了2个数据范围分片的方案,一个是纯数据范围的分片,比如 1至 10000 号的数据放到分片1 ,10001 至 20000号数据放到分片2里. 另一个是数据常量形式的 ...
- MyCat 学习笔记 第六篇.数据分片 之 按月数据分片
1 应用场景 Mycat 有很多数据分库规则,接下来几篇就相关觉得常用的规则进行试用与总结. 一般来说,按自然月份来进行数据分片的规则比较适用于商城订单查询,类似最近1周.2周.3个月内的数据.或是报 ...
- MyCat 学习笔记 第十三篇.数据分片 之 通过HINT执行存储过程
1 环境说明 VM 模拟3台MYSQL 5.6 服务器 VM1 192.168.31.187:3307 VM2 192.168.31.212:3307 VM3 192.168.31.150: 330 ...
- MyCat 学习笔记 第十一篇.数据分片 之 分片数据查询 ( select * from table_name limit 100000,100 )
1 环境说明 VM 模拟3台MYSQL 5.6 服务器 VM1 192.168.31.187:3307 VM2 192.168.31.212:3307 VM3 192.168.31.150: 330 ...
- ES[7.6.x]学习笔记(八)数据的增删改
在前面几节的内容中,我们学习索引.字段映射.分析器等,这些都是使用ES的基础,就像在数据库中创建表一样,基础工作做好以后,我们就要真正的使用它了,这一节我们要看看怎么向索引里写入数据.修改数据.删除数 ...
- Django学习笔记第八篇--实战练习四--为你的视图函数自定义装饰器
零.背景: 对于登录后面所有视图函数,都需要验证登录信息,一般而言就是验证cookie里面的一些信息.所以你可以这么写函数: def personinfo(request): ": retu ...
- Vue.js学习笔记 第八篇 组件
全局注册组件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...
- MyCat 学习笔记 第九篇.数据分片 之 数值分布
1 应用场景 Mycat 自带了多套数据分片的机制,其实根据数值分片也是比较简单,其实这个和数据取摸是类似的实现. 优.缺点同上一篇 2 环境说明 参考 <MyCat 学习笔记>第六篇. ...
随机推荐
- .net winform程序下使用firefox作为Web浏览器
在winform程序中,要在程序中展示一个web页面,最常用的就是.net自带的webbrowser,但是大家都知道它是IE,也知道IE是有多么强(er)大(bi).而且微软已经宣布了IE的死亡... ...
- mysql如何更改数据库名(一键实现mysql改数据库名)
由于某种原因,有时我们有可能需要数据库的名称,但是不像官方有rename可以去更改表名,并没有一个命令可以去更新数据库的名字. 思路:借助rename这个命令 基本操作:rename olddb.ta ...
- MySQL5中大数据错误:Packet for query is too large (****** > ******). You can change this value on the server by setting the max_allowed_packet' variable.;
使用的MySQL数据库版本:5.5 插入或更新字段有大数据时(大于1M),会出现如下错误: ### Cause: com.mysql.jdbc.PacketTooBigException: Packe ...
- 重构第29天 去除中间人对象(Remove Middle Man)
理解:本文中的”去除中间人对象”是指把 在中间关联而不起任何其他作用的类移除,让有关系的两个类直接进行交互. 详解:有些时候在我们的代码会存在一些”幽灵类“,设计模式大师Martin Fowler称它 ...
- 设计模式--简单工厂(Factory)模式
温故而知新,看了以前写的博文<Asp.net读取Excel文件 2>http://www.cnblogs.com/insus/archive/2011/05/05/2037808.html ...
- C#验证身份证号码
一.18位的身份证号码 如:130429####%%%%00781.1~6位为地区代码,其中1.2位数为各省级政府的代码,3.4位数为地.市级政府的代码,5.6位数为县.区级政府代码.如13(河北省) ...
- 重新想象 Windows 8 Store Apps (54) - 绑定: 增量方式加载数据
[源码下载] 重新想象 Windows 8 Store Apps (54) - 绑定: 增量方式加载数据 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 绑定 通过实 ...
- fibonacci数列从a到b的个数
Description 我们定义斐波那契数列如下: f1=1 f2=2 f(n)=f(n-1)+f(n-2)(n>=3) 现在,给定两个数a和b,计算有多少个斐波那契数列中的数在a和b之间( ...
- Oracle 查询并删除重复记录的SQL语句
查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select ...
- c#多线程生产者消费者(手稿)
屋舍简陋,隔壁的娃娃哭了一晚,心中无恶意纯中性的想,有病就赶紧带孩子去看医生吧,能哭这么久估计孩子真的不舒服.