Mycat sharding rule sharding-by-murmur

Source: Internet
Author: User

Mycat sharding rule sharding-by-murmur
The murmur algorithm hash fields and distribute them to different databases. The field types support int and varchar.
1. rule. xml

  1. <TableRule name = "sharding-by-murmur-userid">
  2. <Rule>
  3. <Columns> userid </columns>
  4. <Algorithm> murmur </algorithm>
  5. </Rule>
  6. </TableRule>

  7. <Function name = "murmur"
  8. Class = "io. mycat. route. function. partitionbymurhash">
  9. <Property name = "seed"> 0 </property> <! -- The default value is 0 -->
  10. <Property name = "count"> 6 </property> <! -- The number of database nodes to be sharded must be specified; otherwise, the database nodes cannot be sharded. -->
  11. <Property name = "virtualBucketTimes"> 160 </property> <! -- If an actual database node is mapped to so many virtual nodes, the default value is 160 times.
  12. The number of virtual nodes is 160 times the number of physical nodes -->
  13. <! -- <Property name = "weightMapFile"> weightMapFile </property> indicates the node weight. If no weight is specified, the default value is 1. Take the properties File
  14. Enter the value in the format, starting from 0 to count-1, that is, the node index is the key, and the node weight is the value. The ownership value must be a positive integer. Otherwise, replace 1 with -->
  15. <! -- <Property name = "bucketMapPath">/etc/mycat/bucketMapPath </property>
  16. Observe the distribution of each physical node and virtual node during the test. If this attribute is specified, the murmur hash value of the virtual node is mapped to the physical node.
  17. Output to this file by row. No default value exists. If this parameter is not specified, nothing will be output. -->
  18. </Function>
Name = "count" is set based on the number of sub-databases. I have 6 sub-databases here.


2. schema. xml configuration file

  1. <? Xml version = "1.0"?>
  2. <! DOCTYPE mycat: schema SYSTEM "schema. dtd">
  3. <Mycat: schema xmlns: mycat = "http://io.mycat/">

  4. <Schema name = "logdb" checkSQLschema = "false" sqlMaxLimit = "100">
  5. <Table name = "tb_log_t" primaryKey = "ID" autoIncrement = "true" dataNode = "dn1, dn2, dn3, dn4, dn5, dn6 "rule =" mod-long "/>
  6. <Table name = "tb_user_t" dataNode = "dn1, dn2, dn3, dn4, dn5, dn6" rule = "sharding-by-intfile-provcode"/>
  7. <Table name = "tb_user_detail_t" dataNode = "dn1, dn2, dn3, dn4, dn5, dn6" rule = "auto-sharding-long-userid"/>
  8. <Table name = "tb_user_murmur_t" dataNode = "dn1, dn2, dn3, dn4, dn5, dn6" rule = "sharding-by-murmur"/>
  9. <Table name = "tb_user_murmur_string_t" dataNode = "dn1, dn2, dn3, dn4, dn5, dn6" rule = "sharding-by-murmur-userid"/>
  10. </Schema>
  11. <Schema name = "coss03" checkSQLschema = "false" sqlMaxLimit = "100" dataNode = "dnoss03"/>
  12. <DataNode name = "dn1" dataHost = "localhost1" database = "log01"/>
  13. <DataNode name = "dn2" dataHost = "localhost1" database = "log02"/>
  14. <DataNode name = "dn3" dataHost = "localhost1" database = "log03"/>
  15. <DataNode name = "dn4" dataHost = "localhost1" database = "log04"/>
  16. <DataNode name = "dn5" dataHost = "localhost1" database = "log05"/>
  17. <DataNode name = "dn6" dataHost = "localhost1" database = "log06"/>
  18. <DataNode name = "dnoss03" dataHost = "localhost1" database = "oss03"/>
  19. <DataHost name = "localhost1" maxCon = "1000" minCon = "10" balance = "0"
  20. WriteType = "0" dbType = "mysql" dbDriver = "native" switchType = "1" slaveThreshold = "100">
  21. <Heartbeat> select user ()
  22. <! -- Can have multi write hosts -->
  23. <WriteHost host = "hostM1" url = "192.168.56.141: 3306" user = "root"
  24. Password = "mysql">
  25. <! -- Can have multi read hosts -->
  26. <ReadHost host = "hostS2" url = "192.168.56.142: 3306" user = "root" password = "mysql"/>
  27. </WriteHost>
  28. </DataHost>
  29. </Mycat: schema>


3. Create a table


Create table 'tb _ user_murmur_string_t '(
'Userid' varchar (32) not null,
'Name' varchar (64) default null,
'Createtime' datetime DEFAULT CURRENT_TIMESTAMP,
'Moditytime' datetime DEFAULT CURRENT_TIMESTAMP,
Primary key ('userid ')
) ENGINE = InnoDB default charset = utf8;


Write Data
Insert into tb_user_murmur_string_t (userid, name) values ('user002', 'name002 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user003 ', 'name003 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user004 ', 'name004 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user005 ', 'name005 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user006 ', 'name006 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user007 ', 'name007 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user008 ', 'name008 ');
Insert into tb_user_mur_string_t (userid, name) values ('user009', 'name009 ');
Insert into tb_user_murmur_string_t (userid, name) values ('user010 ', 'name010 ');

-- The End --

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.