Method and system for parallel optimization of Praft of distributed power storage system
By introducing parallel optimized Raft algorithm (PRaft) in distributed power storage systems, combined with the leader election strategy of Paxos algorithm, the problem of insufficient efficiency and reliability of traditional systems in high concurrency and large-scale data processing is solved, and efficient and reliable data processing and storage are achieved.
Patent Information
- Application Number
- CN202411685173.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-04-29
AI Technical Summary
Traditional power data storage systems are inefficient in the face of large-scale real-time data and high concurrent requests, especially under the serial submission and log replication restrictions of the Raft consensus algorithm.
A parallel optimization Raft algorithm (PRaft) is proposed, combined with the leader election strategy of the Paxos algorithm, and by finely managing the dependencies between logs, the parallel execution of log items is realized, and the system's parallel processing capabilities and execution efficiency are improved.
The PRaft algorithm significantly improves the system's parallel processing capability and execution efficiency, reduces the probability of conflict in client delay and consensus processes, ensures data consistency and system reliability, and is suitable for handling large-scale real-time data and high concurrent requests.
Smart Images

Figure CN119906722A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer storage technology, and in particular to a method and system for parallel optimization of a distributed power storage system PRaft. Background Art
[0002] In recent years, the rapid development of smart grid technology has led to a sharp increase in the amount of data in key equipment such as metering terminals and smart meters. This data not only includes a large amount of user electricity consumption information, the real-time operation status of the power grid, and the health status of the equipment, but also poses a huge challenge to the real-time read and write capabilities and system reliability of the storage system. Faced with such a large amount of data and high concurrent access requirements, traditional power data storage systems are no longer sufficient. Therefore, improving the efficiency and security of data storage is crucial for power data storage systems. In the power scenario, distributed storage has gradually shifted to distributed storage technology due to its excellent data decentralized storage capabilities, fast data access speed, and good scalability [1][2]. By distributing and storing data on multiple computing nodes, distributed storage technology effectively disperses storage pressure and improves data access efficiency.
[0003] Distributed storage systems usually ensure high availability through a multi-copy mechanism and use a consensus algorithm to achieve consistency between nodes to ensure that the system remains coordinated and consistent in the event of failures or network delays. Consensus algorithms are crucial for data consistency and system reliability in distributed systems. As the core mechanism for achieving consistency in distributed systems, the Paxos algorithm completes proposal confirmation in the two stages of pre-preparation and acceptance through three roles: proposer, acceptor, and learner, laying the foundation for data consistency. Although Fast Paxos improves efficiency by reducing the number of interaction rounds, it performs poorly in high-conflict environments, while Generalized Paxos reduces the probability of conflicts by processing commands independently. Although Paxos is of great theoretical significance, its complexity and lack of implementation details of log sequence consensus limit its widespread adoption in industrial applications. To address these limitations, Diego et al. proposed the Raft consensus algorithm
[12] , which improves ease of use by simplifying the consensus process and has a significant effect on the system's anti-attack and data consistency. Raft adopts a leader-based architecture, which elects a leader to receive client requests and synchronize data to other replicas, but its design sacrifices the concurrency of log replication, so that logs can only be replicated and committed serially. In addition, since Raft is implemented based on a replicated state machine, all log items must be executed serially, which limits the utilization of multi-core computing power and affects the data access efficiency of the distributed storage system.
[0004] In order to improve the data access efficiency of distributed storage systems and overcome the limitations of the Raft consensus algorithm used in distributed storage systems in terms of serial submission, this paper proposes a performance optimization algorithm for distributed power storage systems - Parallel Optimized Raft Algorithm (PRaft for short). The PRaft algorithm integrates the leader election strategy in the Paxos algorithm and the Raft algorithm. This combination not only ensures the consistency of logs, but also effectively reduces client delays and the probability of conflicts in the consensus process. In addition, the PRaft algorithm achieves parallel execution of log items by finely managing the dependencies between logs, thereby significantly enhancing the parallel processing capability of the system and greatly improving the execution efficiency. In the scenarios of processing large-scale real-time data and responding to high concurrent requests, the PRaft algorithm shows obvious advantages, which is of great significance for ensuring the rapid response and stable operation of power grid storage systems. Summary of the invention
[0005] In view of the above existing problems, the present invention provides a method and system for parallel optimization of a distributed power storage system PRaft, so as to solve the problem in the prior art that selecting an incorrect energy storage method will cause waste of electric energy.
[0006] In order to solve the above technical problems, a method for parallel optimization of distributed power storage system PRaft is proposed, including:
[0007] Elect a leader, accept state machine command requests from the client, convert the commands into log items, copy the logs and submit them; replicate the logs in the cluster, copy the log items sent by the client, and execute the logs in the same order on all nodes; monitor in real time whether there are any abnormalities in the connection between the client and the leader node. If there are any abnormalities, reselect the leader node, process the request instructions, and analyze the correctness of the consensus algorithm.
[0008] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the leader election includes: the PRaft algorithm triggers the leader election through a timeout mechanism and initiates an election among the candidates.
[0009] The timeout mechanism includes that when the follower does not receive a message from the leader within a set time, the leader is judged to be disconnected, and the follower becomes a candidate and initiates an election. The candidate increases the current term. After being successfully elected, the candidate synchronizes its own log according to the follower log.
[0010] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the log submission includes: the leader accepts a state machine command request from the client, converts the command request into a log item, initiates consensus, copies the node log and submits the log item, and notifies the remaining nodes of the submission status of the node to complete the log submission.
[0011] Among them, when the leader fails or loses connection with the remaining nodes, a new leader election is performed.
[0012] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the log replication includes performing log replication in the cluster, replicating the log items sent by the client, and executing the logs in the same order on all nodes.
[0013] Among them, when a node becomes a leader, the leader provides services to the client. The client sends commands and execution groups to the leader through the interface. The leader converts the information into log items and copies the log items to the remaining nodes. When the remaining nodes accept the log items, the leader submits the log items and notifies the remaining nodes to advance the execution. When any node cannot be contacted, the leader continues to try RPC to synchronize log items for all nodes.
[0014] The log entry includes the state machine command and the proposer_id when it was generated. Each log entry has a unique integer index identifying its position in the log sequence. When the log entry is successfully copied to the node, it is judged to have been submitted and executed by the state machine. The leader tracks the sequence number of the submitted log entry and synchronizes the tracking information.
[0015] Among them, under normal circumstances, the logs of the leader and followers are kept synchronized, and updated log items are copied; when the leader crashes and restarts, the old log items of the previous term need to be synchronized; when there is a hole in the follower's log, the leader needs to gradually copy the old log items until the logs are completely consistent.
[0016] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the execution log includes recording execution groups and dependency logs, determining log submission and execution groups, triggering log execution algorithm after log submission, and processing execution order and dependency relationships.
[0017] The recording of the execution group and the dependent diary includes recording the execution group specified by the user before the log is copied, and writing the latest record as a dependent item into the log item.
[0018] The determination of the log submission and execution group includes that after the log submission, when the dependent log item has completed execution, the corresponding log is also executed without waiting for the previous adjacent log.
[0019] The log execution algorithm includes constructing a data structure, and for each log item in the log that has not been executed, the algorithm adds a corresponding mapping; when the log that the log item depends on has not been executed, the algorithm updates the number of dependent logs; when the log that the log item depends on has been executed, the algorithm executes the log item and removes all mappings that depend on the log item; for log items that do not have unexecuted dependencies, the algorithm will continue to execute the log item and repeat the inspection and execution process, and adopt a breadth-first search strategy, starting from the log items without dependencies, and processing the log items with dependencies after executing the log items without dependencies.
[0020] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the processing of the request instruction includes starting the client, finding a leader, obtaining the leader address, and processing the request instruction.
[0021] The leader search includes connecting to a randomly selected node when the client is first started. When the selected node is not the leader, the client rejects the request and tries to connect to the remaining random nodes. The client finds the leader after trying (n+1) / 2 times.
[0022] The request instruction processing includes the client's request being processed by the leader. When the leader cannot communicate with the node, the election times out and there is no successful heartbeat, the leader will give up the position and allow the client to retry the request. The follower needs to track the leader's identity, redirect the client, and discard information in the event of a new election or term change; when the client loses connection with the leader, it retries to a random node.
[0023] As a preferred solution of the method for parallel optimization of a distributed power storage system PRaft described in the present invention, the correctness analysis includes proving Theorem 1, proving Theorem 2, proving Theorem 3, and analyzing the security of log execution.
[0024] The proof of Theorem 1 includes analyzing the IDs used by different nodes in elections after becoming candidates and the IDs of their terms. The leader overwrites the logs after taking office, and after the preparation phase, the leader no longer overwrites the logs.
[0025] The proof of Theorem 2 includes analyzing the situation where there are two leaders at the same time, one of which cannot submit logs because it does not obtain a majority of votes. After being successfully elected as the leader, the node updates the status and obtains the only leader.
[0026] The proof of Theorem 3 includes the use of mathematical induction to prove that the initial condition is that it has been submitted and more than half of the votes have been obtained when taking office. Since it has been submitted, it is guaranteed that most nodes must have logs on the index, and empty logs will not be used to fill it. Instead, the largest log item is selected to obtain the conclusion that for two log items of the same index, if one log item has been submitted, the other log item must also be submitted.
[0027] The security of the analysis log execution includes the analysis log submission integrity, the limitations of the replication state machine, and the forced sequential execution is only performed on the log after the leader switch.
[0028] Another object of the present invention is to provide a distributed power storage system PRaft parallel optimization system, which improves the performance of the distributed power storage system through parallel log processing, load balancing, fault recovery, consistency maintenance and performance analysis; the system of the present invention realizes load balancing by monitoring the load of the node in real time and dynamically adjusting the replication and execution order of the log according to this information, which helps to avoid hot spots in the system and ensure that resources are used reasonably. In terms of fault recovery, the system introduces a timeout mechanism and a heartbeat mechanism to detect the communication status of the leader and follower nodes. Once an abnormality is found, the system will trigger a new leader election and allow the client to retry the request, thereby ensuring the reliability and availability of the system.
[0029] As a preferred solution of the system for parallel optimization of a distributed power storage system PRaft described in the present invention, it is characterized by including a leader election module, a log submission module, a log replication module, a log execution module and a client interaction module.
[0030] The leader election module is used to elect a node as a leader in the PRaft algorithm to manage log replication.
[0031] The log submission module is used to convert the client's state machine command request into a log item, initiate consensus, submit the log item after copying the node log, and notify the remaining nodes of the submission status of the node to complete the log submission.
[0032] The log replication module is used to replicate logs in the cluster, replicate log items sent by the client, and execute logs in the same order for all nodes.
[0033] The log execution module is used to record the execution group and dependent logs, determine the log submission and execution group, trigger the log execution algorithm after the log is submitted, and process the execution order and dependency relationship.
[0034] The client interaction module is used to process client requests, find leaders, obtain leader addresses, process request instructions, and analyze the correctness of the consensus algorithm.
[0035] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and is characterized in that when the processor executes the computer program, the steps of the method described in a method for parallel optimization of a distributed power storage system PRaft are implemented.
[0036] A computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of the method described in a method for parallel optimization of a distributed power storage system PRaft are implemented.
[0037] Beneficial effects of the present invention: The present invention realizes the optimization of log processing in distributed power storage systems by electing a leader, accepting state machine command requests from the client, converting commands into log items, and submitting logs after copying the logs. This optimization improves the throughput of the system, shortens the average delay of log processing, and ensures the efficiency and consistency of log processing; log replication is performed in the cluster, and the log items sent by the client are copied, and all nodes execute logs in the same order. The system of the present invention realizes the optimization of log replication and execution process. This optimization ensures the consistent execution of logs in the cluster, avoids the problem of data inconsistency, and improves the reliability and stability of the system; real-time monitoring is performed to see if there is an abnormal connection between the client and the leader node. In the case of an abnormality, the leader node needs to be reselected, the request instruction is processed, and the correctness of the consensus algorithm is analyzed. The system of the present invention realizes rapid response and fault recovery to system failures. This optimization improves the availability and reliability of the system, ensures that the system can recover quickly when a failure occurs, and ensures the consistency and integrity of the data. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work, among which:
[0039] Figure 1 An overall flow chart of a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0040] Figure 2 A schematic diagram of log contents of a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0041] Figure 3 A schematic diagram of parallel execution of a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0042] Figure 4 A schematic diagram of node state transition of a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0043] Figure 5 A schematic diagram of a leader election process for a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0044] Figure 6 A log replication flow chart of a method for parallel optimization of a distributed power storage system PRaft provided by an embodiment of the present invention.
[0045] Figure 7 A system solution flow chart of a distributed power storage system PRaft parallel optimization system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0047] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0048] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor is it an embodiment that is mutually exclusive with other embodiments, either individually or selectively.
[0049] The present invention is described in detail with reference to schematic diagrams. When describing the embodiments of the present invention, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.
[0050] At the same time, in the description of the present invention, it should be noted that the directions or positional relationships indicated by the terms "upper, lower, inner and outer" are based on the directions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as limiting the present invention. In addition, the terms "first, second or third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0051] In the present invention, unless otherwise clearly specified and limited, the terms "install, connect, connect" should be understood in a broad sense, for example: it can be a fixed connection, a detachable connection or an integral connection; it can also be a mechanical connection, an electrical connection or a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0052] Example 1, reference Figure 1-Figure 6 , which is the first embodiment of the present invention, and provides a method for parallel optimization of a distributed power storage system PRaft, comprising:
[0053] S1: Elect a leader, accept state machine command requests from clients, convert commands into log entries, copy logs, and commit logs.
[0054] like Figure 5 , the leader election includes, the PRaft algorithm triggers the leader election through a timeout mechanism and initiates an election among the candidates.
[0055] The timeout mechanism includes that when the follower does not receive a message from the leader within a set time, the leader is judged to be disconnected, and the candidate is converted to a candidate and an election is initiated. The candidate increases the current term, generates a unique proposer_id, votes for himself, and sends a RequestVote RPC to the remaining nodes. During the election process, if a node message with a larger proposer_id is received, the candidate immediately ends the election and turns to the follower state. If the majority of nodes do not respond before the timeout, the candidate terminates the current round of elections and initiates a new round. After being successfully elected, the candidate synchronizes its own log according to the follower log.
[0056] The log submission includes that the leader accepts the state machine command request from the client, converts the command request into a log item, initiates consensus, commits the log item after copying the node log, and notifies the remaining nodes of the submission status of the node to complete the log submission.
[0057] Among them, when the leader fails or loses connection with the remaining nodes, a new leader election is performed.
[0058] S2: Perform log replication in the cluster, copy the log items sent by the client, and execute the logs in the same order on all nodes.
[0059] like Figure 6 ,The log replication includes performing log replication in the cluster, replicating the log items sent by the client, and executing the logs in the same order for all nodes.
[0060] Among them, when the node becomes a leader, the leader provides services to the client. The client sends commands and execution groups to the leader through the interface. The leader converts the information into log items and copies the log items to the remaining nodes through SendEntry RPC. When the remaining nodes accept the log items, the leader submits the log items and notifies the remaining nodes to advance the execution through Heartbeat RPC. When any node cannot be contacted, the leader continues to try RPC to synchronize log items for all nodes.
[0061] It should be noted that the log entry includes the state machine command and the proposer_id when it was generated. Each log entry has a unique integer index identifying its position in the log sequence. When the log entry is successfully copied to the node, it is judged to have been submitted and executed by the state machine. The leader tracks the sequence number of the submitted log entry and synchronizes the tracked information in SendEntry and HeartbeatRPC.
[0062] Among them, under normal circumstances, the logs of the leader and followers are kept synchronized, and updated log items are copied; when the leader crashes and restarts, the old log items of the previous term need to be synchronized; when there is a hole in the follower's log, the leader needs to gradually copy the old log items until the logs are completely consistent.
[0063] like Figure 3 ,The execution log includes ,recording the execution group and dependency log, determining the log submission and ,execution group, triggering the log execution algorithm after the log submission, and processing the ,execution order and dependency relationship.
[0064] The recording of the execution group and the dependent diary includes recording the execution group specified by the user before the log is copied, and writing the latest record as a dependent item into the log item.
[0065] It should be further explained that the determination of log submission and execution group includes that after the log is submitted, when the dependent log item has completed execution, the corresponding log is also executed without waiting for the previous adjacent log.
[0066] The log execution algorithm includes constructing a data structure, and for each log item in the log that has not been executed, the algorithm adds a corresponding mapping; when the log that the log item depends on has not been executed, the algorithm updates the number of dependent logs; when the log that the log item depends on has been executed, the algorithm executes the log item and removes all mappings that depend on the log item; for log items that do not have unexecuted dependencies, the algorithm will continue to execute the log item and repeat the inspection and execution process, and adopt a breadth-first search strategy, starting from the log items without dependencies, and processing the log items with dependencies after executing the log items without dependencies.
[0067] S3: Monitor in real time whether there is any abnormality in the connection between the client and the leader node. If there is any abnormality, reselect the leader node, process the request instructions, and analyze the correctness of the consensus algorithm.
[0068] Furthermore, the processing of the request instruction includes starting the client, searching for a leader, obtaining the leader address, and processing the request instruction.
[0069] The leader search includes connecting to a randomly selected node when the client is first started. When the selected node is not the leader, the client rejects the request and tries to connect to the remaining random nodes. The client finds the leader after trying (n+1) / 2 times.
[0070] Furthermore, the request instruction processing includes the client's request being processed by the leader. When the leader cannot communicate with the node, the election times out and there is no successful heartbeat, the leader will give up the position and allow the client to retry the request. The follower needs to track the leader's identity, redirect the client, and discard information in the event of a new election or term change; when the client loses connection with the leader, it retries to a random node.
[0071] The correctness analysis includes proving Theorem 1, proving Theorem 2, proving Theorem 3, and analyzing the security of log execution.
[0072] The proof of Theorem 1 includes analyzing the IDs used by different nodes in elections after becoming candidates and the IDs of their terms. The leader overwrites the logs after taking office, and after the preparation phase, the leader no longer overwrites the logs.
[0073] The proof of Theorem 2 includes analyzing the situation where there are two leaders at the same time, one of which cannot submit logs because it does not obtain a majority of votes. After being successfully elected as the leader, the node updates the status and obtains the only leader.
[0074] The proof of Theorem 3 includes the use of mathematical induction to prove that the initial condition is that it has been submitted and more than half of the votes have been obtained when taking office. Since it has been submitted, it is guaranteed that most nodes must have logs on the index, and empty logs will not be used to fill it. Instead, the largest log item is selected to obtain the conclusion that for two log items of the same index, if one log item has been submitted, the other log item must also be submitted.
[0075] The security of the analysis log execution includes the analysis log submission integrity, the limitations of the replication state machine, and the forced sequential execution is only performed on the log after the leader switch.
[0076] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
[0077] Example 2, reference Figure 7 , which is the second embodiment of the present invention, provides a system for parallel optimization of a distributed power storage system PRaft, including a leader election module 100, a log submission module 200, a log replication module 300, a log execution module 400 and a client interaction module 500.
[0078] The leader election module 100 is used to elect a node as a leader in the PRaft algorithm to manage log replication.
[0079] The log submission module 200 is used to convert the client's state machine command request into a log item, initiate consensus, submit the log item after copying the node log, and notify the remaining nodes of the submission status of the node to complete the log submission.
[0080] The log replication module 300 is used to perform log replication in the cluster, replicate the log items sent by the client, and execute the logs in the same order for all nodes.
[0081] The log execution module 400 is used to record the execution group and dependency logs, determine the log submission and execution group, trigger the log execution algorithm after the log submission, and process the execution order and dependency relationship.
[0082] The client interaction module 500 is used to process the client's request, find the leader, obtain the leader's address, process the request instruction, and analyze the correctness of the consensus algorithm.
[0083] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
[0084] Embodiment 3, the third embodiment of the present invention, is different from the first two embodiments in that:
[0085] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0086] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.
[0087] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.
[0088] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
Claims
1. A method for parallel optimization of a distributed power storage system PRaft, characterized in that: include, Elect a leader, accept state machine command requests from clients, convert commands into log entries, copy logs, and commit logs; Perform log replication in the cluster, copy the log items sent by the client, and execute the logs in the same order on all nodes; Monitor in real time whether there are any abnormalities in the connection between the client and the leader node. If there are any abnormalities, reselect the leader node, process the request instructions, and analyze the correctness of the consensus algorithm.
2. A method for parallel optimization of a distributed power storage system PRaft according to claim 1, characterized in that: The leader election includes: the PRaft algorithm triggers the leader election through a timeout mechanism and initiates an election among the candidates; The timeout mechanism includes that when the follower does not receive a message from the leader within a set time, the leader is judged to be disconnected, and the follower becomes a candidate and initiates an election. The candidate increases the current term and votes for himself. After being successfully elected, the candidate synchronizes his own log according to the follower log.
3. A method for parallel optimization of a distributed power storage system PRaft according to claim 2, characterized in that: The log submission includes: the leader accepts the state machine command request from the client, converts the command request into a log item, initiates consensus, commits the log item after copying the node log, and notifies the remaining nodes of the submission status of the node to complete the log submission; Among them, when the leader fails or loses connection with the remaining nodes, a new leader election is performed.
4. A method for parallel optimization of a distributed power storage system PRaft according to claim 3, characterized in that: The log replication includes performing log replication in the cluster, replicating the log items sent by the client, and executing the logs in the same order on all nodes; Among them, when a node becomes a leader, the leader provides services to the client. The client sends commands and execution groups to the leader through the interface. The leader converts the information into log items and copies the log items to the remaining nodes. When the remaining nodes accept the log items, the leader submits the log items and notifies the remaining nodes to advance the execution. When any node cannot be contacted, the leader continues to try RPC to synchronize log items for all nodes. The log entry includes the state machine command and the proposer_id when it was generated. Each log entry has a unique integer index identifying its position in the log sequence. When the log entry is successfully copied to the node, it is considered to have been submitted and executed by the state machine. The leader tracks the sequence number of the submitted log entry and synchronizes the tracking information. Among them, under normal circumstances, the logs of the leader and followers are kept synchronized, and updated log items are copied; when the leader crashes and restarts, the old log items of the previous term need to be synchronized; when there is a hole in the follower's log, the leader needs to gradually copy the old log items until the logs are completely consistent.
5. A method for parallel optimization of a distributed power storage system PRaft according to claim 4, characterized in that: The execution log includes recording the execution group and dependency log, determining the log submission and execution group, triggering the log execution algorithm after the log submission, and processing the execution order and dependency relationship; The recording of the execution group and dependency log includes recording the execution group specified by the user before the log is copied, and writing the latest record as a dependency item into the log item; After the log submission and execution group is determined to include the log submission, when the dependent log item has completed execution, the corresponding log is also executed without waiting for the previous adjacent log; The log execution algorithm includes constructing a data structure, and for each unexecuted log item in the log, the algorithm adds a corresponding mapping; when the log item depends on a log item that has not been executed, the algorithm updates the number of dependent logs; when the log item depends on a log item that has been executed, the algorithm executes the log item and removes all mappings that depend on the log item; For log items that do not have unexecuted dependencies, the algorithm will continue to execute the log items and repeat the inspection and execution process, and adopt a breadth-first search strategy, starting from log items without dependencies, and processing log items with dependencies after executing log items without dependencies.
6. A method for parallel optimization of a distributed power storage system PRaft according to claim 5, characterized in that: The processing of the request instruction includes starting the client, searching for a leader, obtaining the leader address, and processing the request instruction; The leader search includes connecting to a randomly selected node when the client is first started. When the selected node is not the leader, the client rejects the request and tries to connect to the remaining random nodes. The client finds the leader after trying (n+1) / 2 times. The request instruction processing includes the client's request being processed by the leader. When the leader cannot communicate with the node, the election times out and there is no successful heartbeat, the leader will give up the position and allow the client to retry the request. The follower needs to track the leader's identity, redirect the client, and discard information in the event of a new election or term change; when the client loses connection with the leader, it retries to a random node.
7. A method for parallel optimization of a distributed power storage system PRaft according to claim 6, characterized in that: The correctness analysis includes proving Theorem 1, proving Theorem 2, proving Theorem 3, and analyzing the security of log execution; The proof of Theorem 1 includes analyzing the IDs used by different nodes in elections after becoming candidates and the IDs of their terms. The leader overwrites the logs after taking office, and after the preparation phase, the leader no longer overwrites the logs. The proof of Theorem 2 includes analyzing the situation where there are two leaders at the same time, one of which cannot submit logs because it does not obtain a majority of votes. After being successfully elected as a leader, the node updates the status and obtains the sole leader; The proof of Theorem 3 includes the use of mathematical induction to prove that the initial condition is that it has been submitted and that more than half of the votes have been obtained when taking office. Since it has been submitted, it is guaranteed that most nodes must have logs on the index, and empty logs will not be used to fill it. Instead, the largest log item is selected to obtain the conclusion that for two log items of the same index, if one log item has been submitted, the other log item must also be submitted; The security of the analysis log execution includes the analysis log submission integrity, the limitations of the replication state machine, and the forced sequential execution is only performed on the log after the leader switch.
8. A system using the method for parallel optimization of a distributed power storage system PRaft according to any one of claims 1 to 7, characterized in that: It includes leader election module, log submission module, log replication module, log execution module and client interaction module; The leader election module is used to elect a node as a leader in the PRaft algorithm to manage log replication; The log submission module is used to convert the client's state machine command request into a log item, initiate consensus, submit the log item after copying the node log, and notify the remaining nodes of the submission status of the node to complete the log submission; The log replication module is used to replicate logs in the cluster, replicate log items sent by the client, and execute logs in the same order for all nodes; The log execution module is used to record the execution group and dependent logs, determine the log submission and execution group, trigger the log execution algorithm after the log submission, and process the execution order and dependency relationship; The client interaction module is used to process client requests, find leaders, obtain leader addresses, process request instructions, and analyze the correctness of the consensus algorithm.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of a method for parallel optimization of a distributed power storage system PRaft according to any one of claims 1 to 7 are implemented.
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 steps of a method for parallel optimization of a distributed power storage system PRaft according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Block chain consensus method and device based on Raft consensus mechanism, equipment, medium and product
CN120750942A