Read "Distributed database architecture and Enterprise Practice"---notes four _ reading notes

Source: Internet
Author: User
Tags modulus
Detailed explanation of Mycat fragment rules
Er Relation Fragment table
ER model is an entity relation model, which is widely used in conceptual pattern design, which is the entity, relation and attribute of the basic elements. Mycat creatively introduced it into the data segmentation rules, so that the interdependent tables can be divided into the same node according to a rule, avoiding Cross Library Join Association query.

Fragment Rule Rule.xml file detailed
1.Function Label
<function name= "Rang-mod" class= "Org.opencloudb.route.function.PartitionByRangeMod" >
<property name= "Mapfile" >partition-range-mod.txt</property>
</function>
Interpretation: The Name property specifies the names of the algorithms in which the file is unique.
Class attribute corresponding to the specific slicing algorithm, you need to specify the specific algorithm class.
Property properties are specified according to the algorithm's requirements.
2.tableRule Label
<tablerule name= "Auto-sharding-rang-mod" >
<rule>
<columns>id</columns>
<algorithm>rang-mod</algorithm>
</rule>
</tableRule>
Interpretation: The Name property specifies the names of piecewise unique algorithms.
The Rule property specifies the exact contents of the algorithm, including the columns and algorithm two properties.
The Columns property specifies the name of the column used for fragmentation in the corresponding table.
The algorithm property corresponds to the name of the algorithm specified in the function.

Take modulus Fragment
The configuration is as follows:
<tablerule name= "Mod-long" >
<rule>
<columns>id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<function name= "Mod-long" class= "Org.opencloudb.route.function.PartitionByMod" >
<!--How many data nodes-->
<property name= "Count" >3</property>
</function>
Configuration Description:
Columns is used to identify the table field that will be fragmented.
algorithm specifies that the fragment function corresponds to the functions.
This piecewise algorithm ID based on the decimal model calculation, compared to fixed fragment hash, this piecewise algorithm in bulk inserts will increase the difficulty of transaction consistency.

Enumerating slices
The configuration is as follows:
<tablerule name= "Sharding-by-intfile" >
<rule>
<columns>sharding_id</columns>
<algorithm>hash-int</algorithm>
</rule>
</tableRule>
<function name= "Hash-int"
class= "Org.opencloudb.route.function.PartitionByFileMap" >
<property name= "Mapfile" >partition-hash-int.txt</property>
<property name= "Type" >0</property>
<property name= "Defaultnode" >0</property>
</function>
Configuration Description:
columns specifies the table column name for fragmentation.
algorithm specifies the name of the fragment function.
The default value for type is 0,0 for integer and Non-zero for string.
All node configurations are starting from 0, and 0 represents node 1.
Defaultnode default node: Less than 0 means no default node is set, greater than or equal to 0 means setting the default node.
The function of the default node, when enumerating fragments, let it be routed to the default node if no other enumeration value is encountered.
If you do not configure a default node (the Defaultnode value is less than 0, which means that the default node is not configured), an error occurs when the recognized enumeration value is encountered.

Range fragmentation
The configuration is as follows:
<tablerule name= "Auto-sharding-long" >
<rule>
<columns>id</columns>
<algorithm>rang-long</algorithm>
</rule>
</tableRule>
<function name= "Rang-long"
class= "Org.opencloudb.route.function.AutoPartitionByLong" >
<property name= "Mapfile" >autopartition-long.txt</property>
<property name= "Defaultnode" >0</property>
</function>
The Autopartition-long.txt configuration is as follows:
# range Start-end, data node index
# k=1000,m=10000.
0-500m=0
500m-1000m=1
1000m-1500m=2
Configuration Description:
columns specifies the table column name for fragmentation.
algorithm specifies the name of the fragment function.
The mapfile in the Rang-long function represents the path to the configuration file.
Defaultnode is the default node after the range is exceeded.

Range-Seeking modulus algorithm:
The algorithm has the advantages of dividing the range, calculating the piecewise group, and then seeking the model in the group, and synthesizing the range slicing and modulus slicing.
The configuration is as follows:
<tablerule name= "Auto-sharding-rang-mod" >
<rule>
<columns>id</columns>
<algorithm>rang-mod</algorithm>
</rule>
</tableRule>
<function name= "Rang-mod" class= "Org.opencloudb.route.function.PartitionByRangeMod" >
<property name= "Mapfile" >partition-range-mod.txt</property>
<property name= "Defaultnode" >0</property>
</function>
Configuration Description:
The mapfile in the Rang-mod function represents the path to the configuration file.

Fixed piecewise hash algorithm
Similar to the decimal modulo operation, but for binary operations, take the ID of the binary 10-bit low, that is, id binary &1111111111.
The advantage of this algorithm is that if you follow the decimal modulo operation, the 1~10 will be divided into ~10 slices when inserting 1~10 continuously, which increases the difficulty of controlling the insert transaction. The algorithm can be divided into successive slices according to the binary system, which reduces the difficulty of the control of insert transaction.
The configuration is as follows:
<tablerule name= "Rule1" >
<rule>
<columns>id</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>
<function name= "func1" class= "Org.opencloudb.route.function.PartitionByLong" >
<property name= "Partitioncount" >2,1</property>
<property name= "Partitionlength" >256,512</property>
</function>
Configuration Description:
Partitioncount is a list of fragmented numbers.
The partitionlength is a fragment range list, with the default maximum partition length of 2 n times = 1024, which is the maximum support for 1024 partitions.
Constraints are as follows:
The length of count, length two arrays must be the same.
1024=sum ((Count[i]*length[i]), the dot product constant of count and length two vectors equals 1024.

Take the model surround algorithm
The combination of the scope constraint of modulo operation is mainly to prepare for the subsequent migration, that is, the node distribution of the data can be determined independently after the model is taken.

A model surround algorithm for string hash
Similar to the model surround algorithm, the algorithm supports the numerical, symbolic, and alphabetic modulo.

Apply the specified algorithm
In the runtime, there are applications that decide which partition to route to.

String Hash parsing algorithm
intercepts the int value hash fragment in the string.

Consistent hash algorithm
The consistency hash algorithm effectively solves the problem of the expansion of distributed data.

Piecewise algorithm by date (day)

One-month-per-hour algorithm

Natural month slicing algorithm

Date range Hash Algorithm










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.