Active switching method and device of master and slave nodes, equipment and medium

By sending a blocking command to the master node of the Redis network and switching the slave node that has completed data synchronization to the new master node, the problem of data loss during master-slave node switching in the existing technology is solved, realizing the active switching of master-slave nodes and ensuring data integrity and consistency.

CN121125452APending Publication Date: 2025-12-12BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD +1

Patent Information

Application Number
CN202410756555.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing Redis network high availability solutions cannot achieve proactive switching between master and slave nodes. This means that when the master node experiences a planned power outage, restart, or maintenance, data may not be synchronized to the new master node, resulting in data loss.

Method used

By sending a blocking command to the current master node to stop data processing within a preset time, a slave node that has completed data synchronization with the current master node is selected as the target slave node, and it is switched to the new master node within a preset time. At the same time, a network mapping is constructed to achieve active switching between master and slave nodes.

Benefits of technology

This ensures data integrity and consistency during master-slave failover, improves failover reliability, and prevents data loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121125452A_ABST
    Figure CN121125452A_ABST
Patent Text Reader

Abstract

The invention relates to an active switching method and device of master and slave nodes, equipment and a medium. The method comprises the following steps: in response to a received master node switching request for a remote dictionary service network, sending a blocking instruction to a current master node of the remote dictionary service network, so that the current master node stops executing a data processing instruction of a client within a preset duration required by the blocking instruction; selecting one slave node in the remote dictionary service network as a target slave node, wherein the target slave node is in an available state and data synchronization of the target slave node and the current master node is completed; switching the target slave node to a new master node of the remote dictionary service network within a preset duration, switching the current master node to slave nodes, and constructing a first network mapping between each slave node and the new master node and a second network mapping between the new master node and a master node address of the remote dictionary service network, the active operation of master-slave switching is realized, and the integrity and consistency of data in the master-slave switching process are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer, and particularly relates to an active switching method and device of master-slave nodes, equipment and medium. BACKGROUND

[0002] Redis (Remote Dictionary Server) is an open source Key-Value database written in ANSI C language, supporting network, based on memory and also persistent log, and providing API in multiple languages. Redis is widely used in Internet services to cope with storage and access of a large amount of data.

[0003] The current high availability solution of Redis network can only passively start the master-slave node switching solution when the master node is down or the Redis network is unreachable, switch the original master node to a slave node, and switch a slave node to a new master node to avoid the impact of the failure.

[0004] However, the existing high availability solution cannot achieve active switching of master-slave nodes. When the device where the master node is located exists planned power-off, restart, maintenance and the like, the passive master-slave switching solution cannot guarantee the integrity of data, and forced master-slave switching may cause some data to be not synchronized to the new master node, resulting in data loss. SUMMARY

[0005] To solve the above technical problems, the present disclosure provides an active switching method, device, equipment and medium of master-slave nodes.

[0006] The first aspect of the present disclosure provides an active switching method of master-slave nodes, comprising:

[0007] In response to receiving a master node switching request of a remote dictionary service network, sending a blocking instruction to a current master node of the remote dictionary service network, so that the current master node stops executing a data processing instruction of a client within a preset time length required by the blocking instruction;

[0008] Selecting one slave node in the remote dictionary service network as a target slave node, the target slave node being in an available state and the data synchronization between the target slave node and the current master node being completed;

[0009] Within the preset time length, switching the target slave node to a new master node of the remote dictionary service network, switching the current master node to a slave node, and constructing a first network mapping between each slave node and the new master node and a second network mapping between the new master node and the master node address of the remote dictionary service network.

[0010] The second aspect of the present disclosure provides a master-slave node active switching device, comprising:

[0011] The sending module is configured to, in response to receiving the master node switching request of the remote dictionary service network, send a blocking instruction to the current master node of the remote dictionary service network, so that the current master node stops executing the data processing instruction of the client within a preset time length required by the blocking instruction;

[0012] The selecting module is configured to select one slave node in the remote dictionary service network as a target slave node, the target slave node is in an available state, and the data synchronization between the target slave node and the current master node has been completed;

