Cluster data fragmentation method

By introducing the load balancing mechanism and data sharding scheduling strategy into the MongoDB cluster, the problem of unbalanced data sharding is solved, the efficient and stable operation of the load and the rationality of data sharding are achieved, and the bottlenecks and business problems of the built-in mechanism are avoided. question.

CN118784661APending Publication Date: 2024-10-15BUBI (BEIJING) NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410829257.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Unbalanced MongoDB cluster data sharding results in low load efficiency and poor shard balance. The built-in automatic balancing mechanism has hidden bottlenecks and cannot guarantee the high availability and stability of the nodes.

Method used

By setting the virtual IP address to bind to the load balancing device, sharding is performed based on the amount of data, and the data is distributed using predefined load balancing algorithms (such as polling, weighted polling, random, minimum connection, source address hashing), Combined with the heartbeat detection mechanism and monitoring and repair mechanism, it ensures the rationality and load balancing of data fragmentation.

Benefits of technology

It achieves efficient and stable operation of the load, avoids business problems caused by load imbalance and abnormal data fragmentation, and ensures effective load balancing and reasonable data fragmentation under large business volumes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784661A_ABST
    Figure CN118784661A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of MongoDB data fragmentation imbalance, and provides a cluster data fragmentation method. The method comprises the steps that a set number of virtual IP addresses are bound to a load balancing device, a client cluster data storage request is received, the data volume carried by the client cluster data storage request is obtained, and each virtual IP address corresponds to a cluster database; if the data volume is greater than a preset data volume threshold value, fragmenting the data volume based on the data volume threshold value to obtain fragmented data; according to a preset load balancing algorithm, cluster databases used for responding to a client cluster data storage request are obtained, and the number of the cluster databases is the same as that of the fragmented data; and distributing the fragmented data to the corresponding cluster database for storage according to the acquired virtual IP address corresponding to the cluster database. According to the method and the device, the conditions of service problems and the like caused by load imbalance and abnormal data fragmentation are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of MongoDB data sharding imbalance, and in particular to a cluster data sharding method. Background Art

[0002] Database cluster sharding is a technology that divides data and load in large-scale databases. It divides the database into multiple fragments, each fragment stores a part of the data, and distributes the load to multiple servers. This sharding technology can improve the performance, scalability and fault tolerance of the database.

[0003] MongoDB is a cluster database. Currently, there are two solutions to the problem of unbalanced data sharding in MongoDB clusters. One is to select the master node through election. After the master node finds a fault, it detects whether other nodes are normal through the heartbeat detection mechanism, re-elects through the Raft algorithm, and switches the faulty node. This method is prone to communication delays, and factors such as the network environment can easily cause the entire cluster to fail. Although the backup node continues to provide services, it cannot guarantee the validity, real-time and accuracy of the data. That is, after the cluster fails, the subsequent sharding process cannot be carried out. The second is the Sharding sharding cluster, which provides external application access by storing all nodes in the cluster and sharding data routing information. All operations are executed through routing nodes, chunk splitting and migration. However, this method has no load balancing mechanism by default, and an additional load balancing strategy needs to be introduced. When the amount of data is large, there is an uneven distribution of shards, resulting in obvious differences in the load ratio size distribution. For example, 10 requests may be randomly assigned to one or two of the five nodes. Especially when the amount of data is large, the system will be seriously stuck and unable to respond. The built-in system cannot guarantee the high availability and stability of the node, and the built-in automatic balancing mechanism has a great bottleneck risk. Summary of the invention

[0004] In view of this, the present invention provides a cluster data sharding method to solve the technical problem in the prior art that database cluster data sharding is unbalanced and cluster load efficiency and sharding balance cannot be improved.

[0005] The present invention provides a cluster data sharding method, comprising:

[0006] S1. Bind a set number of virtual IP addresses to a load balancing device, receive a client cluster data storage request, obtain the amount of data carried by the client cluster data storage request, each of the virtual IP addresses corresponds to a cluster database;

[0007] S2. If the data volume is greater than a preset data volume threshold, based on the data volume threshold, the data volume is fragmented to obtain fragmented data;

[0008] S3. According to a preset load balancing algorithm, obtain a cluster database for responding to the client cluster data storage request, the number of the cluster database is the same as the number of the shard data;

[0009] S4. Distribute the shard data to the corresponding cluster database for storage based on the obtained virtual IP address corresponding to the cluster database.

[0010] Furthermore, the predefined load balancing algorithm includes:

[0011] Round robin, weighted round robin, random, least connections, source address hashing.

[0012] Furthermore, S1 also includes: if the backend server IP address changes in the background, the mapping relationship between the virtual IP address and the backend server IP address is automatically changed.

[0013] Furthermore, the sharding layer number is 4, and a single fragment data is split into an even number of times, which is less than or equal to 12 times.

[0014] Furthermore, the S2 further includes:

[0015] If the data volume is smaller than a preset data volume threshold, no processing is performed on the data volume.

[0016] Furthermore, S2 also includes: monitoring the splitting process, and if abnormal splitting data is found, performing fault elimination processing on the abnormal splitting data.

[0017] Furthermore, the S3 further includes:

[0018] Add monitoring and repair mechanism to obtain data configuration routing error information.

[0019] Furthermore, the monitoring and repairing mechanism is a heartbeat detection mechanism for keeping the network alive.

[0020] Furthermore, the heartbeat detection mechanism is used to detect the communication status between configuration nodes, and the communication status includes normal and abnormal alarms.

[0021] Furthermore, the method also includes: providing corresponding warning functions and processing mechanisms for version differences.

[0022] Compared with the prior art, the present invention has the following beneficial effects:

[0023] 1. The present invention introduces a practical load balancing mechanism and cooperates with the data sharding cluster scheduling strategy to smoothly balance the access address load to multiple back-end routing nodes, ensuring efficient and stable operation of the scheduling load and fault handling;

[0024] 2. The present invention optimizes the range-based sharding mechanism of the cluster, optimizes the configuration of the basic block size, optimizes and adjusts the routing node policy mechanism, and optimizes the stability of the server configuration, thereby ensuring that load balancing is effective and data sharding is reasonable under large business volumes, avoiding bottlenecks of the default mechanism, load imbalance, and business problems caused by abnormal data sharding. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0026] Figure 1 is a flow chart of a cluster data sharding method provided by an embodiment of the present invention;

[0027] Figure 2 It is a schematic diagram of a computer device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0028] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.

[0029] A cluster data sharding method of the present invention will be described in detail below with reference to the accompanying drawings.

[0030] Figure 1 It is a flow chart of a cluster data sharding method provided by an embodiment of the present invention.

[0031] like Figure 1 As shown, the group data sharding method includes:

[0032] S1. Bind a set number of virtual IP addresses to a load balancing device, receive a client cluster data storage request, obtain the amount of data carried by the client cluster data storage request, each of the virtual IP addresses corresponds to a cluster database;

[0033] The predefined load balancing algorithms include:

[0034] Round robin, weighted round robin, random, least connections, source address hashing.

[0035] The S1 also includes: if the backend server IP address changes in the background, the mapping relationship between the virtual IP address and the backend server IP address is automatically changed.

[0036] The present invention introduces a load balancing mechanism, binds a set number of virtual IP addresses to a load balancing device, and obtains the amount of data carried by the client cluster data storage request based on the received client cluster data storage request, wherein each of the virtual IP addresses corresponds to a cluster database.

[0037] S2. If the data volume is greater than a preset data volume threshold, based on the data volume threshold, the data volume is fragmented to obtain fragmented data;

[0038] In one embodiment, database sharding refers to splitting a large database into multiple small databases, each of which is called a shard. In this way, the load of the database is distributed to multiple servers, thereby improving performance bottlenecks and availability. The database sharding can help process large-scale applications, improve database read and write performance, increase scalability, reduce single points of failure, and provide geographical flexibility.

[0039] The sharding layer number is 4, and the single fragment data is split into an even number of times, which is less than or equal to 12 times.

[0040] In one embodiment, the number of split layers and the number of split times are set according to human needs. Too many split layers and too many split times will cause the shards to not match the data volume.

[0041] The S2 further includes:

[0042] If the data volume is smaller than a preset data volume threshold, no processing is performed on the data volume.

[0043] The S2 also includes: monitoring the splitting process, and if abnormal splitting data is found, performing fault elimination processing on the abnormal splitting data.

[0044] In one embodiment, the abnormal split data may be caused by errors in the data splitting process, signal interference, equipment failure, etc. The existence of abnormal split data will seriously affect the quality and accuracy of the data, and thus have an adverse impact on data analysis, decision-making and application. Therefore, it is necessary to perform fault elimination processing on the abnormal split data.

[0045] S3. According to a preset load balancing algorithm, obtain a cluster database for responding to the client cluster data storage request, the number of the cluster database is the same as the number of the shard data;

[0046] The S3 also includes: adding a monitoring and repairing mechanism to obtain data configuration routing error information.

[0047] The monitoring and repair mechanism is a heartbeat detection mechanism that keeps the network alive.

[0048] The heartbeat detection mechanism is used to detect the communication status between configuration nodes, and the communication status includes normal and abnormal alarms.

[0049] In one embodiment, heartbeat detection is an important mechanism in a distributed system, which is used to monitor the node status to ensure smooth communication. By sending signals regularly and handling timeouts, node failures can be effectively detected. In practical applications, optimization strategies are required, such as dynamically adjusting the frequency and optimizing the timeout mechanism, to improve system reliability and performance.

[0050] S4. Distribute the shard data to the corresponding cluster database for storage based on the obtained virtual IP address corresponding to the cluster database.

[0051] In one embodiment, after the sharding work is completed, according to the virtual IP address corresponding to the acquired cluster database, the sharded data will have the corresponding cluster database, and the sharded data will be distributed to the corresponding cluster database for storage.

[0052] The method also includes: providing corresponding warning functions and processing mechanisms for version differences.

[0053] Different versions of MongoDB have an impact on the cluster.

[0054] Prior to version 4.4:

[0055] The shard key cannot exceed 512MB. Only hash shard keys of fields are supported. The file must contain the shard key, which is a column in the table and cannot be modified.

[0056] After version 4.4:

[0057] There is no limit on the size of the shard key, and hash shard keys can be reviewed. The shard key may not be included in the file and is treated as a special value when inserted. The shard key is added with a suffix to set an internal command, and a column in the table included in the shard key can be modified.

[0058] The present invention introduces a load balancing mechanism and cooperates with the data sharding cluster scheduling strategy to smoothly balance the access address load to multiple back-end routing nodes, thereby ensuring efficient and stable operation of the scheduling load and fault handling; by optimizing the cluster's own range sharding mechanism, optimizing the configuration of the basic block size, optimizing and adjusting the routing node strategy mechanism, and optimizing the stability of the server configuration, it is ensured that under a large business volume, load balancing is effective and data sharding is reasonable, avoiding the bottleneck of the default mechanism, load imbalance, and business problems caused by abnormal data sharding.

[0059] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0060] Figure 2 It is a schematic diagram of a computer device provided by an embodiment of the present disclosure.

[0061] like Figure 2 As shown, the computer device 2 of this embodiment includes: a processor 20, a memory 21, and a computer program 22 stored in the memory 21 and executable on the processor 20. When the processor 20 executes the computer program 22, the steps in the above-mentioned various method embodiments are implemented.

[0062] Exemplarily, the computer program 22 may be divided into one or more modules / units, which are stored in the memory 21 and executed by the processor 20 to complete the present disclosure. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 22 in the computer device 2.

[0063] The computer device 2 may be a desktop computer, a notebook computer, a PDA, a cloud server, or other computer devices. The computer device 2 may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 2 It is only an example of computer device 2 and does not constitute a limitation of computer device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.

[0064] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0065] The memory 21 may be an internal storage unit of the computer device 2, for example, a hard disk or memory of the computer device 2. The memory 21 may also be an external storage device of the computer device 2, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FlashCard), etc. equipped on the computer device 2. Further, the memory 21 may also include both an internal storage unit and an external storage device of the computer device 2. The memory 21 is used to store computer programs and other programs and data required by the computer device. The memory 21 may also be used to temporarily store data that has been output or is to be output.

[0066] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0067] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0068] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this disclosure.

[0069] In the embodiments provided in the present disclosure, it should be understood that the disclosed apparatus / computer equipment and methods can be implemented in other ways. For example, the apparatus / computer equipment embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. Multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection of the apparatus or unit, which may be electrical, mechanical or other forms.

[0070] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0071] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0072] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present disclosure implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by a processor, it can implement the steps of the above-mentioned various method embodiments. The computer program may include computer program code, which may be in the form of source code, object code, executable file or some intermediate form. The computer-readable medium may include: a computer program code capable of carrying a computer program code;

[0073] Any entity or device that stores or transmits computer code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0074] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0075] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. A cluster data sharding method, characterized in that: include: S1. Bind a set number of virtual IP addresses to a load balancing device, receive a client cluster data storage request, obtain the amount of data carried by the client cluster data storage request, each of the virtual IP addresses corresponds to a cluster database; S2. If the data volume is greater than a preset data volume threshold, based on the data volume threshold, the data volume is fragmented to obtain fragmented data; S3. According to a preset load balancing algorithm, obtain a cluster database for responding to the client cluster data storage request, the number of the cluster database is the same as the number of the shard data; S4. Distribute the shard data to the corresponding cluster database for storage based on the obtained virtual IP address corresponding to the cluster database.

2. The cluster data sharding method according to claim 1, characterized in that: The predefined load balancing algorithms include: Round robin, weighted round robin, random, least connections, source address hashing.

3. The cluster data sharding method according to claim 1, characterized in that: The S1 also includes: if the backend server IP address changes in the background, the mapping relationship between the virtual IP address and the backend server IP address is automatically changed.

4. The cluster data sharding method according to claim 1, characterized in that: The sharding layer number is 4, and the single fragment data is split into an even number of times, which is less than or equal to 12 times.

5. The cluster data sharding method according to claim 1, characterized in that: The S2 further includes: If the data volume is smaller than a preset data volume threshold, no processing is performed on the data volume.

6. The cluster data sharding method according to claim 1, characterized in that: The S2 also includes: monitoring the splitting process, and if abnormal splitting data is found, performing fault elimination processing on the abnormal splitting data.

7. The cluster data sharding method according to claim 1, characterized in that: The S3 further includes: Add monitoring and repair mechanism to obtain data configuration routing error information.

8. The cluster data sharding method according to claim 7, characterized in that: The monitoring and repair mechanism is a heartbeat detection mechanism that keeps the network alive.

9. The cluster data sharding method according to claim 8, characterized in that: The heartbeat detection mechanism is used to detect the communication status between configuration nodes, and the communication status includes normal and abnormal alarms.

10. The cluster data sharding method according to claim 1, characterized in that: The method also includes: providing corresponding warning functions and processing mechanisms for version differences.