Database switching method and device

By dividing the database switching process into a first synchronization process and a second synchronization process, and setting a first reference point between the processes, the data synchronization is divided into two parts, which solves the problem of long waiting time and efficiency in the existing database switching method. It reduces problems and achieves efficient and non-disruptive database switching.

CN119336845APending Publication Date: 2025-01-21SHANGHAI GAMI TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411418143.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

Existing database switching methods have problems such as long downtime, long user waiting time, and increased labor costs, especially under the multi-service instance deployment strategy.

Method used

By setting a first reference point between the first synchronization process and the second synchronization process, the data synchronization is divided into two parts. The first synchronization process synchronizes the data before the first reference point in the first database, and the second synchronization process synchronizes the data before the first reference point in the first database. Data after a reference point. At the same time, the access request is cached and not forwarded until the second synchronization process is completed.

Benefits of technology

A significant reduction of user waiting time, improving the efficiency of database switching, ensuring the integrity and consistency of the data, and almost no business interruption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336845A_ABST
    Figure CN119336845A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, in particular to a database switching method and device.The method comprises the steps that an access request is received, and the access request is forwarded to a first database; determining that the first synchronization process is completed and the state of the first database meets a first condition, stopping forwarding the received access request to the first database, and triggering a second synchronization process; wherein the first synchronization process is used for synchronizing data before the first reference point in the first database to the second database, and the second synchronization process is used for synchronizing data after the first reference point in the first database to the last piece of data in the first database to the second database; in the execution process of the second synchronization process, caching the received access request; and determining that the second synchronization process is completed, and forwarding the cached access request to a second database. According to the method, the database switching efficiency can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a database switching method and device. Background Art

[0002] With the rapid development of information technology, modern applications often adopt a multi-service instance deployment strategy to achieve efficient traffic load balancing. However, when performing database switching operations, the existence of multiple instances also increases the complexity of the switching operation.

[0003] At present, there are two main methods in the existing technology, namely the shutdown switching method and the dual-write switching method. Among them, the shutdown switching method usually requires shutdown maintenance when performing database migration, making necessary configuration changes and application restarts, and the general downtime is as long as several hours, and users need to wait for a long time; while the dual-write switching method is to perform dual-write operations on the business between the new and old databases, and it is necessary to first close the write operation on the old database while maintaining access to the new database. This process requires writing additional code, which increases labor costs and processing time. Summary of the invention

[0004] The present application provides a database switching method and device for improving database switching efficiency.

[0005] In a first aspect, an embodiment of the present application provides a database switching method, which is applied to a first device and includes:

[0006] receiving an access request, and forwarding the access request to a first database, wherein the access request is used to access the first database;

[0007] Determine that the first synchronization process has been completed and the state of the first database meets the first condition, stop forwarding the received access request to the first database, and trigger the second synchronization process; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database;

[0008] During the execution of the second synchronization process, caching the received access request;

[0009] It is determined that the second synchronization process has been completed, and the cached access request is forwarded to the second database.

[0010] In an embodiment of the present invention, during the execution of the first synchronization process, the first device receives access requests and forwards these access requests to the first database. When the first synchronization process is completed and the state of the first database meets the first condition, the first device will stop forwarding the received access requests to the first database and trigger the second synchronization process; during the execution of the second synchronization process, the first device will cache the received access requests, and after the second synchronization process is completed, the first device will forward the cached access requests to the second database. During the entire database switching process, the time the user needs to wait is the time the first device caches the access request or the time required for the second synchronization process. Since this time is very short, it will hardly cause business interruption, effectively reducing the user's waiting time and optimizing the user experience. Secondly, by setting the first reference point to divide data synchronization into the first synchronization process and the second synchronization process, the efficiency of data synchronization is greatly improved, ensuring the integrity and consistency of the data.

[0011] In a possible embodiment, before receiving the access request, the method includes: starting the first synchronization process;

[0012] Receiving an access request and forwarding the access request to a first database includes: during the execution of the first synchronization process, receiving the access request and forwarding the access request to the first database.

[0013] In this embodiment, the first synchronization process is first performed to synchronize most of the data from the first database to the second database in advance, and a proxy layer is deployed during the first synchronization process. This method can reduce the waiting switching time and improve the switching efficiency.

[0014] In a possible embodiment, the state of the first database satisfies the first condition, which means that there is no unfinished transaction for the first database.

[0015] In this embodiment, the proxy layer ensures that there are no unfinished transactions in the first database before executing the database switching operation based on the status evaluation of the first database, wherein the unfinished transactions include slow queries and active transactions, so that the switching operation will not be interfered by the unfinished operations, thereby ensuring the smooth progress of the switching.

[0016] In a possible embodiment, determining that the second synchronization process has been completed includes: determining that a first marker has been saved in the second database, wherein the first marker is located after the last piece of data in the first database.

[0017] In this embodiment, by detecting whether the first mark appears, the integrity of data synchronization can be verified to ensure that the data in the second database is consistent with the first database.

[0018] In a possible embodiment, the first reference point is determined according to the last piece of data in the first database before starting the first synchronization process;

[0019] Determining that the first synchronization process has been completed includes: determining that the last piece of data in the first database before starting the first synchronization process has been saved in the second database.

[0020] In this embodiment, the first reference point is determined based on the last piece of data in the first database before the first synchronization process is started. Most of the data in the first database (i.e., the stock data) can be synchronized to the second database through the first synchronization process. The access request received during this synchronization process will be forwarded to the first database without stopping access to the first database. Secondly, a small amount of incremental data generated by the first database during the execution of the first synchronization process can be synchronized to the second database in the second synchronization process. This method effectively improves the efficiency of data synchronization and reduces the time of database switching.

[0021] In a possible embodiment, the method is applied to a first device, which saves a first connection credential and a second connection credential, wherein the first connection credential is used by the first device to forward the access request to the first database, and the second connection credential is used by the first device to forward the access request to the second database.

[0022] In a possible embodiment, the first connection credential includes the address and port number of the first database, and the user name and password of the first database;

[0023] The second connection credential includes the address and port number of the second database, and the user name and password of the second database.

[0024] In a second aspect, an embodiment of the present invention further provides a database switching device, the device comprising: a transceiver unit and a processing unit;

[0025] The transceiver unit is used to receive an access request and forward the access request to the first database, wherein the access request is used to access the first database;

[0026] The processing unit is used to stop forwarding the received access request to the first database and trigger the second synchronization process when it is determined that the first synchronization process has been completed and the state of the first database satisfies the first condition; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database; it is also used to cache the received access request during the execution of the second synchronization process; it is also used to cache the received access request during the determination of the execution of the second synchronization process.

[0027] In a possible embodiment, before receiving an access request, it includes: starting the first synchronization process; receiving the access request and forwarding the access request to the first database, including: during the execution of the first synchronization process, receiving the access request and forwarding the access request to the first database.

[0028] In a possible embodiment, the state of the first database satisfies the first condition, which means that there is no unfinished transaction for the first database.

[0029] In a possible embodiment, the processing unit is used to determine that the second synchronization process is completed, including:

[0030] It is determined that a first marker has been saved in the second database, wherein the first marker is located after the last piece of data in the first database.

[0031] In a possible embodiment, the first reference point is determined according to the last piece of data in the first database before starting the first synchronization process.

[0032] The processing unit is used to determine that the first synchronization process has been completed, including:

[0033] It is determined that the last piece of data in the first database before the first synchronization process is started has been stored in the second database.

[0034] In a possible embodiment, the method is applied to a first device, which saves a first connection credential and a second connection credential, wherein the first connection credential is used by the first device to forward the access request to the first database, and the second connection credential is used by the first device to forward the access request to the second database.

[0035] In a possible embodiment, the first connection credential includes the address and port number of the first database, and the user name and password of the first database;

[0036] The second connection credential includes the address and port number of the second database, and the user name and password of the second database.

[0037] In a third aspect, the present application provides a database switching device, including:

[0038] A memory for storing program instructions;

[0039] The processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods in the first aspect according to the obtained program instructions.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes any one of the methods described in the first aspect.

[0041] In a fifth aspect, the present application provides a computer program product, comprising: a computer program code, when the computer program code is run on a computer, the computer executes any one of the methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0043] Figure 1 A flowchart of a database switching method provided by an embodiment of the present invention;

[0044] Figure 2 A schematic diagram of various implementation modules provided for an embodiment of the present invention;

[0045] Figure 3 A schematic diagram of the structure of the database switching device provided in the embodiment of the present application Figure 1 ;

[0046] Figure 4 A schematic diagram of the structure of the database switching device provided in the embodiment of the present application Figure 2 . DETAILED DESCRIPTION

[0047] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] To facilitate understanding, the technical terms involved in the embodiments of the present application are first explained.

[0049] Slow query: refers to a database query whose execution time exceeds a preset threshold.

[0050] Active transaction: refers to a database transaction that is in progress and has not yet been committed or rolled back.

[0051] Binlog: It is a binary log file that records all operations that change data in the database, such as insert, update, and delete. It is mainly used for master-slave replication of the database and incremental recovery of data.

[0052] Currently, both the shutdown switching method and the dual-write switching method have problems such as low database switching efficiency and long waiting time. Figure 1 As shown, a method for switching a database is provided in an embodiment of the present invention.

[0053] Among them, in the following method, the first device can be deployed on the server. This application does not limit the specific deployment location of the first device. The first device is described below using the proxy layer as an example.

[0054] In a specific implementation, a technician can configure a first connection credential and a second connection credential for the proxy layer, wherein the first connection credential is a connection credential between the proxy layer and the first database, and is used for the proxy layer to forward access requests to the first database; the second connection credential is a connection credential between the proxy layer and the second database, and is used for the proxy layer to forward access requests to the second database.

[0055] Exemplarily, the first connection credential includes the address and port number of the first database, and the user name and password of the first database. The second connection credential includes the address and port number of the second database, and the user name and password of the second database.

[0056] For example, the following code shows the connection credentials between the proxy layer and the first database, that is, the first connection credentials:

[0057] spring.datasource.old.jdbc-url=jdbc:mysql: / / rds-old:3306 / dbname? param1=xx

[0058] spring.datasource.old.username=thisisusername

[0059] spring.datasource.old.password=thisispassword

[0060] Among them, in the first line, rds-old is the address of the first database, 3306 is the port number of the first database; the code shown in the second line is used to indicate the user name (username) of the first database; the code shown in the third line is used to indicate the password (password) of the first database.

[0061] As shown in the following code, it is the connection credential between the proxy layer and the second database, that is, the second connection credential:

[0062] spring.datasource.new.jdbc-url=jdbc:mysql: / / rds-new:3306 / dbname? param1=xx

[0063] spring.datasource.new.username=thisisusername

[0064] spring.datasource.new.password=thisispassword

[0065] Among them, in the first line, rds-new is the address of the second database, 3306 is the port number of the second database; the code shown in the second line is used to indicate the user name (username) of the second database; the code shown in the third line is used to indicate the password (password) of the second database.

[0066] Step 100: The proxy layer receives an access request and forwards the access request to a first database, wherein the access request is used to access the first database.

[0067] Before the proxy layer is deployed, the application sends an access request to the first database. After the proxy layer is deployed, the technician changes the relevant configuration of the application so that the application sends an access request to the proxy layer.

[0068] As shown in the following three lines of code, before deploying the proxy layer, the relevant configuration of the application side is:

[0069] spring.datasource.jdbc-url=jdbc:mysql: / / rds-old:3306 / dbname? param1=xx

[0070] spring.datasource.new.username=thisisusername

[0071] spring.datasource.new.password=thisispassword

[0072] Among them, in the first line, rds-old is the address of the first database, 3306 is the port number of the first database; the code shown in the second line is used to indicate the user name (username) of the first database; the code shown in the third line is used to indicate the password (password) of the first database.

[0073] As shown in the following three lines of code, after the proxy layer is deployed, the technician changes the relevant configuration of the application side. At this time, the relevant configuration of the application side is:

[0074] spring.datasource.jdbc-url=jdbc:mysql: / / {proxyhost}:{proxyport} / dbname? par am1=xx

[0075] spring.datasource.new.username=thisisusername

[0076] spring.datasource.new.password=thisispassword

[0077] In the first line, {proxyhost} is the host name of the proxy layer, and {proxyport} is the port number of the proxy layer; the code shown in the second line is used to indicate the user name (username) of the first database; and the code shown in the third line is used to indicate the password (password) of the first database.

[0078] In a specific implementation, by changing the relevant configuration of the application side, the application side can send an access request to the proxy layer instead of directly sending an access request to the first database. Then, the proxy layer receives the access request sent by the application side, parses the access request, extracts key information, such as SQL statements, queries, updates, etc., and uses the pre-configured first connection credentials to establish a secure connection with the first database. Through the secure connection, the proxy layer forwards the parsed access request to the first database; after the first database receives the forwarded access request, it first verifies the connection credentials to ensure that the proxy layer has sufficient authority to perform the access request operation. Once the verification is passed, the first database will perform the corresponding database operation according to the content of the access request, and then return the execution result to the proxy layer. After receiving the response from the first database, the proxy layer will encapsulate and encode the execution result according to the protocol style expected by the application side to meet the protocol style expected by the application side, and return the encapsulated execution result to the application side.

[0079] Step 110: The proxy layer determines that the first synchronization process has been completed and the status of the first database satisfies the first condition, stops forwarding the received access request to the first database, and triggers the second synchronization process; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database.

[0080] Exemplarily, before deploying the proxy layer, the synchronization module will first start the first synchronization process, which is used to synchronize the data before the first reference point in the first database to the second database, wherein the data before the first reference point is the data in the first database before the first synchronization process is started, which can also be called stock data. Therefore, the first synchronization process needs to synchronize more data. The second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database, wherein the data after the first reference point to the last data in the first database is the data generated after the first synchronization process is started to before the second synchronization process is started, which can also be called incremental data. Therefore, the second synchronization process needs to synchronize less data.

[0081] In one possible design, the first reference point is determined based on the last piece of data in the first database before the first synchronization process is started. Exemplarily, the first reference point is the identifier of the last piece of data in the first database before the first synchronization process is started. For example, before the first synchronization process is started, there are 10,000 pieces of data in the first database, then the identifier of the 10,000th piece of data is the first reference point. The first synchronization process is used to synchronize 10,000 pieces of data to the second database, and the incremental data generated after the 10,000th piece of data is the data that needs to be synchronized by the second synchronization process.

[0082] In another possible design, the first reference point is the specific time point when the first synchronization process is started. For example, at 13:00 on XX / XX / XXXX, the first synchronization process is started, then the data before 13:00 in the first database is the data that needs to be synchronized by the first synchronization process, and the incremental data generated after 13:00 is the data that needs to be synchronized by the second synchronization process.

[0083] In the following embodiments, the first reference point takes the identifier of the last piece of data in the first database before starting the first synchronization process as an example.

[0084] When the first synchronization process is started, starting from the first data in the first database, it is synchronized to the second database in sequence until the last data in the first database before starting the first synchronization process, that is, the data corresponding to the first reference point, is saved in the second database, and the first synchronization process is completed.

[0085] During the execution of the first synchronization process, the proxy layer evaluates the state of the first database to detect whether the state of the first database satisfies the first condition. The state of the first database satisfies the first condition when there are no unfinished transactions for the first database. For example, unfinished transactions refer to ongoing slow queries and active transactions.

[0086] For example, if there is no active transaction for the first database, but there is an ongoing slow query, the state of the first database does not meet the first condition, and the proxy layer will attempt to retry, wherein the proxy layer will set a retry cycle and periodically detect the completion status of the slow query until it is detected that the slow query has been completed, at which point the state of the first database meets the first condition.

[0087] For another example, if there is no ongoing slow query for the first database, but there is an active transaction, the status of the first database does not meet the first condition. The proxy layer will also periodically detect the completion status of the active transaction based on the retry cycle. When all active transactions have been committed or rolled back, the status of the first database meets the first condition.

[0088] For another example, if there are no slow queries and no active transactions for the first database, the state of the first database satisfies the first condition.

[0089] When the status of the first database meets the first condition, the proxy layer also needs to confirm whether the first synchronization process is completed. In a specific implementation, the proxy layer can send an inquiry message to the first database, and the inquiry message is used to inquire whether the first synchronization process is completed. The first database receives the inquiry message. If the data corresponding to the first reference point in the first database has been synchronized to the second database, the first database sends an inquiry response message to the proxy layer, and the inquiry response message indicates that the first synchronization process has been completed. If the data corresponding to the first reference point in the first database has not been synchronized to the second database, the first database sends an inquiry response message to the proxy layer, and the inquiry response message indicates that the first synchronization process is not completed. The proxy layer can then send an inquiry message to the first database again after a preset period of time. In addition, the first database can also actively inform the proxy layer that the first synchronization process has been completed, and then the proxy layer determines whether the status of the first database meets the first condition.

[0090] When the first synchronization process has been completed and the state of the first database meets the first condition, the proxy layer stops forwarding the received access request to the first database and triggers the synchronization module to start the second synchronization process.

[0091] Step 120: During the execution of the second synchronization process, the proxy layer caches the received access request.

[0092] In a specific implementation, during the execution of the first synchronization process, the proxy layer receives access requests sent by the application end and forwards the access requests to the first database; during the execution of the second synchronization process, the proxy layer caches all access requests sent by the application end, and does not forward them to the first database.

[0093] Step 130: When the proxy layer determines that the second synchronization process has been completed, the proxy layer forwards the cached access request to the second database.

[0094] If the proxy layer determines that the first mark has been saved in the second database, it is determined that the second synchronization process has been completed.

[0095] For example, the technician will insert a first marker after the last data in the first database. The first marker can be a data record, and the present application does not limit the specific content of the first marker. During the execution of the second synchronization process, by subscribing to the binlog of the second database, it is possible to monitor in real time whether the second database has saved the first marker to ensure that the content saved in the first database is consistent with the content saved in the second database.

[0096] The first mark appears in the second database, indicating that the second database has saved all incremental data after the first reference point, that is, the second synchronization process has been completed. At this time, the second database can also send a notification message to the proxy layer, which is used to indicate that the second synchronization process has been completed.

[0097] Exemplarily, when the proxy layer determines that the second synchronization process has been completed, the proxy layer provides a method of manually triggering database switching through a predefined application programming interface port (API), for example, POST https: / / example.com / proxy / switch. Relevant technicians can quickly trigger the database switching operation through this API interface, where the entire database switching time is in milliseconds, and the application end cannot perceive changes in the underlying database.

[0098] After the database switch is completed, the proxy layer can forward the cached access requests and the newly received access requests to the second database. After the second database receives the forwarded access request, it performs the corresponding database operation according to the content of the access request, and then returns the execution result to the proxy layer. After the proxy layer receives the response from the second database, it will encapsulate and encode the execution result according to the protocol style expected by the application end to conform to the protocol style expected by the application end, and return the execution result to the application end. In addition, the relevant configuration of the application end can also be updated so that the application end directly sends an access request to the second database.

[0099] like Figure 2 As shown, in this application, the proxy layer may include but is not limited to the following modules: a protocol proxy implementation module, a synchronization detection module, a session switching module, and a session maintenance module. Among them, the protocol proxy implementation module is used to implement Figure 1 In step 100, an access request is received; the synchronization detection module is used to implement Figure 1 Step 110 detects the completion progress of the first synchronization process and the status of the first database, and is also used to implement Figure 1 In step 130, the completion progress of the second synchronization process is detected; the session maintenance module is used to realize the connection between the proxy layer and the first database and the second database; the session switching module is used to realize Figure 1 In step 130, the access request is forwarded to the second database. In addition, the synchronization module includes an existing data synchronization module and an incremental data synchronization module. The existing data synchronization module is used to implement the first synchronization process; the incremental data synchronization module is used to implement the second synchronization process.

[0100] In summary, the present application provides a database switching method. During the execution of the first synchronization process, the first device receives access requests and forwards these access requests to the first database. When the first synchronization process is completed and the state of the first database meets the first condition, the first device will stop forwarding the received access requests to the first database and trigger the second synchronization process; during the execution of the second synchronization process, the first device will cache the received access requests, and after the second synchronization process is completed, the first device will forward the cached access requests to the second database. During the entire database switching process, the time the user needs to wait is the time for the first device to cache the access request or the time required for the second synchronization process. Since this time is very short, it will hardly cause business interruption, effectively reducing the user's waiting time and improving the user experience. Secondly, by setting the first reference point to divide the data synchronization into the first synchronization process and the second synchronization process, a large amount of stock data in the first database can be synchronized to the second database through the first synchronization process. The access request received during this synchronization process will be forwarded to the first database without stopping access to the first database. During the execution of the first synchronization process, a small amount of incremental data generated after the first reference point of the first database can be synchronized to the second database in the second synchronization process. This method effectively ensures the integrity and consistency of data, improves the efficiency of data synchronization, and improves the efficiency of database switching.

[0101] Figure 3 and Figure 4 A schematic diagram of a possible database switching device provided in an embodiment of the present invention. The database switching device can be used to implement the function of the proxy layer in the above method embodiment.

[0102] like Figure 3 As shown, the database switching device 300 includes a transceiver unit 310 and a processing unit 320 .

[0103] When the database switching device 300 is used to implement Figure 1 The functions of the proxy layer in the method embodiment shown are:

[0104] The transceiver unit 310 is used to receive an access request and forward the access request to a first database, wherein the access request is used to access the first database.

[0105] The processing unit 320 is used to determine that the first synchronization process has been completed and the status of the first database satisfies the first condition, stop forwarding the received access request to the first database, and trigger the second synchronization process; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database.

[0106] The processing unit 320 is further configured to cache received access requests during the execution of the second synchronization process.

[0107] The processing unit 320 is further configured to determine that the second synchronization process has been completed, and forward the cached access request to the second database.

[0108] In one possible design, before receiving an access request, it includes: starting the first synchronization process; receiving the access request, and forwarding the access request to the first database, including: during the execution of the first synchronization process, receiving the access request, and forwarding the access request to the first database.

[0109] In a possible design, the state of the first database satisfies the first condition, which means that there is no unfinished transaction for the first database.

[0110] In one possible design, the processing unit 320 is further used to determine that the second synchronization process has been completed, including: determining that a first mark has been saved in the second database, wherein the first mark is located after the last data in the first database.

[0111] In a possible design, the first reference point is determined based on the last data in the first database before starting the first synchronization process.

[0112] The processing unit 320 is further configured to determine that the first synchronization process has been completed, including:

[0113] It is determined that the last piece of data in the first database before the first synchronization process is started has been stored in the second database.

[0114] In one possible design, the method is applied to a first device, which stores a first connection credential and a second connection credential, wherein the first connection credential is used by the first device to forward the access request to the first database, and the second connection credential is used by the first device to forward the access request to the second database.

[0115] In one possible design, the first connection credential includes the address and port number of the first database, and the user name and password of the first database;

[0116] The second connection credential includes the address and port number of the second database, and the user name and password of the second database.

[0117] For more detailed description of the transceiver unit 310 and the processing unit 320, please refer to Figure 4 The relevant description in the method embodiment shown is directly obtained and will not be repeated here.

[0118] like Figure 4 As shown, the database switching device 400 includes a processor 410 and a communication interface 420. The processor 410 and the communication interface 420 are coupled to each other. It is understood that the communication interface 420 can be a transceiver or an input-output interface. Optionally, the database switching device 400 can also include a memory 430 for storing instructions executed by the processor 410 or storing input data required by the processor 410 to run the instructions or storing data generated after the processor 410 runs the instructions.

[0119] When the database switching device 300 is used to implement Figure 1 When the method is shown, the processor 410 is used to implement the functions of the processing unit 320, and the communication interface 420 is used to implement the functions of the transceiver unit 310.

[0120] The division of units in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0121] Based on the same inventive concept, the embodiment of the present application provides a computer-readable storage medium, and the computer program product includes: computer program code, when the computer program code is executed on a computer, the computer executes any of the database switching methods discussed above. Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the database switching method, the implementation of the above-mentioned computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.

[0122] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the database switching methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of the database switching method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.

[0123] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0124] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0125] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0126] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A database switching method, characterized in that: The method is applied to a first device, and the method comprises: receiving an access request, and forwarding the access request to a first database, wherein the access request is used to access the first database; Determine that the first synchronization process has been completed and the state of the first database meets the first condition, stop forwarding the received access request to the first database, and trigger the second synchronization process; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database; During the execution of the second synchronization process, caching the received access request; It is determined that the second synchronization process has been completed, and the cached access request is forwarded to the second database.

2. The method according to claim 1, characterized in that Before receiving a request for access, including: Starting the first synchronization process; Receiving an access request and forwarding the access request to a first database includes: During the execution of the first synchronization process, the access request is received and forwarded to the first database.

3. The method according to claim 1 or 2, characterized in that The state of the first database satisfies the first condition, which means that there is no unfinished transaction for the first database.

4. The method according to any one of claims 1 to 3, characterized in that: Determining that the second synchronization process has been completed includes: It is determined that a first marker has been saved in the second database, wherein the first marker is located after the last piece of data in the first database.

5. The method according to any one of claims 1 to 4, characterized in that: The first reference point is determined according to the last piece of data in the first database before the first synchronization process is started; Determining that the first synchronization process has been completed includes: It is determined that the last piece of data in the first database before the first synchronization process is started has been stored in the second database.

6. The method according to any one of claims 1 to 5, characterized in that: The first device saves a first connection credential and a second connection credential, wherein the first connection credential is used by the first device to forward the access request to the first database, and the second connection credential is used by the first device to forward the access request to the second database.

7. The method according to claim 6, characterized in that The first connection credential includes the address and port number of the first database, and the user name and password of the first database; The second connection credential includes the address and port number of the second database, and the user name and password of the second database.

8. A database switching device, characterized in that: The device comprises: a transceiver unit and a processing unit; The transceiver unit is used to receive an access request and forward the access request to the first database, wherein the access request is used to access the first database; The processing unit is used to stop forwarding the received access request to the first database and trigger the second synchronization process when it is determined that the first synchronization process has been completed and the state of the first database satisfies the first condition; wherein the first synchronization process is used to synchronize the data before the first reference point in the first database to the second database, and the second synchronization process is used to synchronize the data after the first reference point in the first database to the last data in the first database to the second database; it is also used to cache the received access request during the execution of the second synchronization process; it is also used to cache the received access request during the determination of the execution of the second synchronization process.

9. A database switching device, characterized in that: include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of claims 1-7 according to the obtained program instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data migration method and device, equipment and storage medium

    CN113010496A

  • Distributed database data online migration method

    CN113986882A