Data synchronization method and device, storage medium and electronic equipment

By obtaining the subscription information of the target message queue and determining the synchronization strategy, the problem of performance degradation caused by data synchronization in the cluster is solved, efficient data synchronization is achieved, and cluster performance is improved.

CN118550971APending Publication Date: 2024-08-27JINAN INSPUR DATA TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410675716.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-28
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

When performing data synchronization in a cluster, data synchronization to all nodes results in performance degradation, and existing technologies cannot effectively solve this problem.

Method used

By obtaining the subscription information of each target message queue, the change in the number of target nodes is determined, the data synchronization strategy is determined based on the number of nodes, and the data is synchronized to the nodes to be synchronized that comply with the strategy to avoid synchronizing to all nodes.

Benefits of technology

It improves cluster performance, solves the problem of performance degradation caused by data synchronization, and implements an efficient data synchronization strategy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550971A
    Figure CN118550971A
Patent Text Reader

Abstract

The embodiment of the invention provides a data synchronization method and device, a storage medium and electronic equipment, and the method comprises the steps: for each target message queue included in a plurality of message queues, obtaining subscription information of the target message queue; under the condition that the subscription information of the target message queue is changed, determining whether the number of the target nodes is changed or not; under the condition that the number of the target nodes changes, determining a second number of the target nodes; determining a target data synchronization strategy for synchronizing the data stored in the target message queue based on the first quantity and the second quantity; and synchronizing the data stored in the target message queue to the to-be-synchronized node indicated by the target data synchronization strategy. Through the method and the device, the problem of relatively poor cluster performance caused by data synchronization in related technologies is solved, and the effect of improving the cluster performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the computer field, and more specifically, to a data synchronization method, device, storage medium and electronic device. Background Art

[0002] In the related art, when data synchronization is performed in a cluster, the data is often synchronized to all nodes, which seriously affects the performance of the cluster when the number of messages is large.

[0003] It can be seen from this that the related technology has the problem of data synchronization leading to poor cluster performance.

[0004] Currently, no effective solution has been proposed for the above-mentioned problems existing in the related technologies. Summary of the invention

[0005] The embodiments of the present application provide a data synchronization method, device, storage medium and electronic device to at least solve the problem of poor cluster performance caused by data synchronization in the related art.

[0006] According to an embodiment of the present application, a data synchronization method is provided, which is applied to a target cluster, wherein the target cluster includes a first number of nodes and multiple message queues, and consumers subscribe to data stored in a target message queue in the multiple message queues through the nodes, including: for each target message queue included in the multiple message queues, obtaining subscription information of the target message queue, wherein the subscription information includes a consumer who subscribes to the data stored in the target message queue, and a target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node; in the case where the subscription information of the target message queue changes, determining whether the number of the target nodes changes; in the case where the number of the target nodes changes, determining a second number of the target nodes; determining a target data synchronization policy for synchronizing the data stored in the target message queue based on the first number and the second number; and synchronizing the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization policy.

[0007] In an exemplary embodiment, determining a target data synchronization strategy based on the first number and the second number includes: determining a candidate synchronization node based on the first number and the second number; and determining the candidate synchronization node as the node to be synchronized indicated by the target data synchronization strategy.

[0008] In an exemplary embodiment, determining the candidate synchronization nodes based on the first number and the second number includes: determining a target sum value of the first number and a first constant; determining a ratio of the target sum value to a second constant, wherein the ratio is greater than a predetermined threshold value, and the predetermined threshold value is a threshold value determined based on the first number, and when the number of nodes to be synchronized in the target cluster is greater than or equal to the predetermined threshold value, the target cluster is in a high availability state; determining the ratio as a synchronization number threshold value; when the second number is greater than the synchronization number threshold value, determining the target nodes of the second number as candidate synchronization nodes; when the second number is less than the synchronization number threshold value, determining a target difference between the second number and the synchronization number threshold value; determining a first node other than the target node included in the nodes of the first number; determining a second node in the first node, wherein the number of the second nodes is the target difference value; determining the target nodes of the second number and the second nodes of the target difference value as candidate synchronization nodes.

[0009] In an exemplary embodiment, synchronizing the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization policy includes: for each target node to be synchronized included in the node to be synchronized, performing the following operations to synchronize the data stored in the target message queue to the target node to be synchronized: determining whether there is a historical synchronization policy in the target node to be synchronized; if there is a historical synchronization policy in the target node to be synchronized, deleting the historical synchronization policy included in the target node to be synchronized, and creating the target data synchronization policy in the target node to be synchronized; if the historical synchronization policy does not exist in the target node to be synchronized, creating the target data synchronization policy in the target node to be synchronized; controlling the target node to be synchronized to execute the target data synchronization policy to synchronize the data stored in the target message queue to the target node to be synchronized.

