Rail transit system control method, system and storage medium based on Raft algorithm
By adopting a control method based on Raft algorithm in the rail transit system, state data sharing between multiple service instances is solved, and the problem of state data sharing and low network fault tolerance in the prior art is solved, and the stability and resource utilization efficiency of the system are improved.
Patent Information
- Application Number
- CN202210181301.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-02-25
AI Technical Summary
In the existing rail transit system, the main and standby structure based on non-shared states and the state sharing method based on traffic replication have problems such as the sharing of state data between multiple service instances, low network fault tolerance, and waste of control resources.
The rail transit system control method based on Raft algorithm is adopted. By dividing the rail transit system into multiple distributed application services, and a Raft cluster is set up for each application service. The multiple Raft clusters contain multiple service instances to realize state data sharing between service instances.
It realizes high consistency of state data between multiple service instances, improves the system's network fault tolerance and operation stability, reduces control resource waste, and balances load.
Smart Images

Figure CN116743786B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of rail transit technology, and in particular to a rail transit system control method, system and storage medium based on a Raft algorithm. Background Art
[0002] In rail transit systems, a solution based on a master-slave structure with no shared state or a state sharing method based on traffic replication is usually used to process various events in the rail transit system and the state data in the system.
[0003] In the related art, the solution based on the master-slave structure without sharing the state cannot realize the state data sharing between multiple service instances, and when the state sharing method based on traffic replication is used for data processing, the fault tolerance of the network is relatively low. And the above two control methods both require the setting of at least two physical devices, but the actual operation state of the two physical devices is usually one cold and one hot, that is, one device is working and the other is idle, which will cause a large waste of control resources. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, one of the purposes of the present invention is to propose a rail transit system control method based on the Raft algorithm, which can realize the sharing of state data between multiple service instances, and the distributed application service has high fault tolerance to the network, improves the stability of system operation, and reduces resource waste.
[0005] A second objective of the present invention is to propose a rail transit system control system based on the Raft algorithm.
[0006] A third objective of the present invention is to provide a computer-readable storage medium.
[0007] In order to achieve the above-mentioned purpose, a rail transit system control method based on the Raft algorithm is proposed in an embodiment of the first aspect of the present invention. The rail transit system includes multiple distributed application services and multiple service instances. The rail transit system control method includes: each Raft cluster corresponding to the application service selects a leader instance corresponding to the application service from the multiple service instances according to the Raft algorithm; and the multiple Raft clusters respectively respond to the trigger signal of the corresponding application service through the elected leader instance.
[0008] According to the rail transit system control method based on the Raft algorithm of an embodiment of the present invention, the rail transit system is divided into multiple distributed application services, and a corresponding Raft cluster is set for each application service, and multiple Raft clusters contain multiple service instances, and multiple service instances can share status data. Multiple Raft clusters run multiple groups of Raft algorithms, which can ensure that the status data of multiple service instances in a Raft cluster are highly consistent, and the clusters will not affect each other. In addition, multiple Raft clusters run multiple groups of Raft algorithms at the same time, that is, for each application service, a leader instance can be selected to provide services to the outside world, which can effectively improve the waste of control resources in the system and is also conducive to balancing the connected load.
[0009] In addition, since distributed systems have natural fault-tolerant characteristics, setting up a rail transit system to include multiple distributed application services provides an efficient fault-tolerant solution for the services of the rail transit system. The real-time status data synchronization between multiple service instances can ensure that the offline of any single service instance in each application service will not affect the data integrity of the entire system, thereby ensuring that the entire system can operate stably and improving the safety of the rail transit system.
[0010] In some embodiments of the present invention, the rail transit system control method further includes: when any leader instance of the Raft cluster goes offline, the Raft cluster that has lost the leader instance enters an election process and elects a new leader instance after the leader term time expires.
[0011] In some embodiments of the present invention, the Raft cluster that has lost the leader instance enters an election process and elects a new leader instance after the leader term time expires, including: the Raft cluster that has lost the leader instance enters an election process after the leader term time expires; the online candidate instances in the Raft cluster that has lost the leader instance vote according to the Raft algorithm, and elects the candidate instance that has the complete log data or the latest log data of the offline leader instance as the new leader instance.
[0012] In some embodiments of the present invention, the number of the plurality of service instances is an odd number.
[0013] In some embodiments of the present invention, the number of the plurality of service instances is less than or equal to seven.
[0014] In some embodiments of the present invention, when the number of the service instances is three, one service instance among the multiple service instances is tolerated to be offline; when the number of the service instances is five, two service instances among the multiple service instances are tolerated to be offline; when the number of the service instances is seven, three service instances among the multiple service instances are tolerated to be offline.
[0015] In some embodiments of the present invention, the rail transit system control method further includes: after the offline former leader instance comes back online, the former leader instance enters a follow state; when the former leader instance receives a heartbeat packet from the current leader instance of the Raft cluster to which it belongs, the former leader instance synchronizes the status data of the application service corresponding to the Raft cluster to which it belongs.
[0016] In some embodiments of the present invention, the rail transit system control method further includes: when the status data of the application service corresponding to the Raft cluster to which the service instance belongs is incomplete, the service instance is not qualified to become a leader instance.
[0017] In order to achieve the above-mentioned purpose, a rail transit system control system based on the Raft algorithm proposed in an embodiment of the second aspect of the present invention includes: at least one processor; a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and when the at least one processor executes the computer program, the control method of the rail transit system based on the Raft algorithm described in any one of the above items is implemented.
[0018] According to the rail transit system control system based on the Raft algorithm proposed in the embodiment of the present invention, at least one processor executes the computer program stored in the memory to implement the control method of the rail transit system based on the Raft algorithm in the above embodiment. By adopting this control method, multiple service instances can share state data, which is conducive to protecting the integrity of system data and thus ensuring that the entire system can run stably. In addition, multiple Raft clusters run multiple groups of Raft algorithms, which can ensure that the state data of multiple service instances in a Raft cluster are highly consistent. By electing multiple leader instances to provide external services, the waste of control resources in the system can be effectively improved, and it is also conducive to balancing the connected load.
[0019] In order to achieve the above objectives, the third aspect of the present invention further proposes a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the control method of the rail transit system based on the Raft algorithm described in any one of the above items is implemented.
[0020] The computer storage medium according to the embodiment of the present invention stores a computer program thereon. When the computer program is executed by the processor, the control method of the rail transit system based on the Raft algorithm of the above embodiment can be implemented, and the state data can be shared between multiple service instances, which is conducive to maintaining the integrity of system data and improving the stability and security of system operation. In addition, by electing multiple leader instances to provide external services, the waste of control resources in the system can be effectively improved, and it is also conducive to balancing the connected load.
[0021] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0023] Figure 1 is a flow chart of a rail transit system control method based on the Raft algorithm according to an embodiment of the present invention;
[0024] Figure 2 A schematic diagram of a Raft cluster according to an embodiment of the present invention;
[0025] Figure 3 A schematic diagram of an election process according to an embodiment of the present invention;
[0026] Figure 4 is a schematic diagram of an election process according to another embodiment of the present invention;
[0027] Figure 5 A schematic diagram of a Raft cluster according to an embodiment of the present invention;
[0028] Figure 6 is a flow chart of a rail transit system control method based on Raft algorithm according to another embodiment of the present invention;
[0029] Figure 7 A flowchart of a rail transit system control method based on the Raft algorithm according to another embodiment of the present invention;
[0030] Figure 8 A schematic diagram of an election process according to yet another embodiment of the present invention;
[0031] Fig. 9 A schematic diagram of an election process according to yet another embodiment of the present invention;
[0032] Fig.10A flowchart of a rail transit system control method based on the Raft algorithm according to another embodiment of the present invention;
[0033] Fig.11 The figure is a block diagram of a rail transit system control system based on the Raft algorithm according to an embodiment of the present invention.
[0034] Reference numerals:
[0035] Rail transit system control system based on Raft algorithm 10;
[0036] Processor 1, memory 2. DETAILED DESCRIPTION
[0037] Embodiments of the present invention are described in detail below. The embodiments described with reference to the accompanying drawings are exemplary. Embodiments of the present invention are described in detail below.
[0038] Reference below Figure 1-Figure 10 A rail transit system control method based on the Raft algorithm according to an embodiment of the present invention is described.
[0039] Among them, the Raft algorithm is a consensus algorithm that provides a general method for distributing state machines in a computing system cluster to ensure that each node in the cluster agrees on a series of identical state transitions. Specifically, the Raft algorithm defines the servers in the Raft cluster in normal operation as "leaders" and "followers" respectively. Generally, there is only one "leader" in a Raft cluster, and the "leader" will manage the entire Raft cluster during its entire term. The "leader" is responsible for copying logs to the "followers" so that the "followers" can reach a consensus with the elected "leader". The "leader" also regularly notifies the "followers" of its existence by sending heartbeat messages. Each "follower" sets a timeout, for example, the timeout is usually set to 150ms-300ms. During the term of office corresponding to the "leader", the "followers" will regularly receive the heartbeat packets sent by the "leader". Also, a "follower" can also be a "candidate" in the precise situation of an election. A "candidate" only plays a temporary role. For example, when the heartbeat packet sent by the "leader" times out or the "follower" does not receive the heartbeat packet, the "follower" will think that the "leader" has gone offline, and then change its own status to "candidate" and start a new round of "leader" election.
[0040] In some embodiments of the present invention, the rail transit system includes multiple distributed application services and multiple service instances, wherein the rail transit system may include a bus line system or a subway rail transit system or a Yunba line system, etc. Multiple distributed application services can be understood as multiple events in the rail transit system. For example, application services may include passenger ticketing, passenger services, etc., wherein a Raft cluster may be set up for each event to handle the situation of the event in the corresponding rail transit system. In other words, multiple Raft clusters may be set up for multiple distributed application services to handle multiple events in the rail transit system. The multiple distributed application services may be 3, 4, 5, or 6, etc.
[0041] Multiple service instances are servers in the Raft cluster, such as physical machines or virtual machines, which are used to manage the application status data of the corresponding events and configure data, etc., where the server, as a provider of computing resources in the rail transit system, can provide services based on events. Furthermore, for an application-based system transformed from a distributed application service, multiple service instances can represent multiple nodes under the corresponding event in the distributed system. The multiple service instances can be 3, 4, 5 or 6, etc.
[0042] Furthermore, some application services in the rail transit system can be transformed into distributed systems, such as passenger ticketing systems, passenger service systems, etc., and Raft clusters corresponding to events in the distributed system can be set up to process the corresponding events. By setting up multiple Raft clusters corresponding to multiple application services in the rail transit system, and each Raft cluster contains multiple service instances, multiple service instances in the same event can share state data.
[0043] Among them, Figure 1 As shown, it is a flow chart of a rail transit system control method based on the Raft algorithm according to an embodiment of the present invention, wherein the rail transit system control method based on the Raft algorithm at least includes step S1 and step S2, which are specifically as follows.
[0044] S1, the Raft cluster corresponding to each application service selects the leader instance of the corresponding application service from multiple service instances according to the Raft algorithm.
[0045] The leader is the “leader” mentioned above. Specifically, different Raft clusters can be set for different application services.
[0046] Specifically, it can be combined Figure 2 Describe the Raft cluster, where: Figure 2FIG. 1 is a schematic diagram of a Raft cluster according to an embodiment of the present invention. Figure 2 As shown, taking the three application services set under AFC (Auto Fare Collection, automatic ticket vending and checking system) as an example, the three application services represent three events, and three Raft clusters are set for the three application services, wherein the Raft clusters can exchange data and interact with the outside world through the message bus, but the Raft clusters do not share states, while the multiple service instances within the Raft cluster can share state data, thereby making the states of the multiple service instances consistent. For example, each Raft cluster can be set to contain three service instances, such as the first Raft cluster contains three service instances of AFC-moudle A-1, AFC-moudle B-1 and AFC-moudle C-1, that is, three physical servers or three nodes; the second Raft cluster contains three service instances of AFC-moudle A-2, AFC-moudle B-2 and AFC-moudle C-2; the third Raft cluster contains three service instances of AFC-moudle A-3, AFC-moudle B-3 and AFC-moudle C-3.
[0047] Furthermore, for any Raft cluster in the AFC system, the three service instances in the corresponding Raft cluster are voted on in combination with the Raft algorithm to elect the leader instance of the corresponding application service. Figure 2 Taking the first Raft cluster shown in as an example, if AFC-moudle A-1 is voted as the leader instance, then AFC-moudle B-1 and AFC-moudle C-1 are both "follower" instances. For the three Raft clusters corresponding to the three events in the AFC system, the three leader instances in the three application services are elected in combination with the Raft algorithm, and each leader instance realizes external signal communication through the message bus.
[0048] Specifically, it can be combined Figure 3 and Figure 4 The election process of an embodiment of the present invention is described, wherein: Figure 3 is a schematic diagram of an election process according to an embodiment of the present invention, Figure 4 FIG. 1 is a schematic diagram of an election process according to another embodiment of the present invention. Figure 3As shown, taking the 9 stations in the rail transit system as an example, if there are three physical machines or virtual machines as computing resource providers, the number of application services is 3, where each station can be regarded as a node, and each application service can include data information of multiple stations, that is, each physical machine or virtual machine contains multiple nodes. Among them, the first application service can be set to contain data information of stations 1, 2, and 3, the second application service can contain data information of stations 4, 5, and 6, and the first application service can contain data information of stations 7, 8, and 9. A Raft cluster is set for each application service. When the system starts running, multiple service instances in all application services are all in the Follower state, and the nodes in each application service are online.
[0049] like Figure 4 As shown in the figure, each Raft cluster can elect a corresponding leader instance in combination with the Raft algorithm, and then obtain three leader instances corresponding to the three application services. At this time, the three application services are all online, and the three leader instances are used as external nodes for stations 1, 2, 3, stations 4, 5, 6, and stations 7, 8, 9.
[0050] Furthermore, after the election is completed, the leader instance in a Raft cluster will share its state with other instances. Figure 5 Give a description. Figure 5 FIG. 1 is a schematic diagram of a Raft cluster according to an embodiment of the present invention, wherein Figure 5 As shown in the figure, the three application services set up in the AFC system include three service instances respectively. The status of multiple service instances in a Raft cluster may not be exactly the same. Figure 3Take the first Raft cluster shown in as an example, where the state of AFC-moudle A-1 is state A, the state of AFC-moudle B-1 is state B, and the state of AFC-moudle C-1 is state C. When AFC-moudle A-1 is elected as the leader instance, AFC-moudle B-1 and AFC-moudle C-1 are both "follower" instances. The leader instance sends log data to the other two "follower" instances, and the two "follower" instances begin to synchronize state data. It can be understood that AFC-moudle A-1 can send state A to the other AFC-moudle B-1 and AFC-moudle C-1 in the form of logs. When the states of AFC-moudle B-1 and AFC-moudle C-1 are not exactly the same as state A, AFC-moudle A-1 will force AFC-moudle B-1 and AFC-moudle C-1 to copy the log data it sends to solve the problem of inconsistent log data. The inconsistent logs in the two "follower" instances will be overwritten by the log data sent by the leader instance. Under ideal network conditions, the two follower instances quickly become consistent with the status data of the leader instance, that is, both are in status A. For example, the data recovery time can be controlled to less than 1 second based on the characteristics of the raft algorithm.
[0051] Similarly, the process of sharing state data of multiple service instances in other Raft clusters is similar to the above process, so that the data of the master node, i.e., leader instance, and the backup node, i.e., "follower" instance, in each application service are kept consistent, so that any Raft cluster is externally presented as strong consistency. By setting up multiple Raft clusters according to multiple application services, multiple Raft clusters run multiple sets of Raft algorithms, and Raft clusters will not affect each other, and load balancing can also be achieved.
[0052] Furthermore, multiple groups of Raft algorithms can be encapsulated into a library and placed in the code to support services such as application status data management and data configuration.
[0053] S2: Multiple Raft clusters respond to the trigger signal of the corresponding application service through the elected leader instance.
[0054] Among them, for multiple service instances in any Raft cluster, the elected leader instance performs external data exchange and other operations, that is, the leader instance in the Raft cluster provides services to the outside.
[0055] Specifically, for a Raft cluster, after the leader instance is elected, the leader instance receives the client's request, that is, the leader instance responds to the trigger signal of the corresponding application service. The leader instance can use the received trigger signal of the application service as a log entry, and then obtain the corresponding log data and add it to its own log data, and then send the log data to other "follower" instances in parallel. When the log data is copied to most "follower" instances such as the server, the leader instance applies this log to its state machine and returns the execution result to the client.
[0056] According to the rail transit system control method based on the Raft algorithm of an embodiment of the present invention, the rail transit system is divided into multiple distributed application services, and a corresponding Raft cluster is set for each application service, and multiple Raft clusters contain multiple service instances, and multiple service instances can share status data. Multiple Raft clusters run multiple groups of Raft algorithms, which can ensure that the status data of multiple service instances in a Raft cluster are highly consistent, and the clusters will not affect each other. In addition, multiple Raft clusters run multiple groups of Raft algorithms at the same time, that is, for each application service, a leader instance can be selected to provide services to the outside world, which can effectively improve the waste of control resources in the system and is also conducive to balancing the connected load.
[0057] In addition, since distributed systems have natural fault-tolerant characteristics, setting up a rail transit system to include multiple distributed application services provides an efficient fault-tolerant solution for the services of the rail transit system. The real-time status data synchronization between multiple service instances can ensure that the offline of any single service instance in each application service will not affect the data integrity of the entire system, thereby ensuring that the entire system can operate stably and improving the safety of the rail transit system.
[0058] In some embodiments of the present invention, Figure 6 , which is a flow chart of a rail transit system control method based on the Raft algorithm according to another embodiment of the present invention, wherein the rail transit system control method based on the Raft algorithm further specifically includes step S3.
[0059] S3: When the leader instance of any Raft cluster goes offline, the Raft cluster that loses the leader instance enters the election process and elects a new leader instance after the leader term expires.
[0060] For a Raft cluster, when the leader instance is elected, other "follower" instances will set a timeout period, where the timeout period can be set to 150ms-300ms, for example, the timeout period can be 150ms, 200ms, 250ms, or 300ms. The leader instance sends a heartbeat packet to the "follower" instance at regular intervals, and the "follower" instance determines the online status of the leader instance based on the received heartbeat packet. In other words, during the term corresponding to the leader instance, each "follower" instance will regularly receive the heartbeat packet sent by the leader instance. If the leader instance makes a mistake and the time for sending the heartbeat packet times out or fails to send the heartbeat packet, the "follower" instance cannot receive the heartbeat packet on time, and it will be considered that the leader instance has gone offline.
[0061] Furthermore, since the Raft cluster provides distributed consistency based on the Raft algorithm, the Raft cluster with N service instances can tolerate N / 2 service instances with errors and round them down. Since the process of selecting the leader instance involves voting, an odd number of nodes is selected as much as possible. Therefore, for any Raft cluster including multiple service instances, the number of multiple service instances can be set to an odd number. Among them, the number of service instances can be set to N, that is, the system requires at least three devices, namely three service instances. When the number of service instances N is three, one service instance among multiple service instances is tolerated to be offline; when the number of service instances N is five, two service instances among multiple service instances are tolerated to be offline; when the number of service instances N is seven, three service instances among multiple service instances are tolerated to be offline. The whole system has a high tolerance for the network, and can handle even if the status of the two ends is inconsistent. In the actual production process, when the number of service instances N exceeds seven, it may cause data processing efficiency to slow down, error rate to be high, etc. Therefore, preferably, the number of service instances N can be set to be less than or equal to 7.
[0062] Specifically, it can be combined Figure 7 Describe step S3 of the embodiment of the present invention, Figure 7 This is a flowchart of a rail transit system control method based on the Raft algorithm according to another embodiment of the present invention, wherein the Raft cluster that has lost its leader instance enters the election process and elects a new leader instance after the leader's term time expires, which specifically includes steps S31 and S32.
[0063] S31: The Raft cluster that has lost its leader instance enters the election process after the leader's term expires.
[0064] When a Raft cluster loses its leader instance, the corresponding application service goes offline. In other words, the term of the last elected leader instance has expired, and the Raft cluster needs to elect a new leader instance again.
[0065] Specifically, it can be combined Figure 8 The election process of an embodiment of the present invention is described, wherein: Figure 8 FIG. 1 is a schematic diagram of an election process according to another embodiment of the present invention. Figure 8 As shown in the figure, take the 9 stations in the rail transit system as an example. If there are three physical machines or virtual machines as computing resource providers, the number of application services is 3. When the leader instance in the third application service goes offline, the entire application service will be displayed as Offline, that is, offline. The other two application services will not be affected and will still be displayed as online. Then the nodes in the application service that is offline will be added to the other two application services. For example, the nodes corresponding to the original 7 stations are assigned to the first application service, and the nodes corresponding to the original 8 and 9 stations are assigned to the second application service.
[0066] S32: The online candidate instances in the Raft cluster that has lost the leader instance vote according to the Raft algorithm to elect a candidate instance that has the complete log data or the latest log data of the offline leader instance as the new leader instance.
[0067] A time threshold can be set. When the Raft cluster that has lost its leader instance reaches the time threshold, it will re-enter the election process. That is to say, the Raft cluster that has lost its leader instance will enter the election process after the timeout period and select a new leader instance. Among them, the candidate instance that has the complete log data or the latest log data of the offline leader instance can be regarded as a "candidate" and is eligible to become the new leader instance.
[0068] Furthermore, the rail transit system control method of the embodiment of the present invention specifically includes: when the status data of the application service corresponding to the Raft cluster to which the service instance belongs is incomplete, the service instance is not qualified to become a leader instance.
[0069] Among them, Fig. 9 , which is a schematic diagram of an election process according to another embodiment of the present invention. Specifically, due to the limitation of the synchronization algorithm, under the premise of incomplete data, the corresponding application instance is not qualified to become a Leader instance. Fig. 9The third service application shown in has been back online, but at this time the node corresponding to station 7 has not completed the synchronization of complete data replication in the first application service, and the nodes corresponding to stations 8 and 9 have not completed the synchronization of complete data in the second application service. In this case, none of the three service instances are qualified to become Leader instances, and the three service instances cannot be reallocated to the third application service. At this time, all three application services are online, but the third application service displays the None status, which means that the application service does not contain any application instances. It can only be reallocated to the third application service after the data synchronization of the three application instances is completed. Then the Raft cluster corresponding to the third application service elects a leader instance, and finally the three application services are presented as follows again. Figure 4 Status shown.
[0070] In addition, since multiple Raft clusters are set up, when any application service goes offline, the application instances contained in the application service can also synchronize data from other application services, which will not cause the loss of status data of the application instance, such as the backup connection status, etc. After the application service to which it belongs is reconnected, it can quickly resume operation, saving time. Among them, if the network conditions are good, the entire process from the occurrence of an application service going offline to the raft cluster that loses the leader instance re-entering the election process and further selecting the leader instance can be completed within 1 second, which is very fast. Therefore, the natural fault-tolerant characteristics of the distributed application service provide an efficient fault-tolerant solution for the control method of the present invention, which can ensure seamless switching when a system failure occurs and reduce switching losses.
[0071] In some embodiments of the present invention, Fig.10 As shown, it is a flow chart of a rail transit system control method based on the Raft algorithm according to another embodiment of the present invention, wherein the rail transit system control method based on the Raft algorithm also includes step S4 and step S5, which are specifically as follows.
[0072] S4: After the former leader instance that was offline comes back online, the former leader instance enters the follower state.
[0073] Among them, when the former leader instance that was offline in the system comes back online, the former leader instance will enter the follower state, that is, as a "follower" instance, that is, the former leader instance cannot be a candidate for the current former leader instance.
[0074] S5, when the current leader instance receives the heartbeat packet from the current leader instance of the Raft cluster to which it belongs, the former leader instance synchronizes the status data of the corresponding application service of the Raft cluster to which it belongs.
[0075] After the voting is over, the former leader instance will obey the leadership of the new leader instance as a "follower" instance, and will also receive heartbeat packets sent by the leader instance during the entire term of the new leader. When it receives the heartbeat packet from the current leader instance of the Raft cluster to which it belongs, it will directly resynchronize the data and keep it consistent with the status data of the current leader instance, so as to avoid the loss of status data due to the offline of the former leader instance.
[0076] In some embodiments of the present invention, Fig.11 , which is a block diagram of a rail transit system control system based on the Raft algorithm according to an embodiment of the present invention, wherein the rail transit system control system 10 based on the Raft algorithm includes at least one processor 1 and a memory 2 .
[0077] Among them, the memory 2 is communicatively connected to at least one processor 1, and the memory 2 stores a computer program that can be executed by at least one processor 1. When at least one processor 1 executes the computer program, the control method of the rail transit system based on the Raft algorithm of any of the above embodiments is implemented.
[0078] According to the rail transit system control system 10 based on the Raft algorithm proposed in the embodiment of the present invention, at least one processor 1 executes the computer program stored in the memory 2 to implement the control method of the rail transit system based on the Raft algorithm in the above embodiment. By adopting this control method, multiple service instances can share state data, which is conducive to protecting the integrity of system data, thereby ensuring that the entire system can run stably. In addition, multiple Raft clusters run multiple groups of Raft algorithms, which can ensure that the state data of multiple service instances in a Raft cluster are highly consistent. By electing multiple leader instances to provide external services, it can effectively improve the waste of control resources in the system and help balance the connected load.
[0079] In some embodiments of the present invention, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the control method of a rail transit system based on the Raft algorithm of any of the above embodiments is implemented.
[0080] The computer storage medium according to the embodiment of the present invention stores a computer program thereon. When the computer program is executed by the processor, the control method of the rail transit system based on the Raft algorithm of the above embodiment can be implemented, and the state data can be shared between multiple service instances, which is conducive to maintaining the integrity of system data and improving the stability and security of system operation. In addition, by electing multiple leader instances to provide external services, the waste of control resources in the system can be effectively improved, and it is also conducive to balancing the connected load.
[0081] Other structures and operations of the rail vehicle and rail traffic control system according to the embodiments of the present invention are well known to those skilled in the art and will not be described in detail here.
[0082] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example.
[0083] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A rail transit system control method based on Raft algorithm, characterized in that: The rail transit system includes a plurality of distributed application services and a plurality of service instances, and the rail transit system control method includes: The Raft cluster corresponding to each of the application services selects a leader instance corresponding to the application service from multiple service instances according to the Raft algorithm; The multiple Raft clusters respectively respond to the trigger signal of the corresponding application service through the elected leader instance; When the leader instance in the Raft cluster corresponding to the application service goes offline, the application service displays an offline state, and the service instances in the application service that displays an offline state are added to the Raft clusters corresponding to other application services except the application service that displays an offline state, so as to synchronize the data of the added Raft clusters; After the Raft clusters corresponding to the other application services complete data synchronization, the service instances in the application service that displays the offline status are reallocated to the Raft cluster corresponding to the application service that displays the offline status.
2. The rail transit system control method based on the Raft algorithm according to claim 1 is characterized in that: The rail transit system control method further includes: When any leader instance of the Raft cluster goes offline, the Raft cluster that has lost the leader instance enters the election process and elects a new leader instance after the leader's term expires.
3. The rail transit system control method based on Raft algorithm according to claim 2 is characterized in that: The Raft cluster that has lost the leader instance enters the election process after the leader term expires and elects a new leader instance, including: The Raft cluster that has lost the leader instance enters the election process after the leader's term expires; The online candidate instances in the Raft cluster that has lost the leader instance vote according to the Raft algorithm to elect a candidate instance that has the complete log data or the latest log data of the offline leader instance as the new leader instance.
4. The rail transit system control method based on the Raft algorithm according to claim 2 or 3, characterized in that: The number of the plurality of service instances is an odd number.
5. The rail transit system control method based on the Raft algorithm according to claim 4 is characterized in that: The number of the plurality of service instances is less than or equal to seven.
6. The control method of the rail transit system based on the Raft algorithm according to claim 5 is characterized in that: When the number of the service instances is three, it is tolerated that one of the service instances is offline; When the number of the service instances is five, two service instances among the multiple service instances are tolerated to be offline; When the number of the service instances is seven, three service instances among the plurality of service instances are tolerated to be offline.
7. The rail transit system control method based on Raft algorithm according to claim 2, characterized in that: The rail transit system control method further includes: After the former leader instance that was offline comes back online, the former leader instance enters the follower state; When the former leader instance receives a heartbeat packet from the current leader instance of the Raft cluster to which it belongs, the former leader instance synchronizes the status data of the application service corresponding to the Raft cluster to which it belongs.
8. The rail transit system control method based on Raft algorithm according to claim 3 is characterized in that: The rail transit system control method further includes: When the status data of the application service corresponding to the Raft cluster to which the service instance belongs is incomplete, the service instance is not qualified to become a leader instance.
9. A rail transit system control system based on Raft algorithm, characterized in that: include: at least one processor; a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the at least one processor implements the control method of the rail transit system based on the Raft algorithm as described in any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the control method of the rail transit system based on the Raft algorithm described in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Self-managed micro-service architecture and service method thereof
CN105933448A
Game service system and implementation method thereof
CN109173270A
Rail transit passenger service system
CN109743343A
Distributed server cluster configuration method based on Raft
CN111526186A
Method and device for optimizing Raft cluster and storage medium
CN113204424A