Database switching method and device, equipment, storage medium and program product

By implementing a database switching method in a container cluster in the financial technology field, detecting the health status of the primary database and switching to the slave database, the problem that the standby database only supports read operations after database switching is solved, and the rapid recovery and stability of financial services are achieved.

CN119806917APending Publication Date: 2025-04-11INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411890844.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In the field of financial technology, in the prior art, the backup database after database switching only supports read operations, which affects the continuity and stability of financial services.

Method used

By implementing a database switching method in a container cluster, the health status of the primary database is detected and switched to the slave database in case of abnormalities, thereby ensuring the continuity and stability of financial services.

Benefits of technology

This method quickly restores financial services when the main database fails, reduces interruption time, and improves the continuity and stability of financial services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806917A_ABST
    Figure CN119806917A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a database switching method, device and equipment, a computer readable storage medium and a computer program product. The method can be applied to the field of financial science and technology. The method comprises the steps that when a detection period arrives, the container determines whether a database switching behavior occurs in a set time before the current time of the main database or not; if yes, switching the container from the master database to a slave database; if not, the container detects the health state of the master database, and when the health state of the master database is abnormal, the container is switched from the master database to a slave database; wherein the slave database is a fragmented database in a running state. According to the method, when the health state of the master database is abnormal, rapid switching between the master database and the slave database is achieved, the service interruption time caused by faults of the master database is shortened, and therefore the continuity and stability of services are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of financial technology, and in particular to a database switching method, apparatus, device, computer-readable storage medium, and computer program product. Background Art

[0002] In the field of financial technology, high data availability is the key to the continuous operation of enterprises and customer trust. Therefore, in the daily operation and maintenance of databases in financial institutions, if the main database is unavailable, such as server downtime, abnormal closure of database processes, etc., the main database will be unavailable, and the main database needs to be switched.

[0003] Currently, the main emergency method is to manually select a standby database for switching. However, in this database switching method, the standby database only supports read operations, which reduces the continuity and stability of financial services. Summary of the invention

[0004] Embodiments of the present application provide a database switching method, apparatus, device, computer-readable storage medium, and computer program product for improving the continuity and stability of financial services when a problem occurs in a primary database.

[0005] In a first aspect, an embodiment of the present application provides a database switching method, which is applied to each container in a container cluster, where the container cluster is connected to a primary database, and the method includes:

[0006] When the detection period arrives, the container determines whether the primary database has undergone database switching behavior within a set time before the current time;

[0007] If yes, the container is switched from the master database to the slave database;

[0008] If not, the container detects the health status of the master database, and when the health status of the master database is abnormal, the container switches from the master database to the slave database;

[0009] The slave database is a shard database in operation.

[0010] In a second aspect, an embodiment of the present application provides a database switching device, which is integrated in each container in a container cluster, and the container cluster is connected to a main database, and the device includes:

[0011] A processing module, used for determining, when a detection cycle is reached, whether a database switching behavior has occurred in the primary database within a set time before the current moment;

[0012] A switching module, configured to switch the container from the primary database to the secondary database when a database switching behavior occurs in the primary database within a set time before the current moment;

[0013] The processing module is further configured to detect the health status of the primary database when no database switching behavior has occurred in the primary database within a set time before the current moment;

[0014] The switching module is further configured to switch the container from the master database to the slave database when the health status of the master database is abnormal;

[0015] The slave database is a shard database in operation.

[0016] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the database switching method provided in the first aspect of the embodiment of the present application are implemented.

[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the database switching method provided in the first aspect of the embodiment of the present application are implemented.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product on which a computer program is stored. When the computer program is executed by a processor, the steps of the database switching method provided in the first aspect of the embodiment of the present application are implemented.

[0019] The technical solution provided by the embodiment of the present application determines whether a database switching behavior has occurred in the main database within a set time before the current moment when the detection cycle arrives; if a database switching behavior has occurred, the container directly executes the master-slave database switching; if no data switching behavior has occurred, the container detects the health status of the main database, and executes the master-slave data switching when it is detected that the health status of the main database is abnormal; that is, when the container detects that the main database is abnormal, the container executes the master-slave database switching, then when the remaining containers in the container cluster learn that the database switching behavior has occurred in the main database, there is no need to detect the health status of the main database again, and the master-slave database switching is directly executed, so that the financial business can be quickly restored, reducing the financial business interruption time caused by the failure of the main database, thereby improving the continuity and stability of the financial business. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A schematic diagram of an application environment of the database switching method provided in an embodiment of the present application;

[0021] Figure 2 A schematic diagram of a flow chart of a database switching method provided in an embodiment of the present application;

[0022] Figure 3 Another flowchart of the database switching method provided in the embodiment of the present application;

[0023] Figure 4 A schematic diagram of a database switching method provided in an embodiment of the present application;

[0024] Figure 5 A schematic diagram of the structure of a database switching device provided in an embodiment of the present application;

[0025] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the embodiments of the present application are further described in detail through the following embodiments and in combination with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. Those skilled in the art can make adjustments to them as needed to suit specific application scenarios. It should also be noted that, for ease of description, only the parts related to the present application are shown in the accompanying drawings, rather than all structures.

[0027] Figure 1 A schematic diagram of an application environment of the database switching method provided in the embodiment of the present application. Figure 1 As shown, the application environment includes a container cluster 101, a master database 102 and a slave database 103. Among them, the above-mentioned container cluster 101 may include multiple containers, each of which is connected to the master database 101, that is, the master database 101 serves each container in the container cluster 101. The above-mentioned slave database 103 can be a shard database of the master database 102, which can support data reading operations and data writing operations at the same time. The master database 102 and the slave database 103 synchronize their respective data in a quasi-synchronous manner, thereby ensuring the consistency of data between the two databases. In some cases, the slave database 103 can also be the master database of other container clusters. In this case, the master database 102 can also serve as the slave database of the other container cluster, that is, the identities of the above-mentioned master database 102 and the slave database 103 can be interchangeable, and they are master and slave to each other.

[0028] It should be noted that the database switching method provided in the embodiment of the present application can be executed by a database switching device, which can be implemented by software and / or hardware and can be integrated into each container in the above-mentioned container cluster, that is, each container can perform database switching according to the process described in the following method. The following embodiment only takes any one container in the container cluster as an example.

[0029] Figure 2 A schematic diagram of a flow chart of a database switching method provided in an embodiment of the present application. Figure 2 As shown, the method may include:

[0030] S201. When a detection period arrives, the container determines whether a database switching behavior has occurred in the primary database within a set time before the current time.

[0031] In some examples, each container will periodically detect the health status of the master database. Since the container may be restarted, the startup time of each container may be different. In this way, the time point at which each container reaches the detection cycle for the health status of the master database may also be different. In other examples, the transaction or financial business elements carried by each container may be different. Based on the priority or importance of the financial business elements, the detection cycle of the health status of the master database of each container may also be different. For example, the detection cycle of the container carrying high-priority business may be shorter, and the detection cycle of the container carrying low-priority business may be longer. In this way, for the container that arrives at the detection cycle first, if this type of container detects that the health status of the master database is abnormal, then this type of container will switch the master-slave database and inform the other containers in the container cluster in a corresponding manner that the master database has undergone a database switching behavior; for the container that arrives after the detection cycle, the master-slave database switching behavior of the container that arrives first during the detection cycle can be combined to guide its own behavior. For example, the container that arrives at the detection cycle first switches the master-slave database, indicating that the health status of the master database is abnormal, and the container that arrives after the detection cycle can directly perform the master-slave database switch based on this situation. In this way, when an exception occurs in the main database, each container can quickly switch from the main database to the slave database, improving the efficiency of database switching, thereby improving the continuity and stability of financial services.

[0032] That is to say, for each container in the container cluster, when the detection cycle of the container is reached, the container can first determine whether the main database has undergone a database switching behavior within the set time before the current moment, and determine its own behavior accordingly. If it is determined that the main database has undergone a database switching behavior within the set time before the current moment, execute the following S202; if it is determined that the main database has not undergone a database switching behavior within the set time before the current moment, execute the following S203. Among them, the value of the above-mentioned set time can be set based on actual financial business needs. For example, the length of the set time is set based on financial business tolerance, recovery time objectives, data consistency and other requirements. The embodiment of the present application does not limit the specific value of the set time.

[0033] S202: The container switches from the master database to the slave database.

[0034] Among them, the slave database is a sharded database in operation, which supports both data reading and writing operations. The master database and the slave database synchronize data in a quasi-synchronous manner, ensuring the consistency of data between the two databases. This ensures that after the container switches to the slave database, services and / or transactions can be processed in the slave database, thereby improving the continuity and stability of financial services.

[0035] S203: The container detects the health status of the primary database, and when the health status of the primary database is abnormal, the container switches from the primary database to the secondary database.

[0036] In some examples, the container can detect the health status of the primary database by means of heartbeat detection, that is, the container can send a heartbeat packet to the primary database. If the container receives a response message from the primary database to the heartbeat packet within a preset time, it is determined that the primary database is active; if the container does not receive a response message from the primary database within the preset time, the heartbeat packet is sent again and waits for a response from the primary database. If no response from the primary database is received after multiple consecutive retries, it is determined that the health status of the primary database is abnormal.

[0037] In other examples, the container can also analyze the operation log of the main database to find potential problems from the operation log. If errors or exceptions are recorded in the operation log of the main database, it indicates that the health status of the main database is not good.

[0038] When an abnormal health status of the primary database is detected, the container can switch from the primary database to the secondary database, thereby ensuring the continuity and stability of financial services.

[0039] Optionally, when the health status of the master database is detected to be abnormal, a reminder message can be sent to the terminal held by the maintenance personnel in a preset manner so that the maintenance personnel can take corresponding processing measures in time to improve the fault response speed. Here, the sending method of the reminder message includes but is not limited to SMS, email, and phone calls.

[0040] The database switching method provided in the embodiment of the present application determines whether a database switching behavior has occurred in the main database within a set time before the current moment when the detection cycle arrives; if the database switching behavior has occurred, the container directly executes the master-slave database switching; if the data switching behavior has not occurred, the container detects the health status of the main database, and executes the master-slave data switching when it is detected that the health status of the main database is abnormal; that is, when the container detects that the main database is abnormal, the container executes the master-slave database switching, then when the remaining containers in the container cluster learn that the database switching behavior has occurred in the main database, there is no need to detect the health status of the main database again, and the master-slave database switching is directly executed, so that the financial business can be quickly restored, and the financial business interruption time caused by the failure of the main database is reduced, thereby improving the continuity and stability of the financial business.

[0041] Based on the above embodiment, optionally, after the container is switched from the master database to the slave database, the container may also generate switching log information and store the switching log information in the slave database for subsequent auditing and troubleshooting.

[0042] Based on the above embodiment, optionally, the above container determining whether a database switching behavior has occurred in the main database within a set time before the current moment may include: the container obtains operation log information of the slave database within the set time before the current moment; if the operation log information includes the switching log information of the main database, the container determines that a database switching behavior has occurred in the main database within the set time before the current moment; if the operation log information does not include the switching log information of the main database, the container determines that no database switching behavior has occurred in the main database within the set time before the current moment.

[0043] Specifically, the container can obtain the operation log information of the slave database within a set time before the current moment by calling the application program interface, and search for keywords related to the master-slave database switch (i.e., the switch log information) in the operation log information. If the operation log information contains information related to the master-slave database switch, it can be determined that the master database has undergone a database switch behavior within the set time before the current moment; if the operation log information does not contain information related to the master-slave database switch, it is determined that the master database has not undergone a database switch behavior within the set time before the current moment.

[0044] After executing the master-slave database switch, the container records the switch log information in the slave database, so that the remaining containers in the container cluster can quickly learn the current health status of the master database by analyzing whether the slave database contains the master-slave database switch log information, so that when the health status of the master database is abnormal, it can quickly switch to the slave database, thereby improving the continuity and stability of financial services.

[0045] In some embodiments, optionally, Figure 3 As shown, after the container is switched from the master database to the slave database, the method further includes:

[0046] S301: The container detects the health status of the main database according to a first preset period.

[0047] Among them, the above-mentioned first preset period can be set in combination with actual financial business needs. For example, the first preset period can be a few minutes, a few hours or other suitable time intervals. In some examples, the container can detect the health status of the main database by heartbeat detection, that is, the container can send a heartbeat packet to the main database. If the container receives the response information of the main database to the heartbeat packet within the preset time, it is determined that the main database is active; if the container does not receive the response information of the main database within the preset time, the heartbeat packet is sent again, waiting for the response of the main database. If the response of the main database is still not received after multiple consecutive retries, it is determined that the health status of the main database is abnormal.

[0048] S302: After detecting that the health status of the primary database is normal, in response to the received transaction information of the transaction to be processed, the container determines the transaction type of the transaction to be processed according to the transaction information.

[0049] After receiving the transaction information of the pending transaction, the container analyzes the transaction information to determine the transaction type of the pending transaction. In this embodiment, the transaction type can be a dependent transaction or an independent transaction. A dependent transaction refers to a transaction that needs to rely on the results of other transactions to be completed, and an independent transaction refers to a transaction that can be completed without relying on the results of other transactions. For example, a revocation transfer transaction needs to rely on the previous transfer transaction to be executed. Here, the transfer transaction can be considered as a previous transaction, and the revocation transfer transaction is considered as a subsequent transaction.

[0050] S303: When the transaction type is a dependent transaction, if the previous transaction on which the pending transaction depends is not stored in the slave database, the container switches the pending transaction to the master database for processing.

[0051] In actual applications, although data is synchronized between the master and slave databases, in some cases, due to the delay in data synchronization, the data in the slave database may not be completely consistent with the master database. Figure 4 As shown, when the transaction type of the pending transaction is a dependent transaction, in order to improve the processing success rate of the pending transaction, the container needs to ensure that the conditions that the pending transaction depends on can be met. Therefore, the container needs to detect whether all the dependent data required for the pending transaction is stored in the slave database. If the necessary previous transaction results are missing, this indicates that the current state of the slave database cannot support the completion of the pending transaction. Therefore, the container can switch the pending transaction back to the main database and execute the pending transaction in the main database. In some cases, before switching the pending transaction back to the main database, the container can also confirm again whether the main database has undergone a database switching behavior within the set time before the current moment. If a database switching behavior has occurred, it indicates that the data that the pending transaction depends on is likely to be stored in the main database, and the pending transaction can be switched back to the main database, thereby improving the processing success rate of the pending transaction.

[0052] If the slave database can satisfy all dependent data of the pending transaction, the pending transaction can be processed directly in the slave database, avoiding frequent switching of databases and improving the processing speed of the pending transaction.

[0053] In this embodiment, after detecting that the health status of the primary database is normal, for dependent pending transactions, the pending transactions of the previous transactions in the primary database can be switched back to the primary database for processing, ensuring data consistency and thus improving the processing success rate of pending transactions.

[0054] In some embodiments, optionally, the method further includes: after detecting that the health status of the primary database is normal, the container detects the health status of the primary database according to a second preset period; if the health status of the primary database is normal within a consecutive preset number of second preset periods, the container switches from the slave database to the primary database.

[0055] The second preset period is shorter than the first preset period. After detecting that the health status of the primary database is normal, the container can perform more frequent health checks on the primary database according to the second preset period. This detection period is shorter, and the purpose is to verify the stability of the primary database more intensively. If the health status of the primary database remains normal within a continuous preset number of second preset periods (for example, 4 periods), it indicates that the status of the primary database is normal and stable. In this way, the container can be switched from connecting to the slave database back to connecting to the primary database, reducing the risk of business interruption due to overload of the slave database.

[0056] In this embodiment, by performing continuous health checks on the master database to ensure that the master database has been fully recovered and is running stably, the container is switched from the slave database back to the master database, thereby reducing the risk of data loss or damage caused by premature switching when the master database has not been fully recovered. In addition, after the master database is running stably, the container is switched back to the master database in time, which also reduces the load pressure of the slave database and improves the performance and response speed of the slave database.

[0057] In some embodiments, optionally, after the container is switched from the master database to the slave database, the container may also perform a health check on the master database during a preset time period, and when it is detected that the master database is in a normal health state, the container is switched from connecting to the slave database back to connecting to the master database. The preset time period may be a low-peak business period, and switching the container back to the master database during the low-peak business period can reduce the impact of database switching on financial services and improve the success rate of database switching.

[0058] In some embodiments, optionally, before the above S201, the method further includes: the container obtains the operating performance data of at least one shard database associated with the main database; the container determines the performance indicator of at least one shard database based on the operating performance data; the container determines the slave database from the at least one shard database based on the performance indicator of the at least one shard database.

[0059] Specifically, the above-mentioned operational performance data may include, but are not limited to, transaction response time, throughput, transaction processing rate, load level (such as the number of requests currently being processed or the length of the queue), and resource usage (such as the utilization rate of the processor, memory, and input / output). The obtained operational performance data is analyzed and processed to evaluate the performance indicators of each shard database, which can determine the health status and processing capacity of the shard database. For example, a higher transaction response time and transaction failure rate may indicate that the shard database is overloaded.

[0060] Based on the evaluated performance indicators, the container compares these performance indicators with the preset indicator requirements and determines the shard database that meets the preset indicator requirements as the slave database. If there are multiple shard databases that meet the preset indicator requirements, the shard database with the best performance indicator can be selected as the slave database. For example, the shard database with the largest performance redundancy can be determined as the slave database. When the master database is unavailable, the container on the master database is switched to the slave database, and the slave database takes on the corresponding read and write operations.

[0061] In this way, the selected slave database has the ability to take over the containers on the master database. In this way, when the health status of the master database is abnormal, the slave database can effectively take over the containers, thereby ensuring the continuity and stability of financial services.

[0062] Figure 5 A schematic diagram of a database switching device provided in an embodiment of the present application. The device is integrated into each container in a container cluster, and the container cluster is connected to a main database. The device may include: a processing module 501 and a switching module 502.

[0063] Specifically, the processing module 501 is used to determine whether the primary database has undergone a database switching behavior within a set time before the current moment when the detection cycle arrives;

[0064] The switching module 502 is used to switch the container from the primary database to the secondary database when a database switching behavior occurs in the primary database within a set time before the current moment;

[0065] The processing module 501 is also used to detect the health status of the primary database when no database switching behavior has occurred in the primary database within a set time before the current moment;

[0066] The switching module 502 is also used to switch the container from the master database to the slave database when the health status of the master database is abnormal;

[0067] The slave database is a shard database in operation.

[0068] Based on the above embodiment, optionally, the processing module 501 is further configured to generate switching log information after the container is switched from the master database to the slave database, and store the switching log information in the slave database.

[0069] Based on the above embodiment, optionally, the processing module 501 is also used to obtain operation log information of the slave database within a set time before the current moment; if the operation log information contains the switching log information of the master database, it is determined that the master database has undergone a database switching behavior within the set time before the current moment; if the operation log information does not contain the switching log information of the master database, it is determined that the master database has not undergone a database switching behavior within the set time before the current moment.

[0070] Based on the above embodiment, optionally, the processing module 501 is further configured to detect the health status of the master database according to a first preset period after the container is switched from the master database to the slave database; after detecting that the health status of the master database is normal, in response to the received transaction information of the pending transaction, determine the transaction type of the pending transaction according to the transaction information;

[0071] The switching module 502 is further configured to switch the pending transaction to the primary database for processing if the transaction type is a dependent transaction and if the previous transaction on which the pending transaction depends is not stored in the secondary database.

[0072] Based on the above embodiment, optionally, the processing module 501 is further configured to detect the health status of the primary database according to a second preset period after detecting that the health status of the primary database is normal; wherein the second preset period is smaller than the first preset period;

[0073] The switching module 502 is further configured to switch the container from the slave database to the master database if the health status of the master database is normal within a continuous preset number of second preset periods.

[0074] Based on the above embodiment, optionally, the processing module 501 is also used to obtain the operating performance data of at least one shard database associated with the main database before the container determines whether a database switching behavior has occurred in the main database within a set time before the current moment when the detection cycle arrives; determine the performance index of the at least one shard database based on the operating performance data; and determine the slave database from the at least one shard database based on the performance index of the at least one shard database.

[0075] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 6 As shown, the device includes a processor 60, a memory 61, an input device 62 and an output device 63; the number of the processor 60 in the device can be one or more. Figure 6 A processor 60 is taken as an example; the processor 60, memory 61, input device 62 and output device 63 in the device can be connected by a bus or other means. Figure 6 The example of connecting through bus is taken in the following.

[0076] The memory 61 is a computer-readable storage medium that can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the database switching method in the embodiments of the present application (for example, the processing module 501 and the switching module 502 used in the database switching device). The processor 60 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 61, that is, implements the database switching method provided in any of the above embodiments.

[0077] The memory 61 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created during a database switching process, etc. In addition, the memory 61 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 61 may further include a memory remotely arranged relative to the processor 60, and these remote memories may be connected to the device / terminal / server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0078] The input device 62 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device. The output device 63 may include a display device such as a display screen.

[0079] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0080] When the detection period arrives, the container determines whether the primary database has undergone database switching behavior within a set time before the current time;

[0081] If yes, the container is switched from the master database to the slave database;

[0082] If not, the container detects the health status of the master database, and when the health status of the master database is abnormal, the container switches from the master database to the slave database;

[0083] The slave database is a shard database in operation.

[0084] In one embodiment, a computer program product is further provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0085] When the detection period arrives, the container determines whether the primary database has undergone database switching behavior within a set time before the current time;

[0086] If yes, the container is switched from the master database to the slave database;

[0087] If not, the container detects the health status of the master database, and when the health status of the master database is abnormal, the container switches from the master database to the slave database;

[0088] The slave database is a shard database in operation.

[0089] The database switching device, electronic device, computer-readable storage medium, and computer program product provided in the above embodiments can execute the database switching method provided in any embodiment of the present application, and have the corresponding functional modules and beneficial effects of executing the method. For technical details not described in detail in the above embodiments, please refer to the database switching method provided in any embodiment of the present application.

[0090] Through the above description of the implementation method, the technicians in the relevant field can clearly understand that the present application can be implemented with the help of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.

[0091] It is worth noting that the various units and modules included in the above embodiments are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application.

[0092] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.

Claims

1. A database switching method, characterized in that: Applied to each container in a container cluster, the container cluster being connected to a master database, the method comprising: When the detection period arrives, the container determines whether the primary database has undergone database switching behavior within a set time before the current time; If yes, the container is switched from the master database to the slave database; If not, the container detects the health status of the master database, and when the health status of the master database is abnormal, the container switches from the master database to the slave database; The slave database is a shard database in operation.

2. The method according to claim 1, characterized in that: After the container is switched from the master database to the slave database, the method further includes: Generate switching log information, and store the switching log information in the slave database.

3. The method according to claim 1, characterized in that The container determines whether a database switching behavior has occurred in the primary database within a set time before the current time, including: The container obtains the operation log information of the slave database within a set time before the current time; If the operation log information includes the switch log information of the primary database, the container determines that a database switch behavior has occurred in the primary database within a set time before the current time; If the operation log information does not include the switch log information of the primary database, the container determines that no database switch behavior has occurred in the primary database within a set time before the current moment.

4. The method according to claim 1, characterized in that After the container is switched from the master database to the slave database, the method further includes: The container detects the health status of the main database according to a first preset period; After detecting that the health status of the primary database is normal, in response to the received transaction information of the pending transaction, the container determines the transaction type of the pending transaction according to the transaction information; When the transaction type is a dependent transaction, if the previous transaction on which the pending transaction depends is not stored in the slave database, the container switches the pending transaction to the master database for processing.

5. The method according to claim 4, characterized in that Also includes: After detecting that the health status of the primary database is normal, the container detects the health status of the primary database according to a second preset period; wherein the second preset period is shorter than the first preset period; If the health status of the primary database is normal within a continuous preset number of second preset periods, the container is switched from the secondary database to the primary database.

6. The method according to claim 1, characterized in that When the detection cycle arrives, before the container determines whether the primary database has undergone a database switching behavior within a set time before the current moment, the method further includes: The container obtains the operating performance data of at least one shard database associated with the main database; The container determines a performance indicator of the at least one shard database based on the operating performance data; The container determines the slave database from the at least one shard database based on a performance indicator of the at least one shard database.

7. A database switching device, characterized in that: Each container integrated in a container cluster, the container cluster is connected to a main database, and the device includes: A processing module, used for determining, when a detection cycle is reached, whether a database switching behavior has occurred in the primary database within a set time before the current moment; A switching module, configured to switch the container from the primary database to the secondary database when a database switching behavior occurs in the primary database within a set time before the current moment; The processing module is further configured to detect the health status of the primary database when no database switching behavior has occurred in the primary database within a set time before the current moment; The switching module is further configured to switch the container from the master database to the slave database when the health status of the master database is abnormal; The slave database is a shard database in operation.

8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.