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

By using double write switches and execution threads in database migration to adjust the traffic in SQL dimensions, the problem of poor universality in the existing technology is solved, real-time consistency of dual database data and simplification of migration process, and improving database migration Availability.

CN119046264APending Publication Date: 2024-11-29CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411229487.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

The existing database migration method based on dual data sources is poor in general, and it is necessary to extract the library factor from business data and requires strong dependence in the dual data sources to simultaneously have basic configuration information, which increases complexity and risk.

Method used

Through dual write switches and execution threads, traffic adjustments are performed on the target database and source database in the SQL dimension, real-time consistency of dual database data is achieved, avoiding the integrity check of the underlying data of dual databases and strong dependence basic configuration information, and directly performing traffic Switch.

Benefits of technology

It improves the availability and universality of database migration, simplifies the migration process, avoids the requirements of library factor extraction and strong dependency configuration, and realizes real-time consistency of dual-store data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046264A_ABST
    Figure CN119046264A_ABST
Patent Text Reader

Abstract

The invention discloses a database migration method and device, equipment, a storage medium and a program product, and relates to the technical field of data migration, and the database migration method comprises the following steps: receiving a database migration request; based on a preset double-write switch and an execution thread, performing flow adjustment on a preset target database and a source database according to the database migration request to obtain a flow adjustment result; and obtaining a database migration result through the double-write switch and the execution thread according to the flow adjustment result. According to the method, flow adjustment is performed on the target database and the source database in the SQL dimension through the double-write switch and the execution thread, double-database data are consistent in real time, the integrity of double-database bottom-layer dependent data is not involved, a sub-database factor does not need to be extracted from service data, and strong-dependency basic configuration information does not need to exist in double data sources at the same time; the problem that an existing database migration method based on double data sources is poor in universality is solved, and the availability of database migration is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data migration, and in particular to a database migration method, device, equipment, storage medium and program product. Background Art

[0002] As the number of projects increases, the corresponding database grows rapidly, and the need for database migration becomes more and more frequent. Complex database systems are often maintained by enterprises, governments, and other large entities (collectively referred to as customers), who have limited tolerance for system offline.

[0003] Traditional database migration solutions based on dual data sources require that there must be strong dependent basic configuration information between the target database and the source database to support the business logic to form a closed loop in the dual data sources, and the business data must have a database partitioning factor for traffic switching. The solution has a narrow scope of application and poor versatility.

[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0005] The main purpose of the present application is to provide a database migration method, device, equipment, storage medium and program product, aiming to solve the technical problem that the existing database migration method based on dual data sources has poor versatility.

[0006] To achieve the above objectives, the present application proposes a database migration method, which includes:

[0007] Receive database migration requests;

[0008] Based on the preset dual-write switch and execution thread, according to the database migration request, flow adjustment is performed on the preset target database and source database to obtain a flow adjustment result;

[0009] According to the traffic adjustment result, the database migration result is obtained through the dual write switch and the execution thread.

[0010] In one embodiment, the execution thread includes a main thread and a secondary thread, and the step of performing flow adjustment on a preset target database and a source database based on a preset dual write switch and an execution thread according to the database migration request, and obtaining a flow adjustment result includes:

[0011] According to the database migration request, the dual write switch is switched to an on state, and a first structured query statement SQL set is obtained;

[0012] According to the first SQL set, traffic verification is performed on the target database and the source database through the main thread and the secondary thread to obtain a traffic verification result;

[0013] According to the traffic verification result, the traffic of the target database and the source database is switched through the main thread and the secondary thread to obtain the traffic adjustment result.

[0014] In one embodiment, the step of performing traffic verification on the target database and the source database through the main thread and the secondary thread according to the first SQL set to obtain the traffic verification result includes:

[0015] Binding the secondary thread to the target database, and binding the main thread to the source database based on a preset thread local variable mechanism;

[0016] By means of the main thread, according to the first SQL set, a corresponding operation is performed on the source database to obtain a first execution result;

[0017] By means of the secondary thread, according to the first SQL set, a corresponding operation is performed on the target database to obtain a second execution result;

[0018] The first execution result and the second execution result are compared to obtain the flow verification result.

