Active / standby switching method and apparatus, and device, storage medium and program product

By determining the thread state and device state in the target device, combined with active and passive switching mechanisms, the problem of low accuracy of main and backup switching in the prior art is solved, and higher switching accuracy and system availability are achieved.

WO2025149840A1PCT designated stage expired Publication Date: 2025-07-17CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
PCT/IB2024/063334
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-01-12
Filing Date
2024-12-31
Publication Date
2025-07-17

AI Technical Summary

Technical Problem

In the prior art, the accuracy of the master-stop switching based on the thread state of the renewal thread is low, resulting in the inaccurate master-stop switching.

Method used

By determining the thread state and device state of the target thread in the target device, the master-sustainment switching is performed in combination with the thread state and device state, including active and passive switching mechanisms, ensuring the accuracy of the switching.

Benefits of technology

Improve the accuracy of master-secure switching, reduce the need for artificial processing, and improve the availability and fault tolerance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2024063334_17072025_PF_FP_ABST
    Figure IB2024063334_17072025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present disclosure are an active / standby switching method and apparatus, and a device, a storage medium and a program product. The method may comprise: determining a thread state of a target thread in a target device, wherein the target device is currently an active device, and the target thread is used for making a request to set the target equipment as an active device; determining a device state of the target device, wherein the device state is the device being normal or the device being abnormal; and performing active / standby switching on the target device on the basis of the thread state and the device state. Thus, the accuracy of active / standby switching is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This disclosure claims priority to Chinese patent application number 202410050499.0, filed with the Chinese Patent Office on January 12, 2024, entitled "Master-Slave Switching Method, Apparatus, Device, Storage Medium, and Program Product," the entire contents of which are incorporated herein by reference. Technical Field This disclosure relates to the field of computers, and more particularly to a master-slave switching method, apparatus, device, storage medium, and program product. Background: In distributed systems, to improve system availability and fault tolerance, a master-slave architecture is often adopted. Specifically, a distributed system may include a master device and at least one slave device, enabling master-slave switching between these multiple devices. In related art, this master-slave architecture is typically implemented using a distributed lock service. When a target device is the master device and the renewal thread is in a normal state, the target device can renew the distributed lock through the renewal thread to maintain the target device as the master device. When the renewal thread is in an abnormal state, renewal cannot be performed, and a master-slave switch can be performed. However, in the above method, the accuracy of master-slave switch based on the thread state of the renewal thread is low. SUMMARY OF THE INVENTION Various aspects of the present disclosure provide a master-slave switch method, apparatus, device, storage medium, and program product for improving the accuracy of master-slave switch. In a first aspect, an embodiment of the present disclosure provides a master-slave switch method, comprising: determining the thread state of a target thread in a target device, the target device currently being the master device, the target thread requesting that the target device be set as the master device; determining the device state of the target device, the device state being either normal or abnormal; and performing a master-slave switch on the target device based on the thread state and the device state. In one possible implementation, performing a master-slave switch on the target device based on the thread state and the device state includes: if the thread state is normal, performing a master-slave switch on the target device based on the device state; and if the thread state is abnormal, switching the target device to the backup device. In a possible implementation, performing active / standby switching on the target device according to the device status includes: if the device status is normal, determining the target device as the active device; if the device status is abnormal, switching the target device to the standby device.In one possible embodiment, switching the target device to a backup device includes: determining the number of active master-slave switchings performed by a distributed system within a preset time period before a current moment, the distributed system being the distributed system where the target device resides, the distributed system including the target device and at least one other device; if the number of active master-slave switchings is less than or equal to a preset threshold, switching the target device to the backup device. In one possible embodiment, switching the target device to the backup device includes: terminating the target thread; and after other devices in the distributed system have switched to the primary device, switching the target device to the backup device. In one possible embodiment, determining the device status of the target device includes: obtaining operating information of the target device, the operating information including at least one of the following: a target service status, a target event processing delay, and a target message accumulation duration; and determining the device status based on the operating information. In one possible implementation, determining the device status based on the operation information includes: determining the device status as a device abnormality when at least one of the following conditions is met: M target services have a service abnormality status, where M is a positive integer; N target events have a processing delay greater than or equal to a corresponding delay threshold, where N is a positive integer; or the message accumulation duration is greater than or equal to the accumulation duration threshold. In a second aspect, embodiments of the present disclosure provide a master-slave switching apparatus, comprising: a first determination module, a second determination module, and a switching module. The first determination module is configured to determine the thread status of a target thread in a target device, where the target device is currently the master device and the target thread is requesting that the target device be set as the master device; the second determination module is configured to determine the device status of the target device, where the device status is either normal or abnormal; and the switching module is configured to perform a master-slave switching on the target device based on the thread status and the device status. In one possible implementation, the switching module is specifically configured to: if the thread status is normal, perform a master / slave switch on the target device based on the device status; and if the thread status is abnormal, switch the target device to the backup device. In another possible implementation, the switching module is specifically configured to: if the device status is normal, determine that the target device is the master device; and if the device status is abnormal, switch the target device to the backup device.In one possible embodiment, the switching module is specifically configured to: determine the number of active master-slave switchings performed by the distributed system within a preset time period before the current moment, wherein the distributed system is the distributed system where the target device is located and includes the target device and at least one other device; determine the operating time of the target device as the master device and determine an operating time threshold; and switch the target device to the backup device if the number of switchings is less than or equal to the preset threshold and the operating time is greater than or equal to the operating time threshold. In one possible embodiment, the switching module is specifically configured to: terminate the target thread; and switch the target device to the backup device after other devices in the distributed system switch to the master device. In one possible embodiment, the second determination module is specifically configured to: obtain operating information of the target device, wherein the operating information includes at least one of the following: the service status of the target service, the processing delay of the target event, and the message accumulation time of the target message; and determine the device status based on the operating information. In one possible implementation, the second determination module is specifically configured to determine that the device status is a device abnormality when at least one of the following conditions is met: M target services have a service abnormality status, where M is a positive integer; N target events have a processing delay greater than or equal to a corresponding delay threshold, where N is a positive integer; and the message accumulation duration is greater than or equal to the accumulation duration threshold. In a third aspect, embodiments of the present disclosure provide an electronic device, comprising: a memory and a processor; the memory storing computer-executable instructions; the processor executing the computer-executable instructions stored in the memory, causing the processor to perform any of the methods described in the first aspect. In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium storing computer-executable instructions, which, when executed by the processor, are used to implement any of the methods described in the first aspect. In a fifth aspect, embodiments of the present disclosure provide a computer program product, comprising a computer program, which, when executed by the processor, implements any of the methods described in the first aspect. Embodiments of the present disclosure provide a method, apparatus, device, storage medium, and program product for master / slave switching, which can determine the thread state of a target thread in a target device and the device state of the target device, and then perform master / slave switching on the target device based on the thread state and device state. Because master / slave switching can be performed based not only on the thread state of the target thread but also on the device state, the accuracy of master / slave switching is improved compared to prior art methods that perform master / slave switching based solely on the thread state of the target thread.BRIEF DESCRIPTION OF THE DRAWINGS The drawings described herein are intended to provide a further understanding of the present disclosure and constitute a part of the present disclosure. The exemplary embodiments of the present disclosure and their descriptions are intended to explain the present disclosure and do not constitute an undue limitation of the present disclosure. In the drawings: Figure 1 is a schematic diagram of a scenario provided by an exemplary embodiment of the present disclosure; Figure 2 is a schematic diagram of the process of master-slave switching in the related art provided by an embodiment of the present disclosure; Figure 3 is a schematic flow diagram of a master-slave switching method provided by an exemplary embodiment of the present disclosure; Figure 4 is a schematic flow diagram of another master-slave switching method provided by an exemplary embodiment of the present disclosure; Figure 5 is a schematic diagram of frequent master-slave switching provided by an exemplary embodiment of the present disclosure; Figure 6 is a schematic diagram of a master-slave switching method provided by an exemplary embodiment of the present disclosure; Figure 7 is a schematic process diagram of a master-slave switching method provided by an exemplary embodiment of the present disclosure; Figure 8 is a schematic diagram of the structure of a master-slave switching device provided by an exemplary embodiment of the present disclosure; Figure 9 is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS: It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, storage, and display) involved in this disclosure are all authorized by the user or fully authorized by all parties. The collection, use, and processing of the relevant data must comply with relevant laws, regulations, and standards, and corresponding operation portals are provided for users to choose to authorize or reject. To further clarify the objectives, technical solutions, and advantages of this disclosure, the technical solutions of this disclosure will be clearly and completely described below in conjunction with specific embodiments of this disclosure and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of this disclosure, and are not exhaustive. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure. Figure 1 is a schematic diagram of a scenario provided by an exemplary embodiment of this disclosure. Referring to Figure 1, a distributed system may include multiple devices. For example, the multiple devices may be device 1, device 2, device 3, and device 4, wherein active / standby switching can be performed between devices 1, 2, and 3; and device 4 may be used to store distributed locks. If device 1 is the master device and devices 2 and 3 are backup devices, device 1 can renew the distributed lock on device 4 through the renewal thread to maintain device 1 as the master device. Devices 2 and 3 can periodically poll and preempt the distributed lock on device 4. If the renewal thread on device 1 fails to renew the lock, either device 2 or device 3 successfully preempts the distributed lock and becomes the new master device.In the related art, the master-slave architecture is typically implemented using a distributed lock service. When the target device is the master device and the renewal thread is in a normal state, the target device can renew the distributed lock through the renewal thread to maintain the master status. When the renewal thread is in an abnormal state and renewal is impossible, a master-slave switch can be performed. However, in this approach, the accuracy of master-slave switch based on the thread state of the renewal thread is low. In the embodiments of the present disclosure, the thread state of the target thread in the target device and the device state of the target device can be determined, and the master-slave switch is performed based on the thread state and device state. The target thread is the renewal thread. Because master-slave switch can be performed based not only on the thread state of the target thread but also on the device state, the accuracy of master-slave switch is improved compared to the prior art that performs master-slave switch based solely on the thread state of the target thread. The following describes the master-slave switch process in the related art with reference to Figure 2. Figure 2 is a schematic diagram of the master-slave switch process in the related art provided by the embodiments of the present disclosure. Referring to Figure 2, a distributed system includes devices 1, 2, 3, and 4, wherein devices 1, 2, and 3 can switch between master and slave modes; device 4 can be used to store distributed locks. Device 1 can include multiple threads, including a Remote Procedure Call (PRC) thread, a service thread, and a renewal thread. The service thread can be used to execute target services. If device 1 is the master device, it can renew the distributed lock in device 4 through the renewal thread to maintain device 1 as the master device. If devices 2 and 3 are slave devices, they can periodically poll and preempt the distributed lock in device 4. If the renewal thread in device 1 fails to renew the lock, either device 2 or device 3 preempts the distributed lock and becomes the new master device. However, in some scenarios, such as when a Machine Check Error (MCE) occurs, causing some threads in device 1 to become abnormal. As shown in Figure 2, when the PRC thread and service thread in device 1 become abnormal and unable to provide normal service, while the renewal thread remains normal, the renewal thread can still renew the contract normally, making it impossible to perform a master-slave switch. This prevents the backup device from successfully preempting the distributed lock and providing normal service. In this case, manual intervention is required. Therefore, in related technologies, the accuracy of master-slave switchover is low. The technical solutions presented in this disclosure are described in detail below through specific embodiments.It should be noted that the following embodiments may exist independently or in combination. Identical or similar content will not be described repeatedly in different embodiments. FIG. 3 is a flow chart illustrating a method for active / standby switching provided by an exemplary embodiment of the present disclosure. Referring to FIG. 3 , the method may include:

