[go: up one dir, main page]

CN117648304A - Database switching method, device, terminal equipment and storage medium - Google Patents

Database switching method, device, terminal equipment and storage medium Download PDF

Info

Publication number
CN117648304A
CN117648304A CN202311551608.9A CN202311551608A CN117648304A CN 117648304 A CN117648304 A CN 117648304A CN 202311551608 A CN202311551608 A CN 202311551608A CN 117648304 A CN117648304 A CN 117648304A
Authority
CN
China
Prior art keywords
service library
application program
database
service
library
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311551608.9A
Other languages
Chinese (zh)
Inventor
赵志瑞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Merchants Bank Co Ltd
Original Assignee
China Merchants Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Merchants Bank Co Ltd filed Critical China Merchants Bank Co Ltd
Priority to CN202311551608.9A priority Critical patent/CN117648304A/en
Publication of CN117648304A publication Critical patent/CN117648304A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/211Schema design and management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a database switching method, a device, terminal equipment and a storage medium, and relates to the field of database data processing, wherein the method comprises the following steps: when a first service library is available, distributing the flow of a first application program to the first service library for read-write processing; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. The recovery time of database failures is reduced.

Description

Database switching method, device, terminal equipment and storage medium
Technical Field
The present disclosure relates to the field of database data processing, and in particular, to a method and apparatus for switching a database, a terminal device, and a storage medium.
Background
The currently mainstream high availability schemes of databases mainly provide high availability services through architectures such as database master-slave mode, cluster mode and the like.
Because these database architectures are very complex, involving multiple components and dependencies, RTOs (Recovery Time Objective, recovery time index) are long. However, some systems require extremely high RTO requirements, such as a 7 x 24 hour service window for a podcast system. If the guest-in-plane system is placed in an unavailable state for a long time, a certain degree of loss is caused for enterprises.
Disclosure of Invention
The main purpose of the application is to provide a database switching method, a device, a terminal device and a storage medium, which aim to reduce recovery time of database faults.
In order to achieve the above object, the present application provides a database switching method, including:
when a first service library is available, distributing the flow of a first application program to the first service library for read-write processing;
and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing.
Optionally, the step of distributing the traffic of the first application program to the first service library for read-write processing includes:
when the traffic of the first application program is distributed to the first service library for writing, acquiring update data of the traffic of the first application program;
based on the timing task, updating data of the traffic of the first application program is synchronized to the second service library.
Optionally, the step of synchronizing the update data of the traffic of the first application program to the second service library includes:
acquiring the dimension of a service table and an identity number of the service table according to the updating data of the traffic of the first application program;
inquiring and obtaining data to be synchronized according to the dimension of the service table;
the data to be synchronized is de-duplicated according to the identity identification number of the service table, and the de-duplicated data to be synchronized is obtained;
and writing the de-duplicated data to be synchronized into the second service library.
Optionally, the update data of the traffic of the first application program includes a first service library log, and the step of synchronizing the update data of the traffic of the first application program to the second service library based on the timing task further includes:
and performing persistent transaction log processing on the updated data of the traffic of the first application program.
Optionally, when the first service library is available, the step of distributing the traffic of the first application program to the first service library for performing read-write processing includes:
distributing traffic of the first application program to the first service library for read-write processing based on cut-plane oriented programming (AOP, aspect Oriented Programming) when the first service library is available;
the step of switching the traffic of the first application program to a second service library for read-only processing when the first service library is not available comprises the following steps:
and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing based on AOP.
Optionally, the method further comprises:
when the second service library is available, the flow of the second application program is distributed to the second service library for reading and writing;
and when the second service library is not available, switching the flow of the second application program to the first service library for read-only processing.
Optionally, the method further comprises:
and when the first service library and the second service library are unavailable, switching the flow of the first application program to a third service library for read-only processing.
The embodiment of the application also provides a database switching device, which comprises:
the database read-write module is used for distributing the flow of the first application program to the first service library for read-write processing when the first service library is available;
and the database read-only module is used for switching the flow of the first application program to a second service library for read-only processing when the first service library is unavailable.
The embodiment of the application also provides a terminal device, which comprises a memory, a processor and a database switching program stored on the memory and capable of running on the processor, wherein the database switching program realizes the steps of the database switching method when being executed by the processor.
The embodiments of the present application also provide a computer-readable storage medium having a database switching program stored thereon, which when executed by a processor, implements the steps of the database switching method as described above.
According to the database switching method, the device, the terminal equipment and the storage medium, when the first service library is available, the traffic of the first application program is distributed to the first service library for reading and writing; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. When the first service library is available, the flow of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the flow of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, most of the functions of the first application program can be supported after the second service library is switched to the second database, the database is not required to be restarted, and the recovery time of database faults is reduced.
Drawings
FIG. 1 is a schematic diagram of functional modules of a terminal device to which a database switching device of the present application belongs;
FIG. 2 is a flowchart of a first exemplary embodiment of a database switching method according to the present application;
FIG. 3 is a schematic diagram of a first database and a second database architecture according to the present application;
FIG. 4 is a schematic diagram of a switching relationship between a first database and a first database according to the present application;
fig. 5 is a schematic diagram of a data synchronization flow between a first database and a second database of the databases of the present application.
The realization, functional characteristics and advantages of the present application will be further described with reference to the embodiments, referring to the attached drawings.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
The main solutions of the embodiments of the present application are: distributing the flow of a first application program to a first service library for reading and writing when the first service library is available; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. When the first service library is available, the flow of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the flow of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, most of the functions of the first application program can be supported after the second service library is switched to the second database, the database is not required to be restarted, and the recovery time of database faults is reduced.
In the embodiment of the application, the high availability scheme of the database in the mainstream at present is considered, and the high availability service is mainly provided through the architectures such as the database master-slave mode, the cluster mode and the like. Because these database architectures are very complex, involving multiple components and dependencies, RTOs (Recovery Time Objective, recovery time index) are long. However, some systems require extremely high RTO requirements, such as a 7 x 24 hour service window for a podcast system. If the guest-in-plane system is placed in an unavailable state for a long time, a certain degree of loss is caused for enterprises.
Based on this, the embodiment of the application proposes a solution, when a first service library is available, the traffic of a first application program is distributed to the first service library for read-write processing, when the first service library is unavailable, the traffic of the first application program is switched to a second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be appreciated that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, and most of the functions of the first application program can be supported after the second service library is switched, without restarting the database, that is, at the cost of changing the database functions from original support read-write to support read-only.
Specifically, referring to fig. 1, fig. 1 is a schematic functional block diagram of a terminal device to which a database switching device of the present application belongs. The database switching device may be a device independent of the terminal device and capable of performing data processing, or may be carried on the terminal device in a form of hardware or software.
In this embodiment, the terminal device to which the database switching apparatus belongs at least includes an output module 110, a processor 120, a memory 130, and a communication module 140.
The memory 130 stores an operating system and a database switching program, and the flow rate of the first application program is stored in the memory 130; the output module 110 may be a display screen, a speaker, etc. The communication module 140 may include a WIFI module, a mobile communication module, a bluetooth module, and the like, and communicates with an external device or a server through the communication module 140.
Wherein the database switching program in the memory 130 when executed by the processor performs the steps of:
when a first service library is available, distributing the flow of a first application program to the first service library for read-write processing; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
when the traffic of the first application program is distributed to the first service library for writing, acquiring update data of the traffic of the first application program; based on the timing task, updating data of the traffic of the first application program is synchronized to the second service library.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
a part identification number; inquiring and obtaining data to be synchronized according to the dimension of the service table; the data to be synchronized is de-duplicated according to the identity identification number of the service table, and the de-duplicated data to be synchronized is obtained; and writing the de-duplicated data to be synchronized into the second service library.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
and performing persistent transaction log processing on the updated data of the traffic of the first application program.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
distributing traffic of the first application program to the first service library for read-write processing based on cut-plane oriented programming (AOP, aspect Oriented Programming) when the first service library is available; the step of switching the traffic of the first application program to a second service library for read-only processing when the first service library is not available comprises the following steps: and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing based on AOP.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
when the second service library is available, the flow of the second application program is distributed to the second service library for reading and writing; and when the second service library is not available, switching the flow of the second application program to the first service library for read-only processing.
Further, the database switching program in the memory 130, when executed by the processor, further performs the steps of:
and when the first service library and the second service library are unavailable, switching the flow of the first application program to a third service library for read-only processing.
According to the scheme, when the first service library is available, the traffic of the first application program is distributed to the first service library for reading and writing; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. When the first service library is available, the flow of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the flow of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, most of the functions of the first application program can be supported after the second service library is switched to the second database, the database is not required to be restarted, and the recovery time of database faults is reduced.
Based on the above terminal device architecture, but not limited to the above architecture, the method embodiments of the present application are presented.
Referring to fig. 2, fig. 2 is a flowchart of a first exemplary embodiment of a database switching method according to the present application.
An embodiment of the present invention provides a database switching method, including:
step S10, when a first service library is available, distributing the flow of a first application program to the first service library for reading and writing;
the currently mainstream high availability schemes of databases mainly provide high availability through architectures such as database master-slave mode, cluster mode and the like.
Because these database architectures are very complex, involving multiple components and dependencies, RTOs (Recovery Time Objective, recovery time index) are long. However, some systems require extremely high RTO requirements, such as a 7 x 24 hour service window for a podcast system. If the guest-in-plane system is placed in an unavailable state for a long time, a certain degree of loss is caused for enterprises.
In particular, in conventional database high availability schemes, fault detection may require some time. The system may experience a delay of some time before a primary database failure is detected.
First, the highly available solutions at the database level, the RTOs corresponding to the different causes of the failure are also different, and the database recovery work is generally responsible for the recovery time that cannot be controlled by the development and operators by the DBA (Database Admini strator ). If the guest-in-plane system is placed in an unavailable state for a long time, a certain degree of loss is caused for enterprises.
Secondly, in the conventional database recovery process, a new database needs to be replaced to support service operation, and the system is required to modify the database configuration to restart the application. If the system does not support automatic switching of data sources, RTO can be further prolonged. Therefore, the related art generally applies dynamic switching of data sources, and there are many applications in the market, specifically, some existing technologies implement dynamic switching of data sources by using database connection and AOP tangential plane programming technology, and dynamically connect to different databases according to different service scenarios. I.e. the database fails, switches to another service scenario, and switches back to the database of the original service scenario after the failure database is successfully repaired. It can be appreciated that active-standby data source dynamic switching is not yet performed on the same service scenario. Therefore, the current database high availability scheme is not able to meet the traffic scenario for rto=0.
Therefore, the embodiment proposes that when the first service library is available, the traffic of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the traffic of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, and most of the functions of the first application program can be supported after the second service library is switched to the second database, so that the database is not required to be restarted, and the recovery time index is reduced.
Specifically, the embodiment provides a highly available single-library architecture based on data backup and dynamic switching of an application layer. The overall structure and workflow is shown in fig. 3.
An app1 (first application) application with high RTO requirements is connected to both the business library 1 (first business library) and the business library 2 (second business library). Wherein the service library 1 (first service library) and the service library 2 (second service library) are independent single-library high-availability architectures. During normal operation of the system, the service library 1 (first service library) takes up read-write traffic of app1 (first application program) application; the service library 2 (second service library) accepts read and write traffic of app2 (second application program) application. App1 (first application) can switch to library 2 (second library) without sense when library 1 (first library) is not available. At any time, the service library 2 (second service library) provides read and write operations to app2 (second application program). When the service library 2 (second service library) is used as a standby library of the service library 1 (first service library), normal service of the app2 (second application program) is not affected.
Furthermore, the embodiment proposes a method corresponding to a service scene with more and less read-write and less service flow, because the database function is changed from original support read-write to support read-only, the influence on the service scene is less, and the superiority of the method, such as scene data of parameters, control classes and the like, can be embodied.
Further, since the second service library is the main database of other application programs, the traffic of the first application program is switched to the second service library for read-only processing only when the first database is unavailable, the databases (second service library) of the existing other programs are fully utilized, and the utilization rate of multiple libraries is improved.
It can be appreciated that the independent single-library high availability architecture of the first service library and the second service library has very low probability of failure, and no special reading library is required to be deployed, so that fewer database resources are occupied to promote high availability of the system, and the database cost is reduced.
Specifically, the first application program and the second application program are two independent application programs, and can support different services respectively, and meanwhile, the first service library and the second service library can be different database types, for example, the first service library is a mysql database and the second service library is an oracle database. It will be appreciated that the overall database switching system is a heterogeneous system.
Specifically, when the first service library is available, the traffic of the first application program is distributed to the first service library for read-write processing, so that the traffic can be distributed to the available first service library uniformly.
Step S20, when the first service library is unavailable, switching the flow of the first application program to a second service library for read-only processing;
when the first service library is not available, the flow of the first application program can be automatically switched to the second service library for read-only processing through a corresponding non-inductive switching technology. Such a handover may be triggered automatically based on the monitoring system detecting that the first service library is not available.
Specifically, the non-inductive switching technology may include AOP tangential plane, java reflection mechanism, custom annotation, threadLocal, and other technologies.
Specifically, the Java reflection mechanism allows for checking information of classes, methods, fields, etc. at runtime and dynamically creating objects, calling methods at runtime. This is useful for dynamically adjusting the behavior of the application at hand-off, and appropriate methods can be invoked depending on the database state.
In particular, custom annotations may be used to mark critical business logic or switch points in the code. By parsing these annotations, the system can perform the corresponding switchover operations as necessary.
It will be appreciated that the use of a combination of these techniques may construct a flexible and highly configurable switching mechanism. When the monitoring system detects that the main service library is not available, the switching logic is triggered, and the flow is switched to the standby library without sense. This helps to improve the usability of the system and reduce the impact of service interruption.
Further, step S11, when the first service library is available, distributes the traffic of the first application program to the first service library for read-write processing based on the section-oriented programming (AOP, aspect Oriented Programming);
and S21, switching the flow of the first application program to a second service library for read-only processing based on AOP when the first service library is not available.
In particular, tangent plane oriented programming (AOP) is a programming paradigm that improves code modularity by separating points of cross-cut interest (e.g., logging, transaction management) from business logic. In this case, the AOP may be used to insert switching logic at the critical point of service library access to enable automatic triggering at the time of switching.
Distributing traffic to a first traffic pool when available using tangent plane oriented programming (AOP) to the pool for read-write processing is a flexible approach. In this case, AOP may be used to insert a facet at an application's critical point to control the routing of traffic.
Specifically, as shown in FIG. 4, an AOP cut is created that contains logic to determine the availability of a first traffic pool and to decide to which pool to route traffic based on the availability of the first traffic pool. And when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. The flexibility of using the AOP switching database enables the database switching system to make intelligent decisions according to actual conditions, and improves the availability and fault tolerance of the system.
The database connection needs to be modified and the application restarted, as opposed to traditional data source switching, for a longer period of time from awareness of system anomalies to system recovery, during which the system is unavailable. In this embodiment, when the high availability database fails, the data source is automatically switched to the redundant service library by using the AOP tangential plane technology, and the program configuration does not need to be modified, so that the system recovery time is 0ms.
In general, for a service scenario with more and less reads and writes and low service traffic, the present embodiment provides a degradation scheme for solving the database single-library architecture failure. The first application program is set to synchronize the data of the first service library to a second service library in use at the application layer based on a single-library high-availability architecture. During a single library architecture failure, the second business library provides read-only downgraded services to the first application. The second service library receives the read-write flow of the second application program in parallel. This is a heterogeneous solution that is more available than the primary and secondary architecture, increasing multi-library usage.
According to the database switching method, when the first service library is available, the traffic of the first application program is distributed to the first service library for reading and writing; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. When the first service library is available, the flow of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the flow of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, most of the functions of the first application program can be supported after the second service library is switched to the second database, the database is not required to be restarted, and the recovery time of database faults is reduced.
Based on the first embodiment, a second embodiment of the present application is presented, which differs from the first embodiment in that:
the step of distributing the traffic of the first application program to the first service library for performing read-write processing in step S10 is refined, where the step may include:
step S12, when the flow of the first application program is distributed to the first service library for writing, acquiring update data of the flow of the first application program;
step S14, based on the timing task, synchronizing the update data of the traffic of the first application program to the second service library.
At the write operation trigger point of the first application program, it is ensured that the update data requiring synchronization is recorded or captured. Logic is added specifically to the business logic of the write operation to capture the data changes to be synchronized.
A timed task may be configured using Quartz to trigger a synchronization operation at certain time intervals. In the execution logic of the timing task, the update data which is recorded before and needs to be synchronized is acquired. Ensuring that the synchronization operation is reliable, possible synchronization conflicts, errors or anomalies that may occur can be handled.
In particular, quartz is an open-source, powerful, enterprise-level Java timed task scheduling framework that provides many advantages in handling timed tasks and scheduling. Quartz allows for simultaneous scheduling of multiple tasks, each of which may have its own independent scheduling rules and configuration. In this way, multiple timing tasks can be managed in the same application without interfering with each other. The Quartz has high reliability and fault tolerance. The method can restore the scheduling state after the restart of the application program, and ensures that the planned task is not lost due to the restart of the system.
Step S141, according to the update data of the flow of the first application program, acquiring the dimension of the service table and the identity identification of the service table;
step S142, inquiring and obtaining data to be synchronized according to the dimension of the service table;
step S143, the duplication of the data to be synchronized is removed according to the identity number of the service table, and the duplicated data to be synchronized is obtained;
and step S144, writing the data to be synchronized after the duplication removal into the second service library.
In order for the second database to provide degraded read-only services for the first application when the first database fails, the first database needs to write the relevant data of the first application and synchronize the relevant data to the second database.
Specifically, as shown in fig. 5, in the writing process, the dimension and (ID) identification number of the service table are acquired from the update data of the traffic of the first application program.
Further, according to the dimension of the service table, query operation is executed, and data to be synchronized are obtained.
Further, according to the duplicate removal of the acquired data to be synchronized, the duplicate removal can be performed according to the identity number of the service table, so that the data of the same identity identification can not be synchronized repeatedly. A data structure (e.g., set) may be used to assist in the deduplication operation.
And then, calling an interface of a second program to write the data to be synchronized after the duplication removal into a second service library. This involves invoking a write operation of the second service library, ensuring that the data is properly synchronized into the target library.
And finally, updating the state of the log record corresponding to the first service library, and successfully synchronizing the mark to the second service library.
And step S13, performing persistent transaction log processing on the updated data of the traffic of the first application program.
Before the traffic update data of the first application program is synchronized to the second service library, persistent transaction logging is performed to ensure reliability and consistency of data synchronization.
Specifically, in write processing logic of the first application, a transaction log is recorded. This may be a log record containing updated data, recording information about the write operation, such as a timestamp, transaction ID, etc.
Ensuring that the logged transaction log can persist to a reliable storage medium, such as a database, file system, or message queue, after a write operation occurs. This may be achieved by using transactional write operations or asynchronous mechanisms.
According to the database switching method, when the flow of the first application program is distributed to the first service library for writing, update data of the flow of the first application program are obtained; based on the timing task, updating data of the traffic of the first application program is synchronized to the second service library, so that the second database can provide degradation read-only service for the first application program when the first database fails.
Based on the first embodiment, a third embodiment of the present application is presented, which differs from the first embodiment in that:
step S30, when the second service library is available, the flow of the second application program is distributed to the second service library for read-write processing;
at any time, the second service library provides read and write operations to the second application. When the second service library is used as a standby library of the first service library, the normal service of the second application program is not affected.
The first and second databases may be of different database types, such as a mysql database for the first and oracle database for the second. The whole system is a heterogeneous system.
And step S40, when the second service library is not available, switching the flow of the second application program to the first service library for read-only processing.
Similarly, the first service library may also be used as a backup library for the second application program, where the first service library may provide a read-only function for the second application program when the second service library is not available. It will be appreciated that the first service library may also provide the second application with a downgrade to address database single library architecture failures.
It can be appreciated that the method of mutually degrading the backup library not only reduces RTO to 0, but also increases the utilization rate of the system and reduces the cost of the database. Compared with the traditional re-reading and writing separation method, the method provided by the embodiment belongs to light-reading and writing separation, and compared with the traditional re-reading and writing separation which requires at least two databases to serve one application program (reading and processing one database and writing and processing one database), the embodiment only requires one database to serve one application program on average, thereby increasing the utilization rate of the system and reducing the cost of the databases.
Further, in step S50, when neither the first service library nor the second service library is available, the traffic of the first application program is switched to a third service library for read-only processing.
Even though the probability that the first service library and the second service library are unavailable is very low at the same time, because of the method for solving the database single-library architecture fault with low cost processing in the embodiment, a third service library can be added, when the first service library and the second service library are unavailable, the flow of the first application program is switched to the third service library to carry out read-only processing, and a method for reducing the flow of the first application program is provided.
According to the database switching method, when the second service library is available, the flow of the second application program is distributed to the second service library for reading and writing; when the second service library is unavailable, the flow of the second application program is switched to the first service library for read-only processing, so that the utilization rate of the system is increased, and the cost of the database is reduced.
In addition, the embodiment of the application also provides a database switching device, which comprises:
the database read-write module is used for distributing the flow of the first application program to the first service library for read-write processing when the first service library is available;
and the database read-only module is used for switching the flow of the first application program to a second service library for read-only processing when the first service library is unavailable.
The principle and implementation process of database switching are implemented in this embodiment, please refer to the above embodiments, and are not described herein again.
In addition, the embodiment of the application also provides a terminal device, which comprises a memory, a processor and a database switching program stored on the memory and capable of running on the processor, wherein the database switching program realizes the steps of the database switching method when being executed by the processor.
Because the database switching program is executed by the processor, all the technical schemes of all the embodiments are adopted, and therefore, the database switching program has at least all the beneficial effects brought by all the technical schemes of all the embodiments, and is not described in detail herein.
In addition, the embodiment of the application also provides a computer readable storage medium, wherein the computer readable storage medium stores a database switching program, and the database switching program realizes the steps of the database switching method when being executed by a processor.
Because the database switching program is executed by the processor, all the technical schemes of all the embodiments are adopted, and therefore, the database switching program has at least all the beneficial effects brought by all the technical schemes of all the embodiments, and is not described in detail herein.
Compared with the prior art, the database switching method, the device, the terminal equipment and the storage medium provided by the embodiment of the application distribute the flow of the first application program to the first service library for read-write processing when the first service library is available; and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing. When the first service library is available, the flow of the first application program is distributed to the first service library for read-write processing, and when the first service library is unavailable, the flow of the first application program is switched to the second service library for read-only processing without sense, wherein the first service library and the second service library are independent single-library high-availability architectures, and the second service library always supports read-write operation of other programs. It can be understood that the above method is a degradation scheme for the situation that the first service library is unavailable, when the first service library is unavailable, the second service library can be switched and called to support the first application program without sense, most of the functions of the first application program can be supported after the second service library is switched to the second database, the database is not required to be restarted, and the recovery time of database faults is reduced.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for describing, and do not represent advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as above, including several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, a controlled terminal, or a network device, etc.) to perform the method of each embodiment of the present application.
The foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the claims, and all equivalent structures or equivalent processes using the descriptions and drawings of the present application, or direct or indirect application in other related technical fields are included in the scope of the claims of the present application.

