A data processing method, device, equipment and storage medium
By determining the cluster working mode and request type, and using message queues to process request traffic, the problem of data consistency between the main cluster and the disaster recovery cluster in different modes is solved, and service stability and traffic peak-cutting effects are achieved.
Patent Information
- Application Number
- CN202210696715.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-20
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2042-06-20
AI Technical Summary
In the existing technology, the main cluster and the disaster recovery cluster fail to achieve data consistency under different working modes, resulting in data inconsistency problems and affecting business logic and service stability.
By obtaining the working mode of the cluster, the type of request traffic is determined, and the forwarding path of the request traffic is determined based on the mode and type. The message queue is used for sequential consumption and asynchronous processing to ensure that the main cluster and disaster recovery cluster are in normal and disaster recovery recovery working modes. data consistency.
It achieves seamless connection and automatic switching under different working modes, ensures the stability of external services, solves data consistency issues, reduces the performance pressure of disaster recovery clusters, and plays a role in peak traffic shaving during peak traffic periods. .
Smart Images

Figure CN115134217B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data management technology, and in particular to a data processing method, device, equipment and storage medium. Background Art
[0002] In the Internet system, due to the high reliability requirements for providing services to the outside world, a main cluster and a disaster recovery cluster are usually designed. When a problem occurs in the main cluster, it is promptly switched to another disaster recovery cluster, so as to achieve uninterrupted external services. The two clusters cooperate with each other to provide external services. Since both the main cluster and the disaster recovery cluster need to provide external services, the data stored in the two clusters must be consistent, otherwise it will cause problems for the upstream business logic. For example, in an e-commerce system, a user has placed an order to purchase a product. When the main cluster is unavailable, after the system switches to the disaster recovery cluster, the user's purchase record, payment record and other data need to be consistent with the main cluster, otherwise it will cause a series of problems such as complaints; for the same purchase order, its logistics order number updates a logistics information (for example, the logistics has arrived at a certain transfer point). If the main cluster is restored to be available at this time, the logistics information should be consistent with the disaster recovery cluster after the system switches back from the disaster recovery cluster to the main cluster, otherwise it will cause problems such as loss of logistics information.
[0003] In the prior art, Figure 1 As shown in the figure, the system consists of a main cluster and a disaster recovery cluster. In the normal working mode, that is, when the main cluster is available, the request traffic is forwarded to the main cluster; in the disaster recovery working mode, that is, when the main cluster is unavailable, the request traffic is forwarded to the disaster recovery cluster; in the disaster recovery recovery working mode, that is, when the main cluster changes from unavailable to available, the request traffic is forwarded to the main cluster again. Based on this background, the scheme has the following disadvantages: 1. In the normal working mode, the main cluster and the disaster recovery cluster do not achieve data consistency. The request traffic data is written to the main cluster, but not to the disaster recovery cluster. Therefore, when the main cluster is unavailable and switched to the disaster recovery cluster, the traffic and feedback data of the same request are different, resulting in data inconsistency, which will cause dirty data and affect the business logic. 2. In the disaster recovery working mode, the request traffic data is written to the disaster recovery cluster, but there is no mechanism to write to the main cluster. Therefore, when the main cluster is restored and available, it is found that the request traffic and feedback data are different, resulting in data inconsistency, which will cause dirty data and affect the business logic. 3. In the disaster recovery working mode, how to deal with the data that is not written to the main cluster during the period when the main cluster is unavailable is also a big problem.
[0004] In summary, how to solve the problem of data consistency under normal working mode, disaster recovery working mode, and disaster recovery working mode, and achieve seamless connection and automatic switching between different working modes to ensure the stability of external services is a problem that needs to be solved at present. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a data processing method, device, equipment and storage medium, which can solve the problem of data consistency in normal working mode, disaster recovery working mode and disaster recovery working mode, and realize seamless connection and automatic switching in different working modes, so as to ensure the stability of external services. The specific scheme is as follows:
[0006] In a first aspect, the present application discloses a data processing method, comprising:
[0007] Obtain the request traffic for service access when the cluster provides external services, and determine the current working mode of the cluster;
[0008] When the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues;
[0009] When the working mode is a second working mode in which the primary cluster is in an unavailable state and the disaster recovery cluster is in an available state, determining a request type of the request traffic, and then determining a forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path;
[0010] When the working mode is a third working mode in which the unavailable state of the main cluster is restored to the available state, it is determined whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and the request traffic is processed according to the determination result.
[0011] Optionally, when the working mode is the first working mode in which both the primary cluster and the disaster recovery cluster are in an available state, forwarding the request traffic to the disaster recovery cluster message queues corresponding to the primary cluster and the disaster recovery cluster, so as to process the request traffic based on the primary cluster and the disaster recovery cluster message queues, including:
[0012] When the working mode is a first working mode in which both the primary cluster and the disaster recovery cluster are in an available state, forwarding the request traffic to the primary cluster so that the primary cluster processes the request traffic;
[0013] The request traffic is forwarded to a disaster recovery cluster message queue corresponding to the disaster recovery cluster, and the disaster recovery cluster message queue is monitored by the disaster recovery cluster so that the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue.
[0014] Optionally, the data processing method further includes:
[0015] The messages of the main cluster message queue and the disaster recovery cluster message queue are consumed sequentially through the sequential consumption strategy in Rocketmq or Kafka.
[0016] Optionally, determining the request type of the request traffic and then determining a forwarding path of the request traffic according to the request type so as to process the request traffic based on the forwarding path includes:
[0017] If the request type is a read request flow, forwarding the request flow to the disaster recovery cluster so that the disaster recovery cluster processes the request flow;
[0018] If the request type is write request traffic, the request traffic is forwarded to the main cluster message queue, and the main cluster message queue is listened to through the disaster recovery cluster message queue, so that when the main cluster consumes the main cluster message queue to be empty, the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue until the disaster recovery cluster message queue is empty and then stops consuming.
[0019] Optionally, the determining whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and processing the request traffic according to the determination result includes:
[0020] If there are message accumulations in the main cluster message queue, the main cluster message queue is monitored by the main cluster, and the messages in the main cluster message queue are consumed sequentially until the main cluster message queue is empty, and then consumption is stopped;
[0021] Execute the step of forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues;
[0022] If there is no message accumulation in the main cluster message queue, the step of directly forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster is performed, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues.
[0023] Optionally, the data processing method further includes:
[0024] Divide the main cluster and the disaster recovery cluster into multiple consumer groups accordingly;
[0025] Different consumer nodes in the consumer group are used to monitor different partitions in the corresponding cluster message queue, and the messages in the partitions are consumed in batches.
[0026] Optionally, after consuming the messages in the partition in batches, the method further includes:
[0027] When a batch of messages is consumed, a consumption completion signal ACK is sent to the corresponding server of the cluster message queue.
[0028] In a second aspect, the present application discloses a data processing device, comprising:
[0029] The request traffic acquisition module is used to obtain the request traffic for service access when the cluster provides external services;
[0030] A working mode determination module, used to determine the current working mode of the cluster;
[0031] A first working mode module is used for forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster when the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues;
[0032] A second working mode module, used for, when the working mode is a second working mode in which the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, determining a request type of the request traffic, and then determining a forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path;
[0033] The third working mode module is used to determine whether there is message accumulation in the main cluster message queue corresponding to the main cluster when the working mode is the third working mode of recovering from the unavailable state of the main cluster to the available state, and process the request traffic according to the determination result.
[0034] In a third aspect, the present application discloses an electronic device, comprising a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the data processing method as described above.
[0035] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein the computer program implements the data processing method as described above when executed by a processor.
[0036] In this application, firstly, the request flow for service access when the cluster provides external services is obtained, and the current working mode of the cluster is determined; when the working mode is the first working mode when both the main cluster and the disaster recovery cluster are in an available state, the request flow is forwarded to the disaster recovery cluster message queue corresponding to the main cluster and the disaster recovery cluster, so as to process the request flow based on the main cluster and the disaster recovery cluster message queue; when the working mode is the second working mode when the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, the request type of the request flow is determined, and then the forwarding path of the request flow is determined according to the request type, so as to process the request flow based on the forwarding path; when the working mode is the third working mode in which the unavailable state of the main cluster is restored to an available state, it is determined whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and the request flow is processed according to the judgment result. It can be seen that this application is mainly used for the management of the main cluster and the disaster recovery cluster. In the normal working mode, that is, the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the message queues of the main cluster and the disaster recovery cluster at the same time, and the message queue of the disaster recovery cluster is consumed in the form of the disaster recovery cluster consuming messages, so as to solve the data consistency problem of the main cluster and the disaster recovery cluster without increasing the performance pressure of the disaster recovery cluster; in the disaster recovery working mode, that is, the main cluster is in an unavailable state and the disaster recovery cluster is in an available state in the second working mode, different request traffic forwarding paths are determined according to different request types, and how to send the request traffic to the disaster recovery cluster in this mode is solved, so that the request traffic can be fed back normally, and at the same time, the data is stored in the main cluster in time through the system, so as to achieve data consistency between the main cluster and the disaster recovery cluster; in the disaster recovery working mode, that is, the third working mode in which the unavailable state of the main cluster is restored to the available state, the request traffic is processed after determining whether there is message accumulation in the main cluster message queue. In this case, after this disaster recovery working mode, the data consistency of the main cluster and the disaster recovery cluster can be guaranteed, so as to smoothly switch to the normal working module. In addition, the present application processes messages based on the main cluster message queue and the disaster recovery cluster message queue, so the performance requirements for the corresponding cluster are not high. During peak traffic periods, the request traffic is stored in the corresponding message queue, which can play a role in traffic peak shaving. By monitoring the current cluster status, the system stability can be effectively guaranteed, and seamless automatic switching can be performed, thereby ensuring the stability of external services. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0038] Figure 1 A schematic diagram of a management solution for a main cluster and a disaster recovery cluster in the prior art;
[0039] Figure 2 A flow chart of a data processing method disclosed in this application;
[0040] Figure 3 A schematic diagram of an overall data processing method disclosed in this application;
[0041] Figure 4 A flowchart of a data processing method in a specific first working mode disclosed in this application;
[0042] Figure 5 A schematic diagram of a data processing method in a first working mode disclosed in the present application;
[0043] Figure 6 A flowchart of a data processing method in a specific second working mode is disclosed in this application;
[0044] Figure 7 A schematic diagram of a data processing method in a second working mode disclosed in the present application;
[0045] Figure 8 A flowchart of a data processing method in a specific third working mode is disclosed in this application;
[0046] Fig. 9 A schematic diagram of a data processing method in a third working mode disclosed in the present application;
[0047] Fig.10 A schematic diagram of the structure of a data processing device disclosed in this application;
[0048] Fig.11 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] Currently, when the main cluster and disaster recovery cluster provide external services, data inconsistency will cause dirty data and affect business logic, and there is no solution for how to handle data that has not been written to the main cluster during the period when the main cluster is unavailable.
[0051] To this end, the present application provides a data processing solution that can solve the problem of data consistency in normal working mode, disaster recovery working mode, and disaster recovery working mode, and achieve seamless connection and automatic switching in different working modes, thereby ensuring the stability of external services.
[0052] The embodiment of the present invention discloses a data processing method, see Figure 2 As shown, the method includes:
[0053] Step S11: Obtain the request flow for service access when the cluster provides external services, and determine the current working mode of the cluster.
[0054] In the embodiment of the present application, since the cluster provides services to the outside world, when there is a need to access the services provided by the cluster, request traffic will be generated. At this time, how to process the request traffic is further determined based on the current working mode of the cluster.
[0055] Step S12: When the working mode is the first working mode in which both the primary cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the disaster recovery cluster message queues corresponding to the primary cluster and the disaster recovery cluster, so as to process the request traffic based on the primary cluster and the disaster recovery cluster message queues.
[0056] In the embodiment of the present application, if the cluster is in normal working mode, that is, when both the main cluster and the disaster recovery cluster are available, the request traffic enters the cluster. Because it is in normal working mode at this time, the main cluster message queue (MQ) corresponding to the main cluster is empty when the main cluster is available. In this case, the request traffic is forwarded to the main cluster, and the main cluster processes and feeds back data according to the request traffic, thereby processing the request traffic; at the same time, the request traffic is also forwarded to the MQ message queue of the disaster recovery cluster, and the request traffic is converted into MQ. At this time, the message sent by the request traffic is used as the producer of the message queue, and the MQ message of the corresponding topic is sent to the cluster according to the information in the request parameters. Further, the disaster recovery cluster monitors the MQ message queue of the disaster recovery cluster and consumes the messages therein, thereby ensuring the consistency of the data of the main cluster and the disaster recovery cluster.
[0057] It should be pointed out that in the process of message queue consumption, in order to maximize the speed of message queue message consumption, consumers are deployed in multiple nodes of the same consumer group. A consumer node in each consumer group listens to a partition queue, and batch consumption is selected for multi-threaded message consumption. After a batch of messages is consumed, a unified ACK is sent to the corresponding message queue server. Specifically, the main cluster and the disaster recovery cluster are divided into multiple consumer groups; different consumer nodes in the consumer group are used to listen to different partitions in the corresponding cluster message queue, and batch consumption is performed on the messages in the partition. When a batch of messages is consumed, the consumption completion signal is ACKed to the corresponding server of the cluster message queue.
[0058] Step S13: When the working mode is a second working mode in which the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, determine the request type of the request traffic, and then determine the forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path.
[0059] In an embodiment of the present application, if the cluster is in a disaster recovery working mode, that is, the main cluster is unavailable and the disaster recovery cluster is available, the request traffic enters the cluster. Because the main cluster is in an unavailable state, the system will determine whether the request traffic is a read traffic request or a write traffic request. It is understandable that the read request traffic does not involve data writing, so it only needs to be processed by the disaster recovery cluster during the processing, which will not destroy the consistency of the data. Therefore, after determining the request type of the request traffic, it is necessary to determine different forwarding paths according to the request type, so as to further achieve the consistency of the data according to the different request types.
[0060] Step S14: when the working mode is the third working mode in which the unavailable state of the main cluster is restored to the available state, it is determined whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and the request traffic is processed according to the determination result.
[0061] In the embodiment of the present application, if the cluster is in the disaster recovery working mode, that is, the main cluster is restored from an unavailable state to an available state, and the main cluster requests traffic to enter the cluster. Because the main cluster is monitored to be available at this time, the system will detect whether there is an accumulation in the main cluster MQ message queue. If there is an accumulation in the main cluster MQ message queue, it means that the messages generated by the system in the disaster recovery working mode have not been fully consumed, the data has not been fully processed, and the data of the main cluster and the disaster recovery cluster are not consistent; if the messages are not accumulated, it means that the messages in the main cluster MQ message queue have all been consumed, and the system enters the normal working mode.
[0062] like Figure 3As shown, it is a schematic diagram of the framework of the overall solution of this application. It includes a cluster disaster recovery management module, a main cluster and a disaster recovery cluster, a main cluster MQ message queue and a disaster recovery cluster MQ message queue. 1. The main functional modules of the cluster disaster recovery management module also include a main cluster availability monitoring module, a disaster recovery cluster availability monitoring module, MQ message queue monitoring, traffic monitoring, etc. The main function is to monitor the availability status of the main cluster and the disaster recovery cluster, automatically connect the traffic seamlessly according to the status of the cluster, automatically switch and manage, and forward the request traffic to the MQ message queue to ensure the stability of external services. 2. The main cluster and the disaster recovery cluster are the management objects of the system and are used to store business-related data. Under normal circumstances, an ordinary ES (Elastic Search) cluster can be used to ensure that the versions of the main and standby clusters are consistent. In this system, no additional modifications to the main cluster and the disaster recovery cluster are required, and no additional configuration is required, and they can be used directly. 3. Main cluster MQ message queue. a. The information sent by this message producer for the request traffic is converted into MQ messages in the order of requests, and saved in order to enter the MQ message queue. There are two situations for the inflow of request traffic: when the main cluster is available and there are messages accumulated in the MQ message queue, the request traffic is forwarded in; when the main cluster is unavailable, non-read request traffic is forwarded in. b. There are two consumers of this message: the main cluster and the disaster recovery cluster MQ message queue. The main cluster listens to this message queue and consumes the messages in this message queue one by one in the order of the message queue until the message queue is empty, and the main cluster stops consuming. The disaster recovery cluster MQ message queue listens to this message queue and asynchronously consumes the messages in this message queue in the order of the message queue until the message queue is empty, and the disaster recovery cluster MQ message queue stops consuming. 4. Disaster recovery cluster MQ message queue. a. There are two producers of this message: the information sent by the request traffic and the main cluster MQ message queue. The information sent by the request traffic is converted into MQ messages in the order of the requests, and is saved in the order and enters the MQ message queue. The disaster recovery cluster MQ message queue listens to the main cluster MQ message queue and asynchronously consumes the messages in this message queue in the order of the message queue until the message queue is empty, and the disaster recovery cluster MQ message queue stops consuming. b. This message consumer is the disaster recovery cluster. The disaster recovery cluster monitors this message queue and consumes the messages in this message queue in the order of the message queue until the message queue is empty and the disaster recovery cluster stops consuming.
[0063] It can be seen that the present application is mainly used for the management of the main cluster and the disaster recovery cluster. In the normal working mode, that is, the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the main cluster and the disaster recovery cluster message queue at the same time, and the disaster recovery cluster message queue is consumed in the form of the disaster recovery cluster consuming messages, so as to solve the data consistency problem of the main cluster and the disaster recovery cluster without increasing the performance pressure of the disaster recovery cluster; in the disaster recovery working mode, that is, the main cluster is in an unavailable state, and the disaster recovery cluster is in an available state. The second working mode determines different forwarding paths of request traffic according to different request types, solves how to send the request traffic to the disaster recovery cluster in this mode, so that the request traffic can be fed back normally, and the data is stored in the main cluster in time through the system, so as to achieve the data consistency of the main cluster and the disaster recovery cluster; in the disaster recovery working mode, that is, the third working mode in which the unavailable state of the main cluster is restored to the available state, and the request traffic is processed after determining whether there is a message accumulation in the main cluster message queue. In this case, after this disaster recovery working mode, the data consistency of the main cluster and the disaster recovery cluster can be guaranteed, so as to smoothly switch to the normal working module. In addition, the present application processes messages based on the main cluster message queue and the disaster recovery cluster message queue, so the performance requirements for the corresponding cluster are not high. During peak traffic periods, the request traffic is stored in the corresponding message queue, which can play a role in traffic peak shaving. By monitoring the current cluster status, the system stability can be effectively guaranteed, and seamless automatic switching can be performed, thereby ensuring the stability of external services.
[0064] The present application embodiment discloses a specific data processing method in the first working mode, see Figure 4 As shown, the method includes:
[0065] Step S21: when the working mode is the first working mode in which both the primary cluster and the disaster recovery cluster are in an available state, forwarding the request traffic to the primary cluster so that the primary cluster processes the request traffic.
[0066] In the embodiment of the present application, because the main cluster is in an available state, the main cluster MQ message queue is empty at this time, and the request traffic is forwarded to the main cluster. The main cluster processes it according to the request traffic and feeds back data, etc., thereby completing the processing of the request traffic.
[0067] Step S22: forwarding the request traffic to the disaster recovery cluster message queue corresponding to the disaster recovery cluster, and monitoring the disaster recovery cluster message queue through the disaster recovery cluster, so that the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue.
[0068] In the embodiment of the present application, the request traffic is also forwarded to the MQ message queue of the disaster recovery cluster. The request traffic is converted to MQ. At this time, the message sent by the request traffic as the producer of the message queue sends the MQ message of the corresponding topic to the cluster according to the information in the request parameters. The disaster recovery cluster monitors this message queue and consumes the messages in this message queue asynchronously according to the message order of the message queue until the message queue is empty, and the MQ message queue of the disaster recovery cluster will no longer consume.
[0069] like Figure 5 As shown, it is a schematic diagram of the process framework under the first working mode in the embodiment of the present application. When the request traffic enters the cluster, the main cluster is in an available state at this time, and there is no message accumulation in the main cluster MQ message queue, the request traffic is forwarded to the main cluster and the disaster recovery cluster MQ message queue, and the disaster recovery cluster consumes the messages in the disaster recovery cluster MQ message queue. It can be seen from the process that the request traffic is forwarded to the main cluster and the disaster recovery cluster at the same time, thereby ensuring the consistency of the data of the main cluster and the disaster recovery cluster.
[0070] In an embodiment of the present application, when the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the main cluster so that the main cluster processes the request traffic; the request traffic is forwarded to the disaster recovery cluster message queue corresponding to the disaster recovery cluster, and the disaster recovery cluster message queue is monitored by the disaster recovery cluster so that the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue. It can be seen that under the normal working mode, when the main cluster is available, the request traffic is synchronized to the disaster recovery cluster by using the disaster recovery cluster MQ message queue without increasing the performance pressure of the disaster recovery cluster, thereby solving the data consistency problem between the main cluster and the disaster recovery cluster. At the same time, since the disaster recovery cluster uses the form of asynchronous consumption of messages, the performance requirements for the disaster recovery cluster are not high. During peak traffic periods, since the traffic is stored in the MQ queue, it can play a role in traffic peak shaving, which can effectively ensure system stability.
[0071] The present application embodiment discloses a specific data processing method in the second working mode, see Figure 6 As shown, the method includes:
[0072] Step S31: when the working mode is a second working mode in which the primary cluster is in an unavailable state and the disaster recovery cluster is in an available state, determining a request type of the request traffic.
[0073] In an embodiment of the present application, since there are two types of request traffic: read request traffic and write request traffic, when the main cluster is in an unavailable state, in order to ensure that the cluster can continue to provide services to the outside world, it is necessary to first determine the request type of the request traffic, and further determine the forwarding path of the request traffic based on the request type.
[0074] Step S32: If the request type is a read request flow, forwarding the request flow to the disaster recovery cluster so that the disaster recovery cluster processes the request flow.
[0075] In the embodiment of the present application, in the case of read request traffic, the request traffic is forwarded to the disaster recovery cluster, and the disaster recovery cluster feeds back data based on the read request traffic, thereby processing the request traffic. In this case, because it is a read request traffic, no data writing is involved, although it is only processed by the disaster recovery cluster, the data of the main cluster and the disaster recovery cluster are still consistent.
[0076] Step S33: If the request type is write request traffic, the request traffic is forwarded to the main cluster message queue, and the main cluster message queue is monitored through the disaster recovery cluster message queue, so that when the main cluster consumes the main cluster message queue to be empty, the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue until the disaster recovery cluster message queue is empty and stops consuming.
[0077] In the embodiment of the present application, in the case of write request traffic, the request traffic is forwarded to the main cluster MQ message queue, the main cluster monitors the main cluster MQ message queue, and consumes the messages in the main cluster MQ message queue in the order of the message queue until the message queue is empty, and the main cluster stops consuming. The disaster recovery cluster MQ message queue monitors the messages in the main cluster MQ message queue, and consumes them in the form of asynchronous consumption until the main cluster MQ message queue is empty. The disaster recovery cluster consumes the messages in the disaster recovery cluster MQ message queue in the order of the messages until the disaster recovery cluster MQ message queue is empty, and the disaster recovery cluster stops consuming.
[0078] In the embodiment of the present application, the messages of the main cluster message queue and the disaster recovery cluster message queue are consumed sequentially through the sequential consumption strategy in Rocketmq or kafka. It should be pointed out that because the main cluster MQ message queue needs to ensure the sequential nature of messages in the same business domain (such as orders), Rocketmq or kafka can be selected in terms of technology selection. For Rocketmq, you can use Rocketmq's sequential message, take the unique identifier of the business domain, such as the order number, as the sharkdingKey parameter, and use the ordered partition characteristics of Rocketmq to achieve the order of each business message; for Kafka, the message order preservation strategy of the producer partition of Kafka is used on the producer side to define a key for each message. This key can be the unique identifier of the business domain (such as the order number). Under this strategy, Kafka will ensure that messages with the same key will enter the same partition partition, and Kafka ensures that the partition is ordered internally, which is conducive to this feature of Kafka to complete the orderly processing of messages.
[0079] like Figure 7 As shown, it is a schematic diagram of the process framework under the second working mode in the embodiment of the present application. The request traffic enters the cluster. At this time, the main cluster is in an unavailable state, and it is further determined whether it is a read request traffic. If it is a read request traffic, the request traffic is forwarded to the disaster recovery cluster. The disaster recovery cluster feeds back data based on the read request traffic, etc., so that the request traffic is processed and the process ends. If it is not a read request traffic, it proves to be a write request traffic, then the request traffic is sent to the main cluster MQ message queue, the main cluster listens to the main cluster MQ message queue, and consumes the messages in this message queue in the order of the message queue until the message queue is empty, and the main cluster no longer consumes. The disaster recovery cluster MQ message queue listens to the messages in the main cluster MQ message queue, and adopts the form of asynchronous consumption. When the main cluster MQ message queue is empty, the disaster recovery cluster consumes the messages in the disaster recovery cluster MQ message queue in the order of the messages until the message queue is empty, and the disaster recovery cluster no longer consumes.
[0080] In an embodiment of the present application, when the working mode is the second working mode in which the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, the request type of the request traffic is determined; if the request type is a read request traffic, the request traffic is forwarded to the disaster recovery cluster so that the disaster recovery cluster processes the request traffic; if the request type is a write request traffic, the request traffic is forwarded to the main cluster message queue, and the main cluster message queue is monitored through the disaster recovery cluster message queue, so that when the main cluster consumes the main cluster message queue to be empty, the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue until the disaster recovery cluster message queue is empty and stops consuming. It can be seen that in the case of read request traffic, the traffic request is forwarded to the disaster recovery cluster. Because it is a read traffic that does not involve data writing, although it is only processed by the disaster recovery cluster, the data of the main cluster and the disaster recovery cluster are still consistent. In the case of write request traffic, because it is write traffic, the write request traffic is written to the main cluster MQ message queue and the disaster recovery cluster MQ message queue in sequence, and then consumed by the main cluster and the disaster recovery cluster one after another, thereby ensuring the data consistency of the main cluster and the disaster recovery cluster. At the same time, since the disaster recovery cluster uses asynchronous message consumption, the performance requirements for the disaster recovery cluster are not high, which can play a role in traffic peak reduction and effectively ensure system stability. In the disaster recovery working mode, when the main cluster is unavailable, the read request traffic is sent to the disaster recovery cluster, so that the request traffic can be fed back normally and the business logic can be fed back normally. The write request traffic sends data to the main cluster and the disaster recovery cluster through the main cluster MQ message queue and the disaster recovery MQ message queue, thereby achieving data consistency between the main cluster and the disaster recovery cluster.
[0081] The present application embodiment discloses a specific data processing method in the third working mode. Figure 8 As shown, the method includes:
[0082] Step S41: when the working mode is the third working mode in which the unavailable state of the main cluster is restored to the available state, it is determined whether there is message accumulation in the main cluster message queue corresponding to the main cluster.
[0083] In an embodiment of the present application, since the main cluster is restored from an unavailable state to an available state, the system will enter the third working mode. In order to ensure data consistency, it is necessary to determine whether there is message accumulation in the main cluster MQ message queue. In this case, the system needs to process the messages in the main cluster MQ message queue first.
[0084] Step S42: If there are message accumulations in the main cluster message queue, the main cluster message queue is monitored by the main cluster, and the messages in the main cluster message queue are consumed sequentially until the main cluster message queue is empty, and then consumption is stopped.
[0085] In the embodiment of the present application, if there is a backlog in the main cluster MQ message queue, it means that the messages generated by the system in the second working mode have not been fully consumed, the data has not been fully processed, and the data of the main cluster and the disaster recovery cluster are not consistent. In this case, it is necessary to continue to process the message, and the request traffic is forwarded to the main cluster MQ message queue. The main cluster monitors the main cluster MQ message queue and consumes the messages in this message queue in the order of the messages until the message queue is empty. The main cluster no longer consumes, and the system enters the normal working mode, which is the first working mode.
[0086] Step S43: forwarding the request traffic to the disaster recovery cluster message queues corresponding to the primary cluster and the disaster recovery cluster, so as to process the request traffic based on the primary cluster and the disaster recovery cluster message queues.
[0087] For a more specific processing procedure of the above step S43, reference may be made to the corresponding contents disclosed in the above embodiments, which will not be described again here.
[0088] Step S44: If there is no message accumulation in the main cluster message queue, directly execute the step of forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues.
[0089] In an embodiment of the present application, if messages are not accumulated, it means that all messages in the main cluster MQ message queue have been consumed, and the system enters a normal working mode, that is, the first working mode. The request traffic is forwarded to the main cluster, and the main cluster processes and feeds back data according to the request traffic, thereby processing the request traffic. In this case, the traffic request is also forwarded to the disaster recovery cluster MQ message queue. The disaster recovery cluster MQ message queue listens to the messages in the main cluster MQ message queue in the form of asynchronous consumption until the main cluster MQ message queue is empty, and the main cluster no longer consumes. The disaster recovery cluster MQ message queue listens to the messages in the main cluster MQ message queue in the form of asynchronous consumption. When the main cluster MQ message queue is empty, the disaster recovery cluster consumes the messages in the disaster recovery cluster MQ message queue in the order of the messages until the message queue is empty, and the disaster recovery cluster no longer consumes.
[0090] like Fig. 9 As shown, it is a schematic diagram of the process framework in the third working mode in the embodiment of the present application. The request traffic enters the cluster, and the main cluster is restored to an available state at this time. It is further determined whether there is message accumulation in the main cluster MQ message queue. If there is no message accumulation, it directly changes to the normal first working mode; if there is message accumulation, it is necessary to consume the messages in the main cluster MQ message queue first, and switch to the normal first working mode after all consumption is completed.
[0091] In an embodiment of the present application, when the working mode is the third working mode in which the unavailable state of the main cluster is restored to the available state, it is determined whether there is a message accumulation in the main cluster message queue corresponding to the main cluster; if there is a message accumulation in the main cluster message queue, the main cluster message queue is monitored by the main cluster, and the messages in the main cluster message queue are consumed sequentially until the main cluster message queue is empty and then consumption is stopped; the request traffic is forwarded to the disaster recovery cluster message queue corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queue; if there is no message accumulation in the main cluster message queue, the step of forwarding the request traffic to the disaster recovery cluster message queue corresponding to the main cluster and the disaster recovery cluster is directly executed, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queue. It can be seen that in the third working mode, the messages in the main cluster MQ message queue are processed first, because this step is an important operation to ensure the data consistency of the main cluster and the disaster recovery cluster, so after the third working mode of disaster recovery, the data consistency of the main cluster and the disaster recovery cluster can be guaranteed, thereby smoothly switching to the normal working module. At the same time, since the disaster recovery cluster uses asynchronous message consumption, the performance requirements for the disaster recovery cluster are not high, which can play a role in traffic peak reduction and effectively ensure system stability. In the disaster recovery working mode, when the main cluster changes from unavailable to available, the main cluster MQ message queue and the disaster recovery cluster MQ message queue are used to handle the data writing problem during the period when the main cluster is unavailable, thereby ensuring the data consistency of the main cluster and the disaster recovery cluster.
[0092] Correspondingly, the present application also discloses a data processing device, see Fig.10 As shown, the device comprises:
[0093] The request traffic acquisition module 11 is used to obtain the request traffic for service access when the cluster provides services to the outside world;
[0094] A working mode determination module 12 is used to determine the current working mode of the cluster;
[0095] The first working mode module 13 is used to forward the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster when the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues;
[0096] The second working mode module 14 is used to determine the request type of the request traffic when the working mode is a second working mode in which the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, and then determine the forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path;
[0097] The third working mode module 15 is used to determine whether there is message accumulation in the main cluster message queue corresponding to the main cluster when the working mode is the third working mode of recovering from the unavailable state of the main cluster to the available state, and process the request traffic according to the determination result.
[0098] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0099] It can be seen that, through the above scheme of this embodiment, firstly, the request flow for service access when the cluster provides external services is obtained, and the current working mode of the cluster is judged; when the working mode is the first working mode when both the main cluster and the disaster recovery cluster are in an available state, the request flow is forwarded to the disaster recovery cluster message queue corresponding to the main cluster and the disaster recovery cluster, so as to process the request flow based on the main cluster and the disaster recovery cluster message queue; when the working mode is the second working mode when the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, the request type of the request flow is judged, and then the forwarding path of the request flow is determined according to the request type, so as to process the request flow based on the forwarding path; when the working mode is the third working mode in which the unavailable state of the main cluster is restored to the available state, it is judged whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and the request flow is processed according to the judgment result. It can be seen that this application is mainly used for the management of the main cluster and the disaster recovery cluster. In the normal working mode, that is, the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the message queues of the main cluster and the disaster recovery cluster at the same time, and the message queue of the disaster recovery cluster is consumed in the form of the disaster recovery cluster consuming messages, so as to solve the data consistency problem of the main cluster and the disaster recovery cluster without increasing the performance pressure of the disaster recovery cluster; in the disaster recovery working mode, that is, the main cluster is in an unavailable state and the disaster recovery cluster is in an available state in the second working mode, different request traffic forwarding paths are determined according to different request types, and how to send the request traffic to the disaster recovery cluster in this mode is solved, so that the request traffic can be fed back normally, and at the same time, the data is stored in the main cluster in time through the system, so as to achieve data consistency between the main cluster and the disaster recovery cluster; in the disaster recovery working mode, that is, the third working mode in which the unavailable state of the main cluster is restored to the available state, the request traffic is processed after determining whether there is message accumulation in the main cluster message queue. In this case, after this disaster recovery working mode, the data consistency of the main cluster and the disaster recovery cluster can be guaranteed, so as to smoothly switch to the normal working module. In addition, the present application processes messages based on the main cluster message queue and the disaster recovery cluster message queue, so the performance requirements for the corresponding cluster are not high. During peak traffic periods, the request traffic is stored in the corresponding message queue, which can play a role in traffic peak shaving. By monitoring the current cluster status, the system stability can be effectively guaranteed, and seamless automatic switching can be performed, thereby ensuring the stability of external services.
[0100] Furthermore, the present application also discloses an electronic device. Fig.11 This is a structural diagram of an electronic device 20 according to an exemplary embodiment, and the content in the diagram cannot be considered as any limitation on the scope of use of the present application.
[0101] Fig.11 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the data processing method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be a computer.
[0102] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0103] In addition, the memory 22 as a carrier for resource storage may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222 and data 223, etc. The data 223 may include various data. The storage method may be temporary storage or permanent storage.
[0104] The operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, and may be Windows Server, Netware, Unix, Linux, etc. In addition to computer programs that can be used to complete the data processing method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 may further include computer programs that can be used to complete other specific tasks.
[0105] Furthermore, the embodiment of the present application also discloses a computer-readable storage medium, wherein the computer-readable storage medium mentioned here includes a random access memory (Random Access Memory, RAM), a memory, a read-only memory (Read-Only Memory, ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a magnetic disk or an optical disk, or any other form of storage medium known in the technical field. Wherein, the computer program implements the aforementioned data processing method when executed by the processor. For the specific steps of the method, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0106] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0107] The steps of data processing or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, software modules executed by a processor, or a combination of the two. The software modules may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0108] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0109] The data processing method, device, equipment and storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A data processing method, characterized in that: include: Obtain the request traffic for service access when the cluster provides external services, and determine the current working mode of the cluster; When the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, the request traffic is forwarded to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster at the same time, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues; The disaster recovery cluster asynchronously consumes the messages in the disaster recovery cluster message queue; When the working mode is a second working mode in which the primary cluster is in an unavailable state and the disaster recovery cluster is in an available state, determining a request type of the request traffic, and then determining a forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path; When the working mode is a third working mode in which the unavailable state of the main cluster is restored to the available state, determining whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and processing the request traffic according to the determination result; The determining of the request type of the request traffic and then determining the forwarding path of the request traffic according to the request type so as to process the request traffic based on the forwarding path includes: If the request type is a read request flow, forwarding the request flow to the disaster recovery cluster so that the disaster recovery cluster processes the request flow; If the request type is write request traffic, the request traffic is forwarded to the main cluster message queue, and the main cluster message queue is listened to through the disaster recovery cluster message queue, so that when the main cluster consumes the main cluster message queue to be empty, the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue until the disaster recovery cluster message queue is empty and then stops consuming.
2. The data processing method according to claim 1, characterized in that: When the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues, including: When the working mode is a first working mode in which both the primary cluster and the disaster recovery cluster are in an available state, forwarding the request traffic to the primary cluster so that the primary cluster processes the request traffic; The request traffic is forwarded to a disaster recovery cluster message queue corresponding to the disaster recovery cluster, and the disaster recovery cluster message queue is monitored by the disaster recovery cluster so that the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue.
3. The data processing method according to claim 1, characterized in that: Also includes: The messages of the main cluster message queue and the disaster recovery cluster message queue are consumed sequentially through the sequential consumption strategy in Rocketmq or Kafka.
4. The data processing method according to claim 1, characterized in that: The determining whether there is message accumulation in the main cluster message queue corresponding to the main cluster, and processing the request traffic according to the determination result, includes: If there are message accumulations in the main cluster message queue, the main cluster message queue is monitored by the main cluster, and the messages in the main cluster message queue are consumed sequentially until the main cluster message queue is empty, and then consumption is stopped; Execute the step of forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues; If there is no message accumulation in the main cluster message queue, the step of directly forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster is performed, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues.
5. The data processing method according to any one of claims 1 to 4, characterized in that: Also includes: Divide the main cluster and the disaster recovery cluster into multiple consumer groups accordingly; Different consumer nodes in the consumer group are used to monitor different partitions in the corresponding cluster message queue, and the messages in the partitions are consumed in batches.
6. The data processing method according to claim 5, characterized in that: After the batch consumption of the messages in the partition, the method further includes: When a batch of messages is consumed, a consumption completion signal ACK is sent to the corresponding server of the cluster message queue.
7. A data processing device, characterized in that: include: The request traffic acquisition module is used to obtain the request traffic for service access when the cluster provides external services; A working mode determination module, used to determine the current working mode of the cluster; A first working mode module is used for forwarding the request traffic to the disaster recovery cluster message queues corresponding to the main cluster and the disaster recovery cluster at the same time when the working mode is the first working mode in which both the main cluster and the disaster recovery cluster are in an available state, so as to process the request traffic based on the main cluster and the disaster recovery cluster message queues; The disaster recovery cluster asynchronously consumes the messages in the disaster recovery cluster message queue; A second working mode module, used for, when the working mode is a second working mode in which the main cluster is in an unavailable state and the disaster recovery cluster is in an available state, determining a request type of the request traffic, and then determining a forwarding path of the request traffic according to the request type, so as to process the request traffic based on the forwarding path; A third working mode module, configured to determine whether there is message accumulation in the main cluster message queue corresponding to the main cluster when the working mode is a third working mode in which the main cluster is restored from an unavailable state to an available state, and process the request traffic according to the determination result; Wherein, the second working mode module includes: If the request type is a read request flow, forwarding the request flow to the disaster recovery cluster so that the disaster recovery cluster processes the request flow; If the request type is write request traffic, the request traffic is forwarded to the main cluster message queue, and the main cluster message queue is listened to through the disaster recovery cluster message queue, so that when the main cluster consumes the main cluster message queue to be empty, the disaster recovery cluster asynchronously consumes the disaster recovery cluster message queue until the disaster recovery cluster message queue is empty and then stops consuming.
8. An electronic device, characterized in that: The electronic device comprises a processor and a memory; wherein the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the data processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: Used to store a computer program; wherein the computer program, when executed by a processor, implements the data processing method according to any one of claims 1 to 6.