[0013] The switching module is configured to switch the target slave node as a new master node of the remote dictionary service network within the preset time length, switch the current master node as a slave node, and construct a first network mapping between each slave node and the new master node and a second network mapping between the new master node and the master node address of the remote dictionary service network.

[0014] The third aspect of the present disclosure provides a control device, comprising:

[0015] The memory and the processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the active switching method of the master-slave node of the first aspect can be realized.

[0016] The fourth aspect of the present disclosure provides a computer readable storage medium, and the storage medium stores a computer program, and when the computer program is executed by the processor, the active switching method of the master-slave node of the first aspect can be realized.

[0017] The technical scheme provided by the present disclosure has the following advantages compared with the prior art:

[0018] This disclosure, in response to a request to switch the master node of a remote dictionary service network, sends a blocking instruction to the current master node of the remote dictionary service network, causing the current master node to stop executing client data processing instructions within a preset duration required by the blocking instruction; selects a slave node in the remote dictionary service network as a target slave node, the target slave node is in an available state and data synchronization between the target slave node and the current master node is completed; within the preset duration, switches the target slave node to the new master node of the remote dictionary service network, switches the current master node to a slave node, and constructs a first network mapping between each slave node and the new master node, and a second network mapping between the new master node and the master node address of the remote dictionary service network. Based on the user's master node switching request, after the data synchronization between the target slave node and the current master node is completed, the master node of the remote dictionary service network is actively switched, switching the current master node to a slave node and the target slave node to the new master node, thus achieving proactive master-slave switching, ensuring data integrity and consistency during the master-slave switching process, and improving the reliability of master-slave switching. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0020] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a flowchart of a method for active switching between master and slave nodes provided in an embodiment of this disclosure;

[0022] Figure 2 This is a flowchart of another active master-slave node switching method provided in this embodiment of the disclosure;

[0023] Figure 3a This is a schematic diagram of a master-slave node before active switching provided in an embodiment of this disclosure;

[0024] Figure 3b This is a schematic diagram illustrating a master-slave node active switchover provided in an embodiment of this disclosure;

[0025] Figure 4 This is a schematic diagram of the structure of an active switching device for master and slave nodes provided in an embodiment of this disclosure;

[0026] Figure 5 This is a schematic diagram of the structure of a control device provided in an embodiment of this disclosure. Detailed Implementation

[0027] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0028] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0029] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0030] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0031] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0032] The active switching method for master-slave nodes provided in this disclosure can be executed by a control device, which can be understood as any electronic device with processing and computing capabilities. The control device is located in a remote dictionary service Redis network, which includes a master node and at least one slave node.

[0033] To better understand the inventive concept of the embodiments of this disclosure, the technical solutions of the embodiments of this disclosure will be described below in conjunction with exemplary embodiments.

[0034] Figure 1This is a flowchart of a method for active master-slave node switching provided in an embodiment of this disclosure, such as... Figure 1 As shown, the active master-slave node switching method provided in this embodiment includes the following steps:

[0035] Step 110: In response to receiving a request to switch the master node of the remote dictionary service network, send a blocking instruction to the current master node of the remote dictionary service network so that the current master node stops executing the client's data processing instructions within the preset duration required by the blocking instruction.

[0036] In this embodiment of the disclosure, the remote dictionary service network is a Redis network, which includes a master node, at least one slave node, and a control device. For example, the control device can be an HA (High Availability) component.

[0037] The master node provides transactional operations (create, read, update) on the data, while the slave nodes only provide read operations. All data on the slave nodes is synchronized from the master node.

[0038] When the device hosting the master node in the remote dictionary service network experiences a planned power outage, restart, or maintenance, the user can send a master node switchover request to the control device of the remote dictionary service network via a specific device. Upon receiving the request, the control device sends a blocking command (client pause) to the current master node of the remote dictionary service network. This blocking command includes a preset duration, which can be set as needed and is not limited here. After receiving the blocking command, the current master node can stop executing client data processing commands for the preset duration, ensuring data stability during the master-slave switchover.