[0010] In an exemplary embodiment, the target data synchronization policy for synchronizing the data stored in the target message queue based on the first quantity and the second quantity includes: generating a data synchronization policy based on the first quantity and the second quantity; determining a queue name included in the data synchronization policy for indicating the message queue to be synchronized; if the queue name meets a predetermined condition, determining the data synchronization policy as the target data synchronization policy, wherein the predetermined condition is that the queue name does not include a field for indicating multiple message queues; if the queue name does not meet the predetermined condition, redetermining the data synchronization policy based on the first quantity and the second quantity until the data synchronization policy meets the predetermined condition.

[0011] In an exemplary embodiment, the obtaining the subscription information of the target message queue includes: when the target cluster starts a management service, obtaining the subscription information based on a target interface of the management service.

[0012] In an exemplary embodiment, obtaining the subscription information of the target message queue includes: obtaining consumer link information included in a subscription list, wherein the subscription list is a list created when the target message queue is created, and the subscription list is used to store consumer link information of consumers who subscribe to data stored in the target message queue, and the consumer link information includes consumers and nodes connected to the consumers; determining the subscription information based on the consumer link information.

[0013] According to another embodiment of the present application, a data synchronization device is provided, which is applied to a target cluster, wherein the target cluster includes a first number of nodes and multiple message queues, and consumers subscribe to data stored in a target message queue in the multiple message queues through the nodes, including: an acquisition module, which is used to acquire subscription information of the target message queue for each target message queue included in the multiple message queues, wherein the subscription information includes consumers who subscribe to the data stored in the target message queue and target nodes corresponding to the consumers, and the consumers subscribe to the data stored in the target message queue through the target nodes; a first determination module, which is used to determine whether the number of target nodes has changed if the subscription information of the target message queue has changed; a second determination module, which is used to determine the second number of target nodes if the number of target nodes has changed; a third determination module, which is used to determine a target data synchronization strategy for synchronizing the data stored in the target message queue based on the first number and the second number; and a synchronization module, which is used to synchronize the data stored in the target message queue to the nodes to be synchronized indicated by the target data synchronization strategy.

[0014] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0015] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0016] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.

[0017] Through the present application, for each target message queue included in multiple message queues, the subscription information of the target message queue is obtained, wherein the subscription information includes consumers who subscribe to the data stored in the target message queue, and the target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node; in the case where the subscription information of the target message queue changes, it is determined whether the number of target nodes changes; in the case where the number of target nodes changes, the second number of target nodes is determined; based on the first number and the second number, a target data synchronization policy for synchronizing the data stored in the target message queue is determined; the data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy. Since the subscription information of each target message queue can be determined in the target cluster, in the case where the subscription information of the target message queue changes, it is determined whether the number of target nodes changes, in the case where the number of target nodes changes, the second number of target nodes is determined, the target data synchronization policy is determined according to the first number and the second number of nodes included in the target cluster, and the data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy. That is, when the number of target nodes accessing the target message queue changes, the target data synchronization strategy can be determined according to the second number of target nodes and the first number of all nodes in the target cluster, and the data stored in the target message queue can be synchronized to the nodes to be synchronized indicated by the target data synchronization strategy. There is no need to synchronize the data to all nodes. Therefore, the problem of poor cluster performance caused by data synchronization in related technologies can be solved, thereby achieving the effect of improving cluster performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a hardware structure block diagram of a server device of a data synchronization method according to an embodiment of the present application;

[0019] Figure 2 is a flow chart of a method for synchronizing data according to an embodiment of the present application;

[0020] Figure 3 is a schematic diagram of data synchronization of a target cluster according to an embodiment of the present application;

[0021] Figure 4 is a working schematic diagram of a target cluster according to an embodiment of the present application;

[0022] Figure 5 This is an example of determining a candidate synchronization node according to an embodiment of the present application. Figure 1 ;

[0023] Figure 6 This is an example of determining a candidate synchronization node according to an embodiment of the present application. Figure 2 ;

[0024] Figure 7 It is a structural block diagram of a data synchronization device according to an embodiment of the present application. DETAILED DESCRIPTION

[0025] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0027] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of a data synchronization method according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the server device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0028] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the data synchronization method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0029] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0030] In this embodiment, a data synchronization method is provided, which is applied to a target cluster, wherein the target cluster includes a first number of nodes and multiple message queues, and a consumer subscribes to data stored in a target message queue in the multiple message queues through the node. Figure 2 is a flow chart of a method for synchronizing data according to an embodiment of the present application. Figure 2 As shown, the process includes the following steps:

[0031] Step S202: for each target message queue included in the multiple message queues, obtaining subscription information of the target message queue, wherein the subscription information includes a consumer who subscribes to the data stored in the target message queue, and a target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node;

[0032] Step S204, when the subscription information of the target message queue changes, determining whether the number of the target nodes changes;

