High availability method and system for cache database to support bidirectional data synchronization
By redirecting write operation requests to slave nodes and recording key information when the master node fails, and then re-executing the operation logs on the new master node after recovery, the problem of data loss during master-slave node data synchronization is solved, bidirectional data synchronization is achieved, and the system robustness is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-25
- Publication Date
- 2026-04-10
AI Technical Summary
During data synchronization between master and slave nodes, there is a risk of data loss, especially when the master node fails, data cannot be synchronized to the slave node in a timely manner, resulting in data inconsistency and loss.
When the master node fails, write operation requests are redirected to the slave node for execution, and key information is recorded in the reverse operation log. After recovery, the operation logs from the failure period are re-executed on the new master node through the reverse synchronization process, achieving bidirectional data synchronization.
It reduces the risk of data loss, improves the accuracy of data synchronization and the robustness of the cluster system, ensures that data modifications can be synchronized in a timely manner during master node failures, and avoids the problem of data silos.
Smart Images

Figure CN121833776A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a highly available method and system for supporting bidirectional data synchronization in a cache database. Background Technology
[0002] With the development of computer technology, the volume of various types of data is constantly increasing, and distributed database technology has also developed rapidly. Distributed database technology connects multiple nodes to form a database cluster. Database clusters typically adopt a master-slave replication architecture, where the master node is responsible for handling write requests, and the slave nodes synchronize data from the master node and handle read requests. However, there is a risk of data loss during data synchronization between the master and slave nodes. Summary of the Invention
[0003] This disclosure provides a highly available method and system for supporting bidirectional data synchronization in a cache database, which can reduce the risk of data loss and improve the robustness of the cluster system.
[0004] According to one aspect of the present disclosure, a high-availability method for supporting bidirectional data synchronization of a cache database is provided, the cache database including a first node and at least two second nodes; The method includes: When the first node, which acts as the master node, fails, the write operation request is redirected to the second node, which acts as the slave node, and the key information of the write operation is recorded in the reverse operation log. Once the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, a reverse synchronization process is triggered; wherein, the third node is a new master node selected from the second node; Read the operation logs recorded within the fault time window from the reverse operation log, process them, and then re-execute the operation commands corresponding to the operation logs on the third node.
[0005] In some embodiments, the method further includes: after confirming that the operation command corresponding to the operation log has been executed on the third node, deleting the operation log recorded within the fault time window from the reverse operation log.
[0006] In some embodiments, the method further includes: monitoring and intercepting write operation requests sent to the second node before the first node, which is the master node, fails.
[0007] In some embodiments, recording the key information of the write operation into the reverse operation log includes: serializing the key information of the write operation to obtain a log entry; and writing the log entry into the reverse operation log for storage.
[0008] In some embodiments, the method further includes: when the first node recovers and rejoins the cluster as a slave node, synchronizing the data generated on the third node within the fault time window to the first node through full synchronization or incremental synchronization.
[0009] In some embodiments, the method further includes: confirming that the first node, as the master node, has failed when it is detected that the sentinel node has started failover and the third node has not been elected, or when it is detected that the application has sensed that the first node has crashed.
[0010] According to another aspect of the present disclosure, a high-availability system for a cache database supporting bidirectional data synchronization is provided, the cache database including a first node as a master node and a plurality of second nodes as slave nodes, the system comprising: The recording module is used to redirect write operation requests to the second node, which is a slave node, when the first node, which is the master node, fails, and to record key information of the write operation in the reverse operation log. The triggering module is used to trigger the reverse synchronization process when the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node; wherein the third node is a new master node selected from the second node; The processing module is used to read the operation log recorded within the fault time window from the reverse operation log, process it, and then re-execute the operation command corresponding to the operation log on the third node.
[0011] According to another aspect of the present disclosure, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement one or more of the methods described in the present disclosure.
[0012] According to another aspect of the present disclosure, a computer-readable storage medium is provided that stores a computer program thereon, which, when executed by a processor, implements one or more of the methods described in the embodiments of the present disclosure.
[0013] According to another aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements one or more of the methods described in the embodiments of the present disclosure.
[0014] The beneficial effects of the technical solutions provided in this disclosure are: In this embodiment of the disclosure, when the first node, acting as the master node, fails in the cache database, write operation requests can be redirected to the second node, acting as a slave node, to ensure that write operations can be executed smoothly during the master node failure. When the first node fails, key information about the write operations is recorded in the reverse operation log. When the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, which is the new master node, the operation logs recorded within the failure time window are read from the reverse operation log. After processing, the corresponding operation commands in the operation logs are re-executed on the third node. This enables the reverse synchronization of data modifications made to slave nodes during the old master node failure to the new master node, thereby achieving bidirectional data synchronization. This avoids the problem that data modifications made to slave nodes during the old master node failure cannot be synchronized to the master node, reduces the risk of data loss, improves the accuracy of data synchronization, and enhances the robustness of the cluster system.
[0015] Additional aspects and advantages of embodiments of this disclosure will be set forth in part in the description which follows, and will become apparent from the description or may be learned by practice of this disclosure. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments of this disclosure will be briefly introduced below.
[0017] Figure 1 A flowchart illustrating a high-availability method for supporting bidirectional data synchronization in a cache database, provided in an embodiment of this disclosure; Figure 2 This disclosure provides an architectural diagram of a highly available system for a cache database that supports bidirectional data synchronization. Figure 3 A flowchart illustrating a high-availability method for supporting bidirectional data synchronization in a cache database, provided in an embodiment of this disclosure; Figure 4 A schematic diagram of the structure of a high-availability system for a cache database supporting bidirectional data synchronization is provided in an embodiment of this disclosure; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation
[0018] The embodiments of this disclosure are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this disclosure, and do not constitute a limitation on the technical solutions of the embodiments of this disclosure.
[0019] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the terms “comprising” and “including” as used in embodiments of this disclosure mean that the corresponding feature can be implemented as the presented feature, information, data, step, operation, element, and / or component, but do not exclude implementation as other features, information, data, step, operation, element, component, and / or combinations thereof supported by the art. It should be understood that when we say that an element is “connected” or “coupled” to another element, the element can be directly connected or coupled to the other element, or it can mean that the element and the other element are connected through an intermediate element. Furthermore, “connected” or “coupled” as used herein can include wireless connection or wireless coupling. The term “multiple” refers to two or more; therefore, in embodiments of this disclosure, “multiple” may also be understood as “at least two.” The term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the related objects before and after it are in an "or" relationship.
[0020] To make the objectives, technical solutions, and advantages of this disclosure clearer, the embodiments of this disclosure will be described in further detail below with reference to the accompanying drawings.
[0021] This disclosure presents a highly available method, system, electronic device, computer-readable storage medium, and computer program product that supports bidirectional data synchronization for a cached database.
[0022] The following description of several exemplary embodiments illustrates the technical solutions of this disclosure and the technical effects produced by these solutions. It should be noted that the following embodiments can be referenced, learned from, or combined with each other. Identical terms, similar features, and similar implementation steps in different embodiments will not be repeated.
[0023] Figure 1 This is a flowchart illustrating a high-availability method for supporting bidirectional data synchronization in a cache database, as provided in an embodiment of this disclosure.
[0024] In this embodiment, the cache database may include multiple nodes, including one master node and multiple slave nodes. Typically, the master node handles write requests, while the slave nodes synchronize data with the master node and handle read requests. When the master node fails, one of the slave nodes is selected as the new master node, which then handles write requests. Once the old master node recovers, it becomes a slave node of the new master node, synchronizing data with it. For ease of description, the old master node is referred to as the first node, and all slave nodes before the old master node's failure are referred to as the second nodes. There are at least two second nodes, and the new master node selected from the second nodes is referred to as the third node.
[0025] The high-availability method for bidirectional data synchronization of the cache database provided in this disclosure can optionally be executed by a sentinel node or proxy node of the cache database, or by an enhanced client software development kit (SDK), or by any node of the cache database, or by other electronic devices; this disclosure does not limit this. The high-availability method for bidirectional data synchronization of the cache database provided in this disclosure can also be called a data synchronization method, or a data synchronization method based on the cache database.
[0026] like Figure 1 As shown, the method may include the following steps: Step S101: When the first node, which is the master node, fails, the write operation request is redirected to the second node, which is the slave node, and the key information of the write operation is recorded in the reverse operation log.
[0027] In some embodiments, there are three ways to store cached data: Remote DictionaryService (Redis), Memcache (a distributed high-speed caching system), and MongoDB (a database based on distributed file storage). A master-slave replication architecture is typically used, such as Redis Sentinel or Redis Cluster. In this architecture, one master node handles write requests, and multiple slave nodes synchronize data with the master node and handle read requests. When the master node fails, a high-availability component (such as Redis Sentinel) can automatically elect a slave node to become the new master node, and the application will switch to writing data to this new master node. After the old master node recovers, it will act as a slave node of the new master node, catching up with and synchronizing all new data generated on the new master node during the failure period through full or incremental synchronization.
[0028] In a data caching cluster architecture, if data modifications made to the slave database during failover cannot be automatically synchronized back to the master database, there is a risk of data loss, and the robustness of the cluster system cannot be guaranteed. Specifically, during failover, if operations personnel or a specific application (such as a data repair script) directly modify data on a slave database that has not been promoted to the new generation master node, these modifications will become "orphan data," leading to data silos. Furthermore, given that the master-slave replication mechanism is unidirectional, only synchronizing data from the master node to the slave nodes, when the old master node recovers and rejoins the cluster, it will only pull data from the new master node. Changes to the "orphan data" on the old slave nodes that were modified during the failover will not be automatically synchronized back to the new master node, leading to data inconsistency, data loss, and impacting the correctness of business operations.
[0029] In some embodiments, before the first node, which is the master node, fails, the first node handles write operation requests, which refer to requests initiated by clients to write data to the database.
[0030] The second node acts as a slave node, synchronizing data from the first node and handling read operation requests. A read operation request is a request initiated by a client to retrieve data from the database. In the event of a failure of the first node, write operation requests are redirected to the second node for execution. The second node performs the write operation and records key information about the write operation in the reverse operation log for subsequent reverse data synchronization. This key information may include commands, keys, parameters, timestamps, and client identifiers.
[0031] The reverse operation log is specifically used to record key information about write operations performed by the slave node. It is used in the subsequent reverse synchronization process from the slave node to the master node. Reverse synchronization refers to data synchronization from the slave node to the master node; the reverse operation log can also be called the first log, or other names.
[0032] Step S102: When the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, the reverse synchronization process is triggered; wherein, the third node is a new master node selected from the second node.
[0033] In some embodiments, when the first node fails, a node is selected from the second nodes to be promoted to the new master node (i.e., the third node); when the first node recovers, the first node rejoins the cluster as a slave node of the third node, the first node and the third node synchronize data, and after the first node completes the data synchronization with the third node, the reverse synchronization process is triggered.
[0034] Step S103: Read the operation log recorded within the fault time window from the reverse operation log, process it, and then re-execute the operation command corresponding to the operation log on the third node.
[0035] The fault time window refers to the time window between the occurrence of a fault in the first node and the recovery of the first node.
[0036] In some embodiments, the operation logs recorded within the fault time window are read from the reverse operation log in chronological order, that is, the operation logs recorded from the time the first node fails to the time the first node recovers are read in chronological order, and these operation logs are processed. Then, the operation commands corresponding to these operation logs are re-executed on the third node (new master node) in an orderly manner, thereby ensuring that the data written by the slave node during the failure of the first node (old master node) can be synchronized to the master node and avoid data loss.
[0037] In some embodiments, processing the operation log may involve rearranging the operation log, such as merging, deduplicating, and resolving conflicts.
[0038] For example, a cache database consists of three nodes: node A, node B, and node C. Node A is the master node, and nodes B and C are slave nodes. When node A fails, node B is selected as the new master node from among slave nodes B and node C. After node A recovers, node A becomes the slave node of node B, and the data of node B is synchronized to node A. Then, a reverse synchronization process is triggered to synchronize the data changes that occurred on node C during the failure to node B, thus avoiding the problem of data changes that occurred on node C not being synchronized.
[0039] In this embodiment of the disclosure, when the first node, acting as the master node, fails in the cache database, write operation requests can be redirected to the second node, acting as a slave node, to ensure that write operations can be executed smoothly during the master node failure. When the first node fails, key information about the write operations is recorded in the reverse operation log. When the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, which is the new master node, the operation logs recorded within the failure time window are read from the reverse operation log. After processing, the corresponding operation commands in the operation logs are re-executed on the third node. This enables the reverse synchronization of data modifications made to slave nodes during the old master node failure to the new master node, thereby achieving bidirectional data synchronization. This avoids the problem that data modifications made to slave nodes during the old master node failure cannot be synchronized to the master node, reduces the risk of data loss, improves the accuracy of data synchronization, and enhances the robustness of the cluster system.
[0040] In some embodiments, the method may further include: after confirming that the operation command corresponding to the operation log has been executed on the third node, deleting the operation log recorded within the fault time window from the reverse operation log.
[0041] Specifically, after confirming that all operation logs recorded within the failure time window of the old master node have been successfully executed on the new master node, the system can clear or archive the reverse operation logs for that failure time window, saving storage resources. The system then resumes normal master-slave replication mode. The new master node will contain all valid data changes that occurred on all slave nodes during the failure period, reducing the risk of data loss and improving the accuracy of data synchronization.
[0042] In some embodiments, the method may further include: monitoring and intercepting write operation requests sent to a second node before the first node, which is the master node, fails.
[0043] Specifically, a monitoring and interception function can be added between the master and slave nodes, or an enhanced client software development kit (SDK) can be used to monitor all write operation requests sent to the slave nodes. Simultaneously, the liveness and availability of the master node should be continuously monitored. When the master node is functioning normally (i.e., before a master node failure), write operation requests sent to the slave nodes should be intercepted upon detection, ensuring the slave nodes maintain standard read-only behavior. When the master node fails, all write operation requests should be redirected to the slave nodes.
[0044] For example, a cache database consists of three nodes: node A, node B, and node C. Node A acts as the master node, while nodes B and C act as slave nodes for data processing. Node A handles write operation requests. Before node A fails, it monitors and intercepts write operation requests sent to nodes B and C. When node A fails, the write operation requests are redirected to slave nodes B and C, which then handle the write operation requests.
[0045] In some embodiments, monitoring and intercepting write operation requests sent to the second node before the first node, which is the master node, fails can ensure that the write operation requests are made only by the master node, and then the master node synchronizes data to the slave node, thus ensuring the consistency of data across all nodes.
[0046] In some embodiments, recording key information of a write operation into a reverse operation log includes: serializing the key information of the write operation to obtain log entries; and writing the log entries into the reverse operation log for storage.
[0047] Specifically, after the write operation is performed on the second node, the key information of the write operation is serialized and persistently written to a dedicated reverse operation log as a log entry. The key information of the write operation may include at least one of the following: command, key, parameters, timestamp, and client identifier.
[0048] In some embodiments, key information of the write operation is serialized and stored in the reverse operation log to facilitate subsequent reverse synchronization and avoid the problem of data loss written to the slave node during the failure of the first node.
[0049] In some embodiments, the method may further include: confirming that the first node, which is the master node, has failed when it is detected that the sentinel node has started failover and no third node has been elected, or when it is detected that the application has sensed that the first node has crashed.
[0050] For example, if a sentinel node has started failover but a new master node has not yet been elected, or if the application has detected that the master node has crashed, it can confirm that the master node has failed. In this case, write operation requests can be directed to the second node, which is a slave node, and the key information of the write operation can be recorded in the reverse operation log.
[0051] In some embodiments, the behavior of the sentinel node or the application is detected to determine whether the first node has failed, which makes it easier for the system to detect the failure of the first node in a timely manner and improves the efficiency of fault handling.
[0052] In some embodiments, the method may further include: when the first node recovers and rejoins the cluster as a slave node, synchronizing the data generated on the third node within the fault time window to the first node through full synchronization or incremental synchronization.
[0053] Specifically, when the first node fails, a node is selected from the second nodes to be promoted to the new master node (i.e., the third node). When the first node recovers, it rejoins the cluster as a slave node of the third node. The first node synchronizes the data generated on the third node within the first node's failure time window to the first node through full synchronization or incremental synchronization. This ensures that data changes generated during the first node's failure period can be synchronized to the first node, reducing the risk of data loss due to the first node's failure.
[0054] Figure 2 This is a schematic diagram of the architecture of a highly available system that supports bidirectional data synchronization for a cache database, as provided in an embodiment of this disclosure.
[0055] like Figure 2As shown in this embodiment, a status monitoring module is added between the master and slave services. This module, or an enhanced SDK, monitors and intercepts all write operation commands sent to the slave nodes. Simultaneously, it continuously monitors the liveness and availability of the master node. When the master node is functioning normally, the status monitoring module should reject all write requests on the slave nodes, maintaining standard read-only slave node behavior. Only when the master node fails will all write requests be redirected to the slave nodes, at which point the slave node may be promoted to the new master node.
[0056] like Figure 2 As shown in this embodiment, a new reverse log storage module is added. When the system confirms that the master node has failed (for example, Sentinel has started failover but a new master node has not yet been elected, or the application has detected that the master node has crashed), the proxy node or SDK will enter "degraded write mode". In this mode, for write operations that are allowed to be performed on the slave node, after the local execution is completed, the key information of the write operation (including commands, keys, parameters, timestamps, client identifiers, etc.) will be serialized and persistently written to a dedicated "reverse operation log" for storage as a log entry.
[0057] like Figure 2 As shown in this embodiment, a new synchronization coordinator is added to coordinate the synchronization write-back. When the failed master node recovers and rejoins the cluster, and the slave node, acting as the new master node, completes data synchronization, the system triggers the reverse synchronization process. The synchronization coordinator retrieves all operation logs recorded within the failure time window from the reverse operation logs in chronological order. The coordinator rearranges these operation commands (e.g., merging, deduplication, conflict resolution) and then re-executes these commands on the new master node in an orderly manner. This ensures that data generated by the system during the master failure can be recovered normally, thus guaranteeing data integrity. After confirming that all reverse operation logs have been successfully executed on the new master node, the system clears or archives the reverse operation logs for that time period. The system resumes normal master-slave replication mode, and the new master node will contain all valid data changes that occurred on all slave nodes during the failure.
[0058] In this embodiment of the disclosure, a reverse operation log component and a set of collaborative working logic are used, with the monitoring interception module, log storage module and synchronization coordinator working together to achieve "two-way synchronization" of data in the data cache cluster architecture. That is, under specific conditions (during the failure of the master node in the data cache cluster), data changes can be reverse-synchronized from the slave node to the master node, thereby ensuring eventual consistency of data and improving the robustness of the system.
[0059] Figure 3 This is a flowchart illustrating a high-availability method for supporting bidirectional data synchronization in a cache database, as provided in an embodiment of this disclosure.
[0060] like Figure 3 As shown, the method may include the following steps: Step S301: Monitor write requests.
[0061] Step S302: Determine whether the master node is in a normal state.
[0062] If the master node is functioning normally, proceed to step S303; if the master node fails, proceed to step S304.
[0063] Step S303: Reject writes from the node.
[0064] When the master node is functioning normally, it handles write requests and rejects write requests from slave nodes.
[0065] Step S304: Allow writes from the node.
[0066] Step S305: Record the write operation in the reverse operation log.
[0067] When the master node fails, slave nodes are allowed to process write requests and write operations are recorded in the reverse operation log.
[0068] Step S306: Listen for master node recovery events.
[0069] Step S307: Trigger the reverse synchronization mechanism.
[0070] Listen for master node recovery events and trigger the reverse synchronization mechanism after the master node recovers.
[0071] Step S308: Read the orchestration log.
[0072] Read and compile the reverse operation log.
[0073] Step S309: The new master node performs log recovery.
[0074] Step S310: Synchronization complete, clean up logs.
[0075] After synchronization is complete, clean up the reverse operation logs for that time period.
[0076] This disclosure provides a highly available system for a cache database that supports bidirectional data synchronization, such as... Figure 4 As shown, the system 40 includes: The recording module 401 is used to redirect the write operation request to the second node, which is the slave node, when the first node, which is the master node, fails, and to record the key information of the write operation in the reverse operation log. Trigger module 402 is used to trigger the reverse synchronization process when the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node; wherein the third node is a new master node selected from the second node; The processing module 403 is used to read the operation log recorded within the fault time window from the reverse operation log, process it, and then re-execute the operation command corresponding to the operation log on the third node.
[0077] Optionally, the system further includes a deletion module, used to delete the operation log recorded within the fault time window from the reverse operation log after confirming that the operation command corresponding to the operation log has been executed on the third node.
[0078] Optionally, the system further includes an interception module, used to monitor and intercept write operation requests sent to the second node before the first node, which acts as the master node, fails.
[0079] Optionally, the recording module is used to serialize the key information of the write operation to obtain a log entry; and to write the log entry into the reverse operation log for storage.
[0080] Optionally, the system further includes a synchronization module, used to synchronize the data generated on the third node within the fault time window to the first node through full synchronization or incremental synchronization when the first node recovers and rejoins the cluster as a slave node.
[0081] Optionally, the system further includes: a confirmation module, used to confirm that the first node, as the master node, has failed when it is detected that the sentinel node has started failover and has not elected the third node, or when it is detected that the application has sensed that the first node has crashed.
[0082] The system of this disclosure embodiment can execute the method provided in this disclosure embodiment, and its implementation principle is similar, and it has corresponding technical effects. The actions performed by each module in the system of each embodiment of this disclosure correspond to the steps in the method of each embodiment of this disclosure. For a detailed functional description of each module of the system, please refer to the description in the corresponding method shown above, which will not be repeated here.
[0083] This disclosure provides an electronic device including a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to implement the steps of the method provided in any optional embodiment of this disclosure. Compared with the prior art, the cache database provided by this disclosure supports a high-availability method for bidirectional data synchronization. In the cache database, when the first node, acting as the master node, fails, write operation requests can be redirected to the second node, acting as a slave node, to ensure that write operations can be executed smoothly during the master node failure. When the first node fails, key information of the write operation is recorded in the reverse operation log. When the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, acting as the new master node, the operation log recorded within the failure time window is read from the reverse operation log. After processing, the operation command corresponding to the operation log is re-executed on the third node. This enables the reverse synchronization of data modifications made to slave nodes during the old master node failure to the new master node, thereby achieving bidirectional data synchronization. This avoids the problem that data modifications made to slave nodes during the old master node failure cannot be synchronized to the master node, reduces the risk of data loss, improves the accuracy of data synchronization, and enhances the robustness of the cluster system.
[0084] In an alternative embodiment, an electronic device, such as Figure 5 As shown, Figure 5 The illustrated electronic device 5000 includes a processor 5001 and a memory 5003. The processor 5001 and the memory 5003 are connected, for example, via a bus 5002. Optionally, the electronic device 5000 may further include a transceiver 5004, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 5004 is not limited to one type, and the structure of the electronic device 5000 does not constitute a limitation on the embodiments of this disclosure.
[0085] Processor 5001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with this disclosure. Processor 5001 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0086] Bus 5002 may include a pathway for transmitting information between the aforementioned components. Bus 5002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 5002 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0087] The memory 5003 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.
[0088] The memory 5003 is used to store computer programs that execute embodiments of the present disclosure, and is controlled by the processor 5001 to execute them. The processor 5001 is used to execute the computer programs stored in the memory 5003 to implement the steps shown in the foregoing method embodiments.
[0089] Among them, electronic devices include, but are not limited to: mobile terminals such as mobile phones, laptops, digital radio receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (such as in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0090] This disclosure provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.
[0091] This disclosure also provides a computer program product, including a computer program that, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.
[0092] It should be understood that although arrows indicate various operation steps in the flowcharts of the embodiments of this disclosure, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of the embodiments of this disclosure, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured as required, and the embodiments of this disclosure do not limit this.
[0093] The above description is only an optional implementation method for some implementation scenarios of this disclosure. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this disclosure without departing from the technical concept of this disclosure also fall within the protection scope of the embodiments of this disclosure.
Claims
1. A highly available method for supporting bidirectional data synchronization in a cache database, characterized in that, The cache database includes a first node and at least two second nodes; The method includes: When the first node, which acts as the master node, fails, the write operation request is redirected to the second node, which acts as the slave node, and the key information of the write operation is recorded in the reverse operation log. Once the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node, a reverse synchronization process is triggered; wherein, the third node is a new master node selected from the second node; Read the operation logs recorded within the fault time window from the reverse operation log, process them, and then re-execute the operation commands corresponding to the operation logs on the third node.
2. The high-availability method for supporting bidirectional data synchronization in a cache database according to claim 1, characterized in that, The method further includes: After confirming that the operation command corresponding to the operation log has been executed on the third node, delete the operation log recorded within the fault time window from the reverse operation log.
3. The high-availability method for supporting bidirectional data synchronization in a cache database according to claim 1 or 2, characterized in that, The method further includes: Before the first node, which acts as the master node, fails, monitor and intercept write operation requests sent to the second node.
4. The high-availability method for supporting bidirectional data synchronization in a cache database according to claim 1 or 2, characterized in that, The step of recording key information of the write operation into the reverse operation log includes: The key information of the write operation is serialized to obtain log entries; The log entries are written to the reverse operation log for storage.
5. The high-availability method for supporting bidirectional data synchronization in a cache database according to claim 1 or 2, characterized in that, The method further includes: When the first node recovers and rejoins the cluster as a slave node, the data generated on the third node within the fault time window is synchronized to the first node through full synchronization or incremental synchronization.
6. The high-availability method for supporting bidirectional data synchronization in a cache database according to claim 1 or 2, characterized in that, The method further includes: When it is detected that the sentinel node has started failover and the third node has not been elected, or when it is detected that the application has sensed that the first node has crashed, the first node as the master node is confirmed to have failed.
7. A highly available system for a cache database supporting bidirectional data synchronization, characterized in that, The cache database includes a first node as the master node and multiple second nodes as slave nodes. The system includes: The recording module is used to redirect write operation requests to the second node, which is a slave node, when the first node, which is the master node, fails, and to record key information of the write operation in the reverse operation log. The triggering module is used to trigger the reverse synchronization process when the first node recovers and rejoins the cluster as a slave node, and completes data synchronization with the third node; wherein the third node is a new master node selected from the second node; The processing module is used to read the operation log recorded within the fault time window from the reverse operation log, process it, and then re-execute the operation command corresponding to the operation log on the third node.
8. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method of any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.