[0039] A client can be understood as any device with processing and computing capabilities, including but not limited to mobile terminals such as smartphones, laptops, personal digital assistants (PDAs), tablets (PADs), in-vehicle terminals, and wearable devices, as well as fixed electronic devices such as digital TVs and desktop computers.

[0040] Step 120: Select a slave node in the remote dictionary service network as the target slave node. The target slave node is in an available state and the data synchronization between the target slave node and the current master node has been completed.

[0041] In this embodiment of the disclosure, the control device can select a slave node in the remote dictionary service network as the target slave node, wherein the target slave node is in an available state and the data synchronization between the target slave node and the current master node has been completed.

[0042] The data synchronization between the target slave node and the current master node has been completed, which can be understood as the target slave node including all the data of the current master node.

[0043] Step 130: Within a preset time period, switch the target slave node to the new master node of the remote dictionary service network, switch the current master node to a slave node, and construct the first network mapping between each slave node and the new master node, as well as the second network mapping between the new master node and the master node address of the remote dictionary service network.

[0044] In this embodiment of the disclosure, after determining the target slave node, the control device can switch the target slave node to the new master node of the remote dictionary service network within a preset time period, switch the current master node to a slave node, and construct a first network mapping between each slave node and the new master node so that each slave node and the new master node can establish a network connection based on the first network mapping. It also constructs a second network mapping between the new master node and the master node address of the remote dictionary service network so that the client and the new master node can establish a network connection based on the second network mapping.

[0045] In some embodiments, the control device can adjust the data processing function of the target slave node to the data processing function of the master node, thereby switching the target slave node to the new master node of the remote dictionary service. The data processing function of the master node includes data modification functions, which may include the functions of adding data, deleting data, and modifying data.

[0046] The control device can adjust the data processing function of the current master node to that of the slave node, thereby switching the current master node to a slave node. The data processing function of the slave node includes the functions of synchronizing data with the master node and processing data read requests, but does not include data modification functions.

[0047] In other embodiments, constructing a first network mapping between each slave node and the new master node may include S11-S12:

[0048] S11. For each slave node, the master node address stored in the slave node is switched to the target address of the new master node in the remote dictionary service network, and the master node port number stored in the slave node is switched to the target port number of the new master node.

[0049] In this embodiment of the disclosure, the master node address stored in the slave node is the address of the current master node in the remote dictionary service network, and the master node port number stored in the slave node is the port number of the current master node. The control device can, for each slave node, switch the master node address stored in the slave node to the target address of the new master node in the remote dictionary service network, and switch the master node port number stored in the slave node to the target port number of the new master node.

[0050] S12. Based on the target address and target port number, construct the first network mapping between the slave node and the new master node, so that each slave node and the new master node can establish a network connection based on the first network mapping.

[0051] In other embodiments, constructing a second network mapping between the new master node and the master node address of the remote dictionary service network may include S21-S23:

[0052] S21. Delete the original mapping relationship between the address of the current master node in the remote dictionary service network and the address of the master node in the remote dictionary service network.

[0053] S22. Construct the target mapping relationship between the target address of the new master node in the remote dictionary service network and the master node address of the remote dictionary service network.

[0054] S23. Based on the target mapping relationship, construct a second network mapping between the new master node and the master node address of the remote dictionary service network, so that the client and the new master node can establish a network connection based on the second network mapping.

[0055] In this embodiment, in response to a received request to switch the master node of a remote dictionary service network, a blocking instruction is sent to the current master node of the remote dictionary service network to cause the current master node to stop executing client data processing instructions within a preset duration required by the blocking instruction. A slave node in the remote dictionary service network is selected as the target slave node, which is in an available state and whose data synchronization with the current master node has been completed. Within the preset duration, the target slave node is switched to the new master node of the remote dictionary service network, and the current master node is switched to a slave node. A first network mapping between each slave node and the new master node and a second network mapping between the new master node and the master node address of the remote dictionary service network are constructed. According to the user's master node switching request, the master node of the remote dictionary service network is actively switched after the data synchronization between the target slave node and the current master node is completed. The current master node is switched to a slave node, and the target slave node is switched to the new master node. This proactive master-slave switching ensures the integrity and consistency of data during the master-slave switching process and improves the reliability of the master-slave switching.