[0002] S301. Determine the thread state of a target thread in a target device. The execution subject of the disclosed embodiment may be the target device or a master-slave switching device provided in the target device. The master-slave switching device may be implemented via software or a combination of software and hardware. The master-slave switching device may be a processor in the target device. For ease of understanding, the following description uses the target device as an example. The target device is a device in a distributed system. The target device is currently the master device. The target thread may be a renewal thread in the target device that renews a distributed lock. The target thread may be used to request that the target device be set as the master device. The thread state may be normal or abnormal. For example, if the target device is device 1 and the target thread is thread 1, device 1 may determine the thread state of thread 1. Assume that the thread state of thread 1 is normal.

[0003] S302. Determine the device status of the target device. The device status can be normal or abnormal. In an optional embodiment, the device status of the target device can be determined by: obtaining operating information of the target device; and determining the device status based on the operating information. The operating information can include at least one of the following: the service status of the target service, the processing latency of the target event, and the message accumulation duration of the target message. The target service can be a key service in the target device. For example, the target service can be a cloud disk management service, a remote call service, a configuration push service, a session management service, or a storage service. The target event can be an event executed by a thread. For example, the target event can be a cloud disk creation event. The target message can be the first message in the RPC message queue. The message accumulation duration can be the length of time the first message in the RPC message queue waits for processing. For example, if the target device is device 1, and service 1 and service 2 are target services on device 1, the service status of service 1 and service 2 can be determined. If event 1 and event 2 are target events on device 1, the processing delays of event 1 and event 2 can be determined. Assuming that the first message in the PRC message queue is message 1, the message accumulation duration of message 1 can be determined on the target device. The operation information can include the service status of service 1 and service 2, the processing delays of event 1 and event 2, and the message accumulation duration of message 1. The device status of device 1 can then be determined based on this operation information. Assume that the device status of device 1 is abnormal.

[0004] S303: Switch the target device between active and standby based on the thread status and device status. In an optional embodiment, the target device can be switched between active and standby based on the thread status and device status in the following manner: If the thread status is normal, the target device is switched between active and standby based on the device status; if the thread status is abnormal, the target device is switched to a standby device. When the target thread's thread status is normal, it indicates that the target thread can still renew the distributed lock. In this case, the target device is switched between active and standby based on the device status. This switching method is called active switching. When the thread status is abnormal, it indicates that the target device cannot renew the distributed lock through the target thread. In this case, the target device can be switched to a standby device, which is called passive switching. Optionally, switching the target device to a standby device means that the target device no longer renews the distributed lock, allowing another device to preempt the distributed lock and become the new master device, while the target device is switched to a standby device. For example, if the target device is device 1 and the target thread is thread 1, then if the thread state of thread 1 is normal, device 1 can be switched between active and standby based on the device state of device 1. If the thread state of thread 1 is abnormal, and if device 2 is currently the standby device, device 1 can be switched to the standby device and device 2 to the active device. In another alternative embodiment, the target device can be switched between active and standby based on the thread state and device state in the following manner: if the thread state is abnormal and / or the device state is abnormal, the target device can be switched to the standby device. For example, if the target device is device 1 and the target thread is thread 1, then if the thread state of thread 1 is thread exception and the device state of device 1 is device normal, device 1 can be switched to the backup device due to the thread exception state of thread 1; if the thread state of thread 1 is thread normal and the device state of device 1 is device exception, device 1 can be switched to the backup device due to the device exception; and if the thread state of thread 1 is thread exception and the device state of device 1 is device exception, device 1 can be switched to the backup device due to both the thread exception and the device exception. In the disclosed embodiments, the thread state of the target thread in the target device and the device state of the target device can be determined, and then the target device can be switched between active and standby modes based on the thread state and device state. Because active and standby modes switching can be performed based not only on the thread state of the target thread but also on the device state, the accuracy of active and standby modes switching is improved compared to the prior art, which performs active and standby modes switching based solely on the thread state of the target thread.The following describes the active / standby switching method in detail, based on the embodiment shown in FIG3 and in conjunction with FIG4 . FIG4 is a flow chart illustrating another active / standby switching method provided by an exemplary embodiment of the present disclosure. Referring to FIG4 , the method may include: S401: Determining the thread state of a target thread in a target device. It should be noted that the execution process of step S401 can be referred to as step S301 and will not be further described here.

