A method and apparatus for splitting and merging a distributed database cluster

The method automates node distribution in distributed database clusters based on connection frequency and latency for efficient splitting and merging, ensuring data consistency and reducing operational complexity.

CN119760028BActive Publication Date: 2025-07-15TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510260412.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-06
Publication Date
2025-07-15
Estimated Expiration
2045-03-06

AI Technical Summary

Technical Problem

In the prior art, during the splitting process of distributed database clusters, users cannot automatically judge the split nodes, and it is difficult to ensure data consistency without stopping the service. The operation steps are cumbersome and one-click commands are lacking.

Method used

By obtaining cluster information, split nodes are automatically allocated based on the number of access times, delay and number of nodes, and two split methods are provided: the service stop and non-stop service stop are combined with log management and the creation of data consistency points to ensure data consistency.

Benefits of technology

It realizes simple one-click splitting and merging of distributed database clusters, avoids node redundancy, supports downtime and non-stop operations, and ensures data consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119760028B_ABST
    Figure CN119760028B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and apparatus for splitting and merging a distributed database cluster. The method includes: obtaining information of the distributed database cluster to be split, where the information includes the number of database access times, latency, and the number of nodes, and the nodes include CN, GTM, and DN; receiving a cluster splitting request; allocating splitting nodes based on the splitting request and the information of the distributed database cluster; and splitting the distributed database cluster based on the allocated splitting nodes. Through the processing solution of the present disclosure, both the splitting and merging commands are completed with one key, the user operation is simple, and node redundancy is 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 databases, and particularly to a method and apparatus for splitting and merging a distributed database cluster. Background Art

[0002] A distributed database generally includes three types of nodes, namely CN, GTM, and DN (as Figure 1 shown):

[0003] CN: Responsible for receiving client requests, performing SQL parsing and optimization, generating an execution plan, and coordinating data nodes to perform data query and write;

[0004] DN: Completes data storage and local data query and write;

[0005] GTM: Generates and maintains a global timestamp to ensure strong consistency of cluster data.

[0006] There are multiple high-availability groups (shards) in DN. One high-availability group includes multiple replicas, including a primary node and multiple standby nodes. The primary node will synchronize the logs to the standby nodes to keep the data synchronized. If the primary DN fails, the primary-standby switchover can be triggered to upgrade an optimal standby DN to the primary DN to ensure the continuity of the cluster service.

[0007] In order to ensure high availability, GTM also includes multiple replicas, including a primary node and multiple standby nodes. The primary GTM synchronizes the data to the standby GTMs. If the primary GTM fails, the primary-standby switchover can also be triggered to upgrade an optimal standby GTM to the primary GTM.

[0008] For CN nodes, multiple CN nodes are also deployed in a cluster, and the data (DDL data) between each CN is kept in real-time synchronization. Users can select any CN for business. When a CN fails, users can choose to access from another CN.

[0009] As can be seen from the above introduction, in most distributed clusters, in order to ensure high availability, there is a certain redundancy in each node. In some cases, users hope to split a distributed cluster into multiple clusters for different services, and at the same time, they also hope to merge multiple clusters into one cluster to provide services externally.

[0010] The existing cluster splitting has the following problems:

[0011] 1. Users only give instructions on the need to split the cluster, and how to optimally split a cluster into one or more clusters needs to be automatically determined.

[0012] 2. During the splitting process, some users allow the business to stop, while some do not. If the business is not allowed to stop, how to ensure the data consistency of the split-out clusters?

[0013] 3. The specific splitting and merging steps are numerous, and one-click commands need to be provided to facilitate user operation. Summary of the Invention

[0014] In view of this, embodiments of the present disclosure provide a method for splitting a distributed database cluster, which at least partially solves the problems existing in the prior art.

[0015] In a first aspect, embodiments of the present disclosure provide a method for splitting a distributed database cluster, the method including the following steps:

[0016] Obtain information of the distributed database cluster to be split; wherein, the information includes the number of database accesses, latency, and the number of nodes; the nodes include CN, GTM, and DN;

[0017] Receive a cluster splitting request;

[0018] Allocate splitting nodes based on the splitting request and the information of the distributed database cluster;

[0019] Split the distributed database cluster based on the allocated splitting nodes.

[0020] According to a specific implementation manner of the embodiments of the present disclosure, the allocating splitting nodes based on the splitting request and the information of the distributed database cluster includes:

[0021] Sort the CNs from small to large based on the number of database accesses; wherein, obtain the CNs based on the first cluster concurrency number × 120 in the splitting request;

[0022] Sort the DN shard replicas in descending order of data synchronization latency, and the higher the latency of the DN, the higher the splitting weight;

[0023] Analyze the network latency between the CNs obtained from the first cluster and the DN shard replicas, and the smaller the latency, the higher the splitting weight of the DN;

[0024] Calculate the splitting priority of the DN shard replicas based on the DN splitting weight;

[0025] Sort the GTM shard replicas in descending order of data synchronization latency, and the higher the latency of the GTM, the higher the splitting weight;