Claims (10)

1. A database switching method, characterized in that the database switching method comprises:
when a first service library is available, distributing the flow of a first application program to the first service library for read-write processing;
and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing.
2. The method for switching a database according to claim 1, wherein the step of distributing the traffic of the first application program to the first service library for read-write processing comprises:
when the traffic of the first application program is distributed to the first service library for writing, acquiring update data of the traffic of the first application program;
based on the timing task, updating data of the traffic of the first application program is synchronized to the second service library.
3. The database switching method according to claim 2, wherein the step of synchronizing update data of traffic of the first application program to the second service library comprises:
acquiring the dimension of a service table and an identity number of the service table according to the updating data of the traffic of the first application program;
inquiring and obtaining data to be synchronized according to the dimension of the service table;
the data to be synchronized is de-duplicated according to the identity identification number of the service table, and the de-duplicated data to be synchronized is obtained;
and writing the de-duplicated data to be synchronized into the second service library.
4. The database switching method according to claim 2, wherein the update data of the traffic of the first application program includes a first traffic library log, and the step of synchronizing the update data of the traffic of the first application program to the second traffic library based on the timing task further includes, before:
and performing persistent transaction log processing on the updated data of the traffic of the first application program.
5. The method for switching a database according to claim 1, wherein the step of distributing the traffic of the first application program to the first service library for read-write processing when the first service library is available comprises:
when the first service library is available, distributing the traffic of the first application program to the first service library for read-write processing based on the section-oriented programming AOP;
the step of switching the traffic of the first application program to a second service library for read-only processing when the first service library is not available comprises the following steps:
and when the first service library is not available, switching the flow of the first application program to a second service library for read-only processing based on AOP.
6. The database switching method according to claim 1, wherein the method further comprises:
when the second service library is available, the flow of the second application program is distributed to the second service library for reading and writing;
and when the second service library is not available, switching the flow of the second application program to the first service library for read-only processing.
7. The database switching method according to claim 1, wherein the method further comprises:
and when the first service library and the second service library are unavailable, switching the flow of the first application program to a third service library for read-only processing.
8. A database switching apparatus, characterized in that the database switching apparatus comprises:
the database read-write module is used for distributing the flow of the first application program to the first service library for read-write processing when the first service library is available;
and the database read-only module is used for switching the flow of the first application program to a second service library for read-only processing when the first service library is unavailable.
9. A terminal device, characterized in that it comprises a memory, a processor and a database switching program stored on the memory and executable on the processor, which database switching program, when executed by the processor, implements the steps of the database switching method according to any of claims 1-7.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a database switching program, which when executed by a processor, implements the steps of the database switching method according to any of claims 1-7.
CN202311551608.9A 2023-11-20 2023-11-20 Database switching method, device, terminal equipment and storage medium Pending CN117648304A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311551608.9A CN117648304A (en) 2023-11-20 2023-11-20 Database switching method, device, terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311551608.9A CN117648304A (en) 2023-11-20 2023-11-20 Database switching method, device, terminal equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117648304A true CN117648304A (en) 2024-03-05