[0056] Figure 2 This is a flowchart of a method for active master-slave node switching provided in an embodiment of this disclosure, such as... Figure 2 As shown, the active master-slave node switching method provided in this embodiment includes the following steps:

[0057] Step 210: In response to receiving a request to switch the master node of the remote dictionary service network, send a blocking instruction to the current master node of the remote dictionary service network so that the current master node stops executing the client's data processing instructions within the preset duration required by the blocking instruction.

[0058] Step 220: Select an available slave node in the remote dictionary service network as the candidate slave node.

[0059] In this embodiment of the disclosure, the control device in the remote dictionary service network can select one of the available slave nodes in the remote dictionary service network as a candidate slave node.

[0060] In some embodiments, the control device may obtain the identifier of an available slave node in an available state in the remote dictionary service network from the master node switching request;

[0061] When the number of available slave node identifiers is equal to 1, the slave node corresponding to the available slave node identifier is selected as the candidate slave node;

[0062] When the number of available slave node identifiers is greater than 1, select any slave node corresponding to any available slave node identifier as a candidate slave node.

[0063] A node identifier can be understood as identification information that can uniquely identify a node.

[0064] Step 230: Determine whether the data synchronization between the candidate slave node and the current master node has been completed.

[0065] In this embodiment of the disclosure, after determining the candidate slave node, the control device can determine whether the data synchronization between the candidate slave node and the current master node has been completed, that is, whether the candidate slave node has copied all the data of the current master node.

[0066] In some embodiments, determining whether data synchronization between the candidate slave node and the current master node has been completed may include steps 2301-2303:

[0067] Step 2301: Read the first position offset of the data in the current master node and the current master node identifier corresponding to the current master node, as well as the second position offset of the data in the candidate slave node and the source master node identifier corresponding to the data source.

[0068] In this embodiment of the disclosure, the control device can read the first position offset of the data in the current master node of the remote dictionary service network and the current master node identifier corresponding to the current master node, and read the second position offset of the data in the candidate slave node and the source master node identifier corresponding to the data source.

[0069] The offset of data in a node can be understood as the length of the existing data in bytes within the node; the offset can be considered a field.

[0070] After the master node writes data, it accumulates the length of the existing data in the master node to obtain the position offset of the data in the master node (master_repl_offset).

[0071] After data is copied from the slave node, the length of the existing data in the slave node is accumulated and recorded to obtain the position offset of the data in the slave node (slave_repl_offset).

[0072] Step 2302: When the offset of the second position is greater than or equal to the offset of the first position and the source master node identifier is the same as the current master node identifier, it is determined that the data synchronization between the candidate slave node and the current master node has been completed.

[0073] In this embodiment of the disclosure, when the second position offset is greater than or equal to the first position offset and the source master node identifier is the same as the current master node identifier, it indicates that the candidate slave node has copied all the data of the current master node. The candidate slave node stores all the data of the current master node, and the control device can determine that the data synchronization between the candidate slave node and the current master node has been completed.

[0074] Step 2303: When the offset of the second position is less than the offset of the first position or the source master node identifier is different from the current master node identifier, it is determined that the data synchronization between the candidate slave node and the current master node has not been completed.

[0075] In this embodiment of the disclosure, when the second position offset is less than the first position offset or the source master node identifier is different from the current master node identifier, it indicates that the candidate slave node has not yet copied all the data of the current master node, and the candidate slave node does not store all the data of the current master node. The control device can determine that the data synchronization between the candidate slave node and the current master node is not complete.

[0076] Step 240: In response to the completion of data synchronization between the candidate slave node and the current master node, the candidate slave node is determined as the target slave node.