[0019] In one embodiment, the step of performing traffic switching on the target database and the source database through the main thread and the secondary thread according to the traffic verification result to obtain the traffic adjustment result includes:

[0020] Determining whether the flow adjustment result meets a first preset condition;

[0021] If yes, obtain a second SQL set, bind the secondary thread to the source database, and bind the main thread to the target database based on a preset thread local variable mechanism;

[0022] By means of the main thread, according to the second SQL set, a corresponding operation is performed on the target database to obtain a third execution result;

[0023] By means of the secondary thread, according to the second SQL set, a corresponding operation is performed on the source database to obtain a fourth execution result;

[0024] The third execution result and the fourth execution result are compared to obtain the flow adjustment result.

[0025] In one embodiment, the execution thread includes a main thread and a secondary thread, the main thread is a thread supporting application services, and the step of obtaining a database migration result through the dual write switch and the execution thread according to the traffic adjustment result includes:

[0026] Determining whether the flow adjustment result meets a second preset condition;

[0027] If so, the secondary thread is removed, and the dual write switch is switched to an off state to generate the database migration result.

[0028] In one embodiment, the step of performing traffic adjustment on a preset target database and a source database based on a preset dual write switch and an execution thread according to the database migration request, and obtaining a traffic adjustment result also includes:

[0029] receiving a data copy instruction;

[0030] According to the data replication instruction, the data in the source database is fully replicated to a preset original target database through a preset data replication tool to obtain the target database.

[0031] In addition, to achieve the above-mentioned purpose, the present application also proposes a database migration device, which includes:

[0032] A request receiving module, used for receiving a database migration request;

[0033] A traffic adjustment module, configured to adjust the traffic of a preset target database and a source database based on a preset dual-write switch and an execution thread according to the database migration request, and obtain a traffic adjustment result;

[0034] The database migration module is used to obtain the database migration result through the dual write switch and the execution thread according to the traffic adjustment result.

[0035] In addition, to achieve the above objectives, the present application also proposes a database migration device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database migration method described above.

[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the database migration method described above are implemented.

[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the database migration method described above are implemented.

[0038] The present application provides a database migration method, which adjusts the traffic of the target database and the source database in the SQL dimension through a dual write switch and an execution thread. The data of the two databases are consistent in real time, and the integrity of the underlying dependent data of the two databases is not involved. There is no need to extract database partitioning factors from business data, and there is no need for strong dependent basic configuration information to exist in the two data sources at the same time. This solves the technical problem of poor versatility of the existing database migration method based on dual data sources and improves the availability of database migration. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0041] Figure 1 A flowchart of the first embodiment of the database migration method of the present application is provided;

[0042] Figure 2 A flowchart of the second embodiment of the database migration method of the present application is provided;

[0043] Figure 3 A schematic diagram of the principles of the database migration method provided in Example 2 of the present application;

[0044] Figure 4 A schematic diagram of the principle of flow verification provided in Example 2 of the present application;

[0045] Figure 5 This is a schematic diagram of the module structure of the database migration device according to an embodiment of the present application;

[0046] Figure 6 This is a schematic diagram of the device structure of the hardware operating environment involved in the database migration method in the embodiment of the present application.

[0047] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0048] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0050] The main solutions of the embodiments of this application are:

[0051] Receive database migration requests;

[0052] Based on the preset dual-write switch and execution thread, according to the database migration request, flow adjustment is performed on the preset target database and source database to obtain a flow adjustment result;

[0053] According to the traffic adjustment result, the database migration result is obtained through the dual write switch and the execution thread.

[0054] Referring to the patent "A method for migrating MySQL from Oracle without downtime for services with daily transaction volume exceeding 100 million" (CN115658644A), the database migration method based on dual data sources in the prior art has the following shortcomings:

[0055] It is required that business data must be able to distinguish the partitioning factors, and traffic switching is done based on the partitioning factors. The union of the two databases is the complete data. If the traffic needs to be rolled back, the incremental data in MySQL needs to be synchronized back to Oracle, which increases the complexity and risk of rollback.

[0056] The basic configuration information with strong dependencies must be sorted out in advance to ensure that such data exists in both Oracle and MySQL at the same time, otherwise the business logic cannot be completed in a closed loop in different databases.