[0005] S402. Obtain operating information of the target device. Optionally, the operating information may include at least one of the following: the service status of the target service, the processing latency of the target event, and the message accumulation duration of the target message. The target device may include multiple services, including at least one target service. The at least one target service may be manually set. For any target service, the thread status of at least one service thread executing the target service may be determined. If the thread status of at least one service thread is all thread abnormal, the service status of the target service may be determined to be service abnormal; if the thread status of at least one service thread is normal, the service status of the target service may be determined to be service normal. Optionally, the thread status of any service thread may be determined as follows: the service thread may be called multiple times according to a preset period to determine whether the service thread is successfully called. If the number of consecutive failed calls to the service thread is greater than or equal to a preset number, the thread status of the service thread may be determined to be thread abnormal. Optionally, the preset period and the preset number of times may be manually preset. For example, the preset period may be 100 ms (milliseconds), and the preset number of times may be 50. For example, if the target device is device 1, and service 1 in device 1 is the target service, then three service threads executing service 1 may be determined. Assume that these three service threads are service thread 1, service thread 2, and service thread 3. If the preset period is 100 ms and the preset number of times is 50, then service thread 1 may be called once every 100 ms. If the call to service thread 1 fails 50 times in a row, then the thread status of service thread 1 may be determined to be thread abnormal. Similarly, if service thread 2 and service thread 3 are called once every 100 ms, if the call to service thread 2 and service thread 3 fails 50 times in a row, then the thread status of both service thread 2 and service thread 3 may be determined to be thread abnormal. If the thread status of service thread 1, service thread 2, and service thread 3 are all thread abnormal, it can be determined that the service status of service 1 is service abnormal; if the thread status of any service thread among the three service threads is thread normal, it can be determined that the service status of service 1 is service normal.For example, if the target device is device 1, and service 1 and service 2 are target services in device 1, it is assumed that the service status of service 1 can be determined to be service abnormality, and the service status of service 2 can be determined to be service normal; if event 1 and event 2 are target events in device 1, it is assumed that the processing delay of event 1 can be determined to be 1 s, and the processing delay of event 2 can be determined to be 50 ms; if the first message in the PRC message queue is message 1, and it is assumed that the message accumulation time of message 1 can be determined to be 6 s, then the operation information can be obtained, and the operation information can include at least one of the following: the service status of service 1 is service abnormality, the service status of service 2 is service normal, the processing delay of event 1 is 1 s, the processing delay of event 2 is 50 ms, and the message accumulation time of message 1 is 6 s.