[0033] Step S206, when the number of the target nodes changes, determining a second number of the target nodes;

[0034] Step S208, determining a target data synchronization strategy for synchronizing the data stored in the target message queue based on the first number and the second number;

[0035] Step S210: synchronizing the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization policy.

[0036] In the above embodiment, a cluster refers to a group (several) of independent nodes (computers or other units), which form a larger service through a network, and each cluster node is an independent server running its own service. The nodes can communicate with each other, cooperate to provide applications, system resources and data to users, and manage them in a single system mode. Some data content will be synchronized between nodes in the cluster to ensure data consistency. Data synchronization is used for backup and redundancy to reduce the risk of data loss. The role of data synchronization is to copy the data (specific content of the message) in other nodes A to other nodes B, ensuring that the data can be found on node B when node A fails. Data is synchronized between multiple nodes. When a node in the cluster is abnormal (network abnormality, shutdown), other nodes can provide services, and data can also be saved in other nodes, realizing the high availability of the cluster. Among them, the target cluster can be a rabbitmq cluster, a kafka cluster, a k8s cluster, etc. The target cluster can include an exchange, and the production of messages is first pushed (published) to the exchange, and the exchange forwards the message to the message queue according to binds (similar to forwarding rules). The message queue is where messages are stored, and consumers subscribe to specific queues. When a consumer subscribes to a specific queue, if there is a message in the queue, the message will be sent to the specific consumer.

[0037] In the above embodiment, the consumer can be a client, and the consumer can subscribe to the message in the message queue in the target cluster through the node in the target cluster. The connection established between the consumer and the node can be a long link. In network communication, two opposite ends establish a socket, which is generally called a link. If the link is released in a short time, it is a short link. If the link has been in existence for a long time and has not been released, it is a long link. In the process of the client client subscribing to the queue, the client will establish a long link with a node in the rabbitmq cluster. The two ends of the long link are the client and a node of the rabbitmq cluster, and this node of the rabbitmq cluster is the rabbitmq node in the long link. After the client connects to the server (a node in the cluster), the general connection is to establish a long link, and the long link will be maintained for a long time, which is equivalent to the client consuming messages from this node for a long time. Message middleware is a use scenario where messages are consumed quickly. In this use scenario, messages will not exist for a long time. If messages exist for a long time, subsequent messages will be backlogged. In some scenarios, messages have a life cycle, and messages that exceed the life cycle will be automatically deleted.

[0038] In the above embodiment, the target cluster is a RabbitMQ cluster. In the RabbitMQ cluster, data synchronization between nodes is for exchange or queue, and data will be in the queue after exchange. Therefore, it is feasible to configure different policies for different queues in the RabbitMQ cluster. Among them, policy is the synchronization strategy, which is the strategy configured for exchange or queue and is used to synchronize data.

[0039] In the above embodiment, the data synchronization diagram of the target cluster can be found in the attached Figure 3 ,like Figure 3 As shown in the figure, each message from the producer will be synchronized to all nodes in the cluster. The working diagram of the target cluster can be found in the attached Figure 4 ,like Figure 4 As shown in the figure, the process of message production and consumption, the producer produces the message, the message arrives at the exchange (plays the role of forwarding), and the exchange forwards the message to a specific queue according to the rules of binds. The queue is where the message is stored. The message is sent to the consumer according to the consumer's subscription.

[0040] In the above embodiment, the target cluster may include multiple message queues, that is, multiple queues. Different consumers may subscribe to message data in one or more message queues through different or the same nodes. For each target message queue included in the multiple message queues, the subscription information of the target message queue may be obtained, and the consumer subscribing to the target message queue and the target node connected to the consumer may be determined according to the subscription information. When the subscription information of the target message queue changes, it may be determined whether the number of target nodes changes. Among them, the subscription information of the target message queue changes, and the number of consumers subscribing to the target message queue increases, decreases, or disconnects. For example, the current subscription information is that consumer 1 subscribes to the target message queue queueA through the target node node1, and consumer 2 subscribes to the target message queue queueA through the target node node2. When the number of consumers subscribing to the target message queue queueA increases, for example, when consumer 3 subscribes to the target message queue queueA through the target node node1, it may be determined that the subscription information has changed. However, at this time, the nodes accessing the target message queue are still node1 and node2, so it may be determined that the number of target nodes has not changed. For another example, the current subscription information is that consumer 1 subscribes to target message queue queueA through target node node1, and consumer 2 subscribes to target message queue queueA through target node node2. When the number of consumers subscribing to target message queue queueA increases, for example, when consumer 3 subscribes to target message queue queueA through target node node3, it can be determined that the subscription information has changed. Moreover, at this time, the newly added target node node3 indicates that the number of target nodes has changed.

