In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
What are the ways to split the database? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Database split has: 1, divided by function [vertical split], put tables related to different functions into different databases, the advantage of doing so is very intuitive; 2, according to the range of a field value in the table is divided [horizontal split], when the amount of data in a table is getting larger and larger, so that it can not bear, it needs to be further split.
Several ways to split the database:
1. Divided by function (vertical segmentation)
The advantage of putting tables related to different functions in different databases is very intuitive. However, when the amount of data or performance requirements of a certain part of the function is beyond the controllable range, it needs to continue to be further re-segmented.
2. Divide by range of field values in the table (horizontal segmentation)
When the amount of data in a table becomes too large to bear, it needs to be further segmented. One option is to split according to the range of key, for example, if the ID is 1-10000, put it on A, and put on B if the ID is 10000-20000. Such an expansion is predictable. The other is to divide it according to the value of a certain field, for example, according to the initials of the user name, if it is Amurd, it belongs to Amai D, and Emurh belongs to B. There is also an imbalance in doing so, and when a range is beyond what a single point can bear, it needs to continue to be segmented. And slicing by date and so on.
Advantages: single table size can be controlled, natural horizontal expansion
Disadvantages: unable to solve the bottleneck of centralized writing.
3. Segmentation based on hash
Mod is generally used to split, at the beginning to determine the number of database segmentation, through the hash module to decide which one to use. This method can distribute data evenly, but with the increase of the amount of data, when it needs to be expanded, this method can not achieve online expansion. Every time the nodes are added, the hash algorithm needs to be recalculated.
Therefore, using this method, the consistent hash of mod 2 ^ n is recommended.
Taking the unified order library of review as an example, the scheme of sub-database and sub-table is 3232, that is, it is divided into 32 libraries through the last four bits of mod 32 in userId, and each database is divided into 32 tables by div 32 mod 32 in the last four bits of userId, with a total of 1024 tables. Its online deployment is 8 clusters (master-slave), and each cluster has 4 libraries.
4. Segmentation based on routing table
The previous methods determine the operation according to the applied data, and the segmentation based on the routing table is a more loose method. It maintains a separate routing table and looks up the routing table according to a certain attribute of the user to decide which database to use, which is a more general scheme.
Pros: mapping algorithms for id and libraries can be changed at will
Cons: additional single points may be introduced
After reading the above, have you mastered the ways to split the database? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.