Log matching method and apparatus for master and slave nodes, and storage medium and electronic device
By performing term-by-term log matching between master and slave nodes, the problem of long-term log matching in the prior art is solved, and the efficiency of log synchronization and system stability and performance are improved.
Patent Information
- Application Number
- PCT/CN2024/121116
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-26
- Filing Date
- 2024-09-25
- Publication Date
- 2025-07-03
AI Technical Summary
The existing master-slave node log matching scheme takes a long time in scenarios with large log differences, affecting system stability and performance, and reducing the performance of replication groups in scenarios with large-scale writes.
The term-by-term matching method is adopted to determine the maximum matching point by sending a matching request carrying term number and log index number between the master and slave nodes, thereby reducing the time complexity of log matching.
Improve the efficiency of master-slave node log matching, shorten the matching time, and improve the stability and performance of the system.
Smart Images

Figure CN2024121116_03072025_PF_FP_ABST
Abstract
Description
Master-slave node log matching method, device, storage medium and electronic device
[0001] Related applications
[0002] This application claims priority to Chinese patent application number 2023118165313, filed on December 26, 2023, entitled “Log matching method, device, storage medium and electronic device for master-slave nodes”, the entire text of which is hereby incorporated by reference. Technical Field
[0003] The present application relates to the field of distributed storage, and more specifically, to a log matching method, device, storage medium, and electronic device for master and slave nodes. Background Art
[0004] In a distributed system, a consensus protocol algorithm ensures data consistency across replicas when multiple nodes need to work together. This ensures data reliability. A common approach is the master-slave replication architecture.
[0005] In a master-slave replication architecture, one node serves as the master node, and the other nodes serve as slave nodes. The master node is responsible for processing write operations and replicating the results to the slave nodes to ensure data consistency. However, in scenarios such as master-slave network anomalies, slave node changes, slave node failures, and master node changes, to ensure data consistency, the master and slave log progress must be rematched to find the maximum log matching point. Then, log progress synchronization will continue from this maximum log matching point to ensure data consistency between the master and slave nodes. Log progress matching ensures data consistency between the master and slave nodes, improving system reliability and stability.
[0006] In the existing master-slave log progress matching solution, the log progress matching logic is performed by continuously comparing the indexes of the node logs. The master node continuously sends the index to be matched to the slave node. After receiving the information, the slave node compares it with the index in the local log. If there is a discrepancy, it will return a failure. The master node will then reduce the current index and compare again until the maximum matching point (Max Match ID) is found.
[0007] After the old leader fails, the new leader may have some inconsistencies with the logs on a follower. To ensure data consistency, the follower must be forced to copy the logs from the new leader. This means that the leader and other followers need to find the Max Match ID respectively and perform subsequent log synchronization from that location.
[0008] However, the existing synchronization methods have the following problems:
[0009] 1) The time complexity is O(Index). In scenarios where the master-slave logs have a large difference, many rounds of matching are required to find the Max Match ID.
[0010] 2) The log matching process takes a long time, which will affect the stability of the entire replication group, reduce the service capabilities of the entire system, and reduce availability.
[0011] 3) The log matching process is time-consuming. In large-scale write scenarios, this not only affects write performance, but also results in a large amount of logs to be synchronized after matching, reducing the performance of the replication group.
[0012] Currently, no effective solution has been proposed to address the time-consuming problem of the log matching process.
[0013] Summary of the Invention
[0014] In the first aspect, an embodiment of the present application provides a log matching method for a master-slave node, comprising: determining a first term number corresponding to a first term among multiple preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; determining a first log index number corresponding to a target log entry among multiple preset log entries of the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index number increases in sequence according to the time sequence of the preset log entries; sending a matching request carrying a first synchronization log number to the slave node, wherein the first synchronization log number includes: the first term number and the first log index number; receiving a first matching result of the slave node for the first synchronization log number, wherein the first matching result carries a maximum matching point, and the maximum matching point includes: the target term number and the target log index number, In the case that the first term corresponding to the first term number exists in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0015] In some embodiments, after sending a matching request carrying a first synchronization log number to the slave node, the method further includes: detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in the case where the first term number is the minimum term number in the master node, detecting whether a second matching result of the first synchronization log number is received from the slave node, wherein the second matching result indicates that there is no preset term in the slave node that matches the minimum term number in the master node; in the case where the second matching result is received, determining that the matching has failed.
[0016] In some embodiments, after sending a matching request carrying a first synchronization log number to the slave node, the method further includes: receiving a second synchronization log number returned by the slave node, wherein, if the first term matching the first term number does not exist in the slave node, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; detecting whether the second term corresponding to the second term number exists in the master node; if the second term corresponding to the second term number exists in the master node, determining a third matching result carrying the maximum matching point, wherein the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0017] In some embodiments, after receiving the second synchronization log number returned by the slave node, the method further includes: detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; in the case where the second term number is the minimum term number in the slave node, detecting whether there is a preset term in the master node corresponding to the minimum term number in the slave node; in the case where there is no preset term corresponding to the minimum term number in the slave node in the master node, determining a fourth matching result, wherein the fourth matching result indicates a matching failure.
[0018] In the second aspect, an embodiment of the present application also provides a log matching method for a master-slave node, comprising: receiving a matching request sent by a master node carrying a first synchronization log number, wherein the master node comprises: a plurality of preset terms, each of the preset terms has a corresponding preset term number, the preset term numbers increase in sequence according to the time sequence of the preset terms, each of the preset terms comprises: a plurality of preset log entries, each preset log entry has a corresponding preset log index number, the preset log index number increases in sequence according to the time sequence of the preset log entries, the first synchronization log number comprises: a first term number and a first log index number, the first term number is the largest in the master node , and the first log index number is the largest preset log index number in the first term of the master node; detecting whether the first term corresponding to the first term number exists in the slave node; when the first term corresponding to the first term number exists in the slave node, returning the first matching result carrying the maximum matching point to the master node, wherein the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0019] In some embodiments, after receiving a matching request carrying a first synchronization log number sent by the master node, the method further includes: detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in the case where the first term number is the minimum term number in the master node, detecting whether there is a preset term in the slave node corresponding to the minimum term number in the master node; in the case where there is no preset term in the slave node corresponding to the minimum term number in the master node, sending a second matching result to the master node, wherein the second matching result indicates a matching failure.
[0020] In some embodiments, the method also includes: returning a second synchronization log number to the master node when there is no first term matching the first term number in the slave node, wherein the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; receiving a third matching result of the master node for the second synchronization log number, wherein the third matching result carries the maximum matching point, the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0021] In some embodiments, when the first term matching the first term number does not exist in the slave node, after returning the second synchronization log number to the master node, the method further includes: detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; when the second term number is the minimum term number in the slave node, detecting whether a fourth matching result of the second synchronization log number is received from the master node, and when the preset term corresponding to the minimum term number in the slave node does not exist in the master node, the master node sends a fourth matching result to the slave node, and the fourth matching result indicates a matching failure.
[0022] In some embodiments, before determining the first term number corresponding to the first term among multiple preset terms of the master node, the method also includes: obtaining the elected term of the master node; and determining a preset number of historical terms adjacent to the elected term as the preset term.
[0023] In some embodiments, the method further includes: generating a third synchronization log number when the second term corresponding to the second term number does not exist in the master node; wherein the third synchronization log number includes: the third term number, and the largest preset log index number in the third term.
[0024] On the third aspect, an embodiment of the present application further provides a log matching device for a master-slave node, which includes: a first determination module for determining a first term number corresponding to a first term in a plurality of preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term number increases in sequence according to the time sequence of the corresponding preset terms; a second determination module for determining a first log index number corresponding to a target log entry in a plurality of preset log entries in the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index number increases in sequence according to the time sequence of the preset log entries; a first sending module for sending a matching request to the slave node, which In the example, the matching request carries a first synchronization log number, and the first synchronization log number includes: the first term number and the first log index number; a first receiving module is used to receive the first matching result of the slave node for the first synchronization log number, wherein the first matching result carries a maximum matching point, and the maximum matching point includes: a target term number and a target log index number. When the first term corresponding to the first term number exists in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node.
[0025] In the fourth aspect, an embodiment of the present application also provides a log matching device for a master-slave node, which includes: a second receiving module for receiving a matching request sent by a master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each of the preset terms has a corresponding preset term number, and the preset term numbers increase in sequence according to the time sequence of the preset terms, and each of the preset terms includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index number increases in sequence according to the time sequence of the preset log entries, and the first synchronization log number includes: a first term number and a first log index number, and the first term number is the largest preset term number in the master node. Assume a term number, the first log index number is the largest preset log index number in the first term of the master node; a detection module is used to detect whether the first term corresponding to the first term number exists in the slave node; a second sending module is used to return the first matching result carrying the maximum matching point to the master node when the first term corresponding to the first term number exists in the slave node, wherein the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0026] In a fifth aspect, an embodiment of the present application further provides a non-volatile storage medium, which is used to store a program, wherein a log matching method of the master-slave node of the device where the non-volatile storage medium is located is controlled when the program is running.
[0027] In a sixth aspect, an embodiment of the present application further provides an electronic device, comprising: a memory and a processor, wherein the processor is configured to run a program stored in the processor, wherein the program executes the above-mentioned master-slave node log matching method when running.
[0028] The details of one or more embodiments of the present application are set forth in the accompanying drawings and the description below. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0030] FIG1 is a flowchart of a log matching method for a master-slave node according to an embodiment of the present application;
[0031] FIG2 is a second flowchart of a log matching method for a master-slave node according to an embodiment of the present application;
[0032] FIG3 is a schematic diagram of a traditional log synchronization process according to an embodiment of the present application;
[0033] FIG4 is a schematic diagram of an optimization algorithm for master-slave node progress matching according to an embodiment of the present application;
[0034] FIG5 is a first schematic diagram of a log matching device for a master-slave node according to an embodiment of the present application;
[0035] FIG6 is a second schematic diagram of a log matching device for a master-slave node according to an embodiment of the present application;
[0036] FIG7 is a structural block diagram of a computer terminal according to an embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0038] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0039] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretations:
[0040] Replica: To combat failures (disk failure, single machine failure, etc.), data in a distributed system is stored in multiple copies, each of which is called a replica.
[0041] ReplicaSet: A replica set consists of multiple replicas of a data set. Replicas in a set are typically distributed across different machines, network segments, or even data centers.
[0042] Leader: The primary replica in a replication group.
[0043] Follower: A follower in a replication group.
[0044] Term: A new term begins each time a primary replica fails. Each term typically consists of an election phase and an external service phase. However, in some extreme cases, if a new primary replica cannot be elected, the current term ends and the next begins. A term is the logical clock of the replica set.
[0045] Index: The index of the log number. Each log entry has a unique index that identifies its position in the log. The index value is monotonically increasing, that is, each new log entry is assigned a larger index value than the previous entry.
[0046] LogID: Synchronization log ID. It consists of Term and Index. Both Term and Index are numbers that increase in sequence and never go back.
[0047] MaxMatchTerm: The maximum matching term for the master and slave nodes to match log progress.
[0048] MaxMatchID: The maximum matching point of the master and slave nodes in log progress, in LogID format, including Term and Index.
[0049] According to an embodiment of the present application, an embodiment of a log matching method for a master-slave node is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0050] FIG1 is a flowchart of a log matching method for a master node and a slave node according to an embodiment of the present application. As shown in FIG1 , the method can be executed on the master node side and includes the following steps:
[0051] Step S102: Determine a first term number corresponding to a first term among multiple preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in chronological order of the corresponding preset terms;
[0052] Step S104: Determine a first log index number corresponding to the target log entry from among the plurality of preset log entries in the first term, where the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase in chronological order of the preset log entries.
[0053] Step S106: Send a matching request carrying a first synchronization log number to the slave node, wherein the first synchronization log number includes: a first term number and a first log index number;
[0054] Step S108, receiving the first matching result of the slave node for the first synchronization log number, wherein the first matching result carries the maximum matching point, and the maximum matching point includes: the target term number and the target log index number. When there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node.
[0055] In an embodiment of the present application, among multiple preset terms of the master node, a first term number corresponding to the first term is determined, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; among multiple preset log entries in the first term, a first log index number corresponding to the target log entry is determined, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase in sequence according to the time sequence of the preset log entries; a matching request carrying a first synchronization log number is sent to the slave node, wherein the first synchronization log number includes: the first term number and the first log index number; the slave node receives the first synchronization log number. The first matching result of the master node and the slave node is obtained by performing a maximum matching operation on the master node and the slave node, wherein the first matching result carries the maximum matching point, and the maximum matching point includes: the target term number and the target log index number. When the slave node has a first term corresponding to the first term number, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node, so that the log matching process of the master and slave nodes is adjusted from log-by-log matching to term-by-term matching, thereby achieving the purpose of reducing the time complexity of log matching for the master and slave nodes, thereby achieving the technical effect of improving the log matching efficiency of the master and slave nodes, and thus solving the technical problem of [keywords].
[0056] It should be noted that the log matching method of the master-slave node can be applied in a distributed system, which includes multiple nodes. The multiple nodes jointly store copies. In order to ensure the accuracy of the stored copies, multiple nodes can be used to store the same copy. Then, a master node can be selected from multiple nodes by election, and the copy in the master node is used as the master copy. The master node responds to operations on the master copy (such as write operations), and then the master node can synchronize the stored master copy to the slave node.
[0057] In some embodiments, multiple replicas can be stored in the master node and the slave node through a replica set. Since the newly added replica needs to be written to the master node before it can be synchronized to other slave nodes, there may be differences between the replicas stored in the master node and the replicas stored in the slave node. The replicas stored in the master node and the slave node can then be synchronized through log synchronization operations.
[0058] It should be noted that the storage status of replicas in the master node and the slave node can be represented by logs. The writing of each replica will generate a log entry in the log. When the replicas stored in the master node and the slave node are synchronized, it can be represented as the log synchronization of the master node and the slave node. Then, in the process of log synchronization between the master node and the slave node, the logs of the master node and the slave node can be matched first, and the matching point of log synchronization in the master node and the slave node can be determined. Then, the log progress of subsequent log entries can be synchronized based on the matching point.
[0059] In the above step S102, the master node is elected from multiple nodes, and multiple nodes select the master node according to a preset period. Therefore, the preset period can be used as the term of the master node, and other nodes that are not selected as the master node can be used as slave nodes of the master node. During the term of the master node, the master node responds to the write operation of the replica, and the slave node synchronizes the data written during the term of the master node. If the master node fails to be elected in the next term, the master node will serve as a slave node to synchronize the replica written by the master node in the next term. Therefore, both the master node and the slave node can store replicas for multiple terms.
[0060] In some embodiments, the master node and the slave node can store copies generated by multiple terms and generate corresponding log entries. Therefore, there can be at least one log entry for each term, and the term can be represented by the term number, and the log entry can also be represented by the log index number.
[0061] It should be noted that multiple terms in the master node and the slave node can be numbered in chronological order. The term with the added number is the preset term, and the number of the preset term is the preset term number. Since multiple preset terms have time attributes, the earlier the preset term, the smaller the preset term number corresponding to the earlier preset term. In other words, the larger the preset term number, the closer the preset term is to the current term. The preset term corresponding to the largest preset term number is the latest generated term. Among them, each log entry has a unique index, which identifies the position of the log entry in the log. Therefore, numbering the log entry is equivalent to numbering the index of the log entry.
[0062] In some embodiments, the multiple preset terms in the master node and the slave node can be a preset number of historical terms adjacent to the elected term of the current master node.
[0063] As an optional example, before determining the first term number corresponding to the first term among multiple preset terms of the master node, the method also includes: obtaining the elected term of the master node; and determining a preset number of historical terms adjacent to the elected term as the preset term.
[0064] In some embodiments, the preset number may be five.
[0065] It should be noted that each term can have at least one log entry and can also be numbered in chronological order. The log with the added number is the preset log entry, and the index number of the preset log entry is the preset log index number. Since multiple preset log entries have time attributes, the earlier the preset log entry, the smaller the preset log index number corresponding to it. In other words, the larger the preset log index number, the closer the preset log entry is to the current time. The preset log entry corresponding to the largest preset log index number is the most recently generated log entry.
[0066] In the above step S108, the maximum matching point includes: the target term number and the target log index number, which can be expressed as:
[0067] MaxMatchID=(MaxMatchTerm, min(l_max_match_term_max_index, f_max_match_term_max_index));
[0068] Among them, MaxMatchTerm is the target term number; min(l_max_match_term_max_index, f_max_match_term_max_index)) is the target log index number, l_max_match_term_max_index is the maximum preset log index number determined in the master node, that is, the first log index number; f_max_match_term_max_index is the maximum preset log index number determined in the slave node.
[0069] In some embodiments, when MaxMatchTerm is the first term number, l_max_match_term_max_index is the first log index number, and f_max_match_term_max_index is the second log index number.
[0070] As an optional embodiment, after sending a matching request carrying the first synchronization log number to the slave node, the method also includes: detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in the case where the first term number is the minimum term number in the master node, detecting whether a second matching result of the first synchronization log number is received from the slave node, wherein the second matching result indicates that there is no preset term in the slave node that matches the minimum term number in the master node; in the case where the second matching result is received, determining that the matching has failed.
[0071] In the above embodiment of the present application, the master node can detect whether the first term number sent to the slave node is the minimum term number in the master node. If the first term number is the minimum term number in the master node, it means that there is no term earlier than the first term in the master node. If the slave node cannot complete the match based on the first term number, it means that the master-slave node cannot be matched, and the slave node can return a second matching result to the master node, indicating that the match failed.
[0072] In some embodiments, when the slave node cannot match based on the first term number, the slave node can return an earlier term number to the master node, which then queries the master node. If the earlier term number returned by the slave node does not exist in the master node, it means that the slave node has returned a second matching result.
[0073] As an optional embodiment, after sending a matching request carrying a first synchronization log number to the slave node, the method also includes: receiving a second synchronization log number returned by the slave node, wherein, if there is no first term matching the first term number in the slave node, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; detecting whether there is a second term corresponding to the second term number in the master node; if there is a second term corresponding to the second term number in the master node, determining a third matching result carrying the maximum matching point, wherein the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0074] In the above embodiment of the present application, after sending a matching request carrying the first synchronization log number to the slave node, the slave node can match based on the first term number in the first synchronization log number. If the first term number does not exist in the slave node, it means that the slave node has not yet synchronized the first term, then the largest preset term number can be selected from the slave node as the second term number, and the largest third log index number in the second term, and the slave node returns the second synchronization log number carrying the second term number and the third log index number to the master node, instructing the master node based on the second synchronization log number, and then the master node can perform a corresponding detection process to detect whether there is a second term corresponding to the second term number in the master node, and if the second term exists in the master node, determine the largest fourth log index number of the master node in the second term, and then use the second term number as the target term number of the maximum matching point, and use the minimum log number between the third log index number and the fourth log index number as the target log index number in the maximum matching point, so that the master and slave nodes can complete the matching through one interaction, thereby achieving the technical effect of improving the log matching efficiency of the master and slave nodes, and thus solving the [keyword] technical problem.
[0075] In some embodiments, the second term number is smaller than the first term number, and the second term corresponding to the second term number is earlier than the first term.
[0076] In some embodiments, when MaxMatchTerm is the second term number, l_max_match_term_max_index is the fourth log index number, and f_max_match_term_max_index is the third log index number.
[0077] In some embodiments, when there is no second term corresponding to the second term number in the master node, a third synchronization log number can be generated. The third synchronization log number includes: a third term number that is smaller than the second term number, and the largest preset log index number in the third term. The third synchronization log number instructs the slave node to match based on the third synchronization log number in the same manner as matching based on the first synchronization log number. If the slave node fails to match again, the slave node can return the second synchronization log number to the master node again, and repeat this process until either the master node or the slave node generates a synchronization log number based on the minimum term number.
[0078] As an optional embodiment, after receiving the second synchronization log number returned by the slave node, the method also includes: detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; when the second term number is the minimum term number in the slave node, detecting whether there is a preset term in the master node corresponding to the minimum term number in the slave node; when there is no preset term in the master node corresponding to the minimum term number in the slave node, determining a fourth matching result, wherein the fourth matching result indicates a matching failure.
[0079] In the above embodiment of the present application, when the second term number returned by the slave node is the minimum term number, it means that there is no term earlier than the second term in the slave node. If the master node cannot complete the match based on the second term number, it means that the master-slave node cannot be matched, and the master node can generate a fourth matching result, indicating that the match failed.
[0080] In some embodiments, the master node may send a fourth matching result to the slave node to inform the slave node that the matching has failed.
[0081] FIG2 is a second flowchart of a log matching method for a master and slave node according to an embodiment of the present application. As shown in FIG2 , the method can be executed on the slave node side and includes the following steps:
[0082] Step S202, receiving a matching request sent by the master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, the preset term numbers increase in sequence according to the time sequence of the preset terms, each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, the preset log index number increases in sequence according to the time sequence of the preset log entries, the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node;
[0083] Step S204, detecting whether there is a first term corresponding to the first term number in the slave node;
[0084] Step S206, when there is a first term corresponding to the first term number in the slave node, returns the first matching result carrying the maximum matching point to the master node, wherein the maximum matching point includes: the target term number and the target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node.
[0085] The above embodiment of the present application receives a matching request sent by a master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, and the preset term number increases in sequence according to the time sequence of the preset terms, and each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index number increases in sequence according to the time sequence of the preset log entries, and the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; detect whether there is a slave node with the same number as the first term The first term corresponding to the term number; when there is a first term corresponding to the first term number in the slave node, the first matching result carrying the maximum matching point is returned to the master node, wherein the maximum matching point includes: the target term number and the target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node; the log matching process of the master and slave nodes is adjusted from log-by-log matching to term-by-term matching, thereby achieving the purpose of reducing the time complexity of log matching for the master and slave nodes, thereby realizing the technical effect of improving the log matching efficiency of the master and slave nodes, and thus solving the technical problem of [keywords].
[0086] As an optional embodiment, after receiving a matching request carrying a first synchronization log number sent by the master node, the method also includes: detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; when the first term number is the minimum term number in the master node, detecting whether there is a preset term in the slave node corresponding to the minimum term number in the master node; when there is no preset term in the slave node corresponding to the minimum term number in the master node, sending a second matching result to the master node, wherein the second matching result indicates a matching failure.
[0087] As an optional embodiment, the method also includes: in the case that there is no first term matching the first term number in the slave node, returning a second synchronization log number to the master node, wherein the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; receiving a third matching result of the master node for the second synchronization log number, wherein the third matching result carries a maximum matching point, the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0088] As an optional embodiment, when there is no first term matching the first term number in the slave node, after returning the second synchronization log number to the master node, the method also includes: detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; when the second term number is the minimum term number in the slave node, detecting whether a fourth matching result of the second synchronization log number is received from the master node, and when there is no preset term corresponding to the minimum term number in the slave node in the master node, the master node sends a fourth matching result to the slave node, and the fourth matching result indicates that the match failed.
[0089] The present application also provides an optional embodiment, which provides an optimization algorithm for master-slave node progress matching, which can improve matching efficiency and greatly improve the service capability and service stability of the entire replication group.
[0090] FIG3 is a schematic diagram of a traditional log synchronization process according to an embodiment of the present application. As shown in FIG3 , the optimization algorithm for master-slave node progress matching needs to be executed according to the traditional log synchronization environment. The traditional log synchronization process includes the following steps:
[0091] Step S301, start.
[0092] Step S302: Obtain the largest local synchronization log number LogID of the master node Leader.
[0093] Step S303: perform matching, and then send a matching request to the follower node.
[0094] Step S304: receiving a matching request.
[0095] Step S305: determine whether the matching result is correct, and obtain a matching result indicating a successful match or a failed match.
[0096] Step S306: Return the matching result and return the matching result to the master node Leader.
[0097] Step S307, determine whether the match is successful, if successful, execute step S308, otherwise execute step S309.
[0098] Step S308: Obtain the maximum matching point MaxMatchID.
[0099] Step S309, LogID Index--, then return to step S303.
[0100] The above steps S301 to S303, and steps S307 to S309 are executed in the master node Leader; the above steps S304 to S306 are executed in the slave node Follower.
[0101] In some embodiments, the above traditional log synchronization process can be implemented by the following pseudo code:
[0102] The purpose of the pseudocode for the traditional log synchronization process above is to find the maximum ID in the current log and match it within the log. First, curr_log_id is set to the maximum log_id in the local log. Then, a do-while loop is used to perform the matching operation. If the match fails, curr_log_id is decremented by 1 until a matching log is found. If the match succeeds, the loop is exited. This code aims to find the maximum ID in the current log and match it within the log.
[0103] It should be noted that the master-slave progress matching optimization algorithm proposed in this application is mainly combined with the basic theory of the distributed algorithm Raft, including: the log log corresponding to a certain synchronization log number LogID is unique among all the log logs of the entire replica; if the term Term and the log number index Index of two logs are the same, then the two logs are consistent; if the log number LogID of two replicas in the same replica set ReplicaSet is the same, then the order and content of all log logs before the synchronization log number LogID must also be the same; in all the log logs of a replica, regardless of the term Term, the log number index LogIndex is kept increasing; each term Term has only one master node Leader.
[0104] Based on the basic theory of the distributed Raft algorithm, we can deduce the following: If both the master and slave nodes have the same term, then the first log entry in that term must be the same. This inference stems from the fact that each term has only one leader. Before synchronizing logs, the leader truncates any redundant logs from the followers. Furthermore, each time a follower receives a new log, it ensures that it has received all the previous logs before accepting the next one.
[0105] Based on the above inference, the optimization algorithm for master-slave node progress matching proposed in this application needs to find the largest term Term contained in both the master node Leader and the slave node Follower, and this term Term is called the maximum matching term MaxMatchTerm (that is, the target term number). Also, because the distributed algorithm Raft mentioned above guarantees that "if the term Term and the index of the log number of two logs are the same, then the two logs are consistent", and the master node Leader and the slave node Follower both hold the target term number MaxMatchTerm, and the index of the log number is increasing, so as long as the index of the log number of the master node Leader and the slave node Follower is equal on the target term number MaxMatchTerm, their logs must be consistent.
[0106] Therefore, based on the above analysis, we can conclude that if the logs of the master and slave nodes can match, then the term at which this matching point occurs must be the maximum term shared by both nodes, and the index of the matching log number is the index of the smaller log number between the two nodes in that term.
[0107] Based on the conclusions drawn from the rigorous derivation process above, this application provides an optimization algorithm for master-slave node progress matching, which includes the following steps:
[0108] 1) The master node Leader sends the last synchronization log number LogID (such as the first synchronization log number) of several consecutive terms Term (the default is 5, Term=n-4 to Term=n) before its current term Term to the slave node Follower.
[0109] 2) The slave node Follower matches the term Term in the synchronization log number LogID (such as the first synchronization log number) in its own log according to the term Term from large to small. If the match is successful, the target term number MaxMatchTerm is confirmed and the process goes to 3), otherwise it goes to 4).
[0110] 3) Define the index of the last log number (such as the first log index number) of the master node Leader on the target term number MaxMatchTerm as l_max_match_term_max_index, and the corresponding index on the slave node Follower as f_max_match_term_max_index.
[0111] In some embodiments, the maximum matching point MaxMatchID=(MaxMatchTerm, min(l_max_match_term_max_index, f_max_match_term_max_index)).
[0112] 4) The slave node Follower returns the last synchronization log number LogID (such as the second synchronization log number) of the five terms Term (term = n-9 to term = n-5) that it holds and whose term Term is less than n-5 to the master node Leader. The master node Leader matches from large to small. If the match is successful, it goes to 3), otherwise it goes to 1) and continues sending.
[0113] 5) If the synchronization log number LogID sent by the master node Leader already contains its minimum term Term, and the slave node Follower still does not match it, then continue to send the first synchronization log number LogID. If it still does not match, the entire matching process fails.
[0114] 6) If the synchronization log number LogID returned by the follower node already contains its minimum term Term, and the leader node has not yet matched it, the entire matching process fails.
[0115] FIG4 is a schematic diagram of an optimization algorithm for master-slave node progress matching according to an embodiment of the present application. As shown in FIG4 , the algorithm includes the following steps:
[0116] Step S401, start.
[0117] Step S402: Obtain the largest LogID of the five most recent Term locally on the master node Leader, and then send a matching request from the node Follower.
[0118] Step S403, determine whether there is a matching Term, if the determination result is yes, execute S304, if the determination result is no, execute S405.
[0119] Step S404, find the smallest ID of MatchTerm on the master and slave nodes, such as determining the smallest log index number between the first log index number and the second log index number; or determining the smallest log number between the third log index number and the fourth log index number, determine the maximum matching point MaxMatchID, and send the maximum matching point MaxMatchID to the master node, and then end.
[0120] Step S405, determine whether there are logs after the minimum term of the master node, such as detecting whether the first term number in the first synchronization log number is not the minimum term number in the master node; if the judgment result is yes, execute step S305, if the judgment result is no, it means the match fails and ends.
[0121] Step S406 , determining whether there is a matching Term. If yes, determining the maximum matching point MaxMatchID and ending; if no, executing S407 .
[0122] Step S407, determine whether there are logs after the minimum term of the slave node, such as detecting whether the second term number in the second synchronization log number is not the minimum term number in the slave node; if the judgment result is yes, return to step S402, if the judgment result is no, end.
[0123] In some embodiments, in the process of the optimization algorithm for master-slave node progress matching, the pseudo code implemented on the master node side is:
[0124] The purpose of the pseudocode on the master node is to obtain the maximum LogID for each term from local storage and perform a series of matching operations. First, use the ListLastIds method to obtain the maximum LogID for each term in local storage and store it in leader_last_id_map. Then, by traversing leader_last_id_map, find the minimum term that matched this round. Next, call the FillMatchLogID method to fill the matching log ID list and call the Match method to perform the matching operation. If the match fails, the minimum term is updated and the loop continues until a match is successful. Finally, obtain the term and index of the successful match and exit the loop. The entire process is to obtain the log ID of the successful match.
[0125] In some embodiments, in the process of the optimization algorithm for master-slave node progress matching, the pseudo code implemented on the slave node side is:
[0126] The above slave-side pseudocode is a simple C++ loop that processes the log_id_list in a request. The loop first attempts to find an entry in the follower_last_id_map that matches the log_term in the log_id_list. If a match is found, the log_term of the match point (match_point) is set to the found log_term, the log_index is set to the smaller of the log_index and the log_index of the matching entry, and the match point is added to the response. If no match is found, the log_term of the last entry in the log_id_list is obtained. The follower_last_id_map is then iterated, and entries whose log_id has a log_term less than the min_term are added to the response's log_id_list, until a log_term greater than or equal to the min_term is found. Overall, the purpose is to process the request's log_id_list, attempt to find an entry in the follower_last_id_map that matches, and update the response's log_id_list accordingly.
[0127] In the above embodiment of the present application, if the master and slave logs can be matched, then the Term where the matching point is located must be the largest Term shared by the two, and the matching Index is the relatively smaller Index of the two on this Term.
[0128] In the above embodiment of the present application, the number of matching terms sent in each round can be customized according to the current system log volume to achieve maximum matching efficiency.
[0129] In the above embodiment of the present application, in the log matching process of the master and slave nodes, if the progress of the slave node test is not matched in the current round, the Tern information to be matched in the next round of the slave node test will be returned to the master test along with the matching RPC, and the master node test can directly proceed to the next round of matching; this greatly improves the log matching efficiency and reduces the number of RPCs, thereby reducing the complexity of the entire matching process.
[0130] The above-mentioned embodiments of the present application can improve the matching efficiency of master-slave log nodes, so that when the progress difference between the master and slave nodes is within a few terms, the Max Match ID can be found in one round of matching; the time complexity of the master-slave log matching process is improved from O(Index) to O(Term); because log matching mostly occurs in unstable replication group scenarios such as node failure recovery, network failure recovery, and upgrades, the improved matching efficiency will greatly shorten the instability time of the replication group, thereby improving the stability of the replication group and improving the performance of log synchronization during the master-slave log matching process. By improving the log matching efficiency, the level of logs to be synchronized after the master and slave node progress is matched can be effectively reduced.
[0131] According to an embodiment of the present application, an embodiment of a device for log matching of master-slave nodes is also provided. It should be noted that the log matching device of the master-slave nodes can be used to execute the log matching method of the master-slave nodes in the embodiment of the present application, and the log matching method of the master-slave nodes in the embodiment of the present application can be executed in the log matching device of the master-slave nodes.
[0132] FIG5 is a schematic diagram of a log matching device for a master-slave node according to an embodiment of the present application. As shown in FIG5 , the device may include: a first determining module 52 for determining a first term number corresponding to a first term in a plurality of preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; a second determining module 54 for determining a first log index number corresponding to a target log entry in a plurality of preset log entries in the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase in sequence according to the time sequence of the preset log entries; a first sending module 52 for determining a first log index number corresponding to a target log entry in a plurality of preset log entries in the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase in sequence according to the time sequence of the preset log entries; a first sending module 54 ... of the master node, Module 56 is used to send a matching request carrying a first synchronization log number to the slave node, wherein the first synchronization log number includes: a first term number and a first log index number; a first receiving module 58 is used to receive a first matching result of the slave node for the first synchronization log number, wherein the first matching result carries a maximum matching point, and the maximum matching point includes: a target term number and a target log index number. When there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node.
[0133] It should be noted that the first determination module 52 in this embodiment can be used to execute step S102 in the embodiment of the present application, the second determination module 54 in this embodiment can be used to execute step S104 in the embodiment of the present application, the first sending module 56 in this embodiment can be used to execute step S106 in the embodiment of the present application, and the first receiving module 58 in this embodiment can be used to execute step S108 in the embodiment of the present application. The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments.
[0134] In an embodiment of the present application, among multiple preset terms of the master node, a first term number corresponding to the first term is determined, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; among multiple preset log entries in the first term, a first log index number corresponding to the target log entry is determined, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase in sequence according to the time sequence of the preset log entries; a matching request carrying a first synchronization log number is sent to the slave node, wherein the first synchronization log number includes: the first term number and the first log index number; the slave node receives the first synchronization log number. The first matching result of the master node and the slave node is obtained by performing a maximum matching operation on the master node and the slave node, wherein the first matching result carries the maximum matching point, and the maximum matching point includes: the target term number and the target log index number. When the slave node has a first term corresponding to the first term number, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node, so that the log matching process of the master and slave nodes is adjusted from log-by-log matching to term-by-term matching, thereby achieving the purpose of reducing the time complexity of log matching for the master and slave nodes, thereby achieving the technical effect of improving the log matching efficiency of the master and slave nodes, and thus solving the technical problem of [keywords].
[0135] As an optional embodiment, the device also includes: a first detection submodule, used to detect whether the first term number in the first synchronization log number is the minimum term number in the master node after sending a matching request carrying the first synchronization log number to the slave node; a second detection submodule, used to detect whether a second matching result of the first synchronization log number is received from the slave node when the first term number is the minimum term number in the master node, wherein the second matching result indicates that there is no preset term in the slave node that matches the minimum term number in the master node; a determination submodule, used to determine that the match fails when the second matching result is received.
[0136] As an optional embodiment, the device also includes: a receiving unit, for receiving a second synchronization log number returned by the slave node after sending a matching request carrying the first synchronization log number to the slave node, wherein, if there is no first term matching the first term number in the slave node, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; a detection unit, for detecting whether there is a second term corresponding to the second term number in the master node; a determination unit, for determining a third matching result carrying the maximum matching point when there is a second term corresponding to the second term number in the master node, wherein the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0137] As an optional embodiment, the device also includes: a first detection subunit, used to detect whether the second term number in the second synchronization log number is the minimum term number in the slave node after receiving the second synchronization log number returned by the slave node; a second detection subunit, used to detect whether there is a preset term in the master node corresponding to the minimum term number in the slave node when the second term number is the minimum term number in the slave node; a determination subunit, used to determine a fourth matching result when there is no preset term corresponding to the minimum term number in the slave node in the master node, wherein the fourth matching result indicates a matching failure.
[0138] Figure 6 is a second schematic diagram of a log matching device for a master-slave node according to an embodiment of the present application. As shown in Figure 6, the device may include: a second receiving module 62, for receiving a matching request sent by the master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, the preset term number increases in sequence according to the time sequence of the preset terms, each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, the preset log index number increases in sequence according to the time sequence of the preset log entries, the first synchronization log number includes: the first term number and the first log index number, the first term number The largest preset term number in the master node, the first log index number is the largest preset log index number in the first term of the master node; the detection module 64 is used to detect whether there is a first term corresponding to the first term number in the slave node; the second sending module 66 is used to return the first matching result carrying the maximum matching point to the master node when there is a first term corresponding to the first term number in the slave node, wherein the maximum matching point includes: the target term number and the target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0139] It should be noted that the second receiving module 62 in this embodiment can be used to execute step S202 in the embodiment of the present application, the detection module 64 in this embodiment can be used to execute step S204 in the embodiment of the present application, and the second sending module 66 in this embodiment can be used to execute step S206 in the embodiment of the present application. The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments.
[0140] The above embodiment of the present application receives a matching request sent by a master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, and the preset term number increases in sequence according to the time sequence of the preset terms, and each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index number increases in sequence according to the time sequence of the preset log entries, and the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; detect whether there is a slave node with the same number as the first term The first term corresponding to the term number; when there is a first term corresponding to the first term number in the slave node, the first matching result carrying the maximum matching point is returned to the master node, wherein the maximum matching point includes: the target term number and the target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node; the log matching process of the master and slave nodes is adjusted from log-by-log matching to term-by-term matching, thereby achieving the purpose of reducing the time complexity of log matching for the master and slave nodes, thereby realizing the technical effect of improving the log matching efficiency of the master and slave nodes, and thus solving the technical problem of [keywords].
[0141] As an optional embodiment, the device also includes: a third detection submodule, which is used to detect whether the first term number in the first synchronization log number is the minimum term number in the master node after receiving a matching request carrying the first synchronization log number sent by the master node; a fourth detection submodule, which is used to detect whether there is a preset term in the slave node corresponding to the minimum term number in the master node when the first term number is the minimum term number in the master node; and a sending submodule, which is used to send a second matching result to the master node when there is no preset term corresponding to the minimum term number in the master node in the slave node, wherein the second matching result indicates a matching failure.
[0142] As an optional embodiment, the device also includes: a sending unit, used to return a second synchronization log number to the master node when there is no first term matching the first term number in the slave node, wherein the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; a receiving unit, used to receive a third matching result of the master node for the second synchronization log number, wherein the third matching result carries a maximum matching point, the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0143] As an optional embodiment, the device also includes: a first detection sub-unit, which is used to detect whether the second term number in the second synchronization log number is the minimum term number in the slave node after returning the second synchronization log number to the master node when there is no first term matching the first term number in the slave node; a second detection sub-unit, which is used to detect whether a fourth matching result of the second synchronization log number is received from the master node when the second term number is the minimum term number in the slave node, and when there is no preset term corresponding to the minimum term number in the slave node in the master node, the master node sends a fourth matching result to the slave node, and the fourth matching result indicates that the match failed.
[0144] The embodiment of the present application can provide a computer terminal, which can be any computer terminal device in a computer terminal group. In some embodiments, in this embodiment, the above-mentioned computer terminal can also be replaced by a terminal device such as a mobile terminal.
[0145] In some embodiments, in this embodiment, the above-mentioned computer terminal may be located in at least one network device among multiple network devices of a computer network.
[0146] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the log matching method of the master and slave nodes: determining the first term number corresponding to the first term among multiple preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; determining the first log index number corresponding to the target log entry among multiple preset log entries in the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index number increases in sequence according to the time sequence of the preset log entries; sending a matching request carrying a first synchronization log number to the slave node, wherein the first synchronization log number includes: the first term number and the first log index number; receiving a first matching result of the slave node for the first synchronization log number, wherein the first matching result carries the maximum matching point, and the maximum matching point includes: the target term number and the target log index number, and when there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0147] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the log matching method of the master-slave node: receiving a matching request sent by the master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, and the preset term numbers increase in sequence according to the time sequence of the preset terms, each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index number increases in sequence according to the time sequence of the preset log entries, and the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; detecting whether there is a first term corresponding to the first term number in the slave node; if there is a first term corresponding to the first term number in the slave node, returning a first matching result carrying the maximum matching point to the master node, wherein the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0148] In some embodiments, FIG7 is a block diagram of a computer terminal according to an embodiment of the present application. As shown in FIG7 , the computer terminal 70 may include: one or more (only one is shown in the figure) processors 72 and a memory 74.
[0149] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the log matching method and device of the master-slave node in the embodiment of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the log matching method of the master-slave node mentioned above. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal 70 via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0150] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: determine the first term number corresponding to the first term among multiple preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in sequence according to the time sequence of the corresponding preset terms; determine the first log index number corresponding to the target log entry among multiple preset log entries in the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index number increases in sequence according to the time sequence of the preset log entries; send a matching request carrying the first synchronization log number to the slave node, wherein the first synchronization log number includes: the first term number and the first log index number; receive the first matching result of the slave node for the first synchronization log number, wherein the first matching result carries the maximum matching point, and the maximum matching point includes: the target term number and the target log index number, and when there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0151] Optionally, the processor may also execute the program code of the following steps: after sending a matching request carrying a first synchronization log number to the slave node, detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in the case where the first term number is the minimum term number in the master node, detecting whether a second matching result for the first synchronization log number is received from the slave node, wherein the second matching result indicates that there is no preset term in the slave node that matches the minimum term number in the master node; in the case where the second matching result is received, determining that the matching has failed.
[0152] Optionally, the processor may also execute the following program code: after sending a matching request carrying a first synchronization log number to the slave node, receiving a second synchronization log number returned by the slave node, wherein, if there is no first term matching the first term number in the slave node, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; detecting whether there is a second term corresponding to the second term number in the master node; if there is a second term corresponding to the second term number in the master node, determining a third matching result carrying the maximum matching point, wherein the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0153] Optionally, the processor may also execute the program code of the following steps: after receiving the second synchronization log number returned by the slave node, detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; when the second term number is the minimum term number in the slave node, detecting whether there is a preset term in the master node corresponding to the minimum term number in the slave node; when there is no preset term in the master node corresponding to the minimum term number in the slave node, determining a fourth matching result, wherein the fourth matching result indicates a matching failure.
[0154] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: receiving a matching request carrying a first synchronization log number sent by the master node, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, the preset term numbers increase in sequence according to the time sequence of the preset terms, each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, the preset log index number increases in sequence according to the time sequence of the preset log entries, the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; detecting whether there is a first term corresponding to the first term number in the slave node; if there is a first term corresponding to the first term number in the slave node, returning a first matching result carrying the maximum matching point to the master node, wherein the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0155] Optionally, the processor may also execute the program code of the following steps: after receiving a matching request carrying a first synchronization log number sent by the master node, detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in a case where the first term number is the minimum term number in the master node, detecting whether there is a preset term in the slave node corresponding to the minimum term number in the master node; in a case where there is no preset term in the slave node corresponding to the minimum term number in the master node, sending a second matching result to the master node, wherein the second matching result indicates a matching failure.
[0156] Optionally, the processor may also execute the following program code: in the event that there is no first term matching the first term number in the slave node, returning the second synchronization log number to the master node, wherein the second synchronization log number includes: the second term number and the third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; receiving the third matching result of the master node for the second synchronization log number, wherein the third matching result carries the largest matching point, the target term number in the largest matching point is the second term number, the target log index number in the largest matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0157] Optionally, the processor may also execute the following program code: in the case that there is no first term matching the first term number in the slave node, after returning the second synchronization log number to the master node, detect whether the second term number in the second synchronization log number is the minimum term number in the slave node; in the case that the second term number is the minimum term number in the slave node, detect whether a fourth matching result for the second synchronization log number is received from the master node, and in the case that there is no preset term corresponding to the minimum term number in the slave node in the master node, the master node sends a fourth matching result to the slave node, and the fourth matching result indicates a matching failure.
[0158] By adopting the embodiment of the present application, a log matching scheme for master and slave nodes is provided. By adjusting the log matching process of the master and slave nodes from log-by-log matching to term-by-term matching, the time complexity of log matching for the master and slave nodes is reduced, thereby achieving the technical effect of improving the log matching efficiency of the master and slave nodes, and further solving the technical problem of [keywords].
[0159] Those skilled in the art will appreciate that the structure shown in FIG7 is merely illustrative, and that the computer terminal may also be a smartphone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a handheld computer, a mobile internet device (MID), a PAD, or other terminal device. FIG7 does not limit the structure of the aforementioned electronic devices. For example, the computer terminal 70 may include more or fewer components (e.g., a network interface, a display device, etc.) than those shown in FIG7 , or may have a configuration different from that shown in FIG7 .
[0160] A person skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a non-volatile medium. The non-volatile storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0161] The embodiment of the present application further provides a non-volatile storage medium. In this embodiment, the non-volatile storage medium can be used to store the program code executed by the master-slave node log matching method provided in the above embodiment.
[0162] In some embodiments, the non-volatile storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0163] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: determining a first term number corresponding to a first term among multiple preset terms of the master node, wherein the first term number is the largest preset term number, and the preset term numbers increase in chronological order according to the corresponding preset terms; determining a first log index number corresponding to a target log entry among multiple preset log entries of the first term, wherein the first log index number is the largest preset log index number in the first term of the master node, and the preset log index number increases in chronological order according to the preset log entries; sending a matching request carrying a first synchronization log number to the slave node, wherein the first synchronization log number includes: a first term number and a first log index number; receiving a first matching result of the slave node for the first synchronization log number, wherein the first matching result carries a maximum matching point, and the maximum matching point includes: a target term number and a target log index number, and if there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, the target log index number is the minimum log index number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0164] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: after sending a matching request carrying a first synchronization log number to the slave node, detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in a case where the first term number is the minimum term number in the master node, detecting whether a second matching result for the first synchronization log number is received from the slave node, wherein the second matching result indicates that there is no preset term in the slave node that matches the minimum term number in the master node; in a case where the second matching result is received, determining that the matching has failed.
[0165] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: after sending a matching request carrying a first synchronization log number to the slave node, receiving a second synchronization log number returned by the slave node, wherein, in a case where there is no first term matching the first term number in the slave node, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; detecting whether there is a second term corresponding to the second term number in the master node; in a case where there is a second term corresponding to the second term number in the master node, determining a third matching result carrying the maximum matching point, wherein the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0166] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: after receiving the second synchronization log number returned by the slave node, detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node; in the case where the second term number is the minimum term number in the slave node, detecting whether there is a preset term in the master node corresponding to the minimum term number in the slave node; in the case where there is no preset term in the master node corresponding to the minimum term number in the slave node, determining a fourth matching result, wherein the fourth matching result indicates a matching failure.
[0167] In some embodiments, a non-volatile storage medium is configured to store program code for performing the following steps: receiving a matching request sent by a master node carrying a first synchronization log number, wherein the master node includes: multiple preset terms, each preset term has a corresponding preset term number, the preset term numbers increase in sequence according to the time sequence of the preset terms, each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, the preset log index number increases in sequence according to the time sequence of the preset log entries, the first synchronization log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; detecting whether there is a first term corresponding to the first term number in the slave node; if there is a first term corresponding to the first term number in the slave node, returning a first matching result carrying the maximum matching point to the master node, wherein the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, the target log index number is the minimum log number between the first log index number and the second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
[0168] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: after receiving a matching request carrying a first synchronization log number sent by the master node, detecting whether the first term number in the first synchronization log number is the minimum term number in the master node; in a case where the first term number is the minimum term number in the master node, detecting whether there is a preset term in the slave node corresponding to the minimum term number in the master node; in a case where there is no preset term in the slave node corresponding to the minimum term number in the master node, sending a second matching result to the master node, wherein the second matching result indicates a matching failure.
[0169] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: in the event that there is no first term matching the first term number in the slave node, returning a second synchronization log number to the master node, wherein the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; receiving a third matching result of the master node for the second synchronization log number, wherein the third matching result carries a maximum matching point, the target term number in the maximum matching point is the second term number, the target log index number in the maximum matching point is the minimum log number between the third log index number and the fourth log index number, and the fourth log index number is the largest preset log index number in the second term of the master node.
[0170] In some embodiments, the non-volatile storage medium is configured to store program code for performing the following steps: if there is no first term matching the first term number in the slave node, after returning the second synchronization log number to the master node, detecting whether the second term number in the second synchronization log number is the minimum term number in the slave node;
[0171] When the second term number is the minimum term number among the slave nodes, the master node detects whether the fourth matching result of the second synchronization log number is received from the master node. When there is no preset term corresponding to the minimum term number among the slave nodes in the master node, the master node sends the fourth matching result to the slave node, and the fourth matching result indicates that the matching failed.
[0172] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0173] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0174] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0175] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0176] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0177] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a non-volatile storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned non-volatile storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program code.
[0178] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A log matching method for master and slave nodes, comprising: Determining a first term number corresponding to a first term among multiple preset terms of the master node, where the first term number is the largest preset term number, and the preset term numbers increase sequentially in the chronological order of the corresponding preset terms; Determining a first log index number corresponding to a target log entry among multiple preset log entries of the first term, where the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase sequentially in the chronological order of the preset log entries; Sending a matching request carrying a first synchronization log number to the slave node, where the first synchronization log number includes: the first term number and the first log index number; Receiving a first matching result of the first synchronization log number from the slave node, where the first matching result carries a maximum matching point, and the maximum matching point includes: a target term number and a target log index number. When there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, and the target log index number is the minimum log index number among the first log index number and a second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
2. The method according to claim 1, wherein After sending the matching request carrying the first synchronization log number to the slave node, the method further includes: Detecting whether the first term number in the first synchronization log number is the smallest term number in the master node; When the first term number is the smallest term number in the master node, detecting whether a second matching result of the first synchronization log number is received, where the second matching result indicates that there is no preset term in the slave node that matches the smallest term number in the master node; When the second matching result is received, determining that the matching fails.
3. The method according to claim 1, wherein, After sending the matching request carrying the first synchronization log number to the slave node, the method further includes: Receiving a second synchronization log number returned by the slave node, where when there is no first term in the slave node that matches the first term number, the slave node returns the second synchronization log number to the master node, and the second synchronization log number includes: a second term number and a third log index number, the second term number is the largest preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the largest preset log index number in the second term of the slave node; Detecting whether there is a second term corresponding to the second term number in the master node; When there is a second term corresponding to the second term number in the master node, determine a third matching result carrying the maximum matching point, where the target term number in the maximum matching point is the second term number, and the target log index number in the maximum matching point is the minimum log number among the third log index number and the fourth log index number, and the fourth log index number is the maximum preset log index number in the second term of the master node.
4. The method according to claim 3, wherein, After receiving the second synchronization log number returned by the slave node, the method further includes: Detect whether the second term number in the second synchronization log number is the minimum term number in the slave node; When the second term number is the minimum term number in the slave node, detect whether there is a preset term corresponding to the minimum term number in the slave node in the master node; When there is no preset term corresponding to the minimum term number in the slave node in the master node, Determine a fourth matching result, where the fourth matching result indicates a matching failure.
5. The method according to claim 1, wherein Before determining the first term number corresponding to the first term among the multiple preset terms of the master node, the method further includes: Obtain the elected term of the master node; Determine a preset number of historical terms adjacent to the elected term as preset terms.
6. The method according to claim 3, wherein, The method further includes: When there is no second term corresponding to the second term number in the master node, generate a third synchronization log number; where the third synchronization log number includes: a third term number, and the maximum preset log index number in the third term.
7. A log matching method for master and slave nodes, including: Receiving a matching request carrying a first synchronization log number sent by a master node, where the master node includes: multiple preset terms, each preset term has a corresponding preset term number, and the preset term numbers increase in sequence according to the chronological order of the preset terms, and each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index numbers increase in sequence according to the chronological order of the preset log entries, and the first synchronization log number includes: a first term number and a first log index number, the first term number is the maximum preset term number in the master node, and the first log index number is the maximum preset log index number in the first term of the master node; Detect whether there is a first term corresponding to the first term number in the slave node; When there is a first term corresponding to the first term number in the slave node, return a first matching result carrying the maximum matching point to the master node, where the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, and the target log index number is the minimum log number among the first log index number and the second log index number, and the second log index number is the maximum preset log index number in the first term of the slave node.
8. The method according to claim 7, wherein, After receiving a matching request carrying a first synchronization log number sent by the master node, the method further includes: Detect whether the first term number in the first synchronization log number is the minimum term number in the master node; When the first term number is the minimum term number in the master node, detect whether there is a preset term corresponding to the minimum term number in the master node in the slave node; When there is no preset term corresponding to the minimum term number in the master node in the slave node, send a second matching result to the master node, where the second matching result indicates a matching failure.
9. The method according to claim 7, wherein The method further includes: When there is no first term matching the first term number in the slave node, return a second synchronization log number to the master node, where the second synchronization log number includes: a second term number and a third log index number, the second term number is the maximum preset term number in the slave node, the preset term corresponding to the second term number in the slave node is the second term, and the third log index number is the maximum preset log index number in the second term of the slave node; Receive a third matching result of the master node for the second synchronization log number, where the third matching result carries the maximum matching point, the target term number in the maximum matching point is the second term number, and the target log index number in the maximum matching point is the minimum log number among the third log index number and the fourth log index number, and the fourth log index number is the maximum preset log index number in the second term of the master node.
10. The method according to claim 9, wherein, After returning the second synchronization log number to the master node when there is no first term matching the first term number in the slave node, the method further includes: Detect whether the second term number in the second synchronization log number is the minimum term number; When the second term number is the minimum term number in the slave node, detect whether the fourth matching result of the master node for the second synchronization log number is received. When there is no preset term corresponding to the minimum term number in the slave node in the master node, the master node sends a fourth matching result to the slave node, and the fourth matching result indicates a matching failure.
11. A log matching device for master and slave nodes, including: The first determination module is configured to determine a first term number corresponding to a first term among multiple preset terms of the master node, where the first term number is the largest preset term number, and the preset term numbers increase sequentially in the chronological order of the corresponding preset terms; The second determination module is configured to determine a first log index number corresponding to a target log entry among multiple preset log entries of the first term, where the first log index number is the largest preset log index number in the first term of the master node, and the preset log index numbers increase sequentially in the chronological order of the preset log entries; The first sending module is configured to send a matching request to the slave node, where the matching request carries a first synchronous log number, and the first synchronous log number includes: the first term number and the first log index number; The first receiving module is configured to receive a first matching result of the first synchronous log number from the slave node, where the first matching result carries a maximum matching point, and the maximum matching point includes: a target term number and a target log index number. When there is a first term corresponding to the first term number in the slave node, the target term number is the first term number, and the target log index number is the minimum log index number between the first log index number and a second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
12. A log matching device for master and slave nodes, comprising: The second receiving module is configured to receive a matching request carrying a first synchronous log number sent by the master node, where the master node includes: multiple preset terms, each preset term has a corresponding preset term number, and the preset term numbers increase sequentially in the chronological order of the preset terms. Each preset term includes: multiple preset log entries, each preset log entry has a corresponding preset log index number, and the preset log index numbers increase sequentially in the chronological order of the preset log entries. The first synchronous log number includes: a first term number and a first log index number, the first term number is the largest preset term number in the master node, and the first log index number is the largest preset log index number in the first term of the master node; The detection module is configured to detect whether there is a first term corresponding to the first term number in the slave node; The second sending module is configured to, when there is a first term corresponding to the first term number in the slave node, return a first matching result carrying a maximum matching point to the master node, where the maximum matching point includes: a target term number and a target log index number, the target term number is the first term number, and the target log index number is the minimum log number between the first log index number and a second log index number, and the second log index number is the largest preset log index number in the first term of the slave node.
13. A non-volatile storage medium for storing a program, wherein, When the program is running, control the device where the non-volatile storage medium is located to execute the log matching method of the master-slave nodes described in any one of claims 1 to 10.
14. An electronic device, comprising: A memory and a processor, the processor is used to run a program stored in the processor, wherein, when the program is running, it executes the log matching method of the master-slave nodes described in any one of claims 1 to 10.
Citation Information
Patent Citations
Distributed key value database system with strong consistency and read-write method thereof
CN103268318A
Log transmission method and related equipment
CN110162511A
Node election method and device, electronic equipment and storage medium
CN114363154A
Data processing and node deployment method and device, electronic equipment and medium
CN114528139A
Log matching method and device for master and slave nodes, storage medium and electronic equipment
CN117785828A