[0006] S403. Determine the device status based on the operation information. In an optional embodiment, the device status may be determined to be abnormal if at least one of the following conditions is met: M target services have a service abnormality status, where M is a positive integer; N target events have a processing delay greater than or equal to a corresponding delay threshold, where N is a positive integer; and the message accumulation duration is greater than or equal to the accumulation duration threshold. Optionally, M may be manually preset. For example, M may be 1. When M target services have a service abnormality status, the device status may be determined to be abnormal. For example, if M is 1, and the target device is device 1, and services 1 and 2 on device 1 are target services, and the service status of service 1 is abnormal and the service status of service 2 is abnormal, then the status of one of the two target services is abnormal, and the device status of device 1 may be determined to be abnormal. Optionally, N may be manually preset. For example, N may be 1. For any target event, a corresponding delay threshold may be assigned to the target event. Optionally, the latency threshold can be preset. When the processing delay of the target event is greater than or equal to the corresponding latency threshold, the device status can be determined to be abnormal. For example, if the target device is device 1, target event 1 in device 1 is a cloud disk creation event, if the latency threshold corresponding to target event 1 is 1 second, and the processing delay of target event 1 is 1.5 seconds, and if N is 1, then since there is one target event, namely, target event 1, whose processing delay is greater than the corresponding latency threshold, the device status of device 1 can be determined to be abnormal. Optionally, the accumulation duration threshold can be preset. For example, the accumulation duration threshold can be 5 seconds. When the message accumulation duration is greater than or equal to the accumulation duration threshold, the device status can be determined to be abnormal. For example, if the target device is device 1, the first message in the PRC message queue of device 1 is message 1, and the message accumulation time of message 1 is 6 seconds, this indicates that the first message in the PRC message queue has not been processed within 6 seconds, that is, no messages in the PRC message queue have been processed. If the accumulation time threshold is 5 seconds, since the message accumulation time of message 1 is 6 seconds, which exceeds the accumulation time threshold, it can be determined that the device status of device 1 is abnormal.

[0007] S404: If the thread status is "thread normal" and the device status is "device normal," the target device is determined to be the primary device. For example, if the target device is device 1, if the target thread is thread 1, and if the thread status of thread 1 is "thread normal" and if the device status of device 1 is "device normal," device 1 can be determined to be the primary device.

[0008] S405. If the thread status is normal and the device status is abnormal, the target device is switched to a backup device. If the target thread's thread status is normal, the target thread can still renew the distributed lock. However, if the device status is abnormal, the target device can proactively forgo renewal and switch to a backup device. This switching method is known as active switching. Optionally, since active switching is included in the technical solution of this disclosure, frequent master / slave switching may occur. The phenomenon of frequent master / slave switching is described below with reference to FIG5 . FIG5 is a schematic diagram of frequent master / slave switching provided by an exemplary embodiment of this disclosure. Referring to FIG5 , if a distributed system includes device 1, device 2, and device 3, master / slave switching can be performed among these three devices. If device 1 is currently the master device, and during the first master-slave switchover, the master device can switch from device 1 to device 2, in which case device 1 becomes the slave device and device 2 becomes the master device. During the second master-slave switchover, the master device can switch from device 2 to device 3, in which case device 2 becomes the slave device and device 3 becomes the master device. During the third master-slave switchover, the master device can switch from device 3 to device 1, in which case device 3 becomes the slave device and device 1 becomes the master device. During the fourth master-slave switchover, the master device can again switch from device 1 to device 2, in which case device 1 becomes the slave device and device 2 becomes the master device. Therefore, to prevent frequent master-slave switches, in an optional embodiment, the target device can be switched to the slave device in the following manner: determining the number of master-slave switches that the distributed system has actively performed within a preset time period before the current moment; determining the operating time that the target device has been the master device, and determining an operating time threshold; and if the number of switches is less than or equal to the preset threshold and the operating time is greater than or equal to the operating time threshold, switching the target device to the slave device. If the number of switchovers is greater than or equal to a preset threshold, or the operating time is less than the operating time threshold, active / standby switching of the target device is not actively performed. The distributed system may be the distributed system in which the target device resides, and the distributed system may include the target device and at least one other device. Optionally, each time an active / standby switchover is performed, the distributed system may record the switching mode and time of each active / standby switchover. Switching modes include active switching and passive switching. The preset duration and preset threshold may be manually preset. For example, the preset duration may be 10 minutes, and the preset threshold may be 3 times. The operating time threshold may also be manually preset. For example, the operating time threshold may be 5 minutes.For example, if the target device is device 1, the current time is 3:30 PM, and the preset duration is 10 minutes, device 1 can determine the number of times the distributed system has proactively performed a master-slave switchover within the preset 10-minute period before 3:30 PM. Assume that the number of proactive master-slave switchovers is 2. Device 1 can also determine the duration of its operation as the master device, assuming that the duration is 6 minutes. If the preset threshold is 3 times and the duration threshold is 5 minutes, then because the number of proactive master-slave switches (2) is less than the preset threshold of 3, and the duration of 6 minutes is greater than the duration threshold of 5 minutes, proactive master-slave switchover can be performed again, i.e., device 1 can be proactively switched to the backup device. If the number of proactive master-slave switchovers is 4 times, then because the number of proactive master-slave switchovers (4) is greater than the preset threshold of 3, proactive master-slave switchover is not performed on device 1. If the duration of operation is 4 minutes, which is less than the duration threshold, proactive master-slave switchover is not performed on device 1. It should be noted that passive switching is not restricted. Specifically, the target device can be switched to a backup device by terminating the target thread; after other devices in the distributed system have switched to the primary device, the target device can be switched to the backup device. Terminating the target thread allows the target device to suspend or renew the distributed lock, allowing other devices in the distributed system to preempt the distributed lock and become the new primary device, allowing the target device to switch to the backup device. For example, if the target device is device 1, if the target thread is thread 1, if device 2 is currently the backup device, and if the device status of device 1 is abnormal, thread 1 can be terminated. After device 2 has switched to the primary device, device 1 can be switched to the backup device.