[0041] In the above embodiment, taking the target cluster as rabbitmq as an example, detecting the subscription information change may include running an independent program outside the rabbitmq program to monitor whether the subscriber information of a specific queue (the subscriber information is the client link) is sent to change. The rabbitmq program may also be modified. After rabbitmq establishes a queue, a client subscribes to the queue and the link information of the client link is updated to determine whether the subscription information is sent to change.

[0042] In the above embodiment, when the number of target nodes changes, the second number of target nodes can be determined, and the target data synchronization strategy for storing data in the synchronized target message queue can be determined based on the second number and the first number. The strategy is configured based on the subscription information of the queue, and based on the information of the rabbitmq node in the long link, it is determined which rabbitmq nodes a queue needs to be synchronized to. Among them, the configuration of the strategy can be to add or modify the strategy of rabbitmq, and the operation path or method includes rabbitmqctl command, restapi, etc. The rabbitmqctl command is a command that comes with rabbitmq itself, and the policy can be modified and configured through this command. The restapi is after rabbitmq turns on the management service, the configuration can be modified through the restapi of this service.

[0043] Through the present application, for each target message queue included in multiple message queues, the subscription information of the target message queue is obtained, wherein the subscription information includes consumers who subscribe to the data stored in the target message queue, and the target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node; in the case where the subscription information of the target message queue changes, it is determined whether the number of target nodes changes; in the case where the number of target nodes changes, the second number of target nodes is determined; based on the first number and the second number, a target data synchronization policy for synchronizing the data stored in the target message queue is determined; the data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy. Since the subscription information of each target message queue can be determined in the target cluster, in the case where the subscription information of the target message queue changes, it is determined whether the number of target nodes changes, in the case where the number of target nodes changes, the second number of target nodes is determined, the target data synchronization policy is determined according to the first number and the second number of nodes included in the target cluster, and the data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy. That is, when the number of target nodes accessing the target message queue changes, the target data synchronization strategy can be determined according to the second number of target nodes and the first number of all nodes in the target cluster, and the data stored in the target message queue can be synchronized to the nodes to be synchronized indicated by the target data synchronization strategy. There is no need to synchronize the data to all nodes. Therefore, the problem of poor cluster performance caused by data synchronization in related technologies can be solved, thereby achieving the effect of improving cluster performance.

[0044] The execution subject of the above steps may be a target cluster, such as a processor in the target cluster, but is not limited thereto.

[0045] In an exemplary embodiment, the target data synchronization strategy is determined based on the first number and the second number, including: determining a candidate synchronization node based on the first number and the second number; and determining the candidate synchronization node as the node to be synchronized indicated by the target data synchronization strategy. In this embodiment, the candidate synchronization node can be determined based on the first number and the second number, and the candidate synchronization node can be determined as the node to be synchronized indicated in the target data synchronization strategy. After the target data synchronization strategy indicates the node to be synchronized, the data stored in the target message queue can be synchronized to each node included in the node to be synchronized.

[0046] In the above embodiment, determining the candidate synchronization nodes based on the first number and the second number may include: when the first number is the same as the second number, determining the candidate synchronization nodes as all nodes included in the target cluster. When the second number is less than the first number, a target consumer subscribing to data in the target message queue may be determined, and the node connected to the target consumer may be determined as the candidate synchronization node.

[0047] In the above embodiment, by determining the candidate synchronization node based on the first number of nodes included in the target cluster and the second number of target nodes accessing the target message queue, it is possible to fully consider the relationship between the number of all nodes included in the target cluster and the number of target nodes accessing the target message queue when determining the candidate synchronization node, so that the determined candidate node can adapt to changes in the number of consumers and improve the performance of the target cluster.

[0048] In an exemplary embodiment, the determination of candidate synchronization nodes based on the first number and the second number includes: determining a target sum value of the first number and a first constant; determining a ratio of the target sum value to a second constant, wherein the ratio is greater than a predetermined threshold value, the predetermined threshold value is a threshold value determined based on the first number, and when the number of nodes to be synchronized in the target cluster is greater than or equal to the predetermined threshold value, the target cluster is in a high availability state; determining the ratio as a synchronization number threshold value; when the second number is greater than the synchronization number threshold value, determining the target nodes of the second number as candidate synchronization nodes; when the second number is less than the synchronization number threshold value, determining a target difference between the second number and the synchronization number threshold value; determining a first node other than the target node included in the first number of nodes; determining a second node in the first node, wherein the number of the second node is the target difference value; determining the target nodes of the second number and the second node of the target difference value as candidate synchronization nodes. In this embodiment, the target sum value of the first number and the first constant can be determined, and the ratio of the target sum value to the second constant can be determined. Among them, the first constant and the second constant can be constants determined according to a predetermined threshold, and the values ​​of the first constant and the second constant can make the ratio of the target sum value to the second constant greater than the predetermined threshold. Among them, the predetermined threshold can be a value determined according to the first number, and when the number of synchronized nodes is greater than the predetermined threshold, the target cluster can be in a high availability state. For example, the predetermined threshold can be one-half of the first number, or two-thirds, three-quarters, etc., and the present invention is not limited to this. When the predetermined threshold is one-half of the first number, the first constant can be 1, and the second constant can be, that is, when the first number is n, the ratio can be expressed as (n+1) / 2. It should be noted that the values ​​of the first constant and the second constant are only an exemplary description, and the present invention is not limited to this.

[0049] In the above embodiment, the ratio of the target sum value to the second constant can be determined as the synchronization quantity threshold. When the second number is greater than the synchronization quantity threshold, it means that the target node currently subscribed to the target message queue has exceeded the high availability threshold of the target cluster, that is, the predetermined threshold. Therefore, the second number of target nodes can be directly determined as candidate synchronization nodes.

[0050] In the above embodiment, when the second number is less than or equal to the synchronization number threshold, it means that the target node currently subscribing to the target message queue does not exceed the high availability threshold of the target cluster. In order to achieve the high availability of the target cluster, a target difference second node can be determined from the first node other than the target node included in the target cluster. The target difference can be the difference between the synchronization number threshold and the second number. The second node and the target node are determined as candidate synchronization nodes. At this time, the number of candidate synchronization nodes is the sum of the second number and the target difference, which is greater than or equal to the synchronization number threshold. Therefore, the high availability of the target cluster can be achieved.

[0051] In the above embodiment, determining the second node in the first nodes may include randomly determining the second node in the first nodes.

[0052] In the above embodiment, based on the information of the RabbitMQ nodes in the long link, it can be determined that these nodes belong to the nodes whose data needs to be synchronized. Figure 1 Please refer to the attached Figure 5 ,like Figure 5 As shown, consumer 1 subscribes to QueueA by establishing a link with node1, and consumer 2 subscribes to QueueA by establishing a link with node2. That is, queue QueueA has consumers subscribed on node1 and node2. Data related to QueueA only needs to be synchronized on node1 and node2. If you want to ensure high availability of the cluster, data synchronization needs to be synchronized to more than half of the number of cluster nodes. Assuming that the number of cluster nodes is n, data needs to be synchronized to more than (n+1) / 2 nodes. In other words, the number of nodes synchronizing data must exceed half. If the number of nodes in 1 is less than (n+1) / 2, it is necessary to randomly select nodes from other nodes in the cluster to ensure that the number of nodes synchronizing data is (n+1) / 2. Schematic diagram of determining candidate synchronization nodes Figure 2 Please refer to the attached Figure 6 ,like Figure 6 As shown, the consumer subscribes to the queue and connects to node 2. A result is randomly generated between node 1 and node 3. Finally, the data is synchronized between node 1 and node 2, or between node 3 and node 2.

[0053] In the above embodiment, when the number of target nodes is greater than or equal to the synchronization number threshold, the target node is directly determined as a candidate synchronization node. When the number of target nodes is less than the synchronization number threshold, a target difference number of second nodes is determined from the first nodes other than the target node included in the target cluster, and the target node and the second node are determined as candidate synchronization nodes. With such a setting, high availability of the target cluster can be achieved.

[0054] In an exemplary embodiment, determining a second node in a first node may include: determining attribute information of each node included in the first node, wherein the attribute information is used to indicate the type of the node; when the attribute information indicates that the first node includes multiple types of nodes, classifying the first node according to the attribute information to obtain multiple categories, wherein the types of nodes included in each category are the same, and determining the load status of the nodes included in each category and the processing performance of the nodes; determining a target ratio between the load status and the processing performance, and determining a third node with the smallest target ratio included in each category; determining a third number of the third nodes, and when the third number is equal to the target difference, determining the third node as the second node; when the third number is greater than the target difference, determining the target difference number of nodes with the smallest target ratio included in the third node as the second node; when the third number is less than the target difference, determining the third node as a part of the second node; determining a fourth node from other nodes included in the nodes in each category except the third node, and determining the fourth node as a part of the second node, wherein the sum of the number of the third nodes and the number of the fourth nodes is the target difference. In this embodiment, the nodes can be classified, and one node from each category of nodes is determined as the second node, so that data can be synchronized to nodes of different categories, to prevent the problem of data being unable to be synchronized and cluster performance being reduced when all nodes of a certain category fail. The node with the smallest load in each category is used as the second node, which realizes load balancing and effectively improves the performance of the cluster.

[0055] In an exemplary embodiment, the data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy, including: for each target node to be synchronized included in the node to be synchronized, the following operations are performed to synchronize the data stored in the target message queue to the target node to be synchronized: determine whether there is a historical synchronization policy in the target node to be synchronized; if there is a historical synchronization policy in the target node to be synchronized, delete the historical synchronization policy included in the target node to be synchronized, and create the target data synchronization policy in the target node to be synchronized; if there is no historical synchronization policy in the target node to be synchronized, create the target data synchronization policy in the target node to be synchronized; control the target node to be synchronized to execute the target data synchronization policy to synchronize the data stored in the target message queue to the target node to be synchronized. In this embodiment, all queues can be checked, and policies can be generated and updated according to the current subscription information of the queue. If there is no policy, a new one is created; if there is a policy, the policy is deleted and then a new one is created.

[0056] In the above embodiment, when there is a historical synchronization policy in the target node to be synchronized, the historical synchronization policy is deleted, and a new target data synchronization policy is created in the target node to be synchronized. When there is no historical synchronization policy in the target node to be synchronized, a new target data synchronization policy is created directly in the target node to be synchronized, which ensures that the target node to be synchronized can perform data synchronization according to the latest data synchronization policy, effectively ensures data consistency, and improves the performance of the target cluster.

[0057] In an exemplary embodiment, the target data synchronization strategy for synchronizing the data stored in the target message queue based on the first quantity and the second quantity includes: generating a data synchronization strategy based on the first quantity and the second quantity; determining a queue name included in the data synchronization strategy for indicating the message queue to be synchronized; if the queue name meets a predetermined condition, determining the data synchronization strategy as the target data synchronization strategy, wherein the predetermined condition is that the queue name does not include a field for indicating multiple message queues; if the queue name does not meet the predetermined condition, re-determining the data synchronization strategy based on the first quantity and the second quantity until the data synchronization strategy meets the predetermined condition. In this embodiment, it is possible to check whether there is a rule other than a queue name in the target data synchronization strategy, such as a matching rule such as "*" (* means that all fields are matched, for example, queue* can be understood as queue1, queueA, queue345abc can all be matched). Delete such a strategy. And regenerate the data synchronization strategy, check the queue name included in the regenerated data synchronization strategy again, until the data synchronization strategy meets the predetermined condition, and determine the data synchronization strategy as the target data synchronization strategy.

[0058] In the above embodiment, by detecting the queue name in the data synchronization policy, if the queue name meets the predetermined conditions, the data synchronization policy is determined as the target data synchronization policy, and if the queue name does not meet the predetermined conditions, the data synchronization policy is regenerated until the queue name meets the predetermined conditions. This effectively avoids the situation where synchronization is missed due to different queue naming rules.

[0059] In an exemplary embodiment, obtaining the subscription information of the target message queue includes: obtaining the subscription information based on the target interface of the management service when the management service is enabled in the target cluster. In this embodiment, a program can be written to obtain the subscription information of the queue through some commands and RESTAPI interfaces, and update the policy based on this information. Among them, the target interface can include a RESTAPI interface. RESTAPI is the RESTAPI of the management service that can be used to modify the configuration after RabbitMQ enables the management service.

[0060] In the above embodiment, when the target cluster opens the management service, the subscription information is obtained through the target interface of the management service, which can bring centralized management services to more effectively manage the resources and subscription information in the cluster and improve management efficiency. Subscription information can be automatically obtained and updated, reducing manual intervention and reducing error rates. The accuracy and consistency of subscription information are ensured, avoiding data silos and information inconsistency. Obtaining subscription information through the interface of the management service can implement stricter security control and access rights management.

[0061] In an exemplary embodiment, the acquisition of the subscription information of the target message queue includes: acquiring the consumer link information included in the subscription list, wherein the subscription list is a list created when the target message queue is created, and the subscription list is used to store the consumer link information of the consumer who subscribes to the data stored in the target message queue, and the consumer link information includes the consumer and the node to which the consumer is connected; the subscription information is determined based on the consumer link information. In this embodiment, when creating a queue, an empty subscription list can be created. This list is used to store information about consumers subscribing to the queue, and this information contains information about consumers establishing links. When a new consumer subscribes to the queue, the subscription list will be updated, and then the policy will be updated. In the case of a disconnected link, the subscription list will also be updated, and then the policy will be updated. The code can be modified in the rabbitmq program to allow rabbitmq to support dynamic updates of policies.

[0062] In the above embodiment, by obtaining the consumer link information in the subscription list created when the target message queue is created to determine the subscription information, it is possible to accurately understand which consumers have subscribed to the message queue and their connection relationship. Through the consumer link information, the connection relationship between the consumer and the message queue can be visualized.

[0063] In the previous embodiment, the configuration content of the high availability policy is determined based on the node of the cluster to which the client is connected. Then, the cluster nodes are calculated to determine which nodes the policy needs to be synchronized to. If the queue changes or has other impacts, the high availability policy can be dynamically updated. Ensure that the subscriber is in the policy. If the preset node number requirement is not met, randomly select from other nodes. By configuring the policy, data is guaranteed to be on multiple nodes, ensuring the high availability of the cluster. The high availability of the cluster means that after a node has an abnormality (such as power outage, network disconnection, crash, etc.), the message data is stored in other nodes, and consumers can receive messages from other nodes. Compared with the solution of configuring data synchronization between all nodes, it reduces overhead by 50%, improving system performance.

[0064] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0065] In this embodiment, a data synchronization device is also provided, which is applied to a target cluster, wherein the target cluster includes a first number of nodes and multiple message queues, and consumers subscribe to data stored in a target message queue in multiple message queues through the nodes. The device is used to implement the above-mentioned embodiments and preferred implementation modes, and those that have been described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0066] Figure 7 is a structural block diagram of a data synchronization device according to an embodiment of the present application, such as Figure 7 As shown, the device comprises:

[0067] An acquisition module 702 is used to acquire subscription information of each target message queue included in the multiple message queues, wherein the subscription information includes a consumer who subscribes to the data stored in the target message queue and a target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node;

[0068] A first determining module 704 is used to determine whether the number of the target nodes changes when the subscription information of the target message queue changes;

[0069] A second determining module 706, configured to determine a second number of the target nodes when the number of the target nodes changes;

[0070] A third determining module 708, configured to determine a target data synchronization strategy for synchronizing the data stored in the target message queue based on the first number and the second number;

[0071] The synchronization module 710 is used to synchronize the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization policy.

[0072] In an exemplary embodiment, the third determination module 708 can implement the target data synchronization strategy based on the first number and the second number in the following manner: determine a candidate synchronization node based on the first number and the second number; determine the candidate synchronization node as the node to be synchronized indicated by the target data synchronization strategy.

[0073] In an exemplary embodiment, the third determination module 708 can implement the determination of candidate synchronization nodes based on the first number and the second number in the following manner: determine a target sum of the first number and a first constant; determine a ratio of the target sum to a second constant, wherein the ratio is greater than a predetermined threshold, the predetermined threshold is a threshold determined based on the first number, and when the number of nodes to be synchronized in the target cluster is greater than or equal to the predetermined threshold, the target cluster is in a high availability state; determine the ratio as a synchronization number threshold; when the second number is greater than the synchronization number threshold, determine the target nodes of the second number as candidate synchronization nodes; when the second number is less than the synchronization number threshold, determine a target difference between the second number and the synchronization number threshold; determine a first node other than the target node included in the first number of nodes; determine a second node in the first node, wherein the number of the second nodes is the target difference; determine the target nodes of the second number and the second nodes of the target difference as candidate synchronization nodes.

[0074] In an exemplary embodiment, the synchronization module 710 can implement the synchronization of the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization policy in the following manner: for each target node to be synchronized included in the nodes to be synchronized, the following operations are performed to synchronize the data stored in the target message queue to the target node to be synchronized: determine whether there is a historical synchronization policy in the target node to be synchronized; if there is a historical synchronization policy in the target node to be synchronized, delete the historical synchronization policy included in the target node to be synchronized, and create the target data synchronization policy in the target node to be synchronized; if the historical synchronization policy does not exist in the target node to be synchronized, create the target data synchronization policy in the target node to be synchronized; control the target node to be synchronized to execute the target data synchronization policy to synchronize the data stored in the target message queue to the target node to be synchronized.

[0075] In an exemplary embodiment, the third determination module 708 can implement the target data synchronization policy for synchronizing the data stored in the target message queue based on the first quantity and the second quantity in the following manner: generate a data synchronization policy based on the first quantity and the second quantity; determine the queue name included in the data synchronization policy for indicating the message queue to be synchronized; if the queue name meets a predetermined condition, determine the data synchronization policy as the target data synchronization policy, wherein the predetermined condition is that the queue name does not include a field for indicating multiple message queues; if the queue name does not meet the predetermined condition, redetermine the data synchronization policy based on the first quantity and the second quantity until the data synchronization policy meets the predetermined condition.

[0076] In an exemplary embodiment, the obtaining the subscription information of the target message queue includes: when the target cluster starts a management service, obtaining the subscription information based on a target interface of the management service.

[0077] In an exemplary embodiment, the acquisition module 702 implements the acquisition of the subscription information of the target message queue in the following manner: acquiring consumer link information included in a subscription list, wherein the subscription list is a list created when the target message queue is created, and the subscription list is used to store consumer link information of consumers who subscribe to data stored in the target message queue, and the consumer link information includes consumers and nodes connected to the consumers; determining the subscription information based on the consumer link information.

[0078] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0079] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0080] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0081] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0082] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0083] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.

[0084] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0085] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.

[0086] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.

Claims

1. A data synchronization method, characterized in that: The method is applied to a target cluster, wherein the target cluster includes a first number of nodes and a plurality of message queues, and a consumer subscribes to data stored in a target message queue in the plurality of message queues through the node. include: For each target message queue included in the multiple message queues, the subscription information of the target message queue is obtained, wherein the subscription information includes a consumer who subscribes to the data stored in the target message queue and a target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node; In the case where the subscription information of the target message queue changes, determining whether the number of the target nodes changes; In case the number of the target nodes changes, determining a second number of the target nodes; Determine a target data synchronization strategy for synchronizing data stored in the target message queue based on the first number and the second number; The data stored in the target message queue is synchronized to the node to be synchronized indicated by the target data synchronization policy.

2. The method according to claim 1, characterized in that The determining a target data synchronization strategy based on the first quantity and the second quantity includes: Determine a candidate synchronization node based on the first number and the second number; The candidate synchronization node is determined as the node to be synchronized indicated by the target data synchronization policy.

3. The method according to claim 2, characterized in that The determining of candidate synchronization nodes based on the first number and the second number includes: determining a target and value of the first quantity and a first constant; Determine a ratio of the target sum value to a second constant, wherein the ratio is greater than a predetermined threshold, the predetermined threshold is a threshold determined based on the first number, and when the number of the nodes to be synchronized in the target cluster is greater than or equal to the predetermined threshold, the target cluster is in a high availability state; determining the ratio as a synchronization quantity threshold; In a case where the second number is greater than the synchronization number threshold, determining the second number of target nodes as the candidate synchronization nodes; In a case where the second number is less than the synchronization number threshold, determining a target difference between the second number and the synchronization number threshold; Determine a first node other than the target node included in the first number of nodes; Determine a second node among the first nodes, wherein the number of the second nodes is the target difference; The second number of the target nodes and the second nodes of the target difference are determined as the candidate synchronization nodes.

4. The method according to claim 1, characterized in that: The step of synchronizing the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization strategy includes: For each target node to be synchronized included in the nodes to be synchronized, the following operations are performed to synchronize the data stored in the target message queue to the target node to be synchronized: Determine whether there is a historical synchronization strategy in the target node to be synchronized; In the case where a historical synchronization policy exists in the target node to be synchronized, deleting the historical synchronization policy included in the target node to be synchronized, and creating the target data synchronization policy in the target node to be synchronized; In the case that the historical synchronization policy does not exist in the target node to be synchronized, creating the target data synchronization policy in the target node to be synchronized; The target node to be synchronized is controlled to execute the target data synchronization strategy to synchronize the data stored in the target message queue to the target node to be synchronized.

5. The method according to claim 1, characterized in that The determining, based on the first quantity and the second quantity, a target data synchronization strategy for synchronizing the data stored in the target message queue includes: generating a data synchronization strategy based on the first number and the second number; Determine a queue name included in the data synchronization strategy and used to indicate a message queue to be synchronized; In the case where the queue name satisfies a predetermined condition, determining the data synchronization policy as the target data synchronization policy, wherein the predetermined condition is that the queue name does not include a field for indicating multiple message queues; In a case where the queue name does not satisfy the predetermined condition, the data synchronization policy is redetermined based on the first number and the second number until the data synchronization policy satisfies the predetermined condition.

6. The method according to claim 1, characterized in that The obtaining the subscription information of the target message queue includes: In a case where the target cluster starts a management service, the subscription information is obtained based on a target interface of the management service.

7. The method according to claim 1, characterized in that The obtaining the subscription information of the target message queue includes: Acquire consumer link information included in a subscription list, wherein the subscription list is a list created when the target message queue is created, and the subscription list is used to store consumer link information of consumers who subscribe to data stored in the target message queue, and the consumer link information includes consumers and nodes connected to the consumers; The subscription information is determined based on the consumer link information.

8. A data synchronization device, characterized in that: The method is applied to a target cluster, wherein the target cluster includes a first number of nodes and a plurality of message queues, and a consumer subscribes to data stored in a target message queue in the plurality of message queues through the node. include: an acquisition module, configured to acquire subscription information of each target message queue included in the plurality of message queues, wherein the subscription information includes a consumer subscribing to data stored in the target message queue and a target node corresponding to the consumer, and the consumer subscribes to the data stored in the target message queue through the target node; A first determination module, configured to determine whether the number of the target nodes changes when the subscription information of the target message queue changes; A second determining module, configured to determine a second number of the target nodes when the number of the target nodes changes; A third determining module, configured to determine a target data synchronization strategy for synchronizing the data stored in the target message queue based on the first number and the second number; The synchronization module is used to synchronize the data stored in the target message queue to the node to be synchronized indicated by the target data synchronization strategy.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Multi-cluster message synchronization method and device, medium and electronic equipment

    CN112559628A

  • Block chain account book synchronization method and device based on half nodes

    CN113434599A

  • Message communication method and device

    CN113641511A

  • Dynamic balance coordination method and coordination system for ACTIVEMQ consumer to process messages

    CN116346915A

  • Storage client, message data storage device, system, method and equipment

    CN117499379A