[0057] During the migration process, special query functions that aggregate the data of the two libraries are required, which requires the use of middleware such as ES, which further increases the complexity of the system.

[0058] During the migration process, the business data must have a database partitioning factor, otherwise the solution cannot be used.

[0059] The present application provides a solution, which adjusts the traffic of the target database and the source database in the SQL dimension through a dual write switch and an execution thread. The data of the two databases are consistent in real time, and the integrity of the underlying dependent data of the two databases is not involved. There is no need to extract database partitioning factors from the business data, and there is no need for strong dependent basic configuration information to exist in the two data sources at the same time. It solves the technical problem of poor versatility of the existing database migration method based on dual data sources and improves the availability of database migration.

[0060] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a database migration system, etc. The following takes the database migration system as an example to illustrate this embodiment and the following embodiments.

[0061] Based on this, the present application embodiment provides a database migration method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the database migration method of the present application.

[0062] In this embodiment, the database migration method includes steps S10 to S30:

[0063] Step S10, receiving a database migration request;

[0064] It should be noted that a database migration request is a request or instruction, which usually includes information about the source database, the target database, and specific requirements for the migration.

[0065] Step S20, based on the preset dual-write switch and the execution thread, according to the database migration request, flow adjustment is performed on the preset target database and the source database to obtain a flow adjustment result;

[0066] During the database migration process, in order to reduce the impact on the existing system and optimize the migration performance, the database migration system adjusts the traffic of the source database and the target database according to the dual-write switch and execution thread settings to obtain the traffic adjustment result. The dual-write switch is used to control the bidirectional synchronization of data during the migration process, and the execution thread is used to manage parallel processing capabilities. The traffic adjustment result may involve information on database load, performance indicators, data consistency, etc.

[0067] In a feasible implementation manner, before step S20, steps S401 to S402 may also be included:

[0068] Step S401, receiving a data copy instruction;

[0069] Step S402: According to the data replication instruction, the data in the source database is fully replicated to a preset original target database by using a preset data replication tool to obtain the target database.

[0070] The database migration system receives the data replication instruction, and then according to the data replication instruction, uses the preset data replication tool to copy all the data in the source database to the preset original target database to obtain the target database.

[0071] In this embodiment, by receiving a data replication instruction; according to the data replication instruction, using a preset data replication tool, all the data in the source database is copied to a preset original target database to obtain the target database, and through a systematic data replication and verification process, it is ensured that the data in the source database is accurately migrated to the target database, and the consistency of the operation results is verified in different environments, thereby ensuring that the results of the target database and the source database after the data operation are consistent.

[0072] Step S30, obtaining a database migration result through the dual write switch and the execution thread according to the traffic adjustment result.

[0073] The database migration system processes the dual-write switch and the execution thread according to the traffic adjustment result to obtain the database migration result. The database migration result may include a migration log, a data consistency report, etc.

[0074] In a feasible implementation manner, the execution thread includes a main thread and a secondary thread, and step S30 may include steps S301 to S302:

[0075] Step S301, determining whether the flow adjustment result meets a second preset condition;

[0076] Step S302: If yes, remove the secondary thread, switch the dual write switch to the off state, and generate the database migration result.

[0077] The database migration system determines whether the traffic adjustment result meets the second preset condition, wherein the second preset condition is usually to ensure that the environment is stable after the traffic adjustment and the database performance meets expectations. For example, the conditions may include that the system load is lower than a certain threshold, data synchronization is completed, etc. Then, if the traffic adjustment result meets the second preset condition, the system stops the operation of the secondary thread, which usually involves closing or terminating the operation of the secondary thread, and then switches the dual-write switch to the off state, which means that data is no longer written to the source database and the target database at the same time, but the dual-write mode is stopped, and the database migration result is generated.

[0078] In this implementation, it is determined whether the flow adjustment result meets the second preset condition; if so, the secondary thread is removed, and the dual-write switch is switched to the off state to generate the database migration result. By determining whether the flow adjustment result meets the condition, the effectiveness and accuracy of the flow adjustment are ensured, and the coordination of the main thread and the secondary thread is effectively managed to ensure that the system can still operate efficiently under high load conditions. After the flow adjustment is successful, the secondary thread is removed in time and the dual-write switch is turned off to release system resources and avoid unnecessary system overhead. By generating the database migration result, confirmation of the data migration operation is provided to avoid unclear or inconsistent status problems that may occur during the migration process.