Family

ID=90048739

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311551608.9A Pending CN117648304A (en) 2023-11-20 2023-11-20 Database switching method, device, terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117648304A (en)

Similar Documents

Publication Publication Date Title
US6823474B2 (en) Method and system for providing cluster replicated checkpoint services
CA2339783C (en) Fault tolerant computer system
US20150213100A1 (en) Data synchronization method and system
CN110019514B (en) Data synchronization method and device and electronic equipment
JP2008059583A (en) Cluster system, method for backing up replica in cluster system, and program product
US11550677B2 (en) Client-less database system recovery
CN106557543A (en) Node switching method and system
CN115391337A (en) Database partitioning method and device, storage medium and electronic equipment
WO2017014814A1 (en) Replicating memory volumes
CN115878269A (en) Cluster migration method, related device and storage medium
CN110377664B (en) Data synchronization method, device, server and storage medium
CN109062731B (en) Idempotent control method and device during database switching
CN108804129B (en) Software upgrading method and device
CN111818188B (en) Load balancing availability improving method and device for Kubernetes cluster
US12204927B2 (en) Software updating apparatus, software updating method, and program
US10728326B2 (en) Method and system for high availability topology for master-slave data systems with low write traffic
WO2021082925A1 (en) Transaction processing method and apparatus
CN107291575B (en) Processing method and equipment for data center fault
CN117648304A (en) Database switching method, device, terminal equipment and storage medium
CN116860515A (en) Virtual machine backup method, computing device and computer storage medium
US20240028611A1 (en) Granular Replica Healing for Distributed Databases
CN114385592A (en) Fault transfer method, device, equipment and storage medium
CN111142921A (en) Software upgrading method and device
US11182261B1 (en) Synchronizing a stale component of a distributed object using multiple delta components during maintenance
US11947827B2 (en) Synchronizing a stale component of a distributed object using a delta component during maintenance

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination