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 学习笔记>第六篇. ...
随机推荐
- 重构第12天 分解依赖(Break Dependencies)
理解:“分解依赖” 是指对部分不满足我们要求的类和方法进行依赖分解,通过装饰器来达到我们需要的功能. 详解:今天我们所讲的这个重构方法对于单元测试是非常有用的.如果你要在你的代码中加入单元测试但有一部 ...
- [WCF实践]1.WCF使用net.tcp寄宿到IIS中
一.IIS部分 环境:Windows Server 2008 R2 1.安装WAS,如下图所示: 2.网站net.tcp协议绑定,如下图所示: 3.网站启用net.tcp,如下图所示: 二 ...
- 自定义动画方法animate
animate的使用方法:animate(params,speed,callback); 例子:animate({ right: "-=600px",height:"+= ...
- FreeBSD 9.1安装KMS 这是一个伪命题###### ,9....
FreeBSD 9.1安装KMS 这是一个伪命题###### ,9.1的内核已经加入了KMS内核支持 需要更新ports中的xorg到打了补丁的版本,无意中发现了一个pkg源,这个事也搞定了 free ...
- UGUI之布局的使用
unity的LayoutGroup分为三种, Horizontal Layout Group(水平布局):对象填充总个父物体,水平会填充 Vertical Layout Group(垂直布局):垂直( ...
- Java与线程
导语 我们知道,new一个thread,调用它的start的方法,就可以创建一个线程,并且启动该线程,然后执行该线程需要执行的业务逻辑, 那么run方法是怎么被执行的呢? Java线程和os线程 os ...
- LGLProgressHUD
不想用第三方的指示器,感觉有点大,自己写了一个简单的活动指示器,目前只有两种效果.效果如图 第一种: 第二种 第二种可以随着提示文字的增多而变长 LGLProgressHUD.h // // LGLP ...
- (旧)子数涵数·VB——变量
最近,VB吧频繁出现如下图所示的帖子(现在C吧.VB吧等都已经被二级考生玩坏了) 这主要用到的是变量的概念 首先,我们来看一下变量的数据类型 当然,就这题而言,数据类型不是重点,主要考察的是变量的作用 ...
- ASP.NET Web API 特性
ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP.NET Web API 也是构建 RES ...
- [Tool] 使用Astah绘制UML图形
[Tool] 使用Astah绘制UML图形 前言 在软件开发的过程中,开发人员可以绘制UML图形来将分析设计内容转化为图形化文件,方便在团队之间传递分析设计结果.但在团队经费有限的情景中,可能没办法为 ...