[0079] This embodiment provides a database migration method, which receives a database migration request; based on a preset dual-write switch and an execution thread, according to the database migration request, adjusts the traffic of a preset target database and a source database to obtain a traffic adjustment result; according to the traffic adjustment result, obtains the database migration result through the dual-write switch and the execution thread. Through the dual-write switch and the execution thread, the traffic of the target database and the source database is adjusted in the SQL dimension, and the data of the two databases are consistent in real time, without involving the integrity of the underlying dependent data of the two databases, without extracting the database partitioning factor in the business data, and without the basic configuration information with strong dependencies in the two data sources at the same time, which solves the technical problem of poor versatility of the existing database migration method based on the dual data source and improves the availability of database migration.

[0080] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 2 , the execution thread includes a main thread and a secondary thread, and step S20 also includes steps S201 to S203:

[0081] Step S201: according to the database migration request, the dual write switch is switched to an on state, and a first structured query statement SQL set is obtained;

[0082] Step S202, according to the first SQL set, through the main thread and the secondary thread, flow verification is performed on the target database and the source database to obtain a flow verification result;

[0083] Step S203: According to the traffic verification result, traffic switching is performed on the target database and the source database through the main thread and the secondary thread to obtain the traffic adjustment result.

[0084] According to the database migration request, the database migration system switches the dual-write switch to the on state and enables the dual-write mode of the dual-write switch. In this mode, all write operations on the source database will be written to the target database at the same time to ensure data synchronization between the source database and the target database, and prepare for subsequent data consistency verification, and obtain the first SQL set. Then, based on the first SQL set, the target database and the source database are subjected to traffic verification through the main thread and the secondary thread to obtain the traffic verification result, ensuring the data consistency and synchronization of the source database and the target database in the dual-write mode. The use of the main thread and the secondary thread helps to improve the efficiency and accuracy of the verification process. Finally, based on the traffic verification result, the target database and the source database are subjected to traffic switching through the main thread and the secondary thread to obtain the traffic adjustment result, ensuring the normal operation of the system after the traffic switching, and confirming that the target database has taken over all traffic, realizing the traffic switching from the source database to the target database, and ensuring the stability of the system and the data consistency during the traffic switching process.

[0085] It should be noted that traffic verification is to check the data traffic between the primary database and the source database to ensure data consistency and system load. Traffic switching is to switch the data traffic from the source database to the target database to complete the migration process. The dual-write switch is a control switch in the system that is used to decide whether to write to the source database and the target database at the same time.

[0086] SQL (Structured Query Language) is a programming language used to manage and operate relational databases. It is mainly used to perform the following operations:

[0087] 1. Query: Retrieve data from the database (such as SELECT statement).

[0088] 2. Insert: Add new records to a database table (such as INSERT statement).

[0089] 3. Update: Modify the contents of an existing record (such as an UPDATE statement).

[0090] 4. Delete: Remove records (such as DELETE statement).

[0091] 5. Create and modify structures: Create or adjust the structure of database tables and other objects (such as CREATE TABLE, ALTER TABLE statements).

[0092] SQL also includes sub-languages ​​such as data definition language (DDL) and data manipulation language (DML), which are used for different database operation tasks.

[0093] In a feasible implementation, step S202 may include steps S2021 to S2024:

[0094] Step S2021, binding the secondary thread to the target database, and binding the main thread to the source database based on a preset thread local variable mechanism;

[0095] Step S2022: executing corresponding operations on the source database according to the first SQL set through the main thread to obtain a first execution result;

[0096] Step S2023, executing corresponding operations on the target database according to the first SQL set through the secondary thread to obtain a second execution result;

[0097] Step S2024: compare the first execution result and the second execution result to obtain the flow verification result.

[0098] The database management system binds the secondary thread to the target database, and binds the main thread to the source database based on a preset thread local variable mechanism, ensuring that the main thread and the secondary thread are correctly bound to the source database and the target database respectively, so as to perform subsequent database operations and verification tasks, and then, through the main thread, according to the first SQL set, performs corresponding operations on the source database to obtain a first execution result, and through the secondary thread, according to the first SQL set, performs corresponding operations on the target database to obtain a second execution result, and finally compares the first execution result and the second execution result to check whether the two are consistent or meet the expected matching criteria, which may include comparing the integrity, consistency and accuracy of the data, and obtaining the traffic verification result based on the comparison result. This usually includes generating a report or confirming the success or failure of the traffic switching.

[0099] It should be noted that the thread local variable mechanism is a programming technique used to ensure that threads use independent copies of variables during execution and maintain thread-specific database connections and operating environments in a multi-threaded environment.

[0100] In this implementation, the secondary thread is bound to the target database, and based on a preset thread local variable mechanism, the main thread is bound to the source database; through the main thread, according to the first SQL set, a corresponding operation is performed on the source database to obtain a first execution result; through the secondary thread, according to the first SQL set, a corresponding operation is performed on the target database to obtain a second execution result; the first execution result and the second execution result are compared to obtain the traffic verification result. By performing the same operation on the source database and the target database and comparing the results, the consistency of data during the migration process can be ensured, and the risk of data inconsistency is reduced. The concurrency mechanism of the main thread and the secondary thread is used to improve the efficiency of traffic verification, making the verification process faster and more efficient. Through the thread local variable mechanism, the independence of the main thread and the secondary thread when executing operations is achieved, avoiding interference between different threads, ensuring the accuracy of the verification result, and by comparing the two execution results, potential migration problems can be effectively detected and corrected, thereby improving the reliability and success rate of data migration.

[0101] In another feasible implementation, step S203 may include steps S2031 to S2035:

[0102] Step S2031, determining whether the flow adjustment result meets a first preset condition;

[0103] Step S2032: If yes, obtain a second SQL set, bind the secondary thread to the source database, and bind the main thread to the target database based on a preset thread local variable mechanism;

[0104] Step S2033: executing corresponding operations on the target database according to the second SQL set through the main thread to obtain a third execution result;

[0105] Step S2034: executing corresponding operations on the source database according to the second SQL set through the secondary thread to obtain a fourth execution result;

[0106] Step S2035: compare the third execution result and the fourth execution result to obtain the flow adjustment result.

[0107] The database management system determines whether the traffic adjustment result meets the first preset condition and confirms whether the traffic adjustment is successful. If the traffic adjustment result meets the first preset condition, the system obtains the second SQL set, binds the secondary thread to the source database, and binds the main thread to the target database based on the preset thread local variable mechanism to ensure that database operations can be performed concurrently on the source database and the target database. Then, through the main thread, according to the second SQL set, the target database is executed to obtain a third execution result. Through the secondary thread, according to the second SQL set, the source database is executed to obtain a fourth execution result. Finally, the third execution result is compared with the fourth execution result to verify whether the traffic adjustment achieves the expected effect and obtain the traffic adjustment result.

[0108] In this implementation, it is determined whether the traffic adjustment result satisfies a first preset condition; if so, a second SQL set is obtained, and the secondary thread is bound to the source database, and based on a preset thread local variable mechanism, the main thread is bound to the target database; through the main thread, according to the second SQL set, a corresponding operation is performed on the target database to obtain a third execution result; through the secondary thread, according to the second SQL set, a corresponding operation is performed on the source database to obtain a fourth execution result; the third execution result and the fourth execution result are compared to obtain the traffic adjustment result. By executing the same operation in parallel and comparing the results, the data consistency between the source database and the target database can be effectively checked and ensured. Through the thread local variable mechanism, interference between the main thread and the secondary thread is avoided, and the accuracy of the operation is improved. Through conditional judgment of the traffic adjustment result, it is ensured that further verification is performed only when the conditions are met, thereby optimizing resource utilization efficiency.

[0109] In this embodiment, according to the database migration request, the dual-write switch is switched to the on state, and the first structured query statement SQL set is obtained; according to the first SQL set, the target database and the source database are subjected to traffic verification through the main thread and the secondary thread to obtain a traffic verification result; according to the traffic verification result, the target database and the source database are subjected to traffic switching through the main thread and the secondary thread to obtain the traffic adjustment result, and the data is ensured to remain consistent during the migration process through the dual-write switch to avoid data loss, and the data traffic is ensured to be stable and the system load is reasonable during the migration process through traffic verification and switching, and the traffic is smoothly switched from the source database to the target database through the cooperation of the main thread and the secondary thread, thereby improving the efficiency of traffic verification and switching and handling complex migration tasks.

[0110] Exemplarily, to facilitate understanding of the implementation process of the database migration method obtained by combining the above first embodiment, second embodiment, and third embodiment, please refer to Figure 3 and Figure 4 , Figure 3 which is a schematic diagram of the principle of the database migration method provided in the second embodiment of the present application, Figure 4 and

[0111]

[0112] This embodiment mainly enables two threads: the main thread and the secondary thread. Specifically, in the traffic verification stage, the main thread is bound to the source database through the Java thread copy ThreadLocal, while the secondary thread is bound to the target database; in the traffic switching stage, the main thread is bound to the target database through the Java thread copy ThreadLocal, while the secondary thread is bound to the source database. For one database request, the two threads simultaneously execute the SQL on their respective bound data sources to ensure that the data written to the two data sources is consistent in real time, and finally the main thread responds with the result to provide services for the upper-layer service.

[0113] Correspondingly, the traffic adjustment is divided into two stages, namely the traffic verification stage and the traffic switching stage. In the traffic verification stage, the write operation SQL is written to both the source database and the target database at the same time, and only the execution result of reading the data in the source database is returned to the upper layer after executing the read operation SQL. In the traffic switching stage, the write operation SQL is also written to both the source database and the target database, but only the execution result of reading the data in the target database is returned to the upper layer after executing the read operation SQL. After the traffic verification and switching are completed, the dual-write switch is turned off, and both the read and write operation SQLs are executed on the target database, thereby achieving the purpose of migrating data from the source database to the target database.

[0114]

[0115] Thus, the same write SQL is executed on both the source database and the target database at the same time, so the same data is written to the two databases through this SQL, thereby achieving the real-time synchronization effect. For example, when an administrator adds a user information in the system, the SQL pseudocode generated by the system is as follows: INSERT INTO T_USER (ID, NAME, AGE,...) VALUES (1, 'Zhang San', '18',...); The system will execute the insert operation of this SQL on both the source database and the target database respectively. Therefore, in the T_USER tables of the source database and the target database, the user information 'Zhang San' will be added at the same time.At the same time, since all write operations such as insert, update, and delete in the system are executed on both the source database and the target database at the same time, ideally, the data in the source database and the target database are consistent in real time, achieving redundant backup of the data.

[0116] In addition, when the application starts, all the switch configurations of the application's SQL will be loaded into the cache, and the cache will be automatically refreshed every minute. When the dual database data verification is passed, the dual write switch of a batch of SQL can be switched according to the business scenario (the main thread is bound to the target database, and the secondary thread is bound to the source database) without restarting the application. If any exception occurs after the flow is cut, the switch can be used to quickly hot-cut back to stop the loss in time.

[0117] Compared with the prior art, the database migration method in this embodiment has the following advantages:

[0118] 1. The data of the two data sources are consistent in real time. During the database migration process, if the traffic fails to pass the verification on the target database, the traffic can be quickly switched back to the source database without migrating the incremental traffic data of the target database back to the source database.

[0119] 2. The data in both databases are consistent in real time and have redundant backup. No matter which database the traffic is distributed to, it can independently support all complex query scenarios of the original application.

[0120] 3. Use SQL dimensions to switch traffic, and use the SQL execution results of the main thread to support upper-level business. During the traffic switching process, there is no need to pay attention to whether the business data contains sub-library identifiers, and the supported database migration scenarios are broader.

[0121] 4. The system transformation points are only controlled in the persistence layer of the application, with a small impact and reduced risks. There is no need to perform code adaptation and transformation on the system business logic layer.

[0122] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the database migration method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0123] This application also provides a database migration device, please refer to Figure 5 , the database migration device comprises:

[0124] A request receiving module 10, used to receive a database migration request;

[0125] The traffic adjustment module 20 is used to adjust the traffic of the preset target database and the source database based on the preset dual write switch and the execution thread according to the database migration request to obtain the traffic adjustment result;

[0126] The database migration module 30 is used to obtain the database migration result according to the traffic adjustment result through the dual write switch and the execution thread.

[0127] Optionally, the execution thread includes a main thread and a secondary thread, and the traffic adjustment module 20 is further used for:

[0128] According to the database migration request, the dual write switch is switched to an on state, and a first structured query statement SQL set is obtained;

[0129] According to the first SQL set, traffic verification is performed on the target database and the source database through the main thread and the secondary thread to obtain a traffic verification result;

[0130] According to the traffic verification result, the traffic of the target database and the source database is switched through the main thread and the secondary thread to obtain the traffic adjustment result.

[0131] Optionally, the step of performing flow verification on the target database and the source database through the main thread and the secondary thread according to the first SQL set to obtain the flow verification result includes:

[0132] Binding the secondary thread to the target database, and binding the main thread to the source database based on a preset thread local variable mechanism;

[0133] By means of the main thread, according to the first SQL set, a corresponding operation is performed on the source database to obtain a first execution result;

[0134] By means of the secondary thread, according to the first SQL set, a corresponding operation is performed on the target database to obtain a second execution result;

[0135] The first execution result and the second execution result are compared to obtain the flow verification result.

[0136] Optionally, the step of switching traffic between the target database and the source database through the main thread and the secondary thread according to the traffic verification result to obtain the traffic adjustment result includes:

[0137] Determining whether the flow adjustment result meets a first preset condition;

[0138] If yes, obtain a second SQL set, bind the secondary thread to the source database, and bind the main thread to the target database based on a preset thread local variable mechanism;

[0139] By means of the main thread, according to the second SQL set, a corresponding operation is performed on the target database to obtain a third execution result;

[0140] By means of the secondary thread, according to the second SQL set, a corresponding operation is performed on the source database to obtain a fourth execution result;

[0141] The third execution result and the fourth execution result are compared to obtain the flow adjustment result.

[0142] Optionally, the execution thread includes a main thread and a secondary thread, and the database migration module 30 is further used for:

[0143] Determining whether the flow adjustment result meets a second preset condition;

[0144] If so, the secondary thread is removed, and the dual write switch is switched to an off state to generate the database migration result.

[0145] Optionally, the step of performing traffic adjustment on a preset target database and a source database based on a preset dual-write switch and an execution thread according to the database migration request, and obtaining a traffic adjustment result also includes:

[0146] receiving a data copy instruction;

[0147] According to the data replication instruction, the data in the source database is fully replicated to a preset original target database through a preset data replication tool to obtain the target database.

[0148] The database migration device provided by the present application adopts the database migration method in the above embodiment, which can solve the technical problem that the existing database migration method based on dual data sources has poor universality. Compared with the prior art, the beneficial effects of the database migration device provided by the present application are the same as the beneficial effects of the database migration method provided by the above embodiment, and other technical features in the database migration device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0149] The present application provides a database migration device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the database migration method in the above-mentioned embodiment 1.

[0150] Reference below Figure 6, which shows a schematic diagram of the structure of a database migration device suitable for implementing the embodiment of the present application. The database migration device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The database migration device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0151] like Figure 6 As shown, the database migration device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the database migration device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the database migration device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a database migration device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.

[0152] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0153] The database migration device provided by the present application adopts the database migration method in the above embodiment, which can solve the technical problem that the existing database migration method based on dual data sources has poor universality. Compared with the prior art, the beneficial effects of the database migration device provided by the present application are the same as the beneficial effects of the database migration method provided by the above embodiment, and the other technical features in the database migration device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0154] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0155] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0156] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the database migration method in the above-mentioned embodiment.

[0157] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0158] The computer-readable storage medium may be included in the database migration device; or may exist independently without being assembled into the database migration device.

[0159] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the database migration device, the database migration device:

[0160] Receive database migration requests;

[0161] Based on the preset dual-write switch and execution thread, according to the database migration request, flow adjustment is performed on the preset target database and source database to obtain a flow adjustment result;