[0077] In some embodiments, in response to the incomplete data synchronization between the candidate slave node and the current master node, the control device may wait for the data synchronization between the candidate slave node and the current master node to be completed before determining the candidate slave node as the target slave node.

[0078] In other embodiments, in response to the incomplete data synchronization between the candidate slave node and the current master node, the control device may select one slave node from the remaining available slave nodes in the remote dictionary service network as the candidate slave node, and determine whether the data synchronization between the candidate slave node and the current master node has been completed; in response to the completion of the data synchronization between the candidate slave node and the current master node, the candidate slave node is determined as the target slave node.

[0079] Step 250: Within a preset time period, switch the target slave node to the new master node of the remote dictionary service network, switch the current master node to a slave node, and construct the first network mapping between each slave node and the new master node, as well as the second network mapping between the new master node and the master node address of the remote dictionary service network.

[0080] Therefore, based on the user's master node switching request, after the data synchronization between the target slave node and the current master node is completed, the master node of the remote dictionary service network can be actively switched, the current master node can be switched to a slave node, and the target slave node can be switched to a new master node. This realizes the proactive master-slave switching, ensures the integrity and consistency of data during the master-slave switching process, and improves the reliability of master-slave switching.

[0081] Figure 3a This is a schematic diagram of a master-slave node before active switching, as provided in an embodiment of this disclosure. Figure 3a As shown, the Redis network for remote dictionary services includes one master node, two slave nodes, and a control device. Before the master-slave switch, each slave node interacts with the current master node. The current master node can interact with clients to process their data processing requests. The control device can control the current master node and each slave node.

[0082] Figure 3b This is a schematic diagram illustrating an active switchover between master and slave nodes provided in an embodiment of this disclosure, as shown below. Figure 3b As shown, after the master-slave node switch, the control device will switch one of the slave nodes in the remote dictionary service Redis network to become the new master node, and switch the current master node to become a slave node. Each slave node will interact with the new master node. The new master node can interact with the client to process the client's data processing requests. The control device can control the new master node and each slave node.

[0083] Figure 4 This is a schematic diagram of the structure of an active switching device for master-slave nodes provided in an embodiment of this disclosure. This device can be understood as the aforementioned control device or a functional module within the aforementioned control device. For example... Figure 4 As shown, the active switching device 400 for the master-slave node includes:

[0084] The sending module 410 is used to respond to receiving a request to switch the master node of the remote dictionary service network, and send a blocking instruction to the current master node of the remote dictionary service network, so that the current master node stops executing the client's data processing instructions within a preset time period required by the blocking instruction;

[0085] Select module 420 is used to select a slave node in the remote dictionary service network as the target slave node, wherein the target slave node is in an available state and the data synchronization between the target slave node and the current master node has been completed;

[0086] The switching module 430 is used to switch the target slave node to the new master node of the remote dictionary service network within a preset time period, switch the current master node to a slave node, and construct a first network mapping between each slave node and the new master node, as well as a second network mapping between the new master node and the master node address of the remote dictionary service network.

[0087] Optionally, the above selection module includes:

[0088] The selection submodule is used to select one available slave node in the remote dictionary service network as a candidate slave node;

[0089] The judgment submodule is used to determine whether the data synchronization between the candidate slave node and the current master node has been completed;

[0090] The determination submodule is used to determine the candidate slave node as the target slave node in response to the completion of data synchronization between the candidate slave node and the current master node.

[0091] Optionally, the above selection submodule includes:

[0092] The acquisition unit is used to obtain the identifiers of available slave nodes in the remote dictionary service network that are in an available state from the master node switch request;

[0093] The first determining unit is used to select the slave node corresponding to the available slave node identifier as the candidate slave node when the number of available slave node identifiers is equal to 1.

[0094] The selection unit is used to select any slave node corresponding to any available slave node identifier as a candidate slave node when the number of available slave node identifiers is greater than 1.

[0095] Optionally, the above-mentioned judgment submodule includes:

[0096] The reading unit is used to read the first position offset of the data in the current master node and the current master node identifier corresponding to the current master node, as well as the second position offset of the data in the candidate slave node and the source master node identifier corresponding to the data source;

[0097] The second determining unit is used to determine that the data synchronization between the candidate slave node and the current master node has been completed when the second position offset is greater than or equal to the first position offset and the source master node identifier is the same as the current master node identifier.

[0098] The third determining unit is used to determine that the data synchronization between the candidate slave node and the current master node has not been completed when the second position offset is less than the first position offset or the source master node identifier is different from the current master node identifier.

[0099] Optionally, the switching module mentioned above includes:

[0100] The first adjustment submodule is used to adjust the data processing function of the target slave node to the data processing function of the master node, so as to switch the target slave node to the new master node of the remote dictionary service;

[0101] The second adjustment submodule is used to adjust the data processing function of the current master node to the data processing function of the slave node, so as to switch the current master node to a slave node.

[0102] Optionally, the switching module mentioned above includes:

[0103] The switching submodule is used to switch the master node address stored in the slave node to the target address of the new master node in the remote dictionary service network for each slave node, and to switch the master node port number stored in the slave node to the target port number of the new master node.

[0104] The first construction submodule is used to construct the first network mapping between the slave node and the new master node based on the target address and target port number, so that each slave node can establish a network connection with the new master node based on the first network mapping.

[0105] Optionally, the switching module mentioned above includes:

[0106] The delete submodule is used to delete the original mapping relationship between the address of the current master node in the remote dictionary service network and the address of the master node in the remote dictionary service network.

[0107] The second construction submodule is used to construct the target mapping relationship between the target address of the new master node in the remote dictionary service network and the master node address of the remote dictionary service network.

[0108] The third construction submodule is used to construct a second network mapping between the new master node and the master node address of the remote dictionary service network based on the target mapping relationship, so that the client and the new master node can establish a network connection based on the second network mapping.

[0109] The active switching device for master-slave nodes provided in this disclosure can implement the method of any of the above embodiments, and its execution method and beneficial effects are similar, so they will not be described again here.

[0110] This disclosure also provides a control device, which includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, it can implement the methods of any of the above embodiments. The execution method and beneficial effects are similar and will not be described again here.

[0111] The control device in this disclosure embodiment can be understood as any electronic device with processing and computing capabilities.

[0112] Figure 5 This is a schematic diagram of the structure of a control device provided in an embodiment of this disclosure, such as... Figure 5 As shown, the control device 500 may include a processor 510 and a memory 520. The memory 520 stores a computer program 521. When the computer program 521 is executed by the processor 510, it can implement the method provided in any of the above embodiments. The execution mode and beneficial effects are similar and will not be described again here.

[0113] Of course, for the sake of simplicity, Figure 5 Only some of the components of the control device 500 relevant to the present invention are shown in this illustration; components such as buses, input / output interfaces, input devices, and output devices are omitted. In addition, the control device 500 may include any other suitable components depending on the specific application.

[0114] This disclosure provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the methods of any of the above embodiments. The execution method and beneficial effects are similar, and will not be described again here.

[0115] The aforementioned computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0116] The computer program described above can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this disclosure. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer device, partially on the user's device, as a standalone software package, partially on the user's computer device and partially on a remote computer device, or entirely on a remote computer device or server.

[0117] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0118] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0119] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for active master-slave node switching, characterized in that, include: In response to receiving a request to switch the master node of a remote dictionary service network, a blocking instruction is sent to the current master node of the remote dictionary service network so that the current master node stops executing the client's data processing instructions for a preset duration required by the blocking instruction. Select a slave node in the remote dictionary service network as the target slave node, wherein the target slave node is in an available state and the data synchronization between the target slave node and the current master node has been completed; Within the preset time period, the target slave node is switched to the new master node of the remote dictionary service network, the current master node is switched to a slave node, and a first network mapping between each slave node and the new master node and a second network mapping between the new master node and the master node address of the remote dictionary service network are constructed.

2. The method according to claim 1, characterized in that, Selecting a slave node from the remote dictionary service network as the target slave node includes: Select one available slave node from the remote dictionary service network as the candidate slave node; Determine whether the data synchronization between the candidate slave node and the current master node has been completed; In response to the completion of data synchronization between the candidate slave node and the current master node, the candidate slave node is determined as the target slave node.

3. The method according to claim 2, characterized in that, The step of selecting an available slave node in the remote dictionary service network as a candidate slave node includes: Obtain the identifier of an available slave node in the remote dictionary service network that is in an available state from the master node switch request; When the number of available slave node identifiers is equal to 1, the slave node corresponding to the available slave node identifier is selected as the candidate slave node; When the number of available slave node identifiers is greater than 1, select any slave node corresponding to any available slave node identifier as a candidate slave node.

4. The method according to claim 2, characterized in that, The step of determining whether the data synchronization between the candidate slave node and the current master node has been completed includes: Read the first position offset of the data in the current master node and the current master node identifier corresponding to the current master node, as well as the second position offset of the data in the candidate slave node and the source master node identifier corresponding to the data source; When the second position offset is greater than or equal to the first position offset and the source master node identifier is the same as the current master node identifier, it is determined that the data synchronization between the candidate slave node and the current master node has been completed. If the offset of the second position is less than the offset of the first position or the source master node identifier is different from the current master node identifier, it is determined that the data synchronization between the candidate slave node and the current master node is not complete.

5. The method according to claim 1, characterized in that, The step of switching the target slave node to the new master node of the remote dictionary service network, and switching the current master node to a slave node, includes: Adjust the data processing function of the target slave node to the data processing function of the master node, so as to switch the target slave node to the new master node of the remote dictionary service; Adjust the data processing function of the current master node to the data processing function of the slave node, so as to switch the current master node to a slave node.

6. The method according to claim 1, characterized in that, The construction of the first network mapping between each of the slave nodes and the new master node includes: For each slave node, the master node address stored in the slave node is switched to the target address of the new master node in the remote dictionary service network, and the master node port number stored in the slave node is switched to the target port number of the new master node; Based on the target address and the target port number, a first network mapping is constructed between the slave node and the new master node, so that each slave node and the new master node establish a network connection based on the first network mapping.

7. The method according to claim 1, characterized in that, The construction of the second network mapping between the new master node and the master node address of the remote dictionary service network includes: Delete the original mapping relationship between the address of the current master node in the remote dictionary service network and the address of the master node in the remote dictionary service network; Construct a target mapping relationship between the target address of the new master node in the remote dictionary service network and the address of the master node in the remote dictionary service network; Based on the target mapping relationship, a second network mapping is constructed between the new master node and the master node address of the remote dictionary service network, so that the client and the new master node can establish a network connection based on the second network mapping.

8. A master-slave node active switching device, characterized in that, include: The sending module is used to respond to a request to switch the master node of a remote dictionary service network by sending a blocking instruction to the current master node of the remote dictionary service network, so that the current master node stops executing the client's data processing instructions within a preset duration required by the blocking instruction. The selection module is used to select a slave node in the remote dictionary service network as the target slave node, wherein the target slave node is in an available state and the data synchronization between the target slave node and the current master node has been completed; The switching module is used to switch the target slave node to the new master node of the remote dictionary service network, switch the current master node to a slave node, and construct a first network mapping between each slave node and the new master node, and construct a second network mapping between the new master node and the master node address of the remote dictionary service network within the preset time period.

9. A control device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program that, when executed by the processor, implements the active switching method for master-slave nodes as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the active switching method for master-slave nodes as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Master-slave service system and master node fault recovery method and device

    CN108964948A

  • Main-standby dual-computer switching method, medium and system

    CN116028278A

  • Database switching method and device and computer equipment

    CN116820812A

Cited By

  • Mobile traffic signal lamp control method and system based on photovoltaic power generation

    CN121617265A