[0026] Analyze the network latency between the CNs obtained from the first cluster and the GTM shard replicas, and the smaller the latency, the higher the splitting weight of the GTM;

[0027] Calculate the splitting priority of the GTM shard replicas based on the GTM splitting weight.

[0028] According to a specific implementation manner of an embodiment of the present disclosure, splitting the distributed database cluster based on the allocated splitting nodes includes: a shutdown splitting method and a non-shutdown splitting method.

[0029] According to a specific implementation manner of an embodiment of the present disclosure, the shutdown splitting method includes the following steps:

[0030] Based on the allocated splitting nodes, parse the number of CNs, the number of GTM replicas, and the number of DN replicas required by the second cluster, and retain the remaining CNs, GTM replicas, and DN replicas in the first cluster;

[0031] Stop all nodes included in the second cluster;

[0032] Remove the nodes of the second cluster in the first cluster and retain the node data;

[0033] Modify the connection string information of the GTM and DN nodes in the first cluster, and delete the replication slots of the master node to the corresponding nodes in the second cluster;

[0034] Delete all routing information of the CNs on the first cluster to the CNs in the second cluster;

[0035] Modify the connection string information of the GTM and DN nodes in the second cluster;

[0036] Based on the allocated splitting nodes, start the master node and standby nodes of the second cluster, establish master-standby connections respectively, and start synchronizing data;

[0037] Start the CNs of the second cluster and modify the routing of CNs, GTMs, and DNs.

[0038] According to a specific implementation manner of an embodiment of the present disclosure, the non-shutdown splitting method includes the following steps:

[0039] Increase the number of log retention files;

[0040] Record the wal log positions of each shard;

[0041] In the first cluster, remove the nodes of the second cluster and retain the node data;

[0042] Modify the connection string information of the GTM and DN nodes in the first cluster, and delete the replication slots of the master node to the corresponding nodes in the second cluster;

[0043] Delete all routing information of the CNs on the first cluster to the CNs in the second cluster;

[0044] Split the corresponding nodes of the second cluster out of the first cluster. After the splitting is completed, trigger the first cluster to create a data consistency point;

[0045] Collect the log files of each shard and send the log files to the second cluster;

[0046] Start the master node of the second cluster and set the startup log target to lsn_end;

[0047] Based on the allocated split nodes, start the master node and the standby nodes of the second cluster, establish master-standby connections respectively, and start synchronizing data;

[0048] Start the CN of the second cluster and modify the routing of CN and GTM to DN.

[0049] According to a specific implementation manner of the embodiments of the present disclosure, the method further includes a method for merging distributed database clusters, and the method includes the following steps:

[0050] Obtain the node information of the distributed database cluster to be merged: the distributed database cluster to be merged includes a first cluster and a second cluster;

[0051] Stop all nodes of the second cluster;

[0052] Set the node connection string information of the second cluster and connect to the master node of the first cluster;

[0053] Trigger all GTMs and DNs in the second cluster to build full data, with the source being the corresponding master node of the first cluster;

[0054] Trigger the CN in the second cluster to build full data, with the source being any CN of the first cluster;

[0055] Modify the GTM on the first cluster and the standby machine information on the DN master node, and establish a data replication slot to the corresponding nodes of the second cluster;

[0056] Restart all GTM and DN nodes on the second cluster as standby nodes, and the master and standby start synchronizing data based on the data replication slot;

[0057] Modify the routing information of all CNs on the first cluster and add the routing to the CN of the second cluster;

[0058] Restart the routing of the CN of the second cluster.

[0059] In a second aspect, the embodiments of the present disclosure also provide a distributed database cluster splitting device, and the device includes:

[0060] A data acquisition module, configured to acquire information of a distributed database cluster to be split; wherein, the information includes the number of database accesses, latency, and the number of nodes; the nodes include CN, GTM, and DN;

[0061] A rule module, which is configured to receive a cluster splitting request; and allocate splitting nodes based on the splitting request and the information of the distributed database cluster;

[0062] A node splitting module, which is configured to split the distributed database cluster based on the allocated splitting nodes.

[0063] According to a specific implementation manner of an embodiment of the present disclosure, the apparatus further includes:

[0064] A node merging module, which is configured to obtain the node information of the distributed database cluster to be merged: the distributed database cluster to be merged includes a first cluster and a second cluster;

[0065] Stop all nodes of the second cluster;

[0066] Set the node connection string information of the second cluster and connect to the primary node of the first cluster;

[0067] Trigger all GTMs and DNs in the second cluster to build full data, with the source being the corresponding primary node of the first cluster;

[0068] Trigger the CN full data build in the second cluster, with the source being any CN of the first cluster;

[0069] Modify the GTM on the first cluster and the standby machine information on the primary nodes of the DNs, and establish a data replication slot to the corresponding nodes of the second cluster;

[0070] Restart all GTMs and DNs on the second cluster as standby nodes, and the primary and standby start synchronizing data based on the data replication slot;

[0071] Modify the routing information of all CNs on the first cluster to add a route to the CN of the second cluster; and,

[0072] Restart the routing of the CN of the second cluster.