[0009] S406: If the thread status is "thread abnormal," the target device is switched to a backup device. When the thread status is "thread abnormal," it indicates that the target device cannot renew the distributed lock through the target thread. Therefore, the target device can be switched to a backup device. This switching method is called passive switching. For example, if device 2 is currently a backup device and the thread status of thread state 1 in device 1 is "thread abnormal," device 1 can be switched to a backup device and device 2 can be switched to a primary device. In the disclosed embodiment, the target device can determine the thread status of the target thread in the target device. The target device can obtain operating information of the target device and determine the device status based on the operating information. If the thread status is "thread normal" and the device status is "device normal," the target device is determined to be the primary device. If the thread status is "thread normal" and the device status is "device abnormal," the target device is switched to a backup device. If the thread status is "thread abnormal," the target device is switched to a backup device. Because master / slave switching can be performed not only based on the target thread's thread state but also based on the device state, the accuracy of master / slave switching is improved compared to the prior art, which performs master / slave switching based solely on the target thread's thread state. The following further illustrates the active and passive switching described in Figure 4 , in conjunction with Figure 6 . Figure 6 is a schematic diagram of a master / slave switching method provided by an exemplary embodiment of the present disclosure. Referring to Figure 6 , the technical solution of the present disclosure includes both passive and active master / slave switching. In passive master / slave switching, if the target thread on device 1 experiences a thread exception, device 1 cannot renew the distributed lock through the target thread, and device 2 can poll to preempt the distributed lock. After device 2 successfully preempts the distributed lock, master / slave switching can be performed, switching device 2 to the master device and device 1 to the backup device. During active handover, if the target thread in device 1 is in the thread normal state but the device state of device 1 is in the device abnormal state, device 1 can still renew the distributed lock normally through the target thread because the target thread is normal. However, because the device state is in the device abnormal state, device 1 can proactively forgo renewal, allowing device 2 to successfully preempt the distributed lock, achieving active / standby handover, switching device 2 to the master and device 1 to the standby. The technical solution of this disclosure combines active and passive handover to perform active / standby handover. In some scenarios, this can provide higher availability and improve the accuracy of active / standby handover. The following describes the active / standby handover method further using a specific example, based on any of the above embodiments and in conjunction with Figure 7. Figure 7 is a schematic diagram of the process of an active / standby handover method provided by an exemplary embodiment of this disclosure.Please refer to Figure 7, which includes steps ①, ②, ③, ④, and ⑤. The distributed system may include device 1, device 2, device 3, and device 4. Devices 1, 2, and 3 can switch between active and standby modes. Device 4 stores a distributed lock. Optionally, the distributed lock can be an online file. The target device is device 1, which is currently the active device, and devices 2 and 3 are currently standby devices. Device 1 may include a target thread, a service thread executing a target service, an RPC message waiting queue, and an RPC message processing queue. The target service may include service 1 and an RPC service. In step ①, device 1 may determine the thread state of the target thread. In step ②, device 1 may determine that the two service threads executing the RPC service are thread 1 and thread 2, respectively. O Device 1 can determine the thread status of thread 1 and thread 2. When the thread status of thread 1 and thread 2 are both thread abnormal, the service status of the RPC service is determined to be service abnormal. Device 1 can determine that the service thread executing service 1 is thread 3. O Device 1 can determine the thread status of thread 3. When the thread status of thread 3 is thread exception, the service status of service 1 can be determined to be service exception. In step 3, if the RPC message processing queue includes message 1, device 1 is processing message 1, that is, executing target event 1. Device 1 can determine the processing delay 1 for target event 1. Assume that processing delay 1 is 1 s. o In step 4, if the RPC message queue includes messages 2 and 3, and message 2 is the first message in the queue, device 1 can determine the message accumulation duration of message 2. Assume that the message accumulation duration of message 2 is 6 seconds. In step 5, device 1 can determine the service status of the RPC service, the service status of service 1, the processing delay 1 of target event 1, and the message accumulation duration of message 2 as device 1's operating information. Based on the operating information, device status can be determined. If any of the following conditions are met, device 1's device status can be determined to be abnormal:

[0010] The RPC service's service status is "Service Abnormal"; the service status of service 1 is "Service Abnormal"; the processing latency 1 of target event 1 is greater than the corresponding latency threshold; and the message accumulation duration of message 2 is greater than the accumulation duration threshold. If none of the above conditions are met, the device status of device 1 can be determined to be "Device Normal". After determining the device status, active / standby switching can be performed based on the target thread's thread status and the device status. Specifically, if the thread status is "Thread Normal" and the device status is "Device Normal", device 1 is determined to be the active device. If either the thread status or the device status is abnormal, device 1 is switched to the standby device, and device 2 is switched to the active device. In the disclosed embodiment, the target device can determine the thread status of the target thread in the target device. The target device can obtain the target device's operating information and determine the device status based on the operating information. If the thread status is "Thread Normal" and the device status is "Device Normal", the target device is determined to be the active device. If either the thread status or the device status is abnormal, the target device is switched to the standby device. Because active / standby switching can be performed not only based on the target thread's thread state but also based on the device state, the accuracy of active / standby switching is improved compared to the prior art, which performs active / standby switching based solely on the target thread's thread state. Figure 8 is a schematic structural diagram of an active / standby switching apparatus provided in an embodiment of the present disclosure. Referring to Figure 8 , the active / standby switching apparatus 10 comprises a first determination module 11, a second determination module 12, and a switching module 13. The first determination module 11 is configured to determine the thread state of a target thread in a target device, where the target device is currently the active device and the target thread requests that the target device be set as the active device; the second determination module 12 is configured to determine the device state of the target device, where the device state is either normal or abnormal; and the switching module 13 is configured to perform active / standby switching on the target device based on the thread state and the device state. The active / standby switching apparatus provided in an embodiment of the present disclosure can implement the technical solutions shown in the aforementioned method embodiments. Its implementation principles and beneficial effects are similar and will not be further elaborated here. In one possible implementation, the switching module 13 is specifically configured to: if the thread status is normal, perform a master / slave switch on the target device based on the device status; and if the thread status is abnormal, switch the target device to the backup device. In another possible implementation, the switching module 13 is specifically configured to: if the device status is normal, determine that the target device is the master device; and if the device status is abnormal, switch the target device to the backup device.In one possible embodiment, the switching module 13 is specifically configured to: determine the number of active master-slave switchings performed by the distributed system within a preset time period before the current moment, wherein the distributed system is the distributed system where the target device is located and includes the target device and at least one other device; determine the operating time of the target device as the master device and determine an operating time threshold; and switch the target device to the backup device if the number of switchings is less than or equal to the preset threshold and the operating time is greater than or equal to the operating time threshold. In one possible embodiment, the switching module 13 is specifically configured to: terminate the target thread; and switch the target device to the backup device after other devices in the distributed system switch to the master device. In one possible embodiment, the second determination module 12 is specifically configured to: obtain operating information of the target device, wherein the operating information includes at least one of the following: the service status of the target service, the processing delay of the target event, and the message accumulation time of the target message; and determine the device status based on the operating information. In one possible implementation, the second determination module 12 is specifically configured to determine that the device status is abnormal when at least one of the following conditions is met: M target services have a service abnormality status, where M is a positive integer; N target events have a processing delay greater than or equal to a corresponding delay threshold, where N is a positive integer; and the message accumulation duration is greater than or equal to the accumulation duration threshold. The active / standby switching device provided in the embodiments of the present disclosure can implement the technical solutions described in the above-mentioned method embodiments. The implementation principles and beneficial effects are similar and are not further described here. An exemplary embodiment of the present disclosure provides a schematic diagram of an electronic device. See FIG9 . The electronic device 20 may include a processor 21 and a memory 22. Exemplarily, the processor 21 and the memory 22 are interconnected via a bus 23. The memory 22 stores computer-executable instructions; the processor 21 executes the computer-executable instructions stored in the memory 22, causing the processor 21 to perform the method described in the above-mentioned method embodiments. The electronic device shown in FIG9 may be the target device described in any of the above-mentioned embodiments. Accordingly, embodiments of the present disclosure provide a computer-readable storage medium storing computer-executable instructions. When executed by a processor, the computer-executable instructions are used to implement the methods described in the above method embodiments. Accordingly, embodiments of the present disclosure may also provide a computer program product, including a computer program. When executed by a processor, the computer program is used to implement the methods described in the above method embodiments.Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROMs, optical storage, etc.) containing computer-usable program code. The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, such that execution of the instructions by the processor of the computer or other programmable data processing device generates means for implementing the functions specified in one or more processes in the flowcharts and / or one or more blocks in the block diagrams. These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means that implement the functions specified in one or more flows in a flowchart and / or one or more blocks in a block diagram. These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing the computer or other programmable device to execute a series of operational steps to produce a computer-implemented process, such that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flows in a flowchart and / or one or more blocks in a block diagram. In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory. The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory. OMemory is an example of computer-readable media. Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can implement information storage using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmitting medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves. It should also be noted that the terms "comprise," "include," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, product, or apparatus comprising a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, product, or apparatus. Without further limitation, an element specified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, product, or apparatus comprising the recited element. The foregoing description is merely an example of the present disclosure and is not intended to limit the present disclosure. Various modifications and variations of the present disclosure will be apparent to those skilled in the art. Any modifications, equivalent substitutions, improvements, and the like made within the spirit and principles of the present disclosure are intended to be encompassed by the claims of the present disclosure.

Claims

Claims 1. A primary / backup switching method, comprising: Determine the thread state of the target thread in the target device. The target device is currently the master device, and the target thread is used to request setting the target device as the master device; Determine the device state of the target device. The device state is normal or abnormal; Based on the thread state and the device state, perform master-backup switching on the target device.

2. The method according to claim 1, wherein performing primary / backup switching on the target device according to the thread state and the device state comprises: If the thread state is normal, perform master-backup switching on the target device according to the device state; If the thread state is abnormal, switch the target device to the backup device.

3. The method according to claim 2, wherein performing primary / backup switching on the target device according to the device status comprises: If the device state is normal, determine that the target device is the master device; If the device state is abnormal, switch the target device to the backup device.

4. The method according to claim 2 or 3, wherein switching the target device to a standby device comprises: Determine the number of master-backup switching times actively performed within a preset duration before the current moment in the distributed system. The distributed system is the distributed system where the target device is located, and the distributed system includes the target device and at least one other device; Determine the running duration of the target device as the master device, and determine the running duration threshold; If the number of switching times is less than or equal to the preset threshold and the running duration is greater than or equal to the running duration threshold, switch the target device to the backup device.

5. The method according to claim 4, wherein switching the target device to the standby device comprises: End the target thread; After other devices in the distributed system are switched to the master device, switch the target device to the backup device.

6. The method according to any one of claims 1-5, determining the device state of the target device, includes: Obtain the running information of the target device. The running information includes at least one of the following: the service state of the target service, the processing delay of the target event, the message accumulation duration of the target message; Based on the running information, determine the device state.

7. The method according to claim 6, wherein determining the device state according to the operation information comprises: When at least one of the following conditions is met, determine that the device state is abnormal: There are M target services with abnormal service states, where M is a positive integer; There are N target events with processing delays greater than or equal to the corresponding delay thresholds, where N is a positive integer; The message accumulation duration is greater than or equal to the accumulation duration threshold.

8. A primary / backup switching device, comprising: A first determination module, a second determination module, and a switching module. Among them, the first determination module is used to determine the thread state of the target thread in the target device. The target device is currently the master device, and the target thread is used to request setting the target device as the master device; The second determination module is used to determine the device state of the target device. The device state is normal or abnormal; The switching module is used to perform master-backup switching on the target device based on the thread state and the device state.

9. An electronic device, comprising: At least one processor; And a memory communicatively connected to the at least one processor; Among them, the memory stores instructions executable by the at least one processor. The instructions are executed by the at least one processor to cause the electronic device to execute the method according to any one of claims 1-7.

10. A computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in any one of claims 1-7 is implemented.

11. A computer program product includes a computer program. When the computer program is executed by a processor, the method described in any one of claims 1-7 is implemented.

Citation Information

Patent Citations

  • Distributed lock allocation method and device

    CN109101341A

  • Distributed lock switching method and device, server and storage medium

    CN113239059A

  • Main-standby switching method and device of cloud database and electronic equipment

    CN115827300A