[0162] According to the traffic adjustment result, the database migration result is obtained through the dual write switch and the execution thread.

[0163] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0164] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0165] The modules involved in the embodiments of the present application may be implemented by software or hardware, wherein the name of the module does not limit the unit itself in some cases.

[0166] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned database migration method, and can solve the technical problem that the existing database migration method based on dual data sources has poor versatility. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the database migration method provided in the above-mentioned embodiment, and will not be elaborated here.

[0167] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned database migration method when executed by a processor.

[0168] The computer program product provided by the present application can solve the technical problem that the existing database migration method based on dual data sources has poor versatility. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the database migration method provided by the above embodiment, which will not be repeated here.

[0169] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A database migration method, It is characterized in that The method comprises: Receive database migration requests; Based on the preset dual-write switch and execution thread, according to the database migration request, flow adjustment is performed on the preset target database and source database to obtain a flow adjustment result; According to the traffic adjustment result, the database migration result is obtained through the dual write switch and the execution thread.

2. The method according to claim 1, It is characterized in that The execution thread includes a main thread and a secondary thread. The step of adjusting the traffic of the preset target database and the source database based on the preset dual-write switch and the execution thread according to the database migration request, and obtaining the traffic adjustment result includes: According to the database migration request, the dual write switch is switched to an on state, and a first structured query statement SQL set is obtained; According to the first SQL set, traffic verification is performed on the target database and the source database through the main thread and the secondary thread to obtain a traffic verification result; According to the traffic verification result, the traffic of the target database and the source database is switched through the main thread and the secondary thread to obtain the traffic adjustment result.

3. The method according to claim 2, It is characterized in that The step of performing flow verification on the target database and the source database through the main thread and the secondary thread according to the first SQL set to obtain a flow verification result comprises: Binding the secondary thread to the target database, and binding the main thread to the source database based on a preset thread local variable mechanism; By means of the main thread, according to the first SQL set, a corresponding operation is performed on the source database to obtain a first execution result; By means of the secondary thread, according to the first SQL set, a corresponding operation is performed on the target database to obtain a second execution result; The first execution result and the second execution result are compared to obtain the flow verification result.

4. The method according to claim 2, It is characterized in that The step of switching traffic between the target database and the source database through the main thread and the secondary thread according to the traffic verification result to obtain the traffic adjustment result comprises: Determining whether the flow adjustment result meets a first preset condition; If yes, obtain a second SQL set, bind the secondary thread to the source database, and bind the main thread to the target database based on a preset thread local variable mechanism; By means of the main thread, according to the second SQL set, a corresponding operation is performed on the target database to obtain a third execution result; By means of the secondary thread, according to the second SQL set, a corresponding operation is performed on the source database to obtain a fourth execution result; The third execution result and the fourth execution result are compared to obtain the flow adjustment result.

5. The method according to claim 1, It is characterized in that The execution thread includes a main thread and a secondary thread, the main thread is a thread supporting application services, and the step of obtaining a database migration result through the dual write switch and the execution thread according to the traffic adjustment result includes: Determining whether the flow adjustment result meets a second preset condition; If so, the secondary thread is removed, and the dual write switch is switched to an off state to generate the database migration result.

6. The method according to claim 1, It is characterized in that The step of adjusting the traffic of the preset target database and the source database based on the preset dual-write switch and the execution thread according to the database migration request and obtaining the traffic adjustment result also includes: receiving a data copy instruction; According to the data replication instruction, the data in the source database is fully replicated to a preset original target database through a preset data replication tool to obtain the target database.

7. A database migration device, It is characterized in that The device comprises: A request receiving module, used for receiving a database migration request; A traffic adjustment module, configured to adjust the traffic of a preset target database and a source database based on a preset dual-write switch and an execution thread according to the database migration request, and obtain a traffic adjustment result; The database migration module is used to obtain the database migration result according to the traffic adjustment result through the dual write switch and the execution thread.

8. A database migration device, It is characterized in that The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database migration method according to any one of claims 1 to 6.

9. A storage medium, It is characterized in that The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the database migration method according to any one of claims 1 to 6 are implemented.

10. A computer program product, It is characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the database migration method according to any one of claims 1 to 6 are implemented.