[0073] In a third aspect, an embodiment of the present disclosure further provides an electronic device, which includes:

[0074] At least one processor; and,

[0075] A memory communicatively connected to the at least one processor; wherein,

[0076] The memory stores instructions that can be executed by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor implements the distributed database cluster splitting method according to any one of the preceding first aspect or any implementation manner of the first aspect.

[0077] In a fourth aspect, an embodiment of the present disclosure further provides a computer program product, which includes a computing program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions that, when executed by a computer, cause the computer to execute the distributed database cluster splitting method in the foregoing first aspect or any implementation manner of the first aspect.

[0078] In the distributed database cluster splitting method in the embodiments of the present disclosure, both the splitting and merging commands can be completed with one key, the user operation is simple, and node redundancy is avoided; and it can support both the splitting with downtime and the splitting without downtime. BRIEF DESCRIPTION OF THE DRAWINGS

[0079] The above is only an overview of the technical solutions of the present invention. In order to be able to understand the technical means of the present invention more clearly, the following further describes the present invention in detail in conjunction with the drawings and specific embodiments.

[0080] Figure 1 It is a schematic diagram of a distributed database architecture;

[0081] Figure 2 It is a flowchart of a distributed database cluster splitting method provided by an embodiment of the present disclosure;

[0082] Figure 3 It is a schematic diagram of the process of a distributed database cluster splitting method provided by an embodiment of the present disclosure;

[0083] Figure 4 It is a schematic diagram of a distributed database cluster provided by an embodiment of the present disclosure;

[0084] Figure 5 It is a schematic diagram of the result of a distributed database cluster splitting provided by an embodiment of the present disclosure;

[0085] Figure 6 It is a schematic diagram of the result of a distributed database cluster splitting provided by an embodiment of the present disclosure;

[0086] Figure 7 It is a schematic diagram of the structure of a distributed database cluster splitting device provided by an embodiment of the present disclosure;

[0087] Figure 8 It is a schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0088] The embodiments of the present disclosure will be described in detail below in conjunction with the drawings.

[0089] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that, without conflict, the following embodiments and the features in the embodiments can be combined with each other. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present disclosure without creative efforts belong to the scope of protection of the present disclosure.

[0090] It should be noted that the following describes various aspects of embodiments within the scope of the appended claims. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is illustrative only. Based on the present disclosure, those skilled in the art should understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement an apparatus and / or practice a method. Additionally, this apparatus and / or this method can be implemented using other structures and / or functionality in addition to one or more of the aspects described herein.

[0091] In addition, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that the described aspects can be practiced without these specific details.

[0092] An embodiment of the present invention provides a method for splitting a distributed database cluster, where both the splitting and merging commands are completed with one key, the user operation is simple, and node redundancy is avoided.

[0093] The present invention solves the problems existing in the prior art through three modules, such as Figure 2 As shown, a cluster splitting algorithm module, a cluster splitting execution module, and a cluster merging execution module. The main responsibilities of each module are as follows:

[0094] Cluster splitting algorithm module: Collect information of the database cluster, including information such as the number of database accesses and the latency of shard replicas; Receive the user's cluster splitting request, refer to the database cluster information, and automatically allocate the nodes of each cluster after splitting according to a certain algorithm. Input the node information of each cluster after splitting to the cluster splitting module.

[0095] Cluster splitting execution module: Receives the cluster splitting request from the cluster algorithm module and executes the cluster splitting operation; responsible for ensuring data consistency during the process of splitting the cluster.

[0096] Cluster merging module: Receives the user's cluster splitting / merging request and executes the cluster merging operation.

[0097] Taking the following cluster as an example, there are three CNs in the cluster, namely CN1, CN2, and CN3. The GTM has four replicas, and there are three high-availability groups DN1, DN2, and DN3, with each high-availability group having four replicas respectively. For the GTM and high-availability groups, since they are all four-replica, two synchronous standby machines and one asynchronous standby machine are set to meet the majority principle.

[0098] As Figure 3 shown, at step S310, obtain the information of the distributed database cluster to be split; wherein, the information includes the number of database accesses, latency, and the number of nodes; the nodes include CN, GTM, and DN.

[0099] More specifically, then go to step S320.

[0100] At step S320, receive the cluster splitting request.

[0101] More specifically, then go to step S330.

[0102] At step S330, allocate splitting nodes based on the splitting request and the information of the distributed database cluster.

[0103] More specifically, the factors affecting the allocation of cluster splitting nodes mainly include the following data: the connection concurrency of CN, the data synchronization latency of shard replicas, the communication latency between CN and DN, etc. At the same time, the following basic principles need to be calculated to be met:

[0104] 1) The minimum requirement for the operation of a single distributed cluster: One replica of GTM, one CN, and one replica of each DN shard.

[0105] 2) The recommended high-availability operation of the distributed cluster is that GTM and each DN shard have three replicas respectively. There are two standby machines, one synchronous standby machine and one asynchronous standby machine. When splitting, give priority to ensuring that the old cluster remains three-replica, and the extra nodes are split out, but the split-out cluster needs to meet the minimum operation requirements.

[0106] In the embodiment of the present invention, allocating split nodes based on the split request and the information of the distributed database cluster includes: sorting CNs in ascending order based on the number of database accesses; wherein, obtaining CNs based on the number of concurrent connections in the first cluster in the split request multiplied by 120; sorting DN shard replicas in descending order according to the data synchronization delay, and the higher the delay, the higher the DN split weight; analyzing the network delay between the CNs obtained by the first cluster and the DN shard replicas, and the smaller the delay, the higher the DN split weight; calculating the split priority of the DN shard replicas based on the DN split weight; sorting GTM shard replicas in descending order according to the data synchronization delay, and the higher the delay, the higher the GTM split weight; analyzing the network delay between the CNs obtained by the first cluster and the GTM shard replicas, and the smaller the delay, the higher the GTM split weight; calculating the split priority of the GTM shard replicas based on the GTM split weight.

[0107] More specifically, the specific splitting steps are as follows:

[0108] 1. Continuously collect data such as the connection concurrency of CNs, the data synchronization delay of shard replicas, and the communication delay between CNs and DNs from the database cluster.

[0109] 2. Receive the cluster split request from the user.

[0110] 3. First, split CNs; the CN split refers to the historical connection count and sorts them in ascending order. The smaller the connection count, the higher the split weight. Retain the number of CNs equal to the number of concurrent connections in the first cluster (or the first cluster) multiplied by 120, and split the remaining CNs to other clusters.

[0111] 4. Analyze the data synchronization delay data of DN shard replicas, sort them in descending order according to the delay, and the higher the delay, the higher the split weight, to obtain the first weight score.

[0112] 5. For the CNs split out calculated in step 3, analyze the network delay between these CNs and the DN shard replicas. The smaller the delay, the higher the split weight, to obtain the second weight score.

[0113] 6. Consider steps 4 and 5 comprehensively. Calculate the split priority of the DN shard replicas (i.e., the sum of the first weight score and the second weight score) according to the weights set by the user for 4 and 5 respectively. Split the replicas to the new cluster (the second cluster) according to the priority size while referring to the basic principle.

[0114] The GTM split algorithm is the same as the DN shard split algorithm.

[0115] More specifically, next, go to step S340.

[0116] At step S340, split the distributed database cluster based on the allocated split nodes.

[0117] More specifically, each DN shard and GTM form a multi-copy highly available group. The data of the host will be synchronized to all standby machines through replication slots. Therefore, the information of other replicas will be saved on each replica. The standby node will attempt to connect to the primary node based on the saved information of other replicas. After receiving the connection request from the standby node, the primary node will create a replication slot and start the data transfer between the primary and standby nodes. Since some replicas are removed to other clusters, it is necessary to traverse all the replicas remaining in this cluster and delete the information of the replicas that need to be removed.

[0118] As a cluster, each GTM stores the routing information of other CNs and DNs. Each CN retains the routing information of GTM and DN. When executing an SQL statement, if it is a DDL, the execution plan will be distributed to all CNs and DNs. If it is a DML, the appropriate DN will be selected for distribution according to the routing information of the DN.

[0119] For each DN shard, the CN will save the routing to the primary node and the routing to other standby nodes. When the plan is executed, the primary node routing will be selected first. If the connection to the primary node fails, the standby node will be selected for execution. The advantage of retaining the routing of all replicas is that if a primary-standby switch occurs in the replica, the execution plan can quickly adapt without being notified of the primary-standby switch operation, reducing the SQL execution failure rate.

[0120] Since some CN and DN replicas of the cluster are removed to other clusters, the routing information of the migrated nodes needs to be deleted on all the remaining nodes in this cluster. For example, the GTM originally retained the routing to CN1, CN2, and CN3. After CN3 is migrated to another cluster, the GTM only retains the routing to CN1 and CN2, and the DDL only needs to be distributed to CN1 and CN2.

[0121] Because there are multiple shards in a distributed database, during the splitting process, since the splitting speed of each shard is different, there will be a time difference in the data received by different shards, resulting in data inconsistency problems.

[0122] To solve this problem, the present invention provides a solution to ensure data consistency. Taking the splitting of Cluster 1 (or the first cluster) into Cluster 1 and Cluster 2 (or the second cluster) as an example:

[0123] 1) To ensure that the logs of Cluster 1 are not recycled during the cluster splitting, increase the number of log retention files.

[0124] 2) Before splitting the cluster, the splitting module records the wal log position of each shard. For example, the log position of shard DN1 is lsn_start. Record the log file xlog_file_start where the log is located.

[0125] 3) Execute the splitting operation to split the nodes corresponding to Cluster 2 from Cluster 1.

[0126] 4) After all shard nodes are split from Cluster 1, the splitting module triggers Cluster 1 to create a data consistency point and records the position of this data consistency point for each shard. For example, the log position of shard DN1 is lsn_end. Record the log file xlog_file_end where this log is located.

[0127] 5) The splitting module collects the log files of each shard, such as for shard DN1, that is, the logs between xlog_file_start and xlog_file_end, and sends this part of the log files to Cluster 2.

[0128] 6) Start the nodes of Cluster 2 and set the startup log target to lsn_end. Replay the logs of each shard to lsn_end, and the data at this point can ensure consistency.

[0129] Taking the following cluster as an example, the detailed splitting steps are described as follows:

[0130] As Figure 4 shown, there are three CNs in the cluster, namely CN1, CN2, and CN3. GTM has four replicas, and there are three highly available groups DN1, DN2, and DN3, with each highly available group having four replicas. For GTM and the highly available groups, since they are all four-replica, two synchronous standby machines and one asynchronous standby machine are set to meet the majority principle.

[0131] The user hopes to split the cluster into two clusters. The cluster splitting algorithm module, through automatic calculation, allocates the node information to the two clusters as follows:

[0132] First Cluster: CN: CN1, CN2; GTM: GTM1, GTM2;

[0133] DN1: DN1_1, DN1_2; DN2: DN2_1, DN2_2; DN3: DN3_1, DN3_2

[0134] Second Cluster: CN: CN3; GTM: GTM3, GTM4;

[0135] DN1: DN1_3, DN1_4; DN2: DN2_3, DN2_4; DN3: DN3_3, DN3_4

[0136] The user can choose between two types: splitting with the service stopped and splitting without stopping the service.

[0137] In the embodiments of the present invention, the distributed database cluster is split based on the allocated split nodes, including: a stop-service splitting method and a non-stop-service splitting method.

[0138] In the embodiments of the present invention, the stop-service splitting method includes the following steps: parsing the number of CNs, the number of GTM replicas, and the number of DN replicas required by the second cluster based on the allocated split nodes, and retaining the remaining CNs, GTM replicas, and DN replicas in the first cluster; stopping all nodes included in the second cluster; removing the nodes of the second cluster in the first cluster while retaining the node data; modifying the connection string information of the GTM and DN nodes in the first cluster, and deleting the replication slot from the master node to the corresponding nodes in the second cluster; deleting all routing information from the CNs on the first cluster to the CNs in the second cluster; modifying the connection string information of the GTM and DN nodes in the second cluster; starting the master node and standby nodes of the second cluster based on the allocated split nodes, respectively establishing master-standby connections, and starting data synchronization; starting the CNs of the second cluster and modifying the routing of CNs, GTMs, and DNs.

[0139] More specifically, the steps of the stop-service splitting are as follows:

[0140] 1) The splitting module first sets the status of Cluster 1 to read-only, in which the database can only be read and cannot be written.

[0141] 2) After waiting for all 2PC transactions to be committed, stop all nodes belonging to Cluster 2.

[0142] 3) Remove the nodes of Cluster 2 in Cluster 1, but do not delete the node data.

[0143] 4) Modify the connection string information of the GTM and DN nodes in Cluster 1, and delete the replication slot from the master node to the corresponding nodes in Cluster 2.

[0144] 5) Delete all routing information from all CNs on Cluster 1 to CN3. At this time, Cluster 1 is processed and can provide services externally.

[0145] 6) Modify the status of Cluster 1 to the normal mode, in which it can be read and written.

[0146] 7) Modify the connection string information of the GTM and DN nodes in the new cluster.

[0147] 8) Start GTM3, DN1_3, DN2_3, and DN3_3 as master nodes respectively.

[0148] 9) Start GTM4, DN1_4, DN2_4, and DN3_4 as standby nodes, and respectively establish master-standby connections with GTM3, DN1_3, DN2_3, and DN3_3 to start data synchronization.

[0149] 10) Start CN3 and modify the GTM on CN3 and the routes of the three high-availability groups. After the new cluster is started, it can provide services externally.

[0150] At this point, the original cluster is split into two independent clusters, as Figure 5 , Figure 6 shown, and they provide services externally respectively.

[0151] In the embodiment of the present invention, the non-stop splitting method includes the following steps: increasing the number of log retention files; recording the wal log position of each shard; removing the nodes of the second cluster in the first cluster and retaining the node data; modifying the connection string information of the GTM and DN nodes of the first cluster and deleting the replication slot from the master node to the corresponding nodes of the second cluster; deleting all the routing information from the CNs on the first cluster to the CNs of the second cluster; splitting the corresponding nodes of the second cluster from the first cluster, and after the splitting is completed, triggering the first cluster to create a data consistency point; collecting the log files of each shard and sending the log files to the second cluster; starting the master node of the second cluster and setting the start log target to lsn_end; starting the master node and standby nodes of the second cluster based on the allocated split nodes, establishing master-standby connections respectively, and starting to synchronize data; starting the CNs of the second cluster and modifying the routes of the CNs, GTM, and DN.

[0152] More specifically, the non-stop splitting steps are as follows:

[0153] To ensure that the logs of cluster 1 are not recycled during the cluster splitting, increase the number of log retention files.

[0154] The splitting module records the current wal log position of each shard. For example, the log position of shard DN1 is lsn_start. Record the log file xlog_file_start where this log is located.

[0155] Remove the nodes of cluster 2 from cluster 1, but do not delete the node data;

[0156] Modify the connection string information of the GTM and DN nodes of cluster 1 and delete the replication slot from the master node to the corresponding nodes of cluster 2.

[0157] Delete all the routing information from the CNs on cluster 1 to CN3.

[0158] After all the shard nodes are split from cluster 1, the splitting module triggers cluster 1 to create a data consistency point and records the position of this data consistency point for each shard. For example, the log position of shard DN1 is lsn_end. Record the log file xlog_file_end where this log is located.

[0159] The splitting module collects the log files of each shard. For example, for shard DN1, i.e., the logs between xlog_file_start and xlog_file_end, this part of the log files is sent to Cluster 2.

[0160] Modify the connection string information of the GTM and DN nodes in the new cluster;

[0161] Start GTM3, DN1_3, DN2_3, and DN3_3 as master nodes respectively, and set the startup log target to lsn_end. The log of each shard is replayed to lsn_end, and the data at this point can ensure consistency;

[0162] Start GTM4, DN1_4, DN2_4, and DN3_4 as standby nodes, and establish master-standby connections with GTM3, DN1_3, DN2_3, and DN3_3 respectively to start synchronizing data;

[0163] Start CN3, and modify the GTM and the routes of the three high-availability groups on CN3. The new cluster has been started and can provide services externally.

[0164] At this point, the original cluster is split into the following two independent clusters, which provide services externally respectively.

[0165] In the embodiment of the present invention, the method further includes: judging whether the split distributed database cluster can be split again, including: judging whether the number of each node in the distributed cluster to be split meets a preset standard; wherein, when it meets the preset standard, it is judged that the distributed cluster can be split; when it does not meet the preset standard, it is judged that the distributed cluster cannot be split.

[0166] In the embodiment of the present invention, the preset standard is that the distributed cluster has no less than a single copy of GTM, 1 CN, and a single copy of each DN shard.

[0167] In an embodiment of the present invention, the method also includes a distributed database cluster merging method, which includes the following steps: obtaining node information of the distributed database clusters to be merged: the distributed database clusters to be merged include a first cluster and a second cluster; stopping all nodes of the second cluster; setting the node connection string information of the second cluster, connecting to the master node of the first cluster; triggering the full build data of all GTMs and DNs of the second cluster, the source end is the corresponding master node of the first cluster; triggering the full build data of the CN of the second cluster, the source end is any CN of the first cluster; modifying the GTM on the first cluster and the standby machine information on the DN master node, and establishing a data replication slot to the corresponding node of the second cluster; restarting all GTMs and DN nodes on the second cluster as standby nodes, and starting to synchronize data between the master and standby based on the data replication slot; modifying the routing information of all CNs on the first cluster, adding routes to the CNs of the second cluster; restarting the routes of the CNs of the second cluster.

[0168] More specifically, the node connection string information of the second cluster is set, that is, all GTM and DN nodes are traversed, and the copy information stored therein is modified to be the collection of the copies of the first cluster and the second cluster.

[0169] All GTM and DN nodes of the first cluster need to be added with the replica information of the second cluster. When the backup machine of the second cluster connects to the primary node of the first cluster, the primary node will establish a replication slot to the replica and start data synchronization.

[0170] The CN of the second cluster also needs to be modified to add the routing information of the first cluster. After the nodes of the second cluster are built from the data of the first cluster, the data of the second cluster has been synchronized with the first cluster. Because the second cluster is added, the GTM and DN shards of the first cluster already have a master node, so the GTM and DN nodes of the second cluster are pulled up as backups. After pulling up, the master node will establish a replication slot with the backup node and start master-backup data synchronization.

[0171] After the new service starts, because the routing information of the cluster has been merged with the second cluster, both DML and DDL will be distributed to the corresponding nodes.

[0172] For example, to merge two independent clusters into one cluster, the tool command format is as follows:

[0173] merge_cluster cluster1 cluster2

[0174] Merge cluster2 into cluster1. If cluster2 is merged into cluster1, all data in cluster2 will be discarded and the data on cluster1 will prevail.

[0175] Processing steps of merge_cluster:

[0176] 1. Obtain node information of two clusters:

[0177] 2. First, stop all nodes in cluster2;

[0178] 3. Set the node connection string information of cluster2 and connect to the master node of cluster1;

[0179] 4. Trigger full - scale data building of all GTMs and DNs in cluster2, with the source being the corresponding master node of cluster1;

[0180] 5. Trigger full - scale data building of CNs in cluster2, with the source being any CN in cluster1;

[0181] 6. Modify the standby machine information on the GTM and DN master nodes on cluster1 and establish a data replication slot to the corresponding nodes in cluster2;

[0182] 7. Restart all GTM and DN nodes on cluster2 as standby nodes. Since the replication slot has been established, the master - standby starts to synchronize data;

[0183] 8. Modify the routing information of all CNs on cluster1 to add a route to CN3;

[0184] 9. Restart CN3.

[0185] Thus, two independent clusters are merged into one cluster to provide services externally together.

[0186] Figure 7 The distributed database cluster splitting device 700 provided by the present invention is shown, including a data acquisition module 710, a rule module 720, and a node splitting module 730.

[0187] The data acquisition module 710 acquires information of the distributed database cluster to be split; wherein, the information includes the number of database access times, latency, and the number of nodes; the nodes include CNs, GTMs, and DNs;

[0188] The rule module 720 is used to receive a cluster splitting request; and allocate splitting nodes based on the splitting request and the information of the distributed database cluster;

[0189] The node splitting module 730 is used to split the distributed database cluster based on the allocated splitting nodes.

[0190] In an embodiment of the present invention, the apparatus further includes: a node merging module configured to obtain node information of a distributed database cluster to be merged, where the distributed database cluster to be merged includes a first cluster and a second cluster; stop all nodes of the second cluster; set node connection string information of the second cluster and connect to the master node of the first cluster; trigger full build data of all GTMs and DNs in the second cluster, with the source end being the corresponding master node of the first cluster; trigger full build data of the CN in the second cluster, with the source end being any CN of the first cluster; modify the GTM on the first cluster and the standby machine information on the master node of the DN, and establish a data replication slot to the corresponding node of the second cluster; restart all GTMs and DN nodes in the second cluster as standby nodes, and the master and standby start synchronizing data based on the data replication slot; modify the routing information of all CNs on the first cluster to add a route to the CN of the second cluster; and restart the routing of the CN of the second cluster.

[0191] See Figure 8 , an embodiment of the present disclosure further provides an electronic device 80, which includes:

[0192] at least one processor; and,

[0193] a memory communicatively connected to the at least one processor; wherein,

[0194] the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the distributed database cluster splitting method in the foregoing method embodiment.

[0195] An embodiment of the present disclosure further provides a non-transitory computer-readable storage medium, which stores computer instructions for causing the computer to execute the distributed database cluster splitting method in the foregoing method embodiment.

[0196] An embodiment of the present disclosure further provides a computer program product, which includes a computing program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions that, when executed by a computer, cause the computer to execute the distributed database cluster splitting method in the foregoing method embodiment.

[0197] Next, refer to Figure 8, which shows a schematic structural diagram of an electronic device 80 suitable for implementing the embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The shown electronic device is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present disclosure.

[0198] As Figure 8 shown, the electronic device 80 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 801, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 802 or the program loaded from the storage device 808 into the random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 80 are also stored. The processing device 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. The input / output (I / O) interface 805 is also connected to the bus 804.

[0199] Generally, the following devices may be connected to the I / O interface 805: an input device 806 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 808 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 809. The communication device 809 may allow the electronic device 80 to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows the electronic device 80 with various devices, it should be understood that it is not required to implement or have all the shown devices. More or fewer devices may be implemented or had alternatively.

[0200] Particularly, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from the network through the communication device 809, or installed from the storage device 808, or installed from the ROM 802. When the computer program is executed by the processing device 801, the above functions defined in the methods of the embodiments of the present disclosure are executed.

[0201] It should be noted that the above-mentioned computer-readable medium in the present disclosure can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable signal medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0202] The above-mentioned computer-readable medium can be included in the above-mentioned electronic device; it can also exist separately without being assembled into the electronic device.

[0203] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device is caused to: obtain at least two Internet protocol addresses; send a node evaluation request including the at least two Internet protocol addresses to a node evaluation device, wherein the node evaluation device selects an Internet protocol address from the at least two Internet protocol addresses and returns it; receive the Internet protocol address returned by the node evaluation device; wherein, the obtained Internet protocol addresses indicate edge nodes in a content distribution network.

[0204] Alternatively, the above computer-readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receive a node evaluation request including at least two Internet Protocol addresses; select an Internet Protocol address from the at least two Internet Protocol addresses; return the selected Internet Protocol address; wherein the received Internet Protocol address indicates an edge node in a content delivery network.

[0205] Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0206] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0207] The units involved in the embodiments of the present disclosure may be implemented in software or in hardware. In some cases, the name of the unit does not constitute a limitation on the unit itself. For example, the first acquisition unit may also be described as "the unit for acquiring at least two Internet Protocol addresses".

[0208] It should be understood that the various parts of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof.

[0209] As described above, this is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present disclosure should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims

1. A method for splitting a distributed database cluster, characterized in that The method includes the following steps: Obtain information of the distributed database cluster to be split; wherein, the information includes the number of database accesses, latency, and the number of nodes; the nodes include CN, GTM, and DN; Receive a cluster split request; Allocate split nodes based on the split request and the information of the distributed database cluster; Split the distributed database cluster based on the allocated split nodes. The splitting of the distributed database cluster based on the allocated split nodes includes a stop-service splitting method, and the stop-service splitting method includes the following steps: Based on the allocated split nodes, parse the number of CNs, the number of GTM replicas, and the number of DN replicas required by the second cluster, and retain the remaining CNs, GTM replicas, and DN replicas in the first cluster; Stop all nodes included in the second cluster; Remove the nodes of the second cluster in the first cluster and retain the node data; Modify the connection string information of the GTM and DN nodes in the first cluster, and delete the replication slot from the master node to the corresponding nodes in the second cluster; Delete all routing information from the CNs in the first cluster to the CNs in the second cluster; Modify the connection string information of the GTM and DN nodes in the second cluster; Based on the allocated split nodes, start the master node and standby nodes of the second cluster, establish master-standby connections respectively, and start synchronizing data; Start the CNs of the second cluster and modify the routing of CNs, GTMs, and DNs.

2. The distributed database cluster splitting method according to claim 1, wherein The allocation of split nodes based on the split request and the information of the distributed database cluster includes: sorting the CNs from small to large based on the number of database accesses; wherein, obtain CNs based on the number of concurrent operations in the first cluster in the split request × 120; Sort the DN shard replicas in descending order according to the data synchronization latency. The higher the latency, the higher the DN split weight; Analyze the network latency between the CNs obtained from the first cluster and the DN shard replicas. The lower the latency, the higher the DN split weight; Calculate the split priority of the DN shard replicas based on the DN split weight; Sort the GTM shard replicas in descending order according to the data synchronization latency. The higher the latency, the higher the GTM split weight; Analyze the network latency between the CNs obtained from the first cluster and the GTM shard replicas. The lower the latency, the higher the GTM split weight; Calculate the split priority of the GTM shard replicas based on the GTM split weight.

3. The distributed database cluster splitting method according to claim 1, wherein The splitting of the distributed database cluster based on the allocated split nodes includes a non-stop-service splitting method, and the non-stop-service splitting method includes the following steps: Increase the number of log retention files; Record the wal log positions of each shard; Remove the nodes of the second cluster in the first cluster and retain the node data; Modify the connection string information of the GTM and DN nodes in the first cluster, and delete the replication slot from the master node to the corresponding nodes in the second cluster; Delete all routing information from the CNs in the first cluster to the CNs in the second cluster; Split the corresponding nodes of the second cluster out of the first cluster. After the splitting is completed, trigger the first cluster to create a data consistency point; Collect the log files of each shard and send the log files to the second cluster; Start the second cluster master node and set the startup log target to lsn_end; Based on the allocated split nodes, start the master node and standby nodes of the second cluster, establish master-standby connections respectively, and start synchronizing data; Start the CN of the second cluster and modify the routing of CN and GTM to DN.

4. The distributed database cluster splitting method according to any one of claims 1-3, characterized in that The method further includes a distributed database cluster merging method, which includes the following steps: Obtain the node information of the distributed database cluster to be merged: the distributed database cluster to be merged includes a first cluster and a second cluster; Stop all nodes of the second cluster; Set the node connection string information of the second cluster and connect to the master node of the first cluster; Trigger all GTMs and DNs of the second cluster to build full data, with the source being the corresponding master node of the first cluster; Trigger the CN of the second cluster to build full data, with the source being any CN of the first cluster; Modify the GTM on the first cluster and the standby machine information on the DN master node, and establish a data replication slot to the corresponding nodes of the second cluster; Restart all GTM and DN nodes on the second cluster as standby nodes, and the master and standby start synchronizing data based on the data replication slot; Modify the routing information of all CNs on the first cluster to add a route to the CN of the second cluster; Restart the routing of the CN of the second cluster.

5. A distributed database cluster splitting device, based on the distributed database cluster splitting method according to any one of claims 1-3, characterized in that, The device includes: A data acquisition module configured to acquire information about the distributed database cluster to be split; wherein, the information includes the number of database accesses, latency, and the number of nodes; the nodes include CN, GTM, and DN; A rule module configured to receive a cluster split request; allocate split nodes based on the split request and the information of the distributed database cluster; A node splitting module configured to split the distributed database cluster based on the allocated split nodes.

6. The distributed database cluster splitting device according to claim 5, characterized in that, The device further includes: A node merging module configured to obtain the node information of the distributed database cluster to be merged: the distributed database cluster to be merged includes a first cluster and a second cluster; Stop all nodes of the second cluster; Set the node connection string information of the second cluster and connect to the master node of the first cluster; Trigger all GTMs and DNs of the second cluster to build full data, with the source being the corresponding master node of the first cluster; Trigger the CN of the second cluster to build full data, with the source being any CN of the first cluster; Modify the GTM on the first cluster and the standby machine information on the DN master node, and establish a data replication slot to the corresponding nodes of the second cluster; Restart all GTM and DN nodes on the second cluster as standby nodes, and the master and standby start synchronizing data based on the data replication slot; Modify the routing information of all CNs on the first cluster to add a route to the CN of the second cluster; and, Restart the routing of the CN of the second cluster.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is caused to execute the distributed database cluster splitting method according to any one of claims 1-3.

8. A computer program product, characterized in that, The computer program product includes a computing program stored on a non-transitory computer-readable storage medium, the computer program includes program instructions, and when the program instructions are executed by a computer, the computer is caused to execute the distributed database cluster splitting method according to any one of claims 1-3.

Citation Information

Patent Citations

  • Data storage method and system, node, computing engine and coordinator

    CN116975147A

  • Method and device for adjusting partition distribution of capacity expansion cluster

